pax_global_header00006660000000000000000000000064144764434540014531gustar00rootroot0000000000000052 comment=e1fb4569c64b6b51158b7f1fd1bea591460769e6 hipSPARSE-rocm-5.7.1/000077500000000000000000000000001447644345400141775ustar00rootroot00000000000000hipSPARSE-rocm-5.7.1/.clang-format000066400000000000000000000065421447644345400165610ustar00rootroot00000000000000# Style file for MLSE Libraries based on the modified rocBLAS style # Common settings BasedOnStyle: WebKit TabWidth: 4 IndentWidth: 4 UseTab: Never ColumnLimit: 100 # Other languages JavaScript, Proto --- Language: Cpp # http://releases.llvm.org/6.0.1/tools/clang/docs/ClangFormatStyleOptions.html#disabling-formatting-on-a-piece-of-code # int formatted_code; # // clang-format off # void unformatted_code ; # // clang-format on # void formatted_code_again; DisableFormat: false Standard: Cpp11 AccessModifierOffset: -4 AlignAfterOpenBracket: Align AlignConsecutiveAssignments: true AlignConsecutiveDeclarations: true AlignEscapedNewlines: Left AlignOperands: true AlignTrailingComments: false AllowAllArgumentsOnNextLine: true AllowAllConstructorInitializersOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: true AllowShortBlocksOnASingleLine: false AllowShortCaseLabelsOnASingleLine: false AllowShortFunctionsOnASingleLine: Empty AllowShortIfStatementsOnASingleLine: false AllowShortLoopsOnASingleLine: false AlwaysBreakAfterDefinitionReturnType: false AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: false AlwaysBreakTemplateDeclarations: true BinPackArguments: false BinPackParameters: false # Configure each individual brace in BraceWrapping BreakBeforeBraces: Custom # Control of individual brace wrapping cases BraceWrapping: { AfterCaseLabel: 'true' AfterClass: 'true' AfterControlStatement: 'true' AfterEnum : 'true' AfterFunction : 'true' AfterNamespace : 'true' AfterStruct : 'true' AfterUnion : 'true' BeforeCatch : 'true' BeforeElse : 'true' IndentBraces : 'false' # AfterExternBlock : 'true' } #BreakAfterJavaFieldAnnotations: true #BreakBeforeInheritanceComma: false #BreakBeforeBinaryOperators: None #BreakBeforeTernaryOperators: true #BreakConstructorInitializersBeforeComma: true #BreakStringLiterals: true CommentPragmas: '^ IWYU pragma:' #CompactNamespaces: false ConstructorInitializerAllOnOneLineOrOnePerLine: false ConstructorInitializerIndentWidth: 4 ContinuationIndentWidth: 4 Cpp11BracedListStyle: true SpaceBeforeCpp11BracedList: false DerivePointerAlignment: false ExperimentalAutoDetectBinPacking: false ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] IndentCaseLabels: false IndentPPDirectives: None #FixNamespaceComments: true IndentWrappedFunctionNames: true KeepEmptyLinesAtTheStartOfBlocks: true MacroBlockBegin: '' MacroBlockEnd: '' #JavaScriptQuotes: Double MaxEmptyLinesToKeep: 1 NamespaceIndentation: All ObjCBlockIndentWidth: 4 #ObjCSpaceAfterProperty: true #ObjCSpaceBeforeProtocolList: true PenaltyBreakBeforeFirstCallParameter: 19 PenaltyBreakComment: 300 PenaltyBreakFirstLessLess: 120 PenaltyBreakString: 1000 PenaltyExcessCharacter: 1000000 PenaltyReturnTypeOnItsOwnLine: 60 PointerAlignment: Left SpaceAfterCStyleCast: false SpaceBeforeAssignmentOperators: true SpaceBeforeParens: Never SpaceInEmptyBlock: false SpaceInEmptyParentheses: false SpacesBeforeTrailingComments: 1 SpacesInAngles: false SpacesInContainerLiterals: true SpacesInCStyleCastParentheses: false SpacesInParentheses: false SpacesInSquareBrackets: false #SpaceAfterTemplateKeyword: true #SpaceBeforeInheritanceColon: true #SortUsingDeclarations: true SortIncludes: true # Comments are for developers, they should arrange them ReflowComments: false #IncludeBlocks: Preserve --- hipSPARSE-rocm-5.7.1/.githooks/000077500000000000000000000000001447644345400161045ustar00rootroot00000000000000hipSPARSE-rocm-5.7.1/.githooks/install000077500000000000000000000002231447644345400174750ustar00rootroot00000000000000#!/usr/bin/env bash cd $(git rev-parse --git-dir) cd hooks echo "Installing hooks..." ln -fs ../../.githooks/pre-commit pre-commit echo "Done!" hipSPARSE-rocm-5.7.1/.githooks/pre-commit000077500000000000000000000017671447644345400201210ustar00rootroot00000000000000#!/bin/sh # # This pre-commit hook checks if any versions of clang-format # are installed, and if so, uses the installed version to format # the staged changes. base=/opt/rocm/llvm/bin/clang-format format="" # Redirect output to stderr. exec 1>&2 # check if clang-format is installed type "$base" >/dev/null 2>&1 && format="$base" # no versions of clang-format are installed if [ -z "$format" ] then echo "$base is not installed. Pre-commit hook will not be executed." exit 0 fi # Do everything from top - level cd $(git rev-parse --show-toplevel) if git rev-parse --verify HEAD >/dev/null 2>&1 then against=HEAD else # Initial commit: diff against an empty tree object against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 fi # do the formatting for file in $(git diff-index --cached --name-only $against | grep -E '\.h$|\.hpp$|\.cpp$|\.cl$|\.h\.in$|\.hpp\.in$|\.cpp\.in$') do if [ -e "$file" ] then echo "$format $file" "$format" -i -style=file "$file" fi done hipSPARSE-rocm-5.7.1/.github/000077500000000000000000000000001447644345400155375ustar00rootroot00000000000000hipSPARSE-rocm-5.7.1/.github/CODEOWNERS000066400000000000000000000000451447644345400171310ustar00rootroot00000000000000* @ntrost57 @YvanMokwinski @jsandham hipSPARSE-rocm-5.7.1/.github/dependabot.yml000066400000000000000000000012611447644345400203670ustar00rootroot00000000000000# To get started with Dependabot version updates, you'll need to specify which # package ecosystems to update and where the package manifests are located. # Please see the documentation for all configuration options: # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates version: 2 updates: - package-ecosystem: "pip" # See documentation for possible values directory: "/docs/.sphinx" # Location of package manifests open-pull-requests-limit: 10 schedule: interval: "daily" target-branch: "develop" labels: - "documentation" - "dependencies" - "ci:docs-only" reviewers: - "samjwu" hipSPARSE-rocm-5.7.1/.gitignore000066400000000000000000000006621447644345400161730ustar00rootroot00000000000000# Compiled Object files *.slo *.lo *.o *.obj # Precompiled Headers *.gch *.pch # Compiled Dynamic libraries *.so *.dylib *.dll # Fortran module files *.mod # Compiled Static libraries *.lai *.la *.a *.lib # Executables *.exe *.out *.app # vim tags tags .tags .*.swp # Editors .vscode # build-in-source directory and documentation artifacts build/ _build/ _images/ _static/ _templates/ _toc.yml docBin/ # matrices *.csr *.mtx hipSPARSE-rocm-5.7.1/.jenkins/000077500000000000000000000000001447644345400157165ustar00rootroot00000000000000hipSPARSE-rocm-5.7.1/.jenkins/common.groovy000066400000000000000000000050631447644345400204610ustar00rootroot00000000000000// This file is for internal AMD use. // If you are interested in running your own Jenkins, please raise a github issue for assistance. def runCompileCommand(platform, project, boolean sameOrg=false) { project.paths.construct_build_prefix() def command def getDependenciesCommand = "" if (project.installLibraryDependenciesFromCI) { project.libraryDependencies.each { libraryName -> getDependenciesCommand += auxiliary.getLibrary(libraryName, platform.jenkinsLabel, 'develop', sameOrg) } } String centos7 = platform.jenkinsLabel.contains('centos7') ? 'source scl_source enable devtoolset-7' : ':' command = """#!/usr/bin/env bash set -x ${centos7} cd ${project.paths.project_build_prefix} ${getDependenciesCommand} CXX=${project.compiler.compiler_path} ${project.paths.build_command} """ platform.runCommand(this, command) } def runTestCommand (platform, project, gfilter) { String sudo = auxiliary.sudo(platform.jenkinsLabel) def command = """#!/usr/bin/env bash set -x cd ${project.paths.project_build_prefix}/build/release/clients/staging ${sudo} GTEST_LISTENER=NO_PASS_LINE_IN_LOG ./hipsparse-test --gtest_also_run_disabled_tests --gtest_output=xml --gtest_color=yes #--gtest_filter=${gfilter}-*known_bug* """ platform.runCommand(this, command) junit "${project.paths.project_build_prefix}/build/release/clients/staging/*.xml" } def runPackageCommand(platform, project) { def command if(platform.jenkinsLabel.contains('centos') || platform.jenkinsLabel.contains('sles')) { command = """ set -x cd ${project.paths.project_build_prefix}/build/release make package mkdir -p package mv *.rpm package/ rpm -qlp package/*.rpm """ platform.runCommand(this, command) platform.archiveArtifacts(this, """${project.paths.project_build_prefix}/build/release/package/*.rpm""") } else { command = """ set -x cd ${project.paths.project_build_prefix}/build/release make package mkdir -p package mv *.deb package/ """ platform.runCommand(this, command) platform.archiveArtifacts(this, """${project.paths.project_build_prefix}/build/release/package/*.deb""") } } return this hipSPARSE-rocm-5.7.1/.jenkins/extended.groovy000066400000000000000000000057271447644345400210000ustar00rootroot00000000000000#!/usr/bin/env groovy // This shared library is available at https://github.com/ROCmSoftwarePlatform/rocJENKINS/ @Library('rocJenkins@pong') _ // This file is for internal AMD use. // If you are interested in running your own Jenkins, please raise a github issue for assistance. import com.amd.project.* import com.amd.docker.* import java.nio.file.Path; def runCI = { nodeDetails, jobName-> def prj = new rocProject('hipSPARSE', 'Extended') prj.paths.build_command = './install.sh -c' prj.compiler.compiler_name = 'c++' prj.compiler.compiler_path = 'c++' prj.libraryDependencies = ['rocSPARSE', 'rocPRIM'] prj.defaults.ccache = false // Define test architectures, optional rocm version argument is available def nodes = new dockerNodes(nodeDetails, jobName, prj) boolean formatCheck = false def commonGroovy def compileCommand = { platform, project-> commonGroovy = load "${project.paths.project_src_prefix}/.jenkins/common.groovy" commonGroovy.runCompileCommand(platform, project) } def testCommand = { platform, project-> def gfilter = "*nightly*" commonGroovy.runTestCommand(platform, project, gfilter) } def packageCommand = { platform, project-> commonGroovy.runPackageCommand(platform, project) } buildProject(prj, formatCheck, nodes.dockerArray, compileCommand, testCommand, packageCommand) } ci: { String urlJobName = auxiliary.getTopJobName(env.BUILD_URL) def propertyList = ["compute-rocm-dkms-no-npi":[pipelineTriggers([cron('0 1 * * 0')])], "compute-rocm-dkms-no-npi-hipclang":[pipelineTriggers([cron('0 1 * * 0')])], "rocm-docker":[]] propertyList = auxiliary.appendPropertyList(propertyList) Set standardJobNameSet = ["compute-rocm-dkms-no-npi", "compute-rocm-dkms-no-npi-hipclang", "rocm-docker"] def jobNameList = ["compute-rocm-dkms-no-npi":([ubuntu18:['gfx900'],centos7:['gfx908'],sles15sp1:['gfx900']]), "compute-rocm-dkms-no-npi-hipclang":([ubuntu18:['gfx900'],centos7:['gfx908'],sles15sp1:['gfx900']]), "rocm-docker":([ubuntu18:['gfx900'],centos7:['gfx908'],sles15sp1:['gfx906']])] jobNameList = auxiliary.appendJobNameList(jobNameList) propertyList.each { jobName, property-> if (urlJobName == jobName) properties(auxiliary.addCommonProperties(property)) } Set seenJobNames = [] jobNameList.each { jobName, nodeDetails-> seenJobNames.add(jobName) if (urlJobName == jobName) runCI(nodeDetails, jobName) } // For url job names that are outside of the standardJobNameSet i.e. compute-rocm-dkms-no-npi-1901 if(!seenJobNames.contains(urlJobName)) { properties(auxiliary.addCommonProperties([pipelineTriggers([cron('0 1 * * *')])])) runCI([ubuntu18:['gfx906']], urlJobName) } } hipSPARSE-rocm-5.7.1/.jenkins/precheckin-cuda.groovy000066400000000000000000000034751447644345400222230ustar00rootroot00000000000000#!/usr/bin/env groovy // This shared library is available at https://github.com/ROCmSoftwarePlatform/rocJENKINS/ @Library('rocJenkins@pong') _ // This file is for internal AMD use. // If you are interested in running your own Jenkins, please raise a github issue for assistance. import com.amd.project.* import com.amd.docker.* import java.nio.file.Path; def runCI = { nodeDetails, jobName-> def prj = new rocProject('hipSPARSE', 'PreCheckin-Cuda') prj.paths.build_command = './install.sh -c --cuda' prj.compiler.compiler_name = 'c++' prj.compiler.compiler_path = 'c++' prj.defaults.ccache = false // Define test architectures, optional rocm version argument is available def nodes = new dockerNodes(nodeDetails, jobName, prj) boolean formatCheck = false def commonGroovy def compileCommand = { platform, project-> commonGroovy = load "${project.paths.project_src_prefix}/.jenkins/common.groovy" commonGroovy.runCompileCommand(platform, project) } def packageCommand = { platform, project-> commonGroovy.runPackageCommand(platform, project) } def testCommand = { platform, project-> def gfilter = "*checkin*csrmv*" commonGroovy.runTestCommand(platform, project, gfilter) } buildProject(prj, formatCheck, nodes.dockerArray, compileCommand, testCommand, packageCommand) } ci: { String urlJobName = auxiliary.getTopJobName(env.BUILD_URL) def jobNameList = [:] // For url job names that are not listed by the jobNameList i.e. compute-rocm-dkms-no-npi-1901 if(!jobNameList.keySet().contains(urlJobName)) { properties(auxiliary.addCommonProperties([pipelineTriggers([cron('0 1 * * 6')])])) runCI(['ubuntu20-cuda11':['anycuda']], urlJobName) } } hipSPARSE-rocm-5.7.1/.jenkins/precheckin.groovy000066400000000000000000000057301447644345400213050ustar00rootroot00000000000000#!/usr/bin/env groovy // This shared library is available at https://github.com/ROCmSoftwarePlatform/rocJENKINS/ @Library('rocJenkins@pong') _ // This file is for internal AMD use. // If you are interested in running your own Jenkins, please raise a github issue for assistance. import com.amd.project.* import com.amd.docker.* import java.nio.file.Path; def runCI = { nodeDetails, jobName-> def prj = new rocProject('hipSPARSE', 'PreCheckin') prj.paths.build_command = './install.sh -c' prj.compiler.compiler_name = 'c++' prj.compiler.compiler_path = 'c++' prj.libraryDependencies = ['rocSPARSE', 'rocPRIM'] prj.defaults.ccache = true // Define test architectures, optional rocm version argument is available def nodes = new dockerNodes(nodeDetails, jobName, prj) boolean formatCheck = false def commonGroovy def compileCommand = { platform, project-> commonGroovy = load "${project.paths.project_src_prefix}/.jenkins/common.groovy" commonGroovy.runCompileCommand(platform, project) } def testCommand = { platform, project-> def gfilter = "*checkin*" commonGroovy.runTestCommand(platform, project, gfilter) } def packageCommand = { platform, project-> commonGroovy.runPackageCommand(platform, project) } buildProject(prj, formatCheck, nodes.dockerArray, compileCommand, testCommand, packageCommand) } ci: { String urlJobName = auxiliary.getTopJobName(env.BUILD_URL) def propertyList = ["compute-rocm-dkms-no-npi":[pipelineTriggers([cron('0 1 * * 0')])], "compute-rocm-dkms-no-npi-hipclang":[pipelineTriggers([cron('0 1 * * 0')])], "rocm-docker":[]] propertyList = auxiliary.appendPropertyList(propertyList) Set standardJobNameSet = ["compute-rocm-dkms-no-npi", "compute-rocm-dkms-no-npi-hipclang", "rocm-docker"] def jobNameList = ["compute-rocm-dkms-no-npi":([ubuntu18:['gfx900'],centos7:['gfx908'],sles15sp1:['gfx906']]), "compute-rocm-dkms-no-npi-hipclang":([ubuntu18:['gfx900'],centos7:['gfx908'],sles15sp1:['gfx906']]), "rocm-docker":([ubuntu18:['gfx900'],centos7:['gfx908'],sles15sp1:['gfx906']])] jobNameList = auxiliary.appendJobNameList(jobNameList) propertyList.each { jobName, property-> if (urlJobName == jobName) properties(auxiliary.addCommonProperties(property)) } Set seenJobNames = [] jobNameList.each { jobName, nodeDetails-> seenJobNames.add(jobName) if (urlJobName == jobName) runCI(nodeDetails, jobName) } // For url job names that are outside of the standardJobNameSet i.e. compute-rocm-dkms-no-npi-1901 if(!seenJobNames.contains(urlJobName)) { properties(auxiliary.addCommonProperties([pipelineTriggers([cron('0 1 * * *')])])) runCI([ubuntu18:['gfx906']], urlJobName) } } hipSPARSE-rocm-5.7.1/.jenkins/staticanalysis.groovy000066400000000000000000000017371447644345400222300ustar00rootroot00000000000000#!/usr/bin/env groovy // This shared library is available at https://github.com/ROCmSoftwarePlatform/rocJENKINS/ @Library('rocJenkins@pong') _ // This is file for internal AMD use. // If you are interested in running your own Jenkins, please raise a github issue for assistance. import com.amd.project.* import com.amd.docker.* import java.nio.file.Path def runCI = { nodeDetails, jobName-> def prj = new rocProject('hipSPARSE', 'StaticAnalysis') // Define test architectures, optional rocm version argument is available def nodes = new dockerNodes(nodeDetails, jobName, prj) boolean formatCheck = true boolean staticAnalysis = true buildProject(prj, formatCheck, nodes.dockerArray, null, null, null, staticAnalysis) } ci: { String urlJobName = auxiliary.getTopJobName(env.BUILD_URL) properties(auxiliary.addCommonProperties([pipelineTriggers([cron('0 1 * * 6')])])) stage(urlJobName) { runCI([ubuntu20:['cpu']], urlJobName) } } hipSPARSE-rocm-5.7.1/.jenkins/staticlibrary.groovy000066400000000000000000000060101447644345400220360ustar00rootroot00000000000000#!/usr/bin/env groovy // This shared library is available at https://github.com/ROCmSoftwarePlatform/rocJENKINS/ @Library('rocJenkins@pong') _ // This file is for internal AMD use. // If you are interested in running your own Jenkins, please raise a github issue for assistance. import com.amd.project.* import com.amd.docker.* import java.nio.file.Path; def runCI = { nodeDetails, jobName-> def prj = new rocProject('hipSPARSE', 'Static Library PreCheckin') prj.paths.build_command = './install.sh -c --static' prj.compiler.compiler_name = 'hipcc' prj.compiler.compiler_path = '/opt/rocm/bin/hipcc' prj.libraryDependencies = ['rocSPARSE', 'rocPRIM'] prj.defaults.ccache = false // Define test architectures, optional rocm version argument is available def nodes = new dockerNodes(nodeDetails, jobName, prj) boolean formatCheck = false def commonGroovy def compileCommand = { platform, project-> commonGroovy = load "${project.paths.project_src_prefix}/.jenkins/common.groovy" commonGroovy.runCompileCommand(platform, project,true) } def testCommand = { platform, project-> def gfilter = "*checkin*" commonGroovy.runTestCommand(platform, project, gfilter) } def packageCommand = { platform, project-> commonGroovy.runPackageCommand(platform, project) } buildProject(prj, formatCheck, nodes.dockerArray, compileCommand, testCommand, packageCommand) } ci: { String urlJobName = auxiliary.getTopJobName(env.BUILD_URL) def propertyList = ["compute-rocm-dkms-no-npi":[pipelineTriggers([cron('0 1 * * 0')])], "compute-rocm-dkms-no-npi-hipclang":[pipelineTriggers([cron('0 1 * * 0')])], "rocm-docker":[]] propertyList = auxiliary.appendPropertyList(propertyList) Set standardJobNameSet = ["compute-rocm-dkms-no-npi", "compute-rocm-dkms-no-npi-hipclang", "rocm-docker"] def jobNameList = ["compute-rocm-dkms-no-npi":([ubuntu18:['gfx900'],centos7:['gfx908'],sles15sp1:['gfx906']]), "compute-rocm-dkms-no-npi-hipclang":([ubuntu18:['gfx900'],centos7:['gfx908'],sles15sp1:['gfx906']]), "rocm-docker":([ubuntu18:['gfx900'],centos7:['gfx908'],sles15sp1:['gfx906']])] jobNameList = auxiliary.appendJobNameList(jobNameList) propertyList.each { jobName, property-> if (urlJobName == jobName) properties(auxiliary.addCommonProperties(property)) } Set seenJobNames = [] jobNameList.each { jobName, nodeDetails-> seenJobNames.add(jobName) if (urlJobName == jobName) runCI(nodeDetails, jobName) } // For url job names that are outside of the standardJobNameSet i.e. compute-rocm-dkms-no-npi-1901 if(!seenJobNames.contains(urlJobName)) { properties(auxiliary.addCommonProperties([pipelineTriggers([cron('0 1 * * *')])])) runCI([ubuntu18:['gfx906']], urlJobName) } } hipSPARSE-rocm-5.7.1/.readthedocs.yaml000066400000000000000000000004171447644345400174300ustar00rootroot00000000000000# Read the Docs configuration file # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details version: 2 sphinx: configuration: docs/conf.py formats: [htmlzip] python: version: "3.8" install: - requirements: docs/.sphinx/requirements.txt hipSPARSE-rocm-5.7.1/CHANGELOG.md000066400000000000000000000103671447644345400160170ustar00rootroot00000000000000# Change Log for hipSPARSE ## hipSPARSE 2.3.8 for ROCm 5.7.0 ### Improved - Fix compilation failures when using cusparse 12.1.0 backend - Fix compilation failures when using cusparse 12.0.0 backend - Fix compilation failures when using cusparse 10.1 (non-update versions) as backend - Minor improvements ## hipSPARSE 2.3.7 for ROCm 5.6.1 ### Bugfix - Reverted an undocumented API change in hipSPARSE 2.3.6 that affected hipsparseSpSV_solve function ## hipSPARSE 2.3.6 for ROCm 5.6.0 ### Added - Added SpGEMM algorithms ### Changed - For hipsparseXbsr2csr and hipsparseXcsr2bsr, blockDim == 0 now returns HIPSPARSE_STATUS_INVALID_SIZE ## hipSPARSE 2.3.5 for ROCm 5.5.0 ### Improved - Fixed an issue, where the rocm folder was not removed on upgrade of meta packages - Fixed a compilation issue with cusparse backend - Added more detailed messages on unit test failures due to missing input data - Improved documentation - Fixed a bug with deprecation messages when using gcc9 (Thanks @Maetveis) ## hipSPARSE 2.3.3 for ROCm 5.4.0 ### Added - Added hipsparseCsr2cscEx2_bufferSize and hipsparseCsr2cscEx2 routines ### Changed - HIPSPARSE_ORDER_COLUMN has been renamed to HIPSPARSE_ORDER_COL to match cusparse ## hipSPARSE 2.3.1 for ROCm 5.3.0 ### Added - Add SpMM and SpMM batched for CSC format ## hipSPARSE 2.2.0 for ROCm 5.2.0 ### Added - Packages for test and benchmark executables on all supported OSes using CPack. ## hipSPARSE 2.1.0 for ROCm 5.1.0 ### Added - Added gtsv_interleaved_batch and gpsv_interleaved_batch routines - Add SpGEMM_reuse ### Changed - Changed BUILD_CUDA with USE_CUDA in install script and cmake files - Update googletest to 11.1 ### Improved - Fixed a bug in SpMM Alg versioning ### Known Issues - none ## hipSPARSE 2.0.0 for ROCm 5.0.0 ### Added - Added (conjugate) transpose support for csrmv, hybmv and spmv routines ## hipSPARSE 1.11.2 for ROCm 4.5.0 ### Added - Triangular solve for multiple right-hand sides using BSR format - SpMV for BSRX format - SpMM in CSR format enhanced to work with transposed A - Matrix coloring for CSR matrices - Added batched tridiagonal solve (gtsv\_strided\_batch) - SpMM for BLOCKED ELL format - Generic routines for SpSV and SpSM - Enabling beta support for Windows 10 - Additional atomic based algorithms for SpMM in COO format - Additional algorithm for SpMM in CSR format ### Changed - Packaging split into a runtime package called hipsparse and a development package called hipsparse-devel. The development package depends on runtime. The runtime package suggests the development package for all supported OSes except CentOS 7 to aid in the transition. The suggests feature in packaging is introduced as a deprecated feature and will be removed in a future rocm release. - GTest dependency updated to v1.10.0 ### Improved - Fixed a bug with gemvi on Navi21 - Optimization for pivot based gtsv ### Known Issues - none ## hipSPARSE 1.10.7 for ROCm 4.3.0 ### Added - (batched) tridiagonal solve with and without pivoting - dense matrix sparse vector multiplication (gemvi) - sampled dense-dense matrix multiplication (sddmm) ## hipSPARSE 1.10.6 for ROCm 4.2.0 ### Added - Generic API support, including SpMM ## hipSPARSE 1.10.4 for ROCm 4.1.0 ### Added - Generic API support, including Axpby, Gather, Scatter, Rot, SpVV, SpMV, SparseToDense, DenseToSparse and SpGEMM ## hipSPARSE 1.9.6 for ROCm 4.0.0 ### Added - changelog - csr2gebsr - gebsr2csr - gebsr2gebsc - gebsr2gebsr ### Improved - Updates to debian package name. ## hipSPARSE 1.9.4 for ROCm 3.9 ### Added - prune\_csr2csr, prune\_dense2csr\_percentage and prune\_csr2csr\_percentage - bsrilu0 ### Known Issues - none ## hipSPARSE 1.8.1 for ROCm 3.8 ### Added - bsric0 added. ### Known Issues - none ## hipSPARSE 1.7.1 for ROCm 3.7 ### Added - Fortran bindings - Triangular solve for BSR format (bsrsv) - CentOS 6 support. ### Known Issues - none ## hipSPARSE 1.7.1 for ROCm 3.6 ### Added - Fortran bindings - Triangular solve for BSR format (bsrsv) - CentOS 6 support. ### Known Issues - none ## hipSPARSE 1.6.5 for ROCm 3.5 ### Added - Switched to hip-clang as default compiler - csr2dense, csc2dense, csr2csr\_compress, nnz\_compress, bsr2csr, csr2bsr, bsrmv, csrgeam - static build - more examples ### Optimized - dense2csr, dense2csc ### Improved - Installation process ### Known Issues - none hipSPARSE-rocm-5.7.1/CMakeLists.txt000066400000000000000000000214711447644345400167440ustar00rootroot00000000000000# ######################################################################## # 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. # # ######################################################################## cmake_minimum_required(VERSION 3.5 FATAL_ERROR) if (NOT python) set(python "python3") # default for linux endif() # 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() # Pick up static and dynamic shared object files list( APPEND CMAKE_PREFIX_PATH /opt/rocm/llvm /opt/rocm /opt/rocm/hip ) # CMake modules list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_PREFIX_PATH}/cmake ) # Set a default build type if none was specified if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) message(STATUS "Setting build type to 'Release' as none was specified.") set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "" "Debug" "Release" "MinSizeRel" "RelWithDebInfo") endif() # Honor per-config flags in try_compile() source-file signature. cmake v3.7 and up if(POLICY CMP0066) cmake_policy(SET CMP0066 NEW) endif() if (NOT WIN32) if ( NOT DEFINED CMAKE_Fortran_COMPILER AND NOT DEFINED ENV{FC} ) set( CMAKE_Fortran_COMPILER "gfortran" ) endif() set( fortran_language "Fortran" ) endif( ) # hipSPARSE project project(hipsparse LANGUAGES CXX Fortran) # Build flags set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) # Build options option(BUILD_SHARED_LIBS "Build hipSPARSE as a shared library" ON) option(BUILD_CLIENTS_TESTS "Build tests (requires googletest)" OFF) option(BUILD_CLIENTS_SAMPLES "Build examples" ON) option(BUILD_VERBOSE "Output additional build information" OFF) option(USE_CUDA "Build hipSPARSE using CUDA backend" OFF) option(BUILD_CUDA "Build hipSPARSE using CUDA backend" OFF) option(BUILD_CODE_COVERAGE "Build with code coverage enabled" OFF) option(BUILD_ADDRESS_SANITIZER "Build with address sanitizer enabled" OFF) if(BUILD_CUDA) message(DEPRECATION "Using BUILD_CUDA is deprecated and will be removed as an option in a future release. Instead use USE_CUDA") set(USE_CUDA ${BUILD_CUDA}) endif() if(BUILD_CODE_COVERAGE) add_compile_options(-fprofile-arcs -ftest-coverage) add_link_options(--coverage) endif() if(BUILD_ADDRESS_SANITIZER) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -shared-libasan") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -shared-libasan") add_link_options(-fuse-ld=lld) endif() # Dependencies include(cmake/Dependencies.cmake) # FOR HANDLING ENABLE/DISABLE OPTIONAL BACKWARD COMPATIBILITY for FILE/FOLDER REORG option(BUILD_FILE_REORG_BACKWARD_COMPATIBILITY "Build with file/folder reorg with backward compatibility enabled" ON) if(BUILD_FILE_REORG_BACKWARD_COMPATIBILITY AND NOT WIN32) rocm_wrap_header_dir( ${CMAKE_SOURCE_DIR}/library/include PATTERNS "*.h" GUARDS SYMLINK WRAPPER WRAPPER_LOCATIONS ${CMAKE_INSTALL_INCLUDEDIR} ) endif() # Setup version rocm_setup_version(VERSION 2.3.8) set(hipsparse_SOVERSION 0.1) # hipSPARSE library add_subdirectory(library) if(BUILD_CLIENTS_SAMPLES OR BUILD_CLIENTS_TESTS) if(NOT CLIENTS_OS) rocm_set_os_id(CLIENTS_OS) string(TOLOWER "${CLIENTS_OS}" CLIENTS_OS) rocm_read_os_release(CLIENTS_OS_VERSION VERSION_ID) endif() message(STATUS "OS: ${CLIENTS_OS} ${CLIENTS_OS_VERSION}") set(GFORTRAN_PKG "gcc-gfortran") set(OPENMP_PKG "libgomp") if(CLIENTS_OS STREQUAL "sles") set(GFORTRAN_PKG "gcc-fortran") set(OPENMP_PKG "libgomp1") elseif(CLIENTS_OS STREQUAL "centos" AND CLIENTS_OS_VERSION EQUAL 7) set(GFORTRAN_PKG "devtoolset-7-gcc-gfortran") endif() add_subdirectory(clients) rocm_package_setup_component(clients) if(BUILD_CLIENTS_TESTS) rocm_package_setup_client_component(tests) endif() if(NOT WIN32) rocm_package_add_rpm_dependencies(COMPONENT tests DEPENDS "${GFORTRAN_PKG}") rocm_package_add_deb_dependencies(COMPONENT tests DEPENDS "gfortran") rocm_package_add_rpm_dependencies(COMPONENT benchmarks DEPENDS "${GFORTRAN_PKG}") rocm_package_add_deb_dependencies(COMPONENT benchmarks DEPENDS "gfortran") endif() if(TARGET OpenMP::OpenMP_CXX) rocm_package_add_rpm_dependencies(COMPONENT tests DEPENDS "${OPENMP_PKG}") rocm_package_add_deb_dependencies(COMPONENT tests DEPENDS "libomp-dev") rocm_package_add_rpm_dependencies(COMPONENT benchmarks DEPENDS "${OPENMP_PKG}") rocm_package_add_deb_dependencies(COMPONENT benchmarks DEPENDS "libomp-dev") endif() endif() # Package specific CPACK vars if(NOT USE_CUDA) rocm_package_add_dependencies(DEPENDS "rocsparse >= 1.12.10") endif() set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.md") set(CPACK_RPM_PACKAGE_LICENSE "MIT") if(WIN32) set(CPACK_SOURCE_GENERATOR "ZIP") set(CPACK_GENERATOR "ZIP") set(CMAKE_INSTALL_PREFIX "C:/hipSDK" CACHE PATH "Install path" FORCE) set(INSTALL_PREFIX "C:/hipSDK") set(CPACK_SET_DESTDIR OFF) set(CPACK_PACKAGE_INSTALL_DIRECTORY "C:/hipSDK") set(CPACK_PACKAGING_INSTALL_PREFIX "") set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF) else() if(NOT CPACK_PACKAGING_INSTALL_PREFIX) set(CPACK_PACKAGING_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") endif() endif() set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "\${CPACK_PACKAGING_INSTALL_PREFIX}" ) if(NOT USE_CUDA) set(package_name hipsparse) else() set(package_name hipsparse-alt) endif() set(HIPSPARSE_CONFIG_DIR "\${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" CACHE PATH "Path placed into ldconfig file") rocm_create_package( NAME ${package_name} DESCRIPTION "Radeon Open Compute SPARSE library" MAINTAINER "hipSPARSE Maintainer " LDCONFIG LDCONFIG_DIR ${HIPSPARSE_CONFIG_DIR}) # # ADDITIONAL TARGETS FOR CODE COVERAGE # if(BUILD_CODE_COVERAGE) # # > make coverage_cleanup (clean coverage related files.) # > make coverage GTEST_FILTER=<> # will run: # > make coverage_analysis GTEST_FILTER=<> (analyze tests) # > make coverage_output (generate html documentation) # # # Run coverage analysis # add_custom_target(coverage_analysis COMMAND echo Coverage GTEST_FILTER=\${GTEST_FILTER} COMMAND ./clients/staging/hipsparse-test --gtest_filter=\"\${GTEST_FILTER}\" WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) add_dependencies(coverage_analysis hipsparse) # # Prepare coverage output # This little script is generated because the option '--gcov-tool ' of lcov cannot take arguments. # add_custom_target(coverage_output DEPENDS coverage_analysis COMMAND mkdir -p lcoverage COMMAND echo "\\#!/bin/bash" > llvm-gcov.sh COMMAND echo "\\# THIS FILE HAS BEEN GENERATED" >> llvm-gcov.sh COMMAND printf "exec /opt/rocm/llvm/bin/llvm-cov gcov $$\\@" >> llvm-gcov.sh COMMAND chmod +x llvm-gcov.sh ) # # Generate coverage output. # add_custom_command(TARGET coverage_output COMMAND lcov --directory . --base-directory . --gcov-tool ${CMAKE_BINARY_DIR}/llvm-gcov.sh --capture -o lcoverage/raw_main_coverage.info COMMAND lcov --remove lcoverage/raw_main_coverage.info "'/opt/*'" "'/usr/*'" -o lcoverage/main_coverage.info COMMAND genhtml lcoverage/main_coverage.info --output-directory lcoverage ) add_custom_target(coverage DEPENDS coverage_output) # # Coverage cleanup # add_custom_target(coverage_cleanup COMMAND find ${CMAKE_BINARY_DIR} -name *.gcda -delete WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) endif() hipSPARSE-rocm-5.7.1/LICENSE.md000066400000000000000000000021011447644345400155750ustar00rootroot00000000000000MIT License Copyright © 2018-2023 Advanced Micro Devices, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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-rocm-5.7.1/README.md000066400000000000000000000060511447644345400154600ustar00rootroot00000000000000# hipSPARSE hipSPARSE is a SPARSE marshalling library, with multiple supported backends. It sits between the application and a 'worker' SPARSE library, marshalling inputs into the backend library and marshalling results back to the application. hipSPARSE exports an interface that does not require the client to change, regardless of the chosen backend. Currently, hipSPARSE supports [rocSPARSE](https://github.com/ROCmSoftwarePlatform/rocSPARSE) and [cuSPARSE](https://developer.nvidia.com/cusparse) as backends. ## Documentation Run the steps below to build documentation locally. ``` cd docs pip3 install -r .sphinx/requirements.txt python3 -m sphinx -T -E -b html -d _build/doctrees -D language=en . _build/html ``` ## Installing pre-built packages Download pre-built packages either from [ROCm's package servers](https://rocm.github.io/install.html#installing-from-amd-rocm-repositories) or by clicking the github releases tab and manually downloading, which could be newer. Release notes are available for each release on the releases tab. * `sudo apt update && sudo apt install hipsparse` ## Quickstart hipSPARSE build #### Bash helper build script (Ubuntu only) The root of this repository has a helper bash script `install.sh` to build and install hipSPARSE on Ubuntu with a single command. It does not take a lot of options and hard-codes configuration that can be specified through invoking cmake directly, but it's a great way to get started quickly and can serve as an example of how to build/install. A few commands in the script need sudo access, so it may prompt you for a password. * `./install -h` -- shows help * `./install -id` -- build library, build dependencies and install (-d flag only needs to be passed once on a system) ## Manual build (all supported platforms) If you use a distro other than Ubuntu, or would like more control over the build process, the [hipSPARSE build wiki](https://github.com/ROCmSoftwarePlatform/hipSPARSE/wiki/Build) has helpful information on how to configure cmake and manually build. ### Functions supported A list of [exported functions](https://github.com/ROCmSoftwarePlatform/hipSPARSE/wiki/Exported-functions) from hipSPARSE can be found on the wiki. ## hipSPARSE interface examples The hipSPARSE interface is compatible with rocSPARSE and cuSPARSE-v2 APIs. Porting a CUDA application which originally calls the cuSPARSE API to an application calling hipSPARSE API should be relatively straightforward. For example, the hipSPARSE SCSRMV interface is ### CSRMV API ```c hipsparseStatus_t hipsparseScsrmv(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, const float *alpha, const hipsparseMatDescr_t descrA, const float *csrValA, const int *csrRowPtrA, const int *csrColIndA, const float *x, const float *beta, float *y); ``` hipSPARSE assumes matrix A and vectors x, y are allocated in GPU memory space filled with data. Users are responsible for copying data from/to the host and device memory. hipSPARSE-rocm-5.7.1/clients/000077500000000000000000000000001447644345400156405ustar00rootroot00000000000000hipSPARSE-rocm-5.7.1/clients/CMakeLists.txt000066400000000000000000000070221447644345400204010ustar00rootroot00000000000000# ######################################################################## # 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) 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) endif() # Build flags set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) # 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_TESTS) enable_testing() add_subdirectory(tests) endif() hipSPARSE-rocm-5.7.1/clients/common/000077500000000000000000000000001447644345400171305ustar00rootroot00000000000000hipSPARSE-rocm-5.7.1/clients/common/arg_check.cpp000066400000000000000000000127621447644345400215520ustar00rootroot00000000000000/* ************************************************************************ * 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 } hipSPARSE-rocm-5.7.1/clients/common/hipsparse_template_specialization.cpp000066400000000000000000020264771447644345400266450ustar00rootroot00000000000000/* ************************************************************************ * 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* x_val, const int* x_ind, float* y, hipsparseIndexBase_t idx_base) { return hipsparseSaxpyi(handle, nnz, alpha, x_val, x_ind, y, idx_base); } template <> hipsparseStatus_t hipsparseXaxpyi(hipsparseHandle_t handle, int nnz, const double* alpha, const double* x_val, const int* x_ind, double* y, hipsparseIndexBase_t idx_base) { return hipsparseDaxpyi(handle, nnz, alpha, x_val, x_ind, y, idx_base); } template <> hipsparseStatus_t hipsparseXaxpyi(hipsparseHandle_t handle, int nnz, const hipComplex* alpha, const hipComplex* x_val, const int* x_ind, hipComplex* y, hipsparseIndexBase_t idx_base) { return hipsparseCaxpyi(handle, nnz, alpha, x_val, x_ind, y, idx_base); } template <> hipsparseStatus_t hipsparseXaxpyi(hipsparseHandle_t handle, int nnz, const hipDoubleComplex* alpha, const hipDoubleComplex* x_val, const int* x_ind, hipDoubleComplex* y, hipsparseIndexBase_t idx_base) { return hipsparseZaxpyi(handle, nnz, alpha, x_val, x_ind, y, idx_base); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template <> hipsparseStatus_t hipsparseXdoti(hipsparseHandle_t handle, int nnz, const float* x_val, const int* x_ind, const float* y, float* result, hipsparseIndexBase_t idx_base) { return hipsparseSdoti(handle, nnz, x_val, x_ind, y, result, idx_base); } template <> hipsparseStatus_t hipsparseXdoti(hipsparseHandle_t handle, int nnz, const double* x_val, const int* x_ind, const double* y, double* result, hipsparseIndexBase_t idx_base) { return hipsparseDdoti(handle, nnz, x_val, x_ind, y, result, idx_base); } template <> hipsparseStatus_t hipsparseXdoti(hipsparseHandle_t handle, int nnz, const hipComplex* x_val, const int* x_ind, const hipComplex* y, hipComplex* result, hipsparseIndexBase_t idx_base) { return hipsparseCdoti(handle, nnz, x_val, x_ind, y, result, idx_base); } template <> hipsparseStatus_t hipsparseXdoti(hipsparseHandle_t handle, int nnz, const hipDoubleComplex* x_val, const int* x_ind, const hipDoubleComplex* y, hipDoubleComplex* result, hipsparseIndexBase_t idx_base) { return hipsparseZdoti(handle, nnz, x_val, x_ind, y, result, idx_base); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template <> hipsparseStatus_t hipsparseXdotci(hipsparseHandle_t handle, int nnz, const hipComplex* x_val, const int* x_ind, const hipComplex* y, hipComplex* result, hipsparseIndexBase_t idx_base) { return hipsparseCdotci(handle, nnz, x_val, x_ind, y, result, idx_base); } template <> hipsparseStatus_t hipsparseXdotci(hipsparseHandle_t handle, int nnz, const hipDoubleComplex* x_val, const int* x_ind, const hipDoubleComplex* y, hipDoubleComplex* result, hipsparseIndexBase_t idx_base) { return hipsparseZdotci(handle, nnz, x_val, x_ind, y, result, idx_base); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXgthr(hipsparseHandle_t handle, int nnz, const float* y, float* x_val, const int* x_ind, hipsparseIndexBase_t idx_base) { return hipsparseSgthr(handle, nnz, y, x_val, x_ind, idx_base); } template <> hipsparseStatus_t hipsparseXgthr(hipsparseHandle_t handle, int nnz, const double* y, double* x_val, const int* x_ind, hipsparseIndexBase_t idx_base) { return hipsparseDgthr(handle, nnz, y, x_val, x_ind, idx_base); } template <> hipsparseStatus_t hipsparseXgthr(hipsparseHandle_t handle, int nnz, const hipComplex* y, hipComplex* x_val, const int* x_ind, hipsparseIndexBase_t idx_base) { return hipsparseCgthr(handle, nnz, y, x_val, x_ind, idx_base); } template <> hipsparseStatus_t hipsparseXgthr(hipsparseHandle_t handle, int nnz, const hipDoubleComplex* y, hipDoubleComplex* x_val, const int* x_ind, hipsparseIndexBase_t idx_base) { return hipsparseZgthr(handle, nnz, y, x_val, x_ind, idx_base); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXgthrz(hipsparseHandle_t handle, int nnz, float* y, float* x_val, const int* x_ind, hipsparseIndexBase_t idx_base) { return hipsparseSgthrz(handle, nnz, y, x_val, x_ind, idx_base); } template <> hipsparseStatus_t hipsparseXgthrz(hipsparseHandle_t handle, int nnz, double* y, double* x_val, const int* x_ind, hipsparseIndexBase_t idx_base) { return hipsparseDgthrz(handle, nnz, y, x_val, x_ind, idx_base); } template <> hipsparseStatus_t hipsparseXgthrz(hipsparseHandle_t handle, int nnz, hipComplex* y, hipComplex* x_val, const int* x_ind, hipsparseIndexBase_t idx_base) { return hipsparseCgthrz(handle, nnz, y, x_val, x_ind, idx_base); } template <> hipsparseStatus_t hipsparseXgthrz(hipsparseHandle_t handle, int nnz, hipDoubleComplex* y, hipDoubleComplex* x_val, const int* x_ind, hipsparseIndexBase_t idx_base) { return hipsparseZgthrz(handle, nnz, y, x_val, x_ind, idx_base); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXroti(hipsparseHandle_t handle, int nnz, float* x_val, const int* x_ind, float* y, const float* c, const float* s, hipsparseIndexBase_t idx_base) { return hipsparseSroti(handle, nnz, x_val, x_ind, y, c, s, idx_base); } template <> hipsparseStatus_t hipsparseXroti(hipsparseHandle_t handle, int nnz, double* x_val, const int* x_ind, double* y, const double* c, const double* s, hipsparseIndexBase_t idx_base) { return hipsparseDroti(handle, nnz, x_val, x_ind, y, c, s, idx_base); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXsctr(hipsparseHandle_t handle, int nnz, const float* x_val, const int* x_ind, float* y, hipsparseIndexBase_t idx_base) { return hipsparseSsctr(handle, nnz, x_val, x_ind, y, idx_base); } template <> hipsparseStatus_t hipsparseXsctr(hipsparseHandle_t handle, int nnz, const double* x_val, const int* x_ind, double* y, hipsparseIndexBase_t idx_base) { return hipsparseDsctr(handle, nnz, x_val, x_ind, y, idx_base); } template <> hipsparseStatus_t hipsparseXsctr(hipsparseHandle_t handle, int nnz, const hipComplex* x_val, const int* x_ind, hipComplex* y, hipsparseIndexBase_t idx_base) { return hipsparseCsctr(handle, nnz, x_val, x_ind, y, idx_base); } template <> hipsparseStatus_t hipsparseXsctr(hipsparseHandle_t handle, int nnz, const hipDoubleComplex* x_val, const int* x_ind, hipDoubleComplex* y, hipsparseIndexBase_t idx_base) { return hipsparseZsctr(handle, nnz, x_val, x_ind, y, 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 float* alpha, const hipsparseMatDescr_t descr, const float* csr_val, const int* csr_row_ptr, const int* csr_col_ind, const float* x, const float* beta, float* y) { return hipsparseScsrmv( handle, trans, m, n, nnz, alpha, descr, csr_val, csr_row_ptr, csr_col_ind, 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* csr_val, const int* csr_row_ptr, const int* csr_col_ind, const double* x, const double* beta, double* y) { return hipsparseDcsrmv( handle, trans, m, n, nnz, alpha, descr, csr_val, csr_row_ptr, csr_col_ind, 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* csr_val, const int* csr_row_ptr, const int* csr_col_ind, const hipComplex* x, const hipComplex* beta, hipComplex* y) { return hipsparseCcsrmv( handle, trans, m, n, nnz, alpha, descr, csr_val, csr_row_ptr, csr_col_ind, 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* csr_val, const int* csr_row_ptr, const int* csr_col_ind, const hipDoubleComplex* x, const hipDoubleComplex* beta, hipDoubleComplex* y) { return hipsparseZcsrmv( handle, trans, m, n, nnz, alpha, descr, csr_val, csr_row_ptr, csr_col_ind, 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* pBufferSize) { return hipsparseScsrsv2_bufferSizeExt(handle, transA, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSize); } 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* pBufferSize) { return hipsparseDcsrsv2_bufferSizeExt(handle, transA, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSize); } 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* pBufferSize) { return hipsparseCcsrsv2_bufferSizeExt(handle, transA, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSize); } 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* pBufferSize) { return hipsparseZcsrsv2_bufferSizeExt(handle, transA, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSize); } #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); } 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); } 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); } 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); } 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* pBufferSize) { return hipsparseSbsrsv2_bufferSizeExt(handle, dir, transA, mb, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, pBufferSize); } 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* pBufferSize) { return hipsparseDbsrsv2_bufferSizeExt(handle, dir, transA, mb, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, pBufferSize); } 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* pBufferSize) { return hipsparseCbsrsv2_bufferSizeExt(handle, dir, transA, mb, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, pBufferSize); } 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* pBufferSize) { return hipsparseZbsrsv2_bufferSizeExt(handle, dir, transA, mb, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, pBufferSize); } 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); } 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); } template <> hipsparseStatus_t hipsparseXgemvi_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, int* pBufferSize) { return hipsparseSgemvi_bufferSize(handle, transA, m, n, nnz, pBufferSize); } template <> hipsparseStatus_t hipsparseXgemvi_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, int* pBufferSize) { return hipsparseDgemvi_bufferSize(handle, transA, m, n, nnz, pBufferSize); } template <> hipsparseStatus_t hipsparseXgemvi_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, int* pBufferSize) { return hipsparseCgemvi_bufferSize(handle, transA, m, n, nnz, pBufferSize); } template <> hipsparseStatus_t hipsparseXgemvi_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, int* pBufferSize) { return hipsparseZgemvi_bufferSize(handle, transA, m, n, nnz, pBufferSize); } 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); } 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 trans_A, hipsparseOperation_t trans_B, int m, int n, int k, int nnz, const float* alpha, const hipsparseMatDescr_t descr, const float* csr_val, const int* csr_row_ptr, const int* csr_col_ind, const float* B, int ldb, const float* beta, float* C, int ldc) { return hipsparseScsrmm2(handle, trans_A, trans_B, m, n, k, nnz, alpha, descr, csr_val, csr_row_ptr, csr_col_ind, B, ldb, beta, C, ldc); } template <> hipsparseStatus_t hipsparseXcsrmm2(hipsparseHandle_t handle, hipsparseOperation_t trans_A, hipsparseOperation_t trans_B, int m, int n, int k, int nnz, const double* alpha, const hipsparseMatDescr_t descr, const double* csr_val, const int* csr_row_ptr, const int* csr_col_ind, const double* B, int ldb, const double* beta, double* C, int ldc) { return hipsparseDcsrmm2(handle, trans_A, trans_B, m, n, k, nnz, alpha, descr, csr_val, csr_row_ptr, csr_col_ind, B, ldb, beta, C, ldc); } template <> hipsparseStatus_t hipsparseXcsrmm2(hipsparseHandle_t handle, hipsparseOperation_t trans_A, hipsparseOperation_t trans_B, int m, int n, int k, int nnz, const hipComplex* alpha, const hipsparseMatDescr_t descr, const hipComplex* csr_val, const int* csr_row_ptr, const int* csr_col_ind, const hipComplex* B, int ldb, const hipComplex* beta, hipComplex* C, int ldc) { return hipsparseCcsrmm2(handle, trans_A, trans_B, m, n, k, nnz, alpha, descr, csr_val, csr_row_ptr, csr_col_ind, B, ldb, beta, C, ldc); } template <> hipsparseStatus_t hipsparseXcsrmm2(hipsparseHandle_t handle, hipsparseOperation_t trans_A, hipsparseOperation_t trans_B, int m, int n, int k, int nnz, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descr, const hipDoubleComplex* csr_val, const int* csr_row_ptr, const int* csr_col_ind, const hipDoubleComplex* B, int ldb, const hipDoubleComplex* beta, hipDoubleComplex* C, int ldc) { return hipsparseZcsrmm2(handle, trans_A, trans_B, m, n, k, nnz, alpha, descr, csr_val, csr_row_ptr, csr_col_ind, B, ldb, beta, C, ldc); } #endif 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); } 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); } 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); } #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* pBufferSize) { return hipsparseScsrsm2_bufferSizeExt(handle, algo, transA, transB, m, nrhs, nnz, alpha, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, info, policy, pBufferSize); } 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* pBufferSize) { return hipsparseDcsrsm2_bufferSizeExt(handle, algo, transA, transB, m, nrhs, nnz, alpha, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, info, policy, pBufferSize); } 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* pBufferSize) { return hipsparseCcsrsm2_bufferSizeExt(handle, algo, transA, transB, m, nrhs, nnz, alpha, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, info, policy, pBufferSize); } 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* pBufferSize) { return hipsparseZcsrsm2_bufferSizeExt(handle, algo, transA, transB, m, nrhs, nnz, alpha, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, info, policy, pBufferSize); } 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); } 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 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); } 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); } 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 block_dim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseSbsrilu02_analysis(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, block_dim, 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 block_dim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseDbsrilu02_analysis(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, block_dim, 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 block_dim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseCbsrilu02_analysis(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, block_dim, 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 block_dim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseZbsrilu02_analysis(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, block_dim, info, policy, pBuffer); } 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 block_dim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseSbsrilu02(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, block_dim, 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 block_dim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseDbsrilu02(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, block_dim, 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 block_dim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseCbsrilu02(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, block_dim, 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 block_dim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseZbsrilu02(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, block_dim, info, policy, pBuffer); } 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); } 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); } 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* pBufferSize) { return hipsparseScsrilu02_bufferSizeExt(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSize); } 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* pBufferSize) { return hipsparseDcsrilu02_bufferSizeExt(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSize); } 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* pBufferSize) { return hipsparseCcsrilu02_bufferSizeExt(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSize); } 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* pBufferSize) { return hipsparseZcsrilu02_bufferSizeExt(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSize); } 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); } 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); } 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); } 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 block_dim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseSbsric02_analysis(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, block_dim, 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 block_dim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseDbsric02_analysis(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, block_dim, 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 block_dim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseCbsric02_analysis(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, block_dim, 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 block_dim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseZbsric02_analysis(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, block_dim, info, policy, pBuffer); } 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 block_dim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseSbsric02(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, block_dim, 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 block_dim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseDbsric02(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, block_dim, 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 block_dim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseCbsric02(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, block_dim, 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 block_dim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseZbsric02(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, block_dim, info, policy, pBuffer); } 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); } 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* pBufferSize) { return hipsparseScsric02_bufferSizeExt(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSize); } 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* pBufferSize) { return hipsparseDcsric02_bufferSizeExt(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSize); } 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* pBufferSize) { return hipsparseCcsric02_bufferSizeExt(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSize); } 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* pBufferSize) { return hipsparseZcsric02_bufferSizeExt(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSize); } 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); } 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); } 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); } 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); } #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 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* bufferSize) { return hipsparseSpruneDense2csr_bufferSize( handle, m, n, A, lda, threshold, descr, csrVal, csrRowPtr, csrColInd, bufferSize); } 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* bufferSize) { return hipsparseDpruneDense2csr_bufferSize( handle, m, n, A, lda, threshold, descr, csrVal, csrRowPtr, csrColInd, bufferSize); } 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* bufferSize) { return hipsparseSpruneDense2csr_bufferSizeExt( handle, m, n, A, lda, threshold, descr, csrVal, csrRowPtr, csrColInd, bufferSize); } 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* bufferSize) { return hipsparseDpruneDense2csr_bufferSizeExt( handle, m, n, A, lda, threshold, descr, csrVal, csrRowPtr, csrColInd, bufferSize); } 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); } 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); } 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* bufferSize) { return hipsparseSpruneDense2csrByPercentage_bufferSize(handle, m, n, A, lda, percentage, descr, csrVal, csrRowPtr, csrColInd, info, bufferSize); } 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* bufferSize) { return hipsparseDpruneDense2csrByPercentage_bufferSize(handle, m, n, A, lda, percentage, descr, csrVal, csrRowPtr, csrColInd, info, bufferSize); } 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* bufferSize) { return hipsparseSpruneDense2csrByPercentage_bufferSizeExt(handle, m, n, A, lda, percentage, descr, csrVal, csrRowPtr, csrColInd, info, bufferSize); } 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* bufferSize) { return hipsparseDpruneDense2csrByPercentage_bufferSizeExt(handle, m, n, A, lda, percentage, descr, csrVal, csrRowPtr, csrColInd, info, bufferSize); } 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); } 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); } #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* nnz_per_columns, float* cscVal, int* cscRowInd, int* cscColPtr) { return hipsparseSdense2csc( handle, m, n, descr, A, ld, nnz_per_columns, 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* nnz_per_columns, double* cscVal, int* cscRowInd, int* cscColPtr) { return hipsparseDdense2csc( handle, m, n, descr, A, ld, nnz_per_columns, 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* nnz_per_columns, hipComplex* cscVal, int* cscRowInd, int* cscColPtr) { return hipsparseCdense2csc( handle, m, n, descr, A, ld, nnz_per_columns, 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* nnz_per_columns, hipDoubleComplex* cscVal, int* cscRowInd, int* cscColPtr) { return hipsparseZdense2csc( handle, m, n, descr, A, ld, nnz_per_columns, 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* csr_val, const int* csr_row_ptr, const int* csr_col_ind, float* csc_val, int* csc_row_ind, int* csc_col_ptr, hipsparseAction_t copy_values, hipsparseIndexBase_t idx_base) { return hipsparseScsr2csc(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, csc_row_ind, csc_col_ptr, copy_values, idx_base); } template <> hipsparseStatus_t hipsparseXcsr2csc(hipsparseHandle_t handle, int m, int n, int nnz, const double* csr_val, const int* csr_row_ptr, const int* csr_col_ind, double* csc_val, int* csc_row_ind, int* csc_col_ptr, hipsparseAction_t copy_values, hipsparseIndexBase_t idx_base) { return hipsparseDcsr2csc(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, csc_row_ind, csc_col_ptr, copy_values, idx_base); } template <> hipsparseStatus_t hipsparseXcsr2csc(hipsparseHandle_t handle, int m, int n, int nnz, const hipComplex* csr_val, const int* csr_row_ptr, const int* csr_col_ind, hipComplex* csc_val, int* csc_row_ind, int* csc_col_ptr, hipsparseAction_t copy_values, hipsparseIndexBase_t idx_base) { return hipsparseCcsr2csc(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, csc_row_ind, csc_col_ptr, copy_values, idx_base); } template <> hipsparseStatus_t hipsparseXcsr2csc(hipsparseHandle_t handle, int m, int n, int nnz, const hipDoubleComplex* csr_val, const int* csr_row_ptr, const int* csr_col_ind, hipDoubleComplex* csc_val, int* csc_row_ind, int* csc_col_ptr, hipsparseAction_t copy_values, hipsparseIndexBase_t idx_base) { return hipsparseZcsr2csc(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, csc_row_ind, csc_col_ptr, copy_values, 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 float* csr_val, const int* csr_row_ptr, const int* csr_col_ind, hipsparseHybMat_t hyb, int user_ell_width, hipsparseHybPartition_t partition_type) { return hipsparseScsr2hyb(handle, m, n, descr, csr_val, csr_row_ptr, csr_col_ind, hyb, user_ell_width, partition_type); } template <> hipsparseStatus_t hipsparseXcsr2hyb(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const double* csr_val, const int* csr_row_ptr, const int* csr_col_ind, hipsparseHybMat_t hyb, int user_ell_width, hipsparseHybPartition_t partition_type) { return hipsparseDcsr2hyb(handle, m, n, descr, csr_val, csr_row_ptr, csr_col_ind, hyb, user_ell_width, partition_type); } template <> hipsparseStatus_t hipsparseXcsr2hyb(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipComplex* csr_val, const int* csr_row_ptr, const int* csr_col_ind, hipsparseHybMat_t hyb, int user_ell_width, hipsparseHybPartition_t partition_type) { return hipsparseCcsr2hyb(handle, m, n, descr, csr_val, csr_row_ptr, csr_col_ind, hyb, user_ell_width, partition_type); } template <> hipsparseStatus_t hipsparseXcsr2hyb(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipDoubleComplex* csr_val, const int* csr_row_ptr, const int* csr_col_ind, hipsparseHybMat_t hyb, int user_ell_width, hipsparseHybPartition_t partition_type) { return hipsparseZcsr2hyb(handle, m, n, descr, csr_val, csr_row_ptr, csr_col_ind, hyb, user_ell_width, partition_type); } #endif template <> hipsparseStatus_t hipsparseXgebsr2gebsc_bufferSize(hipsparseHandle_t handle, int mb, int nb, int nnzb, const float* 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) { return hipsparseSgebsr2gebsc_bufferSize(handle, mb, nb, nnzb, bsr_val, bsr_row_ptr, bsr_col_ind, row_block_dim, col_block_dim, p_buffer_size); } template <> hipsparseStatus_t hipsparseXgebsr2gebsc_bufferSize(hipsparseHandle_t handle, int mb, int nb, int nnzb, const double* 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) { return hipsparseDgebsr2gebsc_bufferSize(handle, mb, nb, nnzb, bsr_val, bsr_row_ptr, bsr_col_ind, row_block_dim, col_block_dim, p_buffer_size); } template <> hipsparseStatus_t hipsparseXgebsr2gebsc_bufferSize(hipsparseHandle_t handle, int mb, int nb, int nnzb, const hipComplex* 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) { return hipsparseCgebsr2gebsc_bufferSize(handle, mb, nb, nnzb, bsr_val, bsr_row_ptr, bsr_col_ind, row_block_dim, col_block_dim, p_buffer_size); } template <> hipsparseStatus_t hipsparseXgebsr2gebsc_bufferSize(hipsparseHandle_t handle, int mb, int nb, int nnzb, const hipDoubleComplex* 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) { return hipsparseZgebsr2gebsc_bufferSize(handle, mb, nb, nnzb, bsr_val, bsr_row_ptr, bsr_col_ind, row_block_dim, col_block_dim, p_buffer_size); } template <> hipsparseStatus_t hipsparseXgebsr2gebsc(hipsparseHandle_t handle, int mb, int nb, int nnzb, const float* bsr_val, const int* bsr_row_ptr, const int* bsr_col_ind, int row_block_dim, int col_block_dim, float* bsc_val, int* bsc_row_ind, int* bsc_col_ptr, hipsparseAction_t copy_values, hipsparseIndexBase_t idx_base, void* temp_buffer) { return 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, temp_buffer); } template <> hipsparseStatus_t hipsparseXgebsr2gebsc(hipsparseHandle_t handle, int mb, int nb, int nnzb, const double* bsr_val, const int* bsr_row_ptr, const int* bsr_col_ind, int row_block_dim, int col_block_dim, double* bsc_val, int* bsc_row_ind, int* bsc_col_ptr, hipsparseAction_t copy_values, hipsparseIndexBase_t idx_base, void* temp_buffer) { return 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, temp_buffer); } template <> hipsparseStatus_t hipsparseXgebsr2gebsc(hipsparseHandle_t handle, int mb, int nb, int nnzb, const hipComplex* bsr_val, const int* bsr_row_ptr, const int* bsr_col_ind, int row_block_dim, int col_block_dim, hipComplex* bsc_val, int* bsc_row_ind, int* bsc_col_ptr, hipsparseAction_t copy_values, hipsparseIndexBase_t idx_base, void* temp_buffer) { return 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, temp_buffer); } template <> hipsparseStatus_t hipsparseXgebsr2gebsc(hipsparseHandle_t handle, int mb, int nb, int nnzb, const hipDoubleComplex* bsr_val, const int* bsr_row_ptr, const int* bsr_col_ind, int row_block_dim, int col_block_dim, hipDoubleComplex* bsc_val, int* bsc_row_ind, int* bsc_col_ptr, hipsparseAction_t copy_values, hipsparseIndexBase_t idx_base, void* temp_buffer) { return 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, temp_buffer); } template <> hipsparseStatus_t hipsparseXcsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const hipDoubleComplex* 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) { return 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); } template <> hipsparseStatus_t hipsparseXcsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const float* 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) { return 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); } template <> hipsparseStatus_t hipsparseXcsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const double* 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) { return 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); } template <> hipsparseStatus_t hipsparseXcsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const hipComplex* 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) { return 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); } template <> hipsparseStatus_t hipsparseXcsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const float* csr_val, const int* csr_row_ptr, const int* csr_col_ind, const hipsparseMatDescr_t bsr_descr, float* bsr_val, int* bsr_row_ptr, int* bsr_col_ind, int row_block_dim, int col_block_dim, void* p_buffer) { return 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); } template <> hipsparseStatus_t hipsparseXcsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const double* csr_val, const int* csr_row_ptr, const int* csr_col_ind, const hipsparseMatDescr_t bsr_descr, double* bsr_val, int* bsr_row_ptr, int* bsr_col_ind, int row_block_dim, int col_block_dim, void* p_buffer) { return 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); } template <> hipsparseStatus_t hipsparseXcsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const hipComplex* csr_val, const int* csr_row_ptr, const int* csr_col_ind, const hipsparseMatDescr_t bsr_descr, hipComplex* bsr_val, int* bsr_row_ptr, int* bsr_col_ind, int row_block_dim, int col_block_dim, void* p_buffer) { return 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); } template <> hipsparseStatus_t hipsparseXcsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const hipDoubleComplex* csr_val, const int* csr_row_ptr, const int* csr_col_ind, const hipsparseMatDescr_t bsr_descr, hipDoubleComplex* bsr_val, int* bsr_row_ptr, int* bsr_col_ind, int row_block_dim, int col_block_dim, void* p_buffer) { return 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); } 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* bufferSize) { return hipsparseSpruneCsr2csr_bufferSize(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, threshold, descrC, csrValC, csrRowPtrC, csrColIndC, bufferSize); } 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* bufferSize) { return hipsparseDpruneCsr2csr_bufferSize(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, threshold, descrC, csrValC, csrRowPtrC, csrColIndC, bufferSize); } 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* bufferSize) { return hipsparseSpruneCsr2csr_bufferSizeExt(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, threshold, descrC, csrValC, csrRowPtrC, csrColIndC, bufferSize); } 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* bufferSize) { return hipsparseDpruneCsr2csr_bufferSizeExt(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, threshold, descrC, csrValC, csrRowPtrC, csrColIndC, bufferSize); } 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); } 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); } 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* bufferSize) { return hipsparseSpruneCsr2csrByPercentage_bufferSize(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, percentage, descrC, csrValC, csrRowPtrC, csrColIndC, info, bufferSize); } 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* bufferSize) { return hipsparseDpruneCsr2csrByPercentage_bufferSize(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, percentage, descrC, csrValC, csrRowPtrC, csrColIndC, info, bufferSize); } 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* bufferSize) { return hipsparseSpruneCsr2csrByPercentage_bufferSizeExt(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, percentage, descrC, csrValC, csrRowPtrC, csrColIndC, info, bufferSize); } 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* bufferSize) { return hipsparseDpruneCsr2csrByPercentage_bufferSizeExt(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, percentage, descrC, csrValC, csrRowPtrC, csrColIndC, info, bufferSize); } 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); } 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); } 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* bufferSize) { return hipsparseSgebsr2gebsr_bufferSize(handle, dirA, mb, nb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, rowBlockDimC, colBlockDimC, bufferSize); } 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* bufferSize) { return hipsparseDgebsr2gebsr_bufferSize(handle, dirA, mb, nb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, rowBlockDimC, colBlockDimC, bufferSize); } 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* bufferSize) { return hipsparseCgebsr2gebsr_bufferSize(handle, dirA, mb, nb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, rowBlockDimC, colBlockDimC, bufferSize); } 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* bufferSize) { return hipsparseZgebsr2gebsr_bufferSize(handle, dirA, mb, nb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, rowBlockDimC, colBlockDimC, bufferSize); } 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); } 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); } 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); } 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); } 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); } 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); } } // namespace hipsparse hipSPARSE-rocm-5.7.1/clients/common/unit.cpp000066400000000000000000000177441447644345400206300ustar00rootroot00000000000000/* ************************************************************************ * 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, 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 } } } hipSPARSE-rocm-5.7.1/clients/common/utility.cpp000066400000000000000000000160311447644345400213400ustar00rootroot00000000000000/* ************************************************************************ * 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 #ifdef WIN32 #include #endif #include "utility.hpp" #include #include #ifdef WIN32 #define strSUITEcmp(A, B) _stricmp(A, B) #endif #ifdef __cpp_lib_filesystem #include #else #include namespace std { namespace filesystem = experimental::filesystem; } #endif #if 0 #ifdef WIN32 #include #endif #include "utility.hpp" #include #include #include // #include #include //#define _USE_MATH_DEFINES #include #include #ifdef __cpp_lib_filesystem #include #else #include namespace std { namespace filesystem = experimental::filesystem; } #endif #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); } std::filesystem::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 } #ifdef __cplusplus extern "C" { #endif /* ============================================================================================ */ /* query for hipsparse version and git commit SHA-1. */ void query_version(char* version) { hipsparseHandle_t handle; hipsparseCreate(&handle); int ver; hipsparseGetVersion(handle, &ver); char rev[128]; hipsparseGetGitRevision(handle, rev); sprintf(version, "v%d.%d.%d-%s", ver / 100000, ver / 100 % 1000, ver % 100, rev); hipsparseDestroy(handle); } /* ============================================================================================ */ /* 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) { 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) { 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 hipSPARSE-rocm-5.7.1/clients/include/000077500000000000000000000000001447644345400172635ustar00rootroot00000000000000hipSPARSE-rocm-5.7.1/clients/include/arg_check.hpp000066400000000000000000000043771447644345400217150ustar00rootroot00000000000000/* ************************************************************************ * 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 hipSPARSE-rocm-5.7.1/clients/include/hipsparse.hpp000066400000000000000000003103551447644345400220010ustar00rootroot00000000000000/* ************************************************************************ * 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 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); 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* pBufferSize); 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); 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); 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); 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); 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); 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); 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* pBufferSize); 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); 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); template hipsparseStatus_t hipsparseXgemvi_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, int* pBufferSize); 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); 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 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); 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); 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); 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* pBufferSize); 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); 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); #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); 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 template hipsparseStatus_t hipsparseXbsrilu02_numericBoost( hipsparseHandle_t handle, bsrilu02Info_t info, int enable_boost, double* tol, T* boost_val); 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); 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); 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); template hipsparseStatus_t hipsparseXcsrilu02_numericBoost( hipsparseHandle_t handle, csrilu02Info_t info, int enable_boost, double* tol, T* boost_val); 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); 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* pBufferSize); 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); 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); 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); 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); 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); 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); 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* pBufferSize); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); #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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); } // namespace hipsparse #endif // _HIPSPARSE_HPP_ hipSPARSE-rocm-5.7.1/clients/include/hipsparse_test_unique_ptr.hpp000066400000000000000000000241061447644345400253070ustar00rootroot00000000000000/* ************************************************************************ * 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 #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 hipSPARSE-rocm-5.7.1/clients/include/testing_axpby.hpp000066400000000000000000000155651447644345400226700ustar00rootroot00000000000000/* ************************************************************************ * 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 "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(); if(!dx_ind || !dx_val || !dy) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) int64_t size = 15332; int64_t nnz = 500; T alpha = make_DataType(1.5); T beta = make_DataType(0.5); hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; // Index and data type hipsparseIndexType_t idxType = (typeid(I) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipDataType dataType = (typeid(T) == typeid(float)) ? HIP_R_32F : ((typeid(T) == typeid(double)) ? HIP_R_64F : ((typeid(T) == typeid(hipComplex) ? HIP_C_32F : HIP_C_64F))); // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_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(); if(!dx_ind || !dx_val || !dy) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dx_ind || !dx_val || !dy"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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)); // 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()); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpVec(x)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_AXPBY_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_axpyi.hpp000066400000000000000000000213301447644345400226620ustar00rootroot00000000000000/* ************************************************************************ * 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_AXPYI_HPP #define TESTING_AXPYI_HPP #include "hipsparse.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(void) { #if(!defined(CUDART_VERSION)) int nnz = 100; int safe_size = 100; T alpha = 0.6; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseStatus_t status; 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(); if(!dxInd || !dxVal || !dy) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // testing for(nullptr == dxInd) { int* dxInd_null = nullptr; status = hipsparseXaxpyi(handle, nnz, &alpha, dxVal, dxInd_null, dy, idx_base); verify_hipsparse_status_invalid_pointer(status, "Error: xInd is nullptr"); } // testing for(nullptr == dxVal) { T* dxVal_null = nullptr; status = hipsparseXaxpyi(handle, nnz, &alpha, dxVal_null, dxInd, dy, idx_base); verify_hipsparse_status_invalid_pointer(status, "Error: xVal is nullptr"); } // testing for(nullptr == dy) { T* dy_null = nullptr; status = hipsparseXaxpyi(handle, nnz, &alpha, dxVal, dxInd, dy_null, idx_base); verify_hipsparse_status_invalid_pointer(status, "Error: y is nullptr"); } // testing for(nullptr == d_alpha) { T* d_alpha_null = nullptr; status = hipsparseXaxpyi(handle, nnz, d_alpha_null, dxVal, dxInd, dy, idx_base); verify_hipsparse_status_invalid_pointer(status, "Error: alpha is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXaxpyi(handle_null, nnz, &alpha, dxVal, dxInd, dy, idx_base); verify_hipsparse_status_invalid_handle(status); } #endif } template hipsparseStatus_t testing_axpyi(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int N = argus.N; int nnz = argus.nnz; int safe_size = 100; T h_alpha = make_DataType(argus.alpha); hipsparseIndexBase_t idx_base = argus.idx_base; hipsparseStatus_t status; std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; // Argument sanity check before allocating invalid memory if(nnz <= 0) { auto dxInd_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dxVal_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* dxInd = (int*)dxInd_managed.get(); T* dxVal = (T*)dxVal_managed.get(); T* dy = (T*)dy_managed.get(); if(!dxInd || !dxVal || !dy) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dxInd || !dxVal || !dy"); return HIPSPARSE_STATUS_ALLOC_FAILED; } CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); status = hipsparseXaxpyi(handle, nnz, &h_alpha, dxVal, dxInd, dy, idx_base); if(nnz < 0) { verify_hipsparse_status_invalid_size(status, "Error: nnz < 0"); } else { verify_hipsparse_status_success(status, "nnz == 0"); } return HIPSPARSE_STATUS_SUCCESS; } // 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(); if(!dxInd || !dxVal || !dy_1 || !dy_2 || !d_alpha) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dxInd || !dxVal || !dy_1 || !dy_2 || !d_alpha"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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)); // ROCSPARSE 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)); // ROCSPARSE 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]); } // enable unit check, notice unit check is not invasive, but norm check is, // unit check and norm check can not be interchanged their order if(argus.unit_check) { unit_check_general(1, N, 1, hy_gold.data(), hy_1.data()); unit_check_general(1, N, 1, hy_gold.data(), hy_2.data()); } } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_AXPYI_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_bsr2csr.hpp000066400000000000000000000552141447644345400231200ustar00rootroot00000000000000/* ************************************************************************ * 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_BSR2CSR_HPP #define TESTING_BSR2CSR_HPP #include "hipsparse.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(void) { #if(!defined(CUDART_VERSION)) int m = 100; int n = 100; int safe_size = 100; 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; hipsparseStatus_t status; 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), 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), 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(); if(!bsr_row_ptr || !bsr_col_ind || !bsr_val || !csr_row_ptr || !csr_col_ind || !csr_val) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // Testing hipsparseXbsr2csr() // Test invalid handle status = hipsparseXbsr2csr(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_handle(status); // Test invalid pointers status = hipsparseXbsr2csr(handle, dir, m, n, nullptr, 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(status, "Error: bsr_descr is nullptr"); status = 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); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_val is nullptr"); status = hipsparseXbsr2csr(handle, dir, m, n, bsr_descr, bsr_val, nullptr, bsr_col_ind, block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_row_ptr is nullptr"); status = hipsparseXbsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, nullptr, block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_col_ind is nullptr"); status = hipsparseXbsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, block_dim, nullptr, csr_val, csr_row_ptr, csr_col_ind); verify_hipsparse_status_invalid_pointer(status, "Error: csr_descr is nullptr"); status = 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); verify_hipsparse_status_invalid_pointer(status, "Error: csr_val is nullptr"); status = hipsparseXbsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, block_dim, csr_descr, csr_val, nullptr, csr_col_ind); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr is nullptr"); status = hipsparseXbsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, block_dim, csr_descr, csr_val, csr_row_ptr, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind is nullptr"); // Test invalid sizes status = 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); verify_hipsparse_status_invalid_size(status, "Error: m is invalid"); status = 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); verify_hipsparse_status_invalid_size(status, "Error: n is invalid"); status = 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); verify_hipsparse_status_invalid_size(status, "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.idx_base; hipsparseIndexBase_t csr_idx_base = argus.idx_base2; hipsparseDirection_t dir = argus.dirA; std::string binfile = ""; std::string filename = ""; hipsparseStatus_t status; // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu int safe_size = std::max(100, std::max(m, n)); if(m == -99 && n == -99 && argus.timing == 0) { binfile = argus.filename; m = n = safe_size; } if(argus.timing == 1) { filename = argus.filename; } int mb = -1; int nb = -1; if(block_dim > 0) { mb = (m + block_dim - 1) / block_dim; nb = (n + block_dim - 1) / block_dim; } 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(block_dim == 1) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse does not support asynchronous execution if block_dim == 1 return HIPSPARSE_STATUS_SUCCESS; #endif } // Argument sanity check before allocating invalid memory if(mb <= 0 || nb <= 0 || block_dim <= 0) { auto dbsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), 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 dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcsr_val_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(); 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(); // row pointer array must be valid CHECK_HIP_ERROR(hipMemset(dbsr_row_ptr, 0, sizeof(int) * (safe_size + 1))); if(!dbsr_row_ptr || !dbsr_col_ind || !dbsr_val || !dcsr_row_ptr || !dcsr_col_ind || !dcsr_val) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dbsr_row_ptr || !dbsr_col_ind || !dbsr_val || " "!dcsr_row_ptr || !dcsr_col_ind || !dcsr_val"); return HIPSPARSE_STATUS_ALLOC_FAILED; } status = 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); if(mb < 0 || nb < 0 || block_dim <= 0) { verify_hipsparse_status_invalid_size(status, "Error: mb < 0 || nb < 0 || block_dim <= 0"); } else { verify_hipsparse_status_success(status, "mb >= 0 && nb >= 0 && block_dim > 0"); } return HIPSPARSE_STATUS_SUCCESS; } // Read or construct CSR matrix std::vector csr_row_ptr; std::vector csr_col_ind; std::vector csr_val; int nnz; srand(12345ULL); if(binfile != "") { if(read_bin_matrix( binfile.c_str(), m, n, nnz, csr_row_ptr, csr_col_ind, csr_val, csr_idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", binfile.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else if(argus.laplacian) { m = n = gen_2d_laplacian(argus.laplacian, csr_row_ptr, csr_col_ind, csr_val, csr_idx_base); nnz = csr_row_ptr[m]; } else { std::vector coo_row_ind; if(filename != "") { if(read_mtx_matrix( filename.c_str(), m, n, nnz, coo_row_ind, csr_col_ind, csr_val, csr_idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { double scale = 0.02; if(m > 1000 || n > 1000) { scale = 2.0 / std::max(m, n); } nnz = m * scale * n; gen_matrix_coo(m, n, nnz, coo_row_ind, csr_col_ind, csr_val, csr_idx_base); } // Convert COO to CSR csr_row_ptr.resize(m + 1, 0); for(int i = 0; i < nnz; ++i) { ++csr_row_ptr[coo_row_ind[i] + 1 - csr_idx_base]; } csr_row_ptr[0] = csr_idx_base; for(int i = 0; i < m; ++i) { csr_row_ptr[i + 1] += csr_row_ptr[i]; } } // m and n can be modifed if we read in a matrix from a file mb = (m + block_dim - 1) / block_dim; 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(); if(!dbsr_row_ptr || !dbsr_col_ind || !dbsr_val || !dcsr_row_ptr || !dcsr_col_ind || !dcsr_val) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dbsr_row_ptr || !dbsr_col_ind || !dbsr_val || " "!dcsr_row_ptr || !dcsr_col_ind || !dcsr_val"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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()); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_BSR2CSR_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_bsric02.hpp000066400000000000000000000725611447644345400230100ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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; 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_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(); if(!dval || !dptr || !dcol || !dbuffer) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // testing hipsparseXbsric02_bufferSize int size; // testing for(nullptr == dptr) { int* dptr_null = nullptr; status = hipsparseXbsric02_bufferSize( handle, dirA, mb, nnzb, descr, dval, dptr_null, dcol, block_dim, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: dptr is nullptr"); } // testing for(nullptr == dcol) { int* dcol_null = nullptr; status = hipsparseXbsric02_bufferSize( handle, dirA, mb, nnzb, descr, dval, dptr, dcol_null, block_dim, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: dcol is nullptr"); } // testing for(nullptr == dval) { T* dval_null = nullptr; status = hipsparseXbsric02_bufferSize( handle, dirA, mb, nnzb, descr, dval_null, dptr, dcol, block_dim, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: dval is nullptr"); } // testing for(nullptr == buffer_size) { int* size_null = nullptr; status = hipsparseXbsric02_bufferSize( handle, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info, size_null); verify_hipsparse_status_invalid_pointer(status, "Error: size is nullptr"); } // testing for(nullptr == descr) { hipsparseMatDescr_t descr_null = nullptr; status = hipsparseXbsric02_bufferSize( handle, dirA, mb, nnzb, descr_null, dval, dptr, dcol, block_dim, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); } // testing for(nullptr == info) { bsric02Info_t info_null = nullptr; status = hipsparseXbsric02_bufferSize( handle, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info_null, &size); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXbsric02_bufferSize( handle_null, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info, &size); verify_hipsparse_status_invalid_handle(status); } // testing hipsparseXbsric02_analysis // testing for(nullptr == dptr) { int* dptr_null = nullptr; status = hipsparseXbsric02_analysis( handle, dirA, mb, nnzb, descr, dval, dptr_null, dcol, block_dim, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dptr is nullptr"); } // testing for(nullptr == dcol) { int* dcol_null = nullptr; status = hipsparseXbsric02_analysis( handle, dirA, mb, nnzb, descr, dval, dptr, dcol_null, block_dim, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dcol is nullptr"); } // testing for(nullptr == dval) { T* dval_null = nullptr; status = hipsparseXbsric02_analysis( handle, dirA, mb, nnzb, descr, dval_null, dptr, dcol, block_dim, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dval is nullptr"); } // testing for(nullptr == dbuffer) { void* dbuffer_null = nullptr; status = hipsparseXbsric02_analysis( handle, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info, policy, dbuffer_null); verify_hipsparse_status_invalid_pointer(status, "Error: dbuffer is nullptr"); } // testing for(nullptr == descr) { hipsparseMatDescr_t descr_null = nullptr; status = hipsparseXbsric02_analysis( handle, dirA, mb, nnzb, descr_null, dval, dptr, dcol, block_dim, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); } // testing for(nullptr == info) { bsric02Info_t info_null = nullptr; status = hipsparseXbsric02_analysis( handle, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info_null, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXbsric02_analysis( handle_null, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info, policy, dbuffer); verify_hipsparse_status_invalid_handle(status); } // testing hipsparseXbsric02 // testing for(nullptr == dptr) { int* dptr_null = nullptr; status = hipsparseXbsric02( handle, dirA, mb, nnzb, descr, dval, dptr_null, dcol, block_dim, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dptr is nullptr"); } // testing for(nullptr == dcol) { int* dcol_null = nullptr; status = hipsparseXbsric02( handle, dirA, mb, nnzb, descr, dval, dptr, dcol_null, block_dim, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dcol is nullptr"); } // testing for(nullptr == dval) { T* dval_null = nullptr; status = hipsparseXbsric02( handle, dirA, mb, nnzb, descr, dval_null, dptr, dcol, block_dim, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dval is nullptr"); } // testing for(nullptr == dbuffer) { void* dbuffer_null = nullptr; status = hipsparseXbsric02( handle, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info, policy, dbuffer_null); verify_hipsparse_status_invalid_pointer(status, "Error: dbuffer is nullptr"); } // testing for(nullptr == descr) { hipsparseMatDescr_t descr_null = nullptr; status = hipsparseXbsric02( handle, dirA, mb, nnzb, descr_null, dval, dptr, dcol, block_dim, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); } // testing for(nullptr == info) { bsric02Info_t info_null = nullptr; status = hipsparseXbsric02( handle, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info_null, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXbsric02( handle_null, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info, policy, dbuffer); verify_hipsparse_status_invalid_handle(status); } // testing hipsparseXbsric02_zeroPivot int position; // testing for(nullptr == position) { int* position_null = nullptr; status = hipsparseXbsric02_zeroPivot(handle, info, position_null); verify_hipsparse_status_invalid_pointer(status, "Error: position is nullptr"); } // testing for(nullptr == info) { bsric02Info_t info_null = nullptr; status = hipsparseXbsric02_zeroPivot(handle, info_null, &position); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXbsric02_zeroPivot(handle_null, info, &position); verify_hipsparse_status_invalid_handle(status); } #endif } template hipsparseStatus_t testing_bsric02(Arguments argus) { int safe_size = 100; int m = argus.M; int block_dim = argus.block_dim; hipsparseDirection_t dir = argus.dirA; hipsparseIndexBase_t idx_base = argus.idx_base; hipsparseSolvePolicy_t policy = HIPSPARSE_SOLVE_POLICY_USE_LEVEL; std::string binfile = ""; std::string filename = ""; hipsparseStatus_t status; int size; // When in testing mode, M == -99 indicates that we are testing with a real // matrix from cise.ufl.edu if(m == -99 && argus.timing == 0) { binfile = argus.filename; m = safe_size; } if(argus.timing == 1) { filename = argus.filename; } int mb = -1; if(block_dim > 0) { mb = (m + block_dim - 1) / block_dim; } std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; std::unique_ptr test_descr(new descr_struct); hipsparseMatDescr_t descr = test_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)); // Argument sanity check before allocating invalid memory if(mb <= 0 || block_dim <= 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // Do not test args in cusparse return HIPSPARSE_STATUS_SUCCESS; #endif 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 buffer_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* buffer = (void*)buffer_managed.get(); if(!dval || !dptr || !dcol || !buffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dptr || !dcol || !dval || !buffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // Test hipsparseXbsric02_bufferSize status = hipsparseXbsric02_bufferSize( handle, dir, mb, safe_size, descr, dval, dptr, dcol, block_dim, info, &size); if(mb < 0) { verify_hipsparse_status_invalid_size(status, "Error: mb < 0"); } else { verify_hipsparse_status_success(status, "mb >= 0"); } // Test hipsparseXbsric02_analysis status = hipsparseXbsric02_analysis( handle, dir, mb, safe_size, descr, dval, dptr, dcol, block_dim, info, policy, buffer); if(mb < 0) { verify_hipsparse_status_invalid_size(status, "Error: mb < 0"); } else { verify_hipsparse_status_success(status, "mb >= 0"); } // Test hipsparseXbsric02 status = hipsparseXbsric02( handle, dir, mb, safe_size, descr, dval, dptr, dcol, block_dim, info, policy, buffer); if(mb < 0) { verify_hipsparse_status_invalid_size(status, "Error: mb < 0"); } else { verify_hipsparse_status_success(status, "mb >= 0"); } // Test hipsparseXbsric02_zeroPivot int zero_pivot; CHECK_HIPSPARSE_ERROR(hipsparseXbsric02_zeroPivot(handle, info, &zero_pivot)); // Zero pivot should be -1 int res = -1; unit_check_general(1, 1, 1, &res, &zero_pivot); return HIPSPARSE_STATUS_SUCCESS; } // Read or construct CSR matrix std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; int nnz; srand(12345ULL); if(binfile != "") { if(read_bin_matrix( binfile.c_str(), m, m, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", binfile.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else if(argus.laplacian) { m = gen_2d_laplacian(argus.laplacian, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base); nnz = hcsr_row_ptr[m]; } else { std::vector coo_row_ind; if(filename != "") { if(read_mtx_matrix( filename.c_str(), m, m, nnz, coo_row_ind, hcsr_col_ind, hcsr_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { double scale = 0.02; if(m > 1000) { scale = 2.0 / m; } nnz = m * scale * m; gen_matrix_coo(m, m, nnz, coo_row_ind, hcsr_col_ind, hcsr_val, idx_base); } // Convert COO to CSR hcsr_row_ptr.resize(m + 1, 0); for(int i = 0; i < nnz; ++i) { ++hcsr_row_ptr[coo_row_ind[i] + 1 - idx_base]; } hcsr_row_ptr[0] = idx_base; for(int i = 0; i < m; ++i) { hcsr_row_ptr[i + 1] += hcsr_row_ptr[i]; } } // m can be modifed if we read in a matrix from a file 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(); if(!dcsr_val || !dcsr_row_ptr || !dcsr_col_ind || !dbsr_row_ptr) { verify_hipsparse_status_success( HIPSPARSE_STATUS_ALLOC_FAILED, "!dcsr_val || !dcsr_row_ptr || !dcsr_col_ind || !dbsr_row_ptr"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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(); if(!dbsr_val_1 || !dbsr_val_2 || !dbsr_col_ind || !d_analysis_pivot_2 || !d_solve_pivot_2) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dbsr_val_1 || !dbsr_val_2 || !dbsr_col_ind || " "!d_analysis_pivot_2 || !d_solve_pivot_2"); return HIPSPARSE_STATUS_ALLOC_FAILED; } 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); // 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)); // Obtain bsric02 buffer size CHECK_HIPSPARSE_ERROR(hipsparseXbsric02_bufferSize(handle, dir, mb, nnzb, descr, dbsr_val_1, dbsr_row_ptr, dbsr_col_ind, block_dim, info, &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(); if(!dbuffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dbuffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } 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; // 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()); } } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_BSRIC02_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_bsrilu02.hpp000066400000000000000000000777651447644345400232210ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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; 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_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(); if(!dval || !dptr || !dcol || !dbuffer || !dboost_tol || !dboost_val) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // testing hipsparseXbsrilu02_bufferSize int size; // testing for(nullptr == dptr) { int* dptr_null = nullptr; status = hipsparseXbsrilu02_bufferSize( handle, dirA, mb, nnzb, descr, dval, dptr_null, dcol, block_dim, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: dptr is nullptr"); } // testing for(nullptr == dcol) { int* dcol_null = nullptr; status = hipsparseXbsrilu02_bufferSize( handle, dirA, mb, nnzb, descr, dval, dptr, dcol_null, block_dim, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: dcol is nullptr"); } // testing for(nullptr == dval) { T* dval_null = nullptr; status = hipsparseXbsrilu02_bufferSize( handle, dirA, mb, nnzb, descr, dval_null, dptr, dcol, block_dim, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: dval is nullptr"); } // testing for(nullptr == buffer_size) { int* size_null = nullptr; status = hipsparseXbsrilu02_bufferSize( handle, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info, size_null); verify_hipsparse_status_invalid_pointer(status, "Error: size is nullptr"); } // testing for(nullptr == descr) { hipsparseMatDescr_t descr_null = nullptr; status = hipsparseXbsrilu02_bufferSize( handle, dirA, mb, nnzb, descr_null, dval, dptr, dcol, block_dim, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); } // testing for(nullptr == info) { bsrilu02Info_t info_null = nullptr; status = hipsparseXbsrilu02_bufferSize( handle, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info_null, &size); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXbsrilu02_bufferSize( handle_null, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info, &size); verify_hipsparse_status_invalid_handle(status); } // testing hipsparseXbsrilu02_numericBoost // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXbsrilu02_numericBoost(handle_null, info, 1, dboost_tol, dboost_val); verify_hipsparse_status_invalid_handle(status); } // testing for(nullptr == info) { bsrilu02Info_t info_null = nullptr; status = hipsparseXbsrilu02_numericBoost(handle, info_null, 1, dboost_tol, dboost_val); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing for(nullptr == dboost_tol) { double* boost_tol_null = nullptr; status = hipsparseXbsrilu02_numericBoost(handle, info, 1, boost_tol_null, dboost_val); verify_hipsparse_status_invalid_pointer(status, "Error: boost_tol is nullptr"); } // testing for(nullptr == dboost_val) { T* boost_val_null = nullptr; status = hipsparseXbsrilu02_numericBoost(handle, info, 1, dboost_tol, boost_val_null); verify_hipsparse_status_invalid_pointer(status, "Error: boost_val is nullptr"); } // testing hipsparseXbsrilu02_analysis // testing for(nullptr == dptr) { int* dptr_null = nullptr; status = hipsparseXbsrilu02_analysis( handle, dirA, mb, nnzb, descr, dval, dptr_null, dcol, block_dim, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dptr is nullptr"); } // testing for(nullptr == dcol) { int* dcol_null = nullptr; status = hipsparseXbsrilu02_analysis( handle, dirA, mb, nnzb, descr, dval, dptr, dcol_null, block_dim, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dcol is nullptr"); } // testing for(nullptr == dval) { T* dval_null = nullptr; status = hipsparseXbsrilu02_analysis( handle, dirA, mb, nnzb, descr, dval_null, dptr, dcol, block_dim, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dval is nullptr"); } // testing for(nullptr == dbuffer) { void* dbuffer_null = nullptr; status = hipsparseXbsrilu02_analysis( handle, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info, policy, dbuffer_null); verify_hipsparse_status_invalid_pointer(status, "Error: dbuffer is nullptr"); } // testing for(nullptr == descr) { hipsparseMatDescr_t descr_null = nullptr; status = hipsparseXbsrilu02_analysis( handle, dirA, mb, nnzb, descr_null, dval, dptr, dcol, block_dim, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); } // testing for(nullptr == info) { bsrilu02Info_t info_null = nullptr; status = hipsparseXbsrilu02_analysis( handle, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info_null, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXbsrilu02_analysis( handle_null, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info, policy, dbuffer); verify_hipsparse_status_invalid_handle(status); } // testing hipsparseXbsrilu02 // testing for(nullptr == dptr) { int* dptr_null = nullptr; status = hipsparseXbsrilu02( handle, dirA, mb, nnzb, descr, dval, dptr_null, dcol, block_dim, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dptr is nullptr"); } // testing for(nullptr == dcol) { int* dcol_null = nullptr; status = hipsparseXbsrilu02( handle, dirA, mb, nnzb, descr, dval, dptr, dcol_null, block_dim, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dcol is nullptr"); } // testing for(nullptr == dval) { T* dval_null = nullptr; status = hipsparseXbsrilu02( handle, dirA, mb, nnzb, descr, dval_null, dptr, dcol, block_dim, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dval is nullptr"); } // testing for(nullptr == dbuffer) { void* dbuffer_null = nullptr; status = hipsparseXbsrilu02( handle, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info, policy, dbuffer_null); verify_hipsparse_status_invalid_pointer(status, "Error: dbuffer is nullptr"); } // testing for(nullptr == descr) { hipsparseMatDescr_t descr_null = nullptr; status = hipsparseXbsrilu02( handle, dirA, mb, nnzb, descr_null, dval, dptr, dcol, block_dim, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); } // testing for(nullptr == info) { bsrilu02Info_t info_null = nullptr; status = hipsparseXbsrilu02( handle, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info_null, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXbsrilu02( handle_null, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info, policy, dbuffer); verify_hipsparse_status_invalid_handle(status); } // testing hipsparseXbsrilu02_zeroPivot int position; // testing for(nullptr == position) { int* position_null = nullptr; status = hipsparseXbsrilu02_zeroPivot(handle, info, position_null); verify_hipsparse_status_invalid_pointer(status, "Error: position is nullptr"); } // testing for(nullptr == info) { bsrilu02Info_t info_null = nullptr; status = hipsparseXbsrilu02_zeroPivot(handle, info_null, &position); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXbsrilu02_zeroPivot(handle_null, info, &position); verify_hipsparse_status_invalid_handle(status); } #endif } template hipsparseStatus_t testing_bsrilu02(Arguments argus) { int safe_size = 100; 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.idx_base; hipsparseSolvePolicy_t policy = HIPSPARSE_SOLVE_POLICY_USE_LEVEL; std::string binfile = ""; std::string filename = ""; hipsparseStatus_t status; int size; // When in testing mode, M == -99 indicates that we are testing with a real // matrix from cise.ufl.edu if(m == -99 && argus.timing == 0) { binfile = argus.filename; m = safe_size; } if(argus.timing == 1) { filename = argus.filename; } int mb = -1; if(block_dim > 0) { mb = (m + block_dim - 1) / block_dim; } std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; std::unique_ptr test_descr(new descr_struct); hipsparseMatDescr_t descr = test_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)); // Argument sanity check before allocating invalid memory if(mb <= 0 || block_dim <= 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // Do not test args in cusparse return HIPSPARSE_STATUS_SUCCESS; #endif 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 buffer_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* buffer = (void*)buffer_managed.get(); if(!dval || !dptr || !dcol || !buffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dptr || !dcol || !dval || !buffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // Test hipsparseXbsrilu02_bufferSize status = hipsparseXbsrilu02_bufferSize( handle, dir, mb, safe_size, descr, dval, dptr, dcol, block_dim, info, &size); if(mb < 0) { verify_hipsparse_status_invalid_size(status, "Error: mb < 0"); } else { verify_hipsparse_status_success(status, "mb >= 0"); } // Test hipsparseXbsrilu02_analysis status = hipsparseXbsrilu02_analysis( handle, dir, mb, safe_size, descr, dval, dptr, dcol, block_dim, info, policy, buffer); if(mb < 0) { verify_hipsparse_status_invalid_size(status, "Error: mb < 0"); } else { verify_hipsparse_status_success(status, "mb >= 0"); } // Test hipsparseXbsrilu02 status = hipsparseXbsrilu02( handle, dir, mb, safe_size, descr, dval, dptr, dcol, block_dim, info, policy, buffer); if(mb < 0) { verify_hipsparse_status_invalid_size(status, "Error: mb < 0"); } else { verify_hipsparse_status_success(status, "mb >= 0"); } // Test hipsparseXbsrilu02_zeroPivot int zero_pivot; CHECK_HIPSPARSE_ERROR(hipsparseXbsrilu02_zeroPivot(handle, info, &zero_pivot)); // Zero pivot should be -1 int res = -1; unit_check_general(1, 1, 1, &res, &zero_pivot); return HIPSPARSE_STATUS_SUCCESS; } // Read or construct CSR matrix std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; int nnz; srand(12345ULL); if(binfile != "") { if(read_bin_matrix( binfile.c_str(), m, m, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", binfile.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else if(argus.laplacian) { m = gen_2d_laplacian(argus.laplacian, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base); nnz = hcsr_row_ptr[m]; } else { std::vector coo_row_ind; if(filename != "") { if(read_mtx_matrix( filename.c_str(), m, m, nnz, coo_row_ind, hcsr_col_ind, hcsr_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { double scale = 0.02; if(m > 1000) { scale = 2.0 / m; } nnz = m * scale * m; gen_matrix_coo(m, m, nnz, coo_row_ind, hcsr_col_ind, hcsr_val, idx_base); } // Convert COO to CSR hcsr_row_ptr.resize(m + 1, 0); for(int i = 0; i < nnz; ++i) { ++hcsr_row_ptr[coo_row_ind[i] + 1 - idx_base]; } hcsr_row_ptr[0] = idx_base; for(int i = 0; i < m; ++i) { hcsr_row_ptr[i + 1] += hcsr_row_ptr[i]; } } // m can be modifed if we read in a matrix from a file 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(); if(!dcsr_val || !dcsr_row_ptr || !dcsr_col_ind || !dbsr_row_ptr || !dboost_tol || !dboost_val) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dcsr_val || !dcsr_row_ptr || !dcsr_col_ind || " "!dbsr_row_ptr || !dboost_tol || !dboost_val"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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(); if(!dbsr_val_1 || !dbsr_val_2 || !dbsr_col_ind || !d_analysis_pivot_2 || !d_solve_pivot_2) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dbsr_val_1 || !dbsr_val_2 || !dbsr_col_ind || " "!d_analysis_pivot_2 || !d_solve_pivot_2"); return HIPSPARSE_STATUS_ALLOC_FAILED; } 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); // 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)); // Obtain bsrilu02 buffer size CHECK_HIPSPARSE_ERROR(hipsparseXbsrilu02_bufferSize(handle, dir, mb, nnzb, descr, dbsr_val_1, dbsr_row_ptr, dbsr_col_ind, block_dim, info, &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(); if(!dbuffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dbuffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } 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()); } } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_BSRILU02_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_bsrmm.hpp000066400000000000000000000764741447644345400226730ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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(void) { #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 = 0.6; T beta = 0.2; hipsparseDirection_t dirA = HIPSPARSE_DIRECTION_ROW; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; 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 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(); if(!dbsr_val || !dbsr_row_ptr || !dbsr_col_ind || !dB || !dC) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // Testing hipsparseXbsrmm() // Test invalid handle status = hipsparseXbsrmm(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_handle(status); // Test invalid pointers status = 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); verify_hipsparse_status_invalid_pointer(status, "Error: alpha is nullptr"); status = hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, &alpha, nullptr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, &beta, dC, ldc); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); status = 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); verify_hipsparse_status_invalid_pointer(status, "Error: dbsr_val is nullptr"); status = hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, &alpha, descr, dbsr_val, nullptr, dbsr_col_ind, block_dim, dB, ldb, &beta, dC, ldc); verify_hipsparse_status_invalid_pointer(status, "Error: dbsr_row_ptr is nullptr"); status = hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, nullptr, block_dim, dB, ldb, &beta, dC, ldc); verify_hipsparse_status_invalid_pointer(status, "Error: dbsr_col_ind is nullptr"); status = 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); verify_hipsparse_status_invalid_pointer(status, "Error: dB is nullptr"); status = 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); verify_hipsparse_status_invalid_pointer(status, "Error: beta is nullptr"); status = 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); verify_hipsparse_status_invalid_pointer(status, "Error: dC is nullptr"); // Test invalid sizes status = 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); verify_hipsparse_status_invalid_size(status, "Error: mb is invalid"); status = 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); verify_hipsparse_status_invalid_size(status, "Error: n is invalid"); status = 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); verify_hipsparse_status_invalid_size(status, "Error: kb is invalid"); status = 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); verify_hipsparse_status_invalid_size(status, "Error: block_dim is invalid"); // Test not implemented (mapped to hiparse internal error) status = 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); verify_hipsparse_status_not_supported(status, "Error: Passed value for transA is not supported"); status = 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); verify_hipsparse_status_not_supported(status, "Error: Passed value for transA is not supported"); status = 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); verify_hipsparse_status_not_supported(status, "Error: Passed value for transB is not supported"); #endif } template hipsparseStatus_t testing_bsrmm(Arguments argus) { int safe_size = 100; int m = argus.M; int n = argus.N; int k = argus.K; int block_dim = argus.block_dim; int ldb = argus.ldb; int ldc = argus.ldc; 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.idx_base; std::string binfile = ""; std::string filename = ""; hipsparseStatus_t status; // When in testing mode, m == n == -99 indicates that we are testing with a real // matrix from cise.ufl.edu if(m == -99 && k == -99 && argus.timing == 0) { binfile = argus.filename; m = k = safe_size; } if(argus.timing == 1) { filename = argus.filename; } int mb = -1; int kb = -1; if(block_dim > 0) { mb = (m + block_dim - 1) / block_dim; kb = (k + block_dim - 1) / block_dim; } std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; std::unique_ptr test_descr(new descr_struct); hipsparseMatDescr_t descr = test_descr->descr; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); // Argument sanity check before allocating invalid memory if(mb <= 0 || n <= 0 || kb <= 0 || block_dim <= 0) { 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(); if(!dbsr_val || !dbsr_row_ptr || !dbsr_col_ind || !dB || !dC) { verify_hipsparse_status_success( HIPSPARSE_STATUS_ALLOC_FAILED, "!dbsr_row_ptr || !dbsr_col_ind || !dbsr_val || !dB || !dC"); return HIPSPARSE_STATUS_ALLOC_FAILED; } CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); status = hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, safe_size, &h_alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, &h_beta, dC, ldc); if(mb < 0 || n < 0 || kb < 0 || block_dim <= 0) { verify_hipsparse_status_invalid_size( status, "Error: mb < 0 || n < 0 || kb < 0 || block_dim <= 0"); } else { verify_hipsparse_status_success(status, "mb >= 0 && n >= 0 && kb >= 0 && block_dim > 0"); } return HIPSPARSE_STATUS_SUCCESS; } // Read or construct CSR matrix std::vector csr_row_ptr; std::vector csr_col_ind; std::vector csr_val; int nnz; srand(12345ULL); if(binfile != "") { if(read_bin_matrix(binfile.c_str(), m, k, nnz, csr_row_ptr, csr_col_ind, csr_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", binfile.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else if(argus.laplacian) { m = k = gen_2d_laplacian(argus.laplacian, csr_row_ptr, csr_col_ind, csr_val, idx_base); nnz = csr_row_ptr[m]; } else { std::vector coo_row_ind; if(filename != "") { if(read_mtx_matrix( filename.c_str(), m, k, nnz, coo_row_ind, csr_col_ind, csr_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { double scale = 0.02; if(m > 1000 || k > 1000) { scale = 2.0 / std::max(m, k); } nnz = m * scale * k; gen_matrix_coo(m, k, nnz, coo_row_ind, csr_col_ind, csr_val, idx_base); } // Convert COO to CSR csr_row_ptr.resize(m + 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 < m; ++i) { csr_row_ptr[i + 1] += csr_row_ptr[i]; } } // m and k can be modifed if we read in a matrix from a file mb = (m + block_dim - 1) / block_dim; 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(); if(!dcsr_row_ptrA || !dcsr_col_indA || !dcsr_valA || !dbsr_row_ptrA) { verify_hipsparse_status_success( HIPSPARSE_STATUS_ALLOC_FAILED, "!dcsr_row_ptrA || !dcsr_col_indA || !dcsr_valA || !dbsr_row_ptrA"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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(); if(!dbsr_valA || !dbsr_col_indA) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dbsr_valA || !dbsr_col_indA"); return HIPSPARSE_STATUS_ALLOC_FAILED; } 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 ldb = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : n; 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(); if(!dB || !dC_1 || !dC_2 || !d_alpha || !d_beta) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dB || !dC_1 || !dC_2 || !d_alpha || !d_beta"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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()); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_BSRMM_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_bsrmv.hpp000066400000000000000000000746301447644345400226740ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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(void) { #if(!defined(CUDART_VERSION)) int safe_size = 100; int safe_dim = 2; T alpha = 0.6; T beta = 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(); if(!dval || !dptr || !dcol || !dx || !dy) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // Test hipsparseXbsrmv verify_hipsparse_status_invalid_handle(hipsparseXbsrmv(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, 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, 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, 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: xy 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 safe_size = 100; 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.idx_base; hipsparseDirection_t dir = argus.dirA; std::string binfile = ""; std::string filename = ""; hipsparseStatus_t status; // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu if(m == -99 && n == -99 && argus.timing == 0) { binfile = argus.filename; m = n = safe_size; } if(argus.timing == 1) { filename = argus.filename; } std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; std::unique_ptr test_descr(new descr_struct); hipsparseMatDescr_t descr = test_descr->descr; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); int mb = (block_dim == 0) ? -1 : (m + block_dim - 1) / block_dim; int nb = (block_dim == 0) ? -1 : (n + block_dim - 1) / block_dim; if(block_dim == 1) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse only accepts block_dim > 1 return HIPSPARSE_STATUS_SUCCESS; #endif } // Argument sanity check before allocating invalid memory if(mb <= 0 || nb <= 0 || m <= 0 || n <= 0 || block_dim <= 0) { 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(); if(!dval || !dptr || !dcol || !dx || !dy) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dptr || !dcol || !dval || !dx || !dy"); return HIPSPARSE_STATUS_ALLOC_FAILED; } CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); status = hipsparseXbsrmv(handle, dir, transA, mb, nb, safe_size, &h_alpha, descr, dval, dptr, dcol, block_dim, dx, &h_beta, dy); if(mb < 0 || nb < 0 || block_dim <= 0) { verify_hipsparse_status_invalid_size(status, "Error: mb < 0 || nb < 0 || block_dim < 0"); } else { verify_hipsparse_status_success(status, "mb >= 0 && nb >= 0 && block_dim >= 0"); } return HIPSPARSE_STATUS_SUCCESS; } // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; int nnz; // Initial Data on CPU srand(12345ULL); if(binfile != "") { if(read_bin_matrix( binfile.c_str(), m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", binfile.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else if(argus.laplacian) { m = n = gen_2d_laplacian(argus.laplacian, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base); nnz = hcsr_row_ptr[m]; } else { std::vector coo_row_ind; if(filename != "") { if(read_mtx_matrix( filename.c_str(), m, n, nnz, coo_row_ind, hcsr_col_ind, hcsr_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { double scale = 0.02; if(m > 1000 || n > 1000) { scale = 2.0 / std::max(m, n); } nnz = m * scale * n; gen_matrix_coo(m, n, nnz, coo_row_ind, hcsr_col_ind, hcsr_val, idx_base); } // Convert COO to CSR hcsr_row_ptr.resize(m + 1, 0); for(int i = 0; i < nnz; ++i) { ++hcsr_row_ptr[coo_row_ind[i] + 1 - idx_base]; } hcsr_row_ptr[0] = idx_base; for(int i = 0; i < m; ++i) { hcsr_row_ptr[i + 1] += hcsr_row_ptr[i]; } } 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(); if(!dcsr_val || !dcsr_row_ptr || !dcsr_col_ind || !dbsr_row_ptr || !dx || !dy_1 || !dy_2 || !d_alpha || !d_beta) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dval || !dptr || !dcol || !dx || " "!dy_1 || !dy_2 || !d_alpha || !d_beta"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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(); if(!dbsr_val || !dbsr_col_ind) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dbsr_val || !dbsr_col_ind"); return HIPSPARSE_STATUS_ALLOC_FAILED; } 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)); // ROCSPARSE 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)); // ROCSPARSE 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()); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_BSRMV_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_bsrsm2.hpp000066400000000000000000001410211447644345400227400ustar00rootroot00000000000000/* ************************************************************************ * 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_BSRSV2_HPP #define TESTING_BSRSV2_HPP #include "hipsparse.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include using namespace hipsparse; using namespace hipsparse_test; void testing_bsrsm2_bad_arg(void) { #ifdef __HIP_PLATFORM_AMD__ 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(); if(!dval || !dptr || !dcol || !dB || !dX || !dbuf) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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(void) { T h_alpha = make_DataType(2.0); int nrhs = 15; // Determine absolute path of test matrix // Get current executables absolute path // Matrices are stored at the same path in matrices directory std::string filename = get_filename("nos3.bin"); // hipSPARSE handle and opaque structs std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; std::unique_ptr test_descr(new descr_struct); hipsparseMatDescr_t descr = test_descr->descr; std::unique_ptr unique_ptr_bsrsm2_info(new bsrsm2_struct); bsrsm2Info_t info = unique_ptr_bsrsm2_info->info; // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Initial Data on CPU srand(12345ULL); int m; int n; int nnz; if(read_bin_matrix(filename.c_str(), m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, HIPSPARSE_INDEX_BASE_ZERO) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } int block_dim = 3; int mb = (m + block_dim - 1) / block_dim; int ldb = m; int ldx = m; std::vector hB(mb * block_dim * nrhs); std::vector hX_1(mb * block_dim * nrhs); std::vector hX_2(mb * block_dim * nrhs); std::vector hX_gold(mb * block_dim * nrhs); hipsparseInit(hB, m, nrhs); // 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) * mb * block_dim * nrhs), device_free}; auto dX_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * mb * block_dim * nrhs), device_free}; auto dX_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * mb * block_dim * nrhs), 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(); if(!dcsr_val || !dcsr_row_ptr || !dcsr_col_ind || !dbsr_row_ptr || !dB || !dX_1 || !dX_2 || !dalpha || !dposition) { verify_hipsparse_status_success( HIPSPARSE_STATUS_ALLOC_FAILED, "!dcsr_val || !dcsr_row_ptr || !dcsr_col_ind || !dbsr_row_ptr || !dB || !dX_1 || !dX_2 " "|| !dalpha || !dposition"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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) * m * nrhs, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dalpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); // Convert to BSR int nnzb; CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsrNnz(handle, HIPSPARSE_DIRECTION_ROW, 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(); if(!dbsr_val || !dbsr_col_ind) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dbsr_val || !dbsr_col_ind"); return HIPSPARSE_STATUS_ALLOC_FAILED; } CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsr(handle, HIPSPARSE_DIRECTION_ROW, 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 size; CHECK_HIPSPARSE_ERROR(hipsparseXbsrsm2_bufferSize(handle, HIPSPARSE_DIRECTION_ROW, HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_NON_TRANSPOSE, mb, nrhs, nnzb, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, &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(); if(!dbuffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dbuffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // bsrsm2 analysis CHECK_HIPSPARSE_ERROR(hipsparseXbsrsm2_analysis(handle, HIPSPARSE_DIRECTION_ROW, HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_NON_TRANSPOSE, 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); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXbsrsm2_solve(handle, HIPSPARSE_DIRECTION_ROW, HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_NON_TRANSPOSE, 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, HIPSPARSE_DIRECTION_ROW, HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_NON_TRANSPOSE, 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) * m * nrhs, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hX_2.data(), dX_2, sizeof(T) * m * nrhs, 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; bsrsm(mb, nrhs, nnzb, HIPSPARSE_DIRECTION_ROW, HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_NON_TRANSPOSE, 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, HIPSPARSE_INDEX_BASE_ZERO, &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(m, nrhs, ldx, hX_gold.data(), hX_1.data()); unit_check_near(m, nrhs, ldx, hX_gold.data(), hX_2.data()); return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_BSRSV2_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_bsrsv2.hpp000066400000000000000000001103311447644345400227510ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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(void) { /* #ifdef __HIP_PLATFORM_NVIDIA__ // do not test for bad args return; #endif int m = 100; int nnz = 100; int safe_size = 100; T h_alpha = 0.6; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseSolvePolicy_t policy = HIPSPARSE_SOLVE_POLICY_USE_LEVEL; 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_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(); if(!dval || !dptr || !dcol || !dx || !dy || !dbuffer) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // testing hipsparseXbsrsv2_bufferSize int size; // testing for(nullptr == dptr) { int* dptr_null = nullptr; status = hipsparseXbsrsv2_bufferSize( handle, transA, m, nnz, descr, dval, dptr_null, dcol, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: dptr is nullptr"); } // testing for(nullptr == dcol) { int* dcol_null = nullptr; status = hipsparseXbsrsv2_bufferSize( handle, transA, m, nnz, descr, dval, dptr, dcol_null, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: dcol is nullptr"); } // testing for(nullptr == dval) { T* dval_null = nullptr; status = hipsparseXbsrsv2_bufferSize( handle, transA, m, nnz, descr, dval_null, dptr, dcol, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: dval is nullptr"); } // testing for(nullptr == buffer_size) { int* size_null = nullptr; status = hipsparseXbsrsv2_bufferSize( handle, transA, m, nnz, descr, dval, dptr, dcol, info, size_null); verify_hipsparse_status_invalid_pointer(status, "Error: size is nullptr"); } // testing for(nullptr == descr) { hipsparseMatDescr_t descr_null = nullptr; status = hipsparseXbsrsv2_bufferSize( handle, transA, m, nnz, descr_null, dval, dptr, dcol, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); } // testing for(nullptr == info) { bsrsv2Info_t info_null = nullptr; status = hipsparseXbsrsv2_bufferSize( handle, transA, m, nnz, descr, dval, dptr, dcol, info_null, &size); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXbsrsv2_bufferSize( handle_null, transA, m, nnz, descr, dval, dptr, dcol, info, &size); verify_hipsparse_status_invalid_handle(status); } // testing hipsparseXbsrsv2_analysis // testing for(nullptr == dptr) { int* dptr_null = nullptr; status = hipsparseXbsrsv2_analysis( handle, transA, m, nnz, descr, dval, dptr_null, dcol, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dptr is nullptr"); } // testing for(nullptr == dcol) { int* dcol_null = nullptr; status = hipsparseXbsrsv2_analysis( handle, transA, m, nnz, descr, dval, dptr, dcol_null, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dcol is nullptr"); } // testing for(nullptr == dval) { T* dval_null = nullptr; status = hipsparseXbsrsv2_analysis( handle, transA, m, nnz, descr, dval_null, dptr, dcol, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dval is nullptr"); } // testing for(nullptr == dbuffer) { void* dbuffer_null = nullptr; status = hipsparseXbsrsv2_analysis( handle, transA, m, nnz, descr, dval, dptr, dcol, info, policy, dbuffer_null); verify_hipsparse_status_invalid_pointer(status, "Error: dbuffer is nullptr"); } // testing for(nullptr == descr) { hipsparseMatDescr_t descr_null = nullptr; status = hipsparseXbsrsv2_analysis( handle, transA, m, nnz, descr_null, dval, dptr, dcol, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); } // testing for(nullptr == info) { bsrsv2Info_t info_null = nullptr; status = hipsparseXbsrsv2_analysis( handle, transA, m, nnz, descr, dval, dptr, dcol, info_null, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXbsrsv2_analysis( handle_null, transA, m, nnz, descr, dval, dptr, dcol, info, policy, dbuffer); verify_hipsparse_status_invalid_handle(status); } // testing rocsparse_bsrsv2 // testing for(nullptr == dptr) { int* dptr_null = nullptr; status = hipsparseXbsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr, dval, dptr_null, dcol, info, dx, dy, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dptr is nullptr"); } // testing for(nullptr == dcol) { int* dcol_null = nullptr; status = hipsparseXbsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol_null, info, dx, dy, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dcol is nullptr"); } // testing for(nullptr == dval) { T* dval_null = nullptr; status = hipsparseXbsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr, dval_null, dptr, dcol, info, dx, dy, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dval is nullptr"); } // testing for(nullptr == dx) { T* dx_null = nullptr; status = hipsparseXbsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, info, dx_null, dy, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dx is nullptr"); } // testing for(nullptr == dy) { T* dy_null = nullptr; status = hipsparseXbsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, info, dx, dy_null, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dy is nullptr"); } // testing for(nullptr == d_alpha) { T* d_alpha_null = nullptr; status = hipsparseXbsrsv2_solve(handle, transA, m, nnz, d_alpha_null, descr, dval, dptr, dcol, info, dx, dy, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: alpha is nullptr"); } // testing for(nullptr == dbuffer) { void* dbuffer_null = nullptr; status = hipsparseXbsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, info, dx, dy, policy, dbuffer_null); verify_hipsparse_status_invalid_pointer(status, "Error: dbuffer is nullptr"); } // testing for(nullptr == descr) { hipsparseMatDescr_t descr_null = nullptr; status = hipsparseXbsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr_null, dval, dptr, dcol, info, dx, dy, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); } // testing for(nullptr == info) { bsrsv2Info_t info_null = nullptr; status = hipsparseXbsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, info_null, dx, dy, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXbsrsv2_solve(handle_null, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, info, dx, dy, policy, dbuffer); verify_hipsparse_status_invalid_handle(status); } // testing hipsparseXbsrsv2_zeroPivot int position; // testing for(nullptr == position) { int* position_null = nullptr; status = hipsparseXbsrsv2_zeroPivot(handle, info, position_null); verify_hipsparse_status_invalid_pointer(status, "Error: position is nullptr"); } // testing for(nullptr == info) { bsrsv2Info_t info_null = nullptr; status = hipsparseXbsrsv2_zeroPivot(handle, info_null, &position); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXbsrsv2_zeroPivot(handle_null, info, &position); verify_hipsparse_status_invalid_handle(status); } */ } template hipsparseStatus_t testing_bsrsv2(Arguments argus) { int safe_size = 100; int m = argus.M; int block_dim = argus.block_dim; hipsparseIndexBase_t idx_base = argus.idx_base; 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 = HIPSPARSE_SOLVE_POLICY_USE_LEVEL; T h_alpha = make_DataType(argus.alpha); std::string binfile = ""; std::string filename = ""; hipsparseStatus_t status; int size; // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu if(m == -99 && argus.timing == 0) { binfile = argus.filename; m = safe_size; } if(argus.timing == 1) { filename = argus.filename; } std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; std::unique_ptr test_descr(new descr_struct); hipsparseMatDescr_t descr = test_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)); int mb = (block_dim < 1) ? -1 : (m + block_dim - 1) / block_dim; // Argument sanity check before allocating invalid memory if(mb <= 0 || m <= 0 || block_dim <= 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // Do not test args in cusparse return HIPSPARSE_STATUS_SUCCESS; #endif 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 buffer_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* buffer = (void*)buffer_managed.get(); if(!dval || !dptr || !dcol || !dx || !dy || !buffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dptr || !dcol || !dval || " "!dx || !dy || !buffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // Test hipsparseXbsrsv2_bufferSize { size_t lsize; status = hipsparseXbsrsv2_bufferSizeExt(handle, dir, trans, mb, safe_size, descr, dval, dptr, dcol, block_dim, info, &lsize); } if(mb < 0 || block_dim < 0) { verify_hipsparse_status_invalid_size(status, "Error: mb < 0 || block_dim < 0"); } else { verify_hipsparse_status_success(status, "mb >= 0 && block_dim >= 0"); } // Test hipsparseXbsrsv2_analysis status = hipsparseXbsrsv2_analysis(handle, dir, trans, mb, safe_size, descr, dval, dptr, dcol, block_dim, info, policy, buffer); if(mb < 0 || block_dim < 0) { verify_hipsparse_status_invalid_size(status, "Error: mb < 0 || block_dim < 0"); } else { verify_hipsparse_status_success(status, "mb >= 0 && block_dim >= 0"); } // Test hipsparseXbsrsv2_solve status = hipsparseXbsrsv2_solve(handle, dir, trans, mb, safe_size, &h_alpha, descr, dval, dptr, dcol, block_dim, info, dx, dy, policy, buffer); if(mb < 0 || block_dim < 0) { verify_hipsparse_status_invalid_size(status, "Error: mb < 0 || block_dim < 0"); } else { verify_hipsparse_status_success(status, "mb >= 0 && block_dim >= 0"); } // Test hipsparseXbsrsv2_zeroPivot int zero_pivot; CHECK_HIPSPARSE_ERROR(hipsparseXbsrsv2_zeroPivot(handle, info, &zero_pivot)); // Zero pivot should be -1 int res = -1; unit_check_general(1, 1, 1, &res, &zero_pivot); return HIPSPARSE_STATUS_SUCCESS; } // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; int nnz; // Initial Data on CPU srand(12345ULL); if(binfile != "") { int n; if(read_bin_matrix( binfile.c_str(), m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", binfile.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else if(argus.laplacian) { m = gen_2d_laplacian(argus.laplacian, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base); nnz = hcsr_row_ptr[m]; } else { std::vector hcoo_row_ind; if(filename != "") { int n; if(read_mtx_matrix( filename.c_str(), m, n, nnz, hcoo_row_ind, hcsr_col_ind, hcsr_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { double scale = 0.02; if(m > 1000) { scale = 2.0 / m; } nnz = m * scale * m; gen_matrix_coo(m, m, nnz, hcoo_row_ind, hcsr_col_ind, hcsr_val, idx_base); } // Convert COO to CSR hcsr_row_ptr.resize(m + 1, 0); for(int i = 0; i < nnz; ++i) { ++hcsr_row_ptr[hcoo_row_ind[i] + 1 - idx_base]; } hcsr_row_ptr[0] = idx_base; for(int i = 0; i < m; ++i) { hcsr_row_ptr[i + 1] += hcsr_row_ptr[i]; } } 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(); if(!dcsr_val || !dcsr_row_ptr || !dcsr_col_ind || !dbsr_row_ptr || !dx || !dy_1 || !dy_2 || !d_alpha || !d_position) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dval || !dptr || !dcol || !dx || " "!dy_1 || !dy_2 || !d_alpha || !d_position"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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) * 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)); // 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(); if(!dbsr_val || !dbsr_col_ind) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dbsr_val || !dbsr_col_ind"); return HIPSPARSE_STATUS_ALLOC_FAILED; } 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 CHECK_HIPSPARSE_ERROR(hipsparseXbsrsv2_bufferSize(handle, dir, trans, mb, nnzb, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, &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(); if(!dbuffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dbuffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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) * m, hipMemcpyHostToDevice)); // ROCSPARSE 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); // ROCSPARSE 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) * 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 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, m, 1, hy_gold.data(), hy_1.data()); unit_check_near(1, m, 1, hy_gold.data(), hy_2.data()); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_BSRSV2_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_bsrxmv.hpp000066400000000000000000000724101447644345400230560ustar00rootroot00000000000000/* ************************************************************************ * 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_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(); if(!dval || !dptr || !dcol || !dx || !dy || !dend_ptr) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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() { 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); 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)}; 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 test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; std::unique_ptr test_descr(new descr_struct); hipsparseMatDescr_t descr = test_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()); return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_BSRXMV_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_coo2csr.hpp000066400000000000000000000213701447644345400231060ustar00rootroot00000000000000/* ************************************************************************ * 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_COO2CSR_HPP #define TESTING_COO2CSR_HPP #include "hipsparse.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_coo2csr_bad_arg(void) { #if(!defined(CUDART_VERSION)) int m = 100; int nnz = 100; int safe_size = 100; hipsparseStatus_t status; 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(); if(!coo_row_ind || !csr_row_ptr) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // Testing for(coo_row_ind == nullptr) { int* coo_row_ind_null = nullptr; status = hipsparseXcoo2csr( handle, coo_row_ind_null, nnz, m, csr_row_ptr, HIPSPARSE_INDEX_BASE_ZERO); verify_hipsparse_status_invalid_pointer(status, "Error: coo_row_ind is nullptr"); } // Testing for(csr_row_ptr == nullptr) { int* csr_row_ptr_null = nullptr; status = hipsparseXcoo2csr( handle, coo_row_ind, nnz, m, csr_row_ptr_null, HIPSPARSE_INDEX_BASE_ZERO); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr is nullptr"); } // Testing for(handle == nullptr) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXcoo2csr( handle_null, coo_row_ind, nnz, m, csr_row_ptr, HIPSPARSE_INDEX_BASE_ZERO); verify_hipsparse_status_invalid_handle(status); } #endif } hipsparseStatus_t testing_coo2csr(Arguments argus) { int m = argus.M; int n = argus.N; int safe_size = 100; hipsparseIndexBase_t idx_base = argus.idx_base; std::string binfile = ""; std::string filename = ""; hipsparseStatus_t status; // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu if(m == -99 && n == -99 && argus.timing == 0) { binfile = argus.filename; m = n = safe_size; } if(argus.timing == 1) { filename = argus.filename; } double scale = 0.02; if(m > 1000 || n > 1000) { scale = 2.0 / std::max(m, n); } int nnz = m * scale * n; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Argument sanity check before allocating invalid memory if(m <= 0 || n <= 0 || nnz <= 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // Do not test args in cusparse return HIPSPARSE_STATUS_SUCCESS; #endif 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(); if(!coo_row_ind || !csr_row_ptr) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!coo_row_ind || !csr_row_ptr"); return HIPSPARSE_STATUS_ALLOC_FAILED; } status = hipsparseXcoo2csr(handle, coo_row_ind, nnz, m, csr_row_ptr, idx_base); if(m < 0 || nnz < 0) { verify_hipsparse_status_invalid_size(status, "Error: m < 0 || nnz < 0"); } else { verify_hipsparse_status_success(status, "m >= 0 && n >= 0 && nnz >= 0"); } return HIPSPARSE_STATUS_SUCCESS; } // Host structures std::vector hcoo_row_ind; std::vector hcoo_col_ind; std::vector hcoo_val; // Sample initial COO matrix on CPU srand(12345ULL); if(binfile != "") { std::vector hptr(m + 1); if(read_bin_matrix(binfile.c_str(), m, n, nnz, hptr, hcoo_col_ind, hcoo_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", binfile.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } hcoo_row_ind.resize(nnz); // Convert to COO for(int i = 0; i < m; ++i) { for(int j = hptr[i]; j < hptr[i + 1]; ++j) { hcoo_row_ind[j - idx_base] = i + idx_base; } } } else if(argus.laplacian) { std::vector hptr(m + 1); m = n = gen_2d_laplacian(argus.laplacian, hptr, hcoo_col_ind, hcoo_val, idx_base); nnz = hptr[m]; hcoo_row_ind.resize(nnz); // Convert to COO for(int i = 0; i < m; ++i) { for(int j = hptr[i]; j < hptr[i + 1]; ++j) { hcoo_row_ind[j - idx_base] = i + idx_base; } } } else { if(filename != "") { if(read_mtx_matrix( filename.c_str(), m, n, nnz, hcoo_row_ind, hcoo_col_ind, hcoo_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { gen_matrix_coo(m, n, nnz, hcoo_row_ind, hcoo_col_ind, hcoo_val, idx_base); } } 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(); if(!dcoo_row_ind || !dcsr_row_ptr) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dcoo_row_ind || !dcsr_row_ptr"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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()); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_COO2CSR_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_coosort.hpp000066400000000000000000000430411447644345400232230ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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; hipsparseStatus_t status; 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(); if(!coo_row_ind || !coo_col_ind || !perm || !buffer) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // Testing coosort_buffer_size for bad args // Testing for (coo_row_ind == nullptr) { int* coo_row_ind_null = nullptr; status = hipsparseXcoosort_bufferSizeExt( handle, m, n, nnz, coo_row_ind_null, coo_col_ind, &buffer_size); verify_hipsparse_status_invalid_pointer(status, "Error: coo_row_ind is nullptr"); } // Testing for (coo_col_ind == nullptr) { int* coo_col_ind_null = nullptr; status = hipsparseXcoosort_bufferSizeExt( handle, m, n, nnz, coo_row_ind, coo_col_ind_null, &buffer_size); verify_hipsparse_status_invalid_pointer(status, "Error: coo_col_ind is nullptr"); } // Testing for (buffer_size == nullptr) { size_t* buffer_size_null = nullptr; status = hipsparseXcoosort_bufferSizeExt( handle, m, n, nnz, coo_row_ind, coo_col_ind, buffer_size_null); verify_hipsparse_status_invalid_pointer(status, "Error: buffer_size is nullptr"); } // Testing for (handle == nullptr) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXcoosort_bufferSizeExt( handle_null, m, n, nnz, coo_row_ind, coo_col_ind, &buffer_size); verify_hipsparse_status_invalid_handle(status); } // Testing coosort_by_row for bad args // Testing for (coo_row_ind == nullptr) { int* coo_row_ind_null = nullptr; status = hipsparseXcoosortByRow( handle, m, n, nnz, coo_row_ind_null, coo_col_ind, perm, buffer); verify_hipsparse_status_invalid_pointer(status, "Error: coo_row_ind is nullptr"); } // Testing for (coo_col_ind == nullptr) { int* coo_col_ind_null = nullptr; status = hipsparseXcoosortByRow( handle, m, n, nnz, coo_row_ind, coo_col_ind_null, perm, buffer); verify_hipsparse_status_invalid_pointer(status, "Error: coo_col_ind is nullptr"); } // Testing for (buffer == nullptr) { int* buffer_null = nullptr; status = hipsparseXcoosortByRow( handle, m, n, nnz, coo_row_ind, coo_col_ind, perm, buffer_null); verify_hipsparse_status_invalid_pointer(status, "Error: buffer is nullptr"); } // Testing for (handle == nullptr) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXcoosortByRow( handle_null, m, n, nnz, coo_row_ind, coo_col_ind, perm, buffer); verify_hipsparse_status_invalid_handle(status); } // Testing coosort_by_column for bad args // Testing for (coo_row_ind == nullptr) { int* coo_row_ind_null = nullptr; status = hipsparseXcoosortByColumn( handle, m, n, nnz, coo_row_ind_null, coo_col_ind, perm, buffer); verify_hipsparse_status_invalid_pointer(status, "Error: coo_row_ind is nullptr"); } // Testing for (coo_col_ind == nullptr) { int* coo_col_ind_null = nullptr; status = hipsparseXcoosortByColumn( handle, m, n, nnz, coo_row_ind, coo_col_ind_null, perm, buffer); verify_hipsparse_status_invalid_pointer(status, "Error: coo_col_ind is nullptr"); } // Testing for (buffer == nullptr) { int* buffer_null = nullptr; status = hipsparseXcoosortByColumn( handle, m, n, nnz, coo_row_ind, coo_col_ind, perm, buffer_null); verify_hipsparse_status_invalid_pointer(status, "Error: buffer is nullptr"); } // Testing for (handle == nullptr) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXcoosortByColumn( handle_null, m, n, nnz, coo_row_ind, coo_col_ind, perm, buffer); verify_hipsparse_status_invalid_handle(status); } #endif } hipsparseStatus_t testing_coosort(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int m = argus.M; int n = argus.N; int safe_size = 100; int by_row = argus.transA == HIPSPARSE_OPERATION_NON_TRANSPOSE; int permute = argus.temp; hipsparseIndexBase_t idx_base = argus.idx_base; std::string binfile = ""; std::string filename = ""; hipsparseStatus_t status; // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu if(m == -99 && n == -99 && argus.timing == 0) { binfile = argus.filename; m = n = safe_size; } if(argus.timing == 1) { filename = argus.filename; } size_t buffer_size = 0; double scale = 0.02; if(m > 1000 || n > 1000) { scale = 2.0 / std::max(m, n); } int nnz = m * scale * n; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Argument sanity check before allocating invalid memory if(m <= 0 || n <= 0 || nnz <= 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // Do not test args in cusparse return HIPSPARSE_STATUS_SUCCESS; #endif 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(); if(!coo_row_ind || !coo_col_ind || !perm || !buffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!coo_row_ind || !coo_col_ind || !perm || !buffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } status = hipsparseXcoosort_bufferSizeExt( handle, m, n, nnz, coo_row_ind, coo_col_ind, &buffer_size); if(m < 0 || n < 0 || nnz < 0) { verify_hipsparse_status_invalid_size(status, "Error: m < 0 || n < 0 || nnz < 0"); } else { verify_hipsparse_status_success(status, "m >= 0 && n >= 0 && nnz >= 0"); // Buffer size should be 4 size_t four = 4; unit_check_general(1, 1, 1, &four, &buffer_size); } if(by_row) { status = hipsparseXcoosortByRow(handle, m, n, nnz, coo_row_ind, coo_col_ind, perm, buffer); } else { status = hipsparseXcoosortByColumn( handle, m, n, nnz, coo_row_ind, coo_col_ind, perm, buffer); } if(m < 0 || n < 0 || nnz < 0) { verify_hipsparse_status_invalid_size(status, "Error: m < 0 || n < 0 || nnz < 0"); } else { verify_hipsparse_status_success(status, "m >= 0 && n >= 0 && nnz >= 0"); } return HIPSPARSE_STATUS_SUCCESS; } // For testing, assemble a COO matrix and convert it to CSR first (on host) // Host structures std::vector hcoo_row_ind; std::vector hcoo_col_ind; std::vector hcoo_val; // Sample initial COO matrix on CPU srand(12345ULL); if(binfile != "") { std::vector hcsr_row_ptr; if(read_bin_matrix( binfile.c_str(), m, n, nnz, hcsr_row_ptr, hcoo_col_ind, hcoo_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", binfile.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Convert CSR to COO hcoo_row_ind.resize(nnz); for(int i = 0; i < m; ++i) { for(int j = hcsr_row_ptr[i]; j < hcsr_row_ptr[i + 1]; ++j) { hcoo_row_ind[j - idx_base] = i + idx_base; } } } else if(argus.laplacian) { std::vector hcsr_row_ptr; m = n = gen_2d_laplacian(argus.laplacian, hcsr_row_ptr, hcoo_col_ind, hcoo_val, idx_base); nnz = hcsr_row_ptr[m]; // Convert CSR to COO hcoo_row_ind.resize(nnz); for(int i = 0; i < m; ++i) { for(int j = hcsr_row_ptr[i]; j < hcsr_row_ptr[i + 1]; ++j) { hcoo_row_ind[j - idx_base] = i + idx_base; } } } else { if(filename != "") { if(read_mtx_matrix( filename.c_str(), m, n, nnz, hcoo_row_ind, hcoo_col_ind, hcoo_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { gen_matrix_coo(m, n, nnz, hcoo_row_ind, hcoo_col_ind, hcoo_val, idx_base); } } // 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; if(!dcoo_row_ind || !dcoo_col_ind || !dcoo_val || !dcoo_val_sorted || (permute && !dperm)) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dcoo_row_ind || !dcoo_col_ind || !dcoo_val || " "!dcoo_val_sorted || (permute && !dperm)"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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)); if(argus.unit_check) { // Obtain buffer size CHECK_HIPSPARSE_ERROR(hipsparseXcoosort_bufferSizeExt( handle, m, n, nnz, dcoo_row_ind, dcoo_col_ind, &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(!dbuffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dbuffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } if(permute) { // Initialize perm with identity permutation CHECK_HIPSPARSE_ERROR(hipsparseCreateIdentityPermutation(handle, nnz, dperm)); } // 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()); } } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_COOSORT_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_csc2dense.hpp000066400000000000000000000035511447644345400234060ustar00rootroot00000000000000/* ************************************************************************ * 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_CSC2DENSE_HPP #define TESTING_CSC2DENSE_HPP #include "testing_csx2dense.hpp" template void testing_csc2dense_bad_arg(void) { static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_COLUMN; testing_csx2dense_bad_arg(hipsparseXcsc2dense); } template hipsparseStatus_t testing_csc2dense(Arguments argus) { static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_COLUMN; return testing_csx2dense(argus, hipsparseXcsc2dense, hipsparseXdense2csc); } #endif // TESTING_CSC2DENSE hipSPARSE-rocm-5.7.1/clients/include/testing_cscsort.hpp000066400000000000000000000364401447644345400232200ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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; 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; 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(); if(!csc_col_ptr || !csc_row_ind || !perm || !buffer) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // Testing cscsort_buffer_size for bad args // Testing for (csc_col_ptr == nullptr) { int* csc_col_ptr_null = nullptr; status = hipsparseXcscsort_bufferSizeExt( handle, m, n, nnz, csc_col_ptr_null, csc_row_ind, &buffer_size); verify_hipsparse_status_invalid_pointer(status, "Error: csc_col_ptr is nullptr"); } // Testing for (csc_row_ind == nullptr) { int* csc_row_ind_null = nullptr; status = hipsparseXcscsort_bufferSizeExt( handle, m, n, nnz, csc_col_ptr, csc_row_ind_null, &buffer_size); verify_hipsparse_status_invalid_pointer(status, "Error: csc_row_ind is nullptr"); } // Testing for (buffer_size == nullptr) { size_t* buffer_size_null = nullptr; status = hipsparseXcscsort_bufferSizeExt( handle, m, n, nnz, csc_col_ptr, csc_row_ind, buffer_size_null); verify_hipsparse_status_invalid_pointer(status, "Error: buffer_size is nullptr"); } // Testing for (handle == nullptr) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXcscsort_bufferSizeExt( handle_null, m, n, nnz, csc_col_ptr, csc_row_ind, &buffer_size); verify_hipsparse_status_invalid_handle(status); } // Testing cscsort for bad args // Testing for (csc_col_ptr == nullptr) { int* csc_col_ptr_null = nullptr; status = hipsparseXcscsort( handle, m, n, nnz, descr, csc_col_ptr_null, csc_row_ind, perm, buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csc_col_ptr is nullptr"); } // Testing for (csc_row_ind == nullptr) { int* csc_row_ind_null = nullptr; status = hipsparseXcscsort( handle, m, n, nnz, descr, csc_col_ptr, csc_row_ind_null, perm, buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csc_row_ind is nullptr"); } // Testing for (buffer == nullptr) { int* buffer_null = nullptr; status = hipsparseXcscsort( handle, m, n, nnz, descr, csc_col_ptr, csc_row_ind, perm, buffer_null); verify_hipsparse_status_invalid_pointer(status, "Error: buffer is nullptr"); } // Testing for (descr == nullptr) { hipsparseMatDescr_t descr_null = nullptr; status = hipsparseXcscsort( handle, m, n, nnz, descr_null, csc_col_ptr, csc_row_ind, perm, buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); } // Testing for (handle == nullptr) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXcscsort( handle_null, m, n, nnz, descr, csc_col_ptr, csc_row_ind, perm, buffer); verify_hipsparse_status_invalid_handle(status); } #endif } hipsparseStatus_t testing_cscsort(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int m = argus.M; int n = argus.N; int safe_size = 100; int permute = argus.temp; hipsparseIndexBase_t idx_base = argus.idx_base; std::string binfile = ""; std::string filename = ""; hipsparseStatus_t status; // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu if(m == -99 && n == -99 && argus.timing == 0) { binfile = argus.filename; m = n = safe_size; } if(argus.timing == 1) { filename = argus.filename; } size_t buffer_size = 0; double scale = 0.02; if(m > 1000 || n > 1000) { scale = 2.0 / std::max(m, n); } int nnz = m * scale * n; 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)); // Argument sanity check before allocating invalid memory if(m <= 0 || n <= 0 || nnz <= 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // Do not test args in cusparse return HIPSPARSE_STATUS_SUCCESS; #endif 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(); if(!csc_col_ptr || !csc_row_ind || !perm || !buffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!csc_col_ptr || !csc_row_ind || !perm || !buffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } status = hipsparseXcscsort_bufferSizeExt( handle, m, n, nnz, csc_col_ptr, csc_row_ind, &buffer_size); if(m < 0 || n < 0 || nnz < 0) { verify_hipsparse_status_invalid_size(status, "Error: m < 0 || n < 0 || nnz < 0"); } else { verify_hipsparse_status_success(status, "m >= 0 && n >= 0 && nnz >= 0"); // Buffer size should be 4 size_t four = 4; unit_check_general(1, 1, 1, &four, &buffer_size); } status = hipsparseXcscsort(handle, m, n, nnz, descr, csc_col_ptr, csc_row_ind, perm, buffer); if(m < 0 || n < 0 || nnz < 0) { verify_hipsparse_status_invalid_size(status, "Error: m < 0 || n < 0 || nnz < 0"); } else { verify_hipsparse_status_success(status, "m >= 0 && n >= 0 && nnz >= 0"); } return HIPSPARSE_STATUS_SUCCESS; } // For testing, assemble a COO matrix and convert it to CSC first (on host) // Host structures std::vector hcsc_col_ptr; std::vector hcoo_col_ind; std::vector hcsc_row_ind; std::vector hcsc_val; // Sample initial COO matrix on CPU srand(12345ULL); if(binfile != "") { if(read_bin_matrix( binfile.c_str(), n, m, nnz, hcsc_col_ptr, hcsc_row_ind, hcsc_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", binfile.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else if(argus.laplacian) { n = m = gen_2d_laplacian(argus.laplacian, hcsc_col_ptr, hcsc_row_ind, hcsc_val, idx_base); nnz = hcsc_col_ptr[n]; } else { if(filename != "") { if(read_mtx_matrix( filename.c_str(), n, m, nnz, hcoo_col_ind, hcsc_row_ind, hcsc_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { gen_matrix_coo(n, m, nnz, hcoo_col_ind, hcsc_row_ind, hcsc_val, idx_base); } // Convert COO to CSC hcsc_col_ptr.resize(n + 1, 0); for(int i = 0; i < nnz; ++i) { ++hcsc_col_ptr[hcoo_col_ind[i] + 1 - idx_base]; } hcsc_col_ptr[0] = idx_base; for(int i = 0; i < n; ++i) { hcsc_col_ptr[i + 1] += hcsc_col_ptr[i]; } } // 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 if(!dcsc_col_ptr || !dcsc_row_ind || !dcsc_val || !dcsc_val_sorted || (permute && !dperm)) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dcsc_col_ptr || !dcsc_row_ind || !dcsc_val || " "!dcsc_val_sorted || (permute && !dperm)"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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)); if(argus.unit_check) { // Obtain buffer size CHECK_HIPSPARSE_ERROR(hipsparseXcscsort_bufferSizeExt( handle, m, n, nnz, dcsc_col_ptr, dcsc_row_ind, &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(!dbuffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dbuffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } if(permute) { // Initialize perm with identity permutation CHECK_HIPSPARSE_ERROR(hipsparseCreateIdentityPermutation(handle, nnz, dperm)); } // 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()); } } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSCSORT_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_csr2bsr.hpp000066400000000000000000000733461447644345400231260ustar00rootroot00000000000000/* ************************************************************************ * 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_CSR2BSR_HPP #define TESTING_CSR2BSR_HPP #include "hipsparse.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(void) { #if(!defined(CUDART_VERSION)) int m = 100; int n = 100; int safe_size = 100; 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; hipsparseStatus_t status; 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), 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), 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(); if(!csr_row_ptr || !csr_col_ind || !csr_val || !bsr_row_ptr || !bsr_col_ind || !bsr_val) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // Testing hipsparseXcsr2bsrNnz() int bsr_nnzb; // Test invalid handle status = 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_handle(status); // Test invalid pointers status = hipsparseXcsr2bsrNnz(handle, dir, m, n, nullptr, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_row_ptr, &bsr_nnzb); verify_hipsparse_status_invalid_pointer(status, "Error: csr_descr is nullptr"); status = hipsparseXcsr2bsrNnz(handle, dir, m, n, csr_descr, nullptr, csr_col_ind, block_dim, bsr_descr, bsr_row_ptr, &bsr_nnzb); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr is nullptr"); status = hipsparseXcsr2bsrNnz(handle, dir, m, n, csr_descr, csr_row_ptr, csr_col_ind, block_dim, nullptr, bsr_row_ptr, &bsr_nnzb); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_descr is nullptr"); status = hipsparseXcsr2bsrNnz(handle, dir, m, n, csr_descr, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, nullptr, &bsr_nnzb); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_row_ptr is nullptr"); status = hipsparseXcsr2bsrNnz(handle, dir, m, n, csr_descr, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_row_ptr, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_nnzb is nullptr"); // Test invalid sizes status = hipsparseXcsr2bsrNnz(handle, dir, -1, n, csr_descr, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_row_ptr, &bsr_nnzb); verify_hipsparse_status_invalid_size(status, "Error: m is invalid"); status = hipsparseXcsr2bsrNnz(handle, dir, m, -1, csr_descr, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_row_ptr, &bsr_nnzb); verify_hipsparse_status_invalid_size(status, "Error: n is invalid"); status = hipsparseXcsr2bsrNnz(handle, dir, m, n, csr_descr, csr_row_ptr, csr_col_ind, -1, bsr_descr, bsr_row_ptr, &bsr_nnzb); verify_hipsparse_status_invalid_size(status, "Error: block_dim is invalid"); // Testing hipsparseXcsr2bsr() // Test invalid handle status = 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_handle(status); // Test invalid pointers status = 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); verify_hipsparse_status_invalid_pointer(status, "Error: csr_descr is nullptr"); status = 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); verify_hipsparse_status_invalid_pointer(status, "Error: csr_val is nullptr"); status = 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); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr is nullptr"); status = 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); verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind is nullptr"); status = 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); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_descr is nullptr"); status = 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); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_val is nullptr"); status = 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); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_row_ptr is nullptr"); status = 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); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_col_ind is nullptr"); // Test invalid sizes status = 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); verify_hipsparse_status_invalid_size(status, "Error: m is invalid"); status = 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); verify_hipsparse_status_invalid_size(status, "Error: n is invalid"); status = 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); verify_hipsparse_status_invalid_size(status, "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.idx_base; hipsparseIndexBase_t bsr_idx_base = argus.idx_base2; hipsparseDirection_t dir = argus.dirA; std::string binfile = ""; std::string filename = ""; hipsparseStatus_t status; // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu int safe_size = std::max(100, std::max(m, n)); if(m == -99 && n == -99 && argus.timing == 0) { binfile = argus.filename; m = n = safe_size; } if(argus.timing == 1) { 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(block_dim == 1) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse does not support asynchronous execution for block_dim == 1 return HIPSPARSE_STATUS_SUCCESS; #endif } // Argument sanity check before allocating invalid memory if(m <= 0 || n <= 0 || block_dim <= 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // Do not test args in cusparse return HIPSPARSE_STATUS_SUCCESS; #endif auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), 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}; 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(); int* dbsr_col_ind = (int*)dbsr_col_ind_managed.get(); T* dbsr_val = (T*)dbsr_val_managed.get(); // row pointer need to be valid CHECK_HIP_ERROR(hipMemset(dcsr_row_ptr, 0, sizeof(int) * (safe_size + 1))); if(!dcsr_row_ptr || !dcsr_col_ind || !dcsr_val || !dbsr_row_ptr || !dbsr_col_ind || !dbsr_val) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dcsr_row_ptr || !dcsr_col_ind || !dcsr_val || " "!dbsr_row_ptr || !dbsr_col_ind || !dbsr_val || "); return HIPSPARSE_STATUS_ALLOC_FAILED; } int bsr_nnzb; status = hipsparseXcsr2bsrNnz(handle, dir, m, n, csr_descr, dcsr_row_ptr, dcsr_col_ind, block_dim, bsr_descr, dbsr_row_ptr, &bsr_nnzb); if(m < 0 || n < 0 || block_dim <= 0) { verify_hipsparse_status_invalid_size(status, "Error: m < 0 || n < 0 || block_dim <= 0"); } else { verify_hipsparse_status_success(status, "m >= 0 && n >= 0 && block_dim > 0"); } status = 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); if(m < 0 || n < 0 || block_dim <= 0) { verify_hipsparse_status_invalid_size(status, "Error: m < 0 || n < 0 || block_dim <= 0"); } else { verify_hipsparse_status_success(status, "m >= 0 && n >= 0 && block_dim > 0"); } return HIPSPARSE_STATUS_SUCCESS; } // Read or construct CSR matrix std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; int nnz; srand(12345ULL); if(binfile != "") { if(read_bin_matrix( binfile.c_str(), m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, csr_idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", binfile.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else if(argus.laplacian) { m = n = gen_2d_laplacian(argus.laplacian, hcsr_row_ptr, hcsr_col_ind, hcsr_val, csr_idx_base); nnz = hcsr_row_ptr[m]; } else { std::vector coo_row_ind; if(filename != "") { if(read_mtx_matrix( filename.c_str(), m, n, nnz, coo_row_ind, hcsr_col_ind, hcsr_val, csr_idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { double scale = 0.02; if(m > 1000 || n > 1000) { scale = 2.0 / std::max(m, n); } nnz = m * scale * n; gen_matrix_coo(m, n, nnz, coo_row_ind, hcsr_col_ind, hcsr_val, csr_idx_base); } // Convert COO to CSR hcsr_row_ptr.resize(m + 1, 0); for(int i = 0; i < nnz; ++i) { ++hcsr_row_ptr[coo_row_ind[i] + 1 - csr_idx_base]; } hcsr_row_ptr[0] = csr_idx_base; for(int i = 0; i < m; ++i) { hcsr_row_ptr[i + 1] += hcsr_row_ptr[i]; } } int mb = (m + 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(); if(!dcsr_row_ptr || !dcsr_col_ind || !dcsr_val || !dbsr_row_ptr) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dcsr_row_ptr || !dcsr_col_ind || !dcsr_val || " "!dbsr_row_ptr"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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) { // 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(!dbsr_col_ind || !dbsr_val) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!bsr_col_ind || !bsr_val"); return HIPSPARSE_STATUS_ALLOC_FAILED; } 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()); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSR2BSR_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_csr2coo.hpp000066400000000000000000000207571447644345400231160ustar00rootroot00000000000000/* ************************************************************************ * 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_CSR2COO_HPP #define TESTING_CSR2COO_HPP #include "hipsparse.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_csr2coo_bad_arg(void) { #if(!defined(CUDART_VERSION)) int m = 100; int nnz = 100; int safe_size = 100; hipsparseStatus_t status; 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(); if(!csr_row_ptr || !coo_row_ind) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // Testing for(csr_row_ptr == nullptr) { int* csr_row_ptr_null = nullptr; status = hipsparseXcsr2coo( handle, csr_row_ptr_null, nnz, m, coo_row_ind, HIPSPARSE_INDEX_BASE_ZERO); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr is nullptr"); } // Testing for(coo_row_ind == nullptr) { int* coo_row_ind_null = nullptr; status = hipsparseXcsr2coo( handle, csr_row_ptr, nnz, m, coo_row_ind_null, HIPSPARSE_INDEX_BASE_ZERO); verify_hipsparse_status_invalid_pointer(status, "Error: coo_row_ind is nullptr"); } // Testing for(handle == nullptr) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXcsr2coo( handle_null, csr_row_ptr, nnz, m, coo_row_ind, HIPSPARSE_INDEX_BASE_ZERO); verify_hipsparse_status_invalid_handle(status); } #endif } hipsparseStatus_t testing_csr2coo(Arguments argus) { int m = argus.M; int n = argus.N; int safe_size = 100; hipsparseIndexBase_t idx_base = argus.idx_base; std::string binfile = ""; std::string filename = ""; hipsparseStatus_t status; // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu if(m == -99 && n == -99 && argus.timing == 0) { binfile = argus.filename; m = n = safe_size; } if(argus.timing == 1) { filename = argus.filename; } double scale = 0.02; if(m > 1000 || n > 1000) { scale = 2.0 / std::max(m, n); } int nnz = m * scale * n; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Argument sanity check before allocating invalid memory if(m <= 0 || n <= 0 || nnz <= 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // Do not test args in cusparse return HIPSPARSE_STATUS_SUCCESS; #endif 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(); if(!csr_row_ptr || !coo_row_ind) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!csr_row_ptr || !coo_row_ind"); return HIPSPARSE_STATUS_ALLOC_FAILED; } status = hipsparseXcsr2coo(handle, csr_row_ptr, nnz, m, coo_row_ind, idx_base); if(m < 0 || nnz < 0) { verify_hipsparse_status_invalid_size(status, "Error: m < 0 || nnz < 0"); } else { verify_hipsparse_status_success(status, "m >= 0 && n >= 0 && nnz >= 0"); } return HIPSPARSE_STATUS_SUCCESS; } // Host structures std::vector hcsr_row_ptr; std::vector hcoo_row_ind; std::vector hcol_ind; std::vector hval(nnz); // Initial data on CPU srand(12345ULL); if(binfile != "") { if(read_bin_matrix(binfile.c_str(), m, n, nnz, hcsr_row_ptr, hcol_ind, hval, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", binfile.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else if(argus.laplacian) { m = n = gen_2d_laplacian(argus.laplacian, hcsr_row_ptr, hcol_ind, hval, idx_base); nnz = hcsr_row_ptr[m]; } else { if(filename != "") { if(read_mtx_matrix(filename.c_str(), m, n, nnz, hcoo_row_ind, hcol_ind, hval, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { gen_matrix_coo(m, n, nnz, hcoo_row_ind, hcol_ind, hval, idx_base); } // Convert COO to CSR hcsr_row_ptr.resize(m + 1, 0); for(int i = 0; i < nnz; ++i) { ++hcsr_row_ptr[hcoo_row_ind[i] + 1 - idx_base]; } hcsr_row_ptr[0] = idx_base; for(int i = 0; i < m; ++i) { hcsr_row_ptr[i + 1] += hcsr_row_ptr[i]; } } // 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(); if(!dcsr_row_ptr || !dcoo_row_ind) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dcsr_row_ptr || !dcoo_row_ind"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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 hcoo_row_ind.resize(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()); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSR2COO_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_csr2csc.hpp000066400000000000000000000441441447644345400231020ustar00rootroot00000000000000/* ************************************************************************ * 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_CSR2CSC_HPP #define TESTING_CSR2CSC_HPP #include "hipsparse.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(void) { #if(!defined(CUDART_VERSION)) int m = 100; int n = 100; int nnz = 100; int safe_size = 100; hipsparseStatus_t status; 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(); if(!csr_row_ptr || !csr_col_ind || !csr_val || !csc_row_ind || !csc_col_ptr || !csc_val) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // Testing hipsparseXcsr2csc() // Testing for (csr_row_ptr == nullptr) { int* csr_row_ptr_null = nullptr; status = hipsparseXcsr2csc(handle, m, n, nnz, csr_val, csr_row_ptr_null, csr_col_ind, csc_val, csc_row_ind, csc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr is nullptr"); } // Testing for (csr_col_ind == nullptr) { int* csr_col_ind_null = nullptr; status = hipsparseXcsr2csc(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind_null, csc_val, csc_row_ind, csc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO); verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind is nullptr"); } // Testing for (csr_val == nullptr) { T* csr_val_null = nullptr; status = hipsparseXcsr2csc(handle, m, n, nnz, csr_val_null, csr_row_ptr, csr_col_ind, csc_val, csc_row_ind, csc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO); verify_hipsparse_status_invalid_pointer(status, "Error: csr_val is nullptr"); } // Testing for (csc_row_ind == nullptr) { int* csc_row_ind_null = nullptr; status = hipsparseXcsr2csc(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, csc_row_ind_null, csc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO); verify_hipsparse_status_invalid_pointer(status, "Error: csc_row_ind is nullptr"); } // Testing for (csc_col_ptr == nullptr) { int* csc_col_ptr_null = nullptr; status = hipsparseXcsr2csc(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, csc_row_ind, csc_col_ptr_null, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO); verify_hipsparse_status_invalid_pointer(status, "Error: csc_col_ptr is nullptr"); } // Testing for (csc_val == nullptr) { T* csc_val_null = nullptr; status = hipsparseXcsr2csc(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val_null, csc_row_ind, csc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO); verify_hipsparse_status_invalid_pointer(status, "Error: csc_val is nullptr"); } // Testing for (handle == nullptr) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXcsr2csc(handle_null, 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); verify_hipsparse_status_invalid_handle(status); } #endif } template hipsparseStatus_t testing_csr2csc(Arguments argus) { int m = argus.M; int n = argus.N; int safe_size = 100; hipsparseIndexBase_t idx_base = argus.idx_base; hipsparseAction_t action = argus.action; std::string binfile = ""; std::string filename = ""; hipsparseStatus_t status; // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu if(m == -99 && n == -99 && argus.timing == 0) { binfile = argus.filename; m = n = safe_size; } if(argus.timing == 1) { filename = argus.filename; } double scale = 0.02; if(m > 1000 || n > 1000) { scale = 2.0 / std::max(m, n); } int nnz = m * scale * n; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Argument sanity check before allocating invalid memory if(m <= 0 || n <= 0 || nnz <= 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // Do not test args in cusparse return HIPSPARSE_STATUS_SUCCESS; #endif 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(); if(!csr_row_ptr || !csr_col_ind || !csr_val || !csc_row_ind || !csc_col_ptr || !csc_val) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!csr_row_ptr || !csr_col_ind || !csr_val || " "!csc_row_ind || !csc_col_ptr || !csc_val"); return HIPSPARSE_STATUS_ALLOC_FAILED; } status = hipsparseXcsr2csc(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, csc_row_ind, csc_col_ptr, action, idx_base); if(m < 0 || n < 0 || nnz < 0) { verify_hipsparse_status_invalid_size(status, "Error: m < 0 || n < 0 || nnz < 0"); } else { verify_hipsparse_status_success(status, "m >= 0 && n >= 0 && nnz >= 0"); } return HIPSPARSE_STATUS_SUCCESS; } // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Sample initial COO matrix on CPU srand(12345ULL); if(binfile != "") { if(read_bin_matrix( binfile.c_str(), m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", binfile.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else if(argus.laplacian) { m = n = gen_2d_laplacian(argus.laplacian, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base); nnz = hcsr_row_ptr[m]; } else { std::vector hcoo_row_ind; if(filename != "") { if(read_mtx_matrix( filename.c_str(), m, n, nnz, hcoo_row_ind, hcsr_col_ind, hcsr_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { gen_matrix_coo(m, n, nnz, hcoo_row_ind, hcsr_col_ind, hcsr_val, idx_base); } // Convert COO to CSR hcsr_row_ptr.resize(m + 1, 0); for(int i = 0; i < nnz; ++i) { ++hcsr_row_ptr[hcoo_row_ind[i] + 1 - idx_base]; } hcsr_row_ptr[0] = idx_base; for(int i = 0; i < m; ++i) { hcsr_row_ptr[i + 1] += hcsr_row_ptr[i]; } } // 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(); if(!dcsr_row_ptr || !dcsr_col_ind || !dcsr_val || !dcsc_row_ind || !dcsc_col_ptr || !dcsc_val) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dcsr_row_ptr || !dcsr_col_ind || !dcsr_val || " "!dcsc_row_ind || !dcsc_col_ptr || !dcsc_val"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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()); } } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSR2CSC_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_csr2csc_ex2.hpp000066400000000000000000000702351447644345400236600ustar00rootroot00000000000000/* ************************************************************************ * 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_CSR2CSC_EX2_HPP #define TESTING_CSR2CSC_EX2_HPP #include "hipsparse.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(void) { #if(!defined(CUDART_VERSION)) int m = 100; int n = 100; int nnz = 100; int safe_size = 100; size_t buffer_size = 0; hipsparseStatus_t status; 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(); if(!csr_row_ptr || !csr_col_ind || !csr_val || !csc_row_ind || !csc_col_ptr || !csc_val || !buffer) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // Testing hipsparseCsr2cscEx2_bufferSize() // Testing for (handle == nullptr) { hipsparseHandle_t handle_null = nullptr; status = hipsparseCsr2cscEx2_bufferSize(handle_null, 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_handle(status); } // Testing for (csr_row_ptr == nullptr) { int* csr_row_ptr_null = nullptr; status = hipsparseCsr2cscEx2_bufferSize(handle, m, n, nnz, csr_val, csr_row_ptr_null, 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(status, "Error: csr_row_ptr is nullptr"); } // Testing for (csr_col_ind == nullptr) { int* csr_col_ind_null = nullptr; status = hipsparseCsr2cscEx2_bufferSize(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind_null, 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(status, "Error: csr_col_ind is nullptr"); } // Testing for (buffer_size == nullptr) { size_t* buffer_size_null = nullptr; status = 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, buffer_size_null); verify_hipsparse_status_invalid_pointer(status, "Error: buffer_size is nullptr"); } // Testing hipsparseCsr2cscEx2() // Testing for (handle == nullptr) { hipsparseHandle_t handle_null = nullptr; status = hipsparseCsr2cscEx2(handle_null, 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_handle(status); } // Testing for (csr_row_ptr == nullptr) { int* csr_row_ptr_null = nullptr; status = hipsparseCsr2cscEx2(handle, m, n, nnz, csr_val, csr_row_ptr_null, 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(status, "Error: csr_row_ptr is nullptr"); } // Testing for (csr_col_ind == nullptr) { int* csr_col_ind_null = nullptr; status = hipsparseCsr2cscEx2(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind_null, 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(status, "Error: csr_col_ind is nullptr"); } // Testing for (csr_val == nullptr) { T* csr_val_null = nullptr; status = hipsparseCsr2cscEx2(handle, m, n, nnz, csr_val_null, 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(status, "Error: csr_val is nullptr"); } // Testing for (csc_col_ptr == nullptr) { int* csc_col_ptr_null = nullptr; status = hipsparseCsr2cscEx2(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, csc_col_ptr_null, csc_row_ind, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csc_col_ptr is nullptr"); } // Testing for (csc_row_ind == nullptr) { int* csc_row_ind_null = nullptr; status = hipsparseCsr2cscEx2(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, csc_col_ptr, csc_row_ind_null, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csc_row_ind is nullptr"); } // Testing for (csc_val == nullptr) { T* csc_val_null = nullptr; status = hipsparseCsr2cscEx2(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val_null, 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(status, "Error: csc_val is nullptr"); } // Testing for (buffer == nullptr) { T* buffer_null = nullptr; status = 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, buffer_null); verify_hipsparse_status_invalid_pointer(status, "Error: buffer is nullptr"); } #endif } template hipsparseStatus_t testing_csr2csc_ex2(Arguments argus) { int m = argus.M; int n = argus.N; int safe_size = 100; hipsparseIndexBase_t idx_base = argus.idx_base; hipsparseAction_t action = argus.action; std::string binfile = ""; std::string filename = ""; size_t buffer_size = 0; hipsparseStatus_t status; hipsparseCsr2CscAlg_t alg = HIPSPARSE_CSR2CSC_ALG1; hipDataType dataType = (typeid(T) == typeid(float)) ? HIP_R_32F : ((typeid(T) == typeid(double)) ? HIP_R_64F : ((typeid(T) == typeid(hipComplex) ? HIP_C_32F : HIP_C_64F))); // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu if(m == -99 && n == -99 && argus.timing == 0) { binfile = argus.filename; m = n = safe_size; } if(argus.timing == 1) { filename = argus.filename; } double scale = 0.02; if(m > 1000 || n > 1000) { scale = 2.0 / std::max(m, n); } int nnz = m * scale * n; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Argument sanity check before allocating invalid memory if(m <= 0 || n <= 0 || nnz <= 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // Do not test args in cusparse return HIPSPARSE_STATUS_SUCCESS; #endif 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(); if(!csr_row_ptr || !csr_col_ind || !csr_val || !csc_row_ind || !csc_col_ptr || !csc_val || !buffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!csr_row_ptr || !csr_col_ind || !csr_val || " "!csc_row_ind || !csc_col_ptr || !csc_val || !buffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } status = hipsparseCsr2cscEx2_bufferSize(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, csc_col_ptr, csc_row_ind, dataType, action, idx_base, alg, &buffer_size); if(m < 0 || n < 0 || nnz < 0) { verify_hipsparse_status_invalid_size(status, "Error: m < 0 || n < 0 || nnz < 0"); } else { verify_hipsparse_status_success(status, "m >= 0 && n >= 0 && nnz >= 0"); } status = hipsparseCsr2cscEx2(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, csc_col_ptr, csc_row_ind, dataType, action, idx_base, alg, buffer); if(m < 0 || n < 0 || nnz < 0) { verify_hipsparse_status_invalid_size(status, "Error: m < 0 || n < 0 || nnz < 0"); } else { verify_hipsparse_status_success(status, "m >= 0 && n >= 0 && nnz >= 0"); } return HIPSPARSE_STATUS_SUCCESS; } // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Sample initial COO matrix on CPU srand(12345ULL); if(binfile != "") { if(read_bin_matrix( binfile.c_str(), m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", binfile.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else if(argus.laplacian) { m = n = gen_2d_laplacian(argus.laplacian, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base); nnz = hcsr_row_ptr[m]; } else { std::vector hcoo_row_ind; if(filename != "") { if(read_mtx_matrix( filename.c_str(), m, n, nnz, hcoo_row_ind, hcsr_col_ind, hcsr_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { gen_matrix_coo(m, n, nnz, hcoo_row_ind, hcsr_col_ind, hcsr_val, idx_base); } // Convert COO to CSR hcsr_row_ptr.resize(m + 1, 0); for(int i = 0; i < nnz; ++i) { ++hcsr_row_ptr[hcoo_row_ind[i] + 1 - idx_base]; } hcsr_row_ptr[0] = idx_base; for(int i = 0; i < m; ++i) { hcsr_row_ptr[i + 1] += hcsr_row_ptr[i]; } } // 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(); if(!dcsr_row_ptr || !dcsr_col_ind || !dcsr_val || !dcsc_row_ind || !dcsc_col_ptr || !dcsc_val) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dcsr_row_ptr || !dcsr_col_ind || !dcsr_val || " "!dcsc_row_ind || !dcsc_col_ptr || !dcsc_val"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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)); 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, &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(!dbuffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dbuffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } 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()); } } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSR2CSC_EX2_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_csr2csr_compress.hpp000066400000000000000000000674011447644345400250350ustar00rootroot00000000000000/* ************************************************************************ * 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_CSR2CSR_COMPRESS_HPP #define TESTING_CSR2CSR_COMPRESS_HPP #include "hipsparse.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(void) { #if(!defined(CUDART_VERSION)) int m = 100; int n = 100; int nnz_A = 100; int safe_size = 100; T tol = make_DataType(0); hipsparseIndexBase_t csr_idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseStatus_t status; 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), 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), 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(); if(!csr_row_ptr_A || !csr_col_ind_A || !csr_val_A || !csr_row_ptr_C || !csr_col_ind_C || !csr_val_C || !nnz_per_row || !nnz_C) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // Testing hipsparseXnnz_compress() // Test invalid handle status = hipsparseXnnz_compress( nullptr, m, csr_descr, csr_val_A, csr_row_ptr_A, nnz_per_row, nnz_C, tol); verify_hipsparse_status_invalid_handle(status); // Test invalid pointers status = hipsparseXnnz_compress( handle, m, nullptr, csr_val_A, csr_row_ptr_A, nnz_per_row, nnz_C, tol); verify_hipsparse_status_invalid_pointer(status, "Error: Matrix descriptor is invalid"); status = hipsparseXnnz_compress(handle, m, csr_descr, csr_val_A, nullptr, nnz_per_row, nnz_C, tol); verify_hipsparse_status_invalid_pointer(status, "Error: CSR row pointer array is invalid"); status = hipsparseXnnz_compress( handle, m, csr_descr, csr_val_A, csr_row_ptr_A, nullptr, nnz_C, tol); verify_hipsparse_status_invalid_pointer(status, "Error: Number of elements per row array is invalid"); status = hipsparseXnnz_compress( handle, m, csr_descr, csr_val_A, csr_row_ptr_A, nnz_per_row, nullptr, tol); verify_hipsparse_status_invalid_pointer(status, "Error: Total number of elements pointer is invalid"); // Test invalid size status = hipsparseXnnz_compress( handle, -1, csr_descr, csr_val_A, csr_row_ptr_A, nnz_per_row, nnz_C, tol); verify_hipsparse_status_invalid_size(status, "Error: Matrix size is invalid"); // Test invalid tolerance status = hipsparseXnnz_compress( handle, m, csr_descr, csr_val_A, csr_row_ptr_A, nnz_per_row, nnz_C, make_DataType(-1)); verify_hipsparse_status_invalid_size(status, "Error: Tolerance is invalid"); // Testing hipsparseXcsr2csr_compress() // Test invalid handle status = 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_handle(status); // Test invalid pointers status = 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); verify_hipsparse_status_invalid_pointer(status, "Error: Matrix descriptor is invalid"); status = 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); verify_hipsparse_status_invalid_pointer(status, "Error: CSR matrix values array is invalid"); status = 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); verify_hipsparse_status_invalid_pointer(status, "Error: CSR matrix column indices array is invalid"); status = 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); verify_hipsparse_status_invalid_pointer(status, "Error: CSR matrix row pointer array is invalid"); status = 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); verify_hipsparse_status_invalid_pointer(status, "Error: Number of elements per row array is invalid"); status = 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); verify_hipsparse_status_invalid_pointer(status, "Error: CSR matrix values array is invalid"); status = 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); verify_hipsparse_status_invalid_pointer(status, "Error: CSR matrix column indices array is invalid"); status = 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); verify_hipsparse_status_invalid_pointer(status, "Error: CSR matrix row pointer array is invalid"); // Test invalid sizes status = 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); verify_hipsparse_status_invalid_size(status, "Error: Matrix size is invalid"); status = 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); verify_hipsparse_status_invalid_size(status, "Error: Matrix size is invalid"); status = 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); verify_hipsparse_status_invalid_size(status, "Error: Matrix size is invalid"); // Test invalid tolerance status = 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)); verify_hipsparse_status_invalid_value(status, "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); int safe_size = 100; hipsparseIndexBase_t idx_base = argus.idx_base; std::string binfile = ""; std::string filename = ""; hipsparseStatus_t status; // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu if(m == -99 && n == -99 && argus.timing == 0) { binfile = argus.filename; m = n = safe_size; } if(argus.timing == 1) { 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); // Argument sanity check before allocating invalid memory if(m <= 0 || n <= 0 || testing_real(tol) < testing_real(make_DataType(0))) { #ifdef __HIP_PLATFORM_NVIDIA__ // Do not test args in cusparse return HIPSPARSE_STATUS_SUCCESS; #endif 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(T) * 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(T) * safe_size), device_free}; auto dnnz_per_row_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dnnz_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), 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* dcsr_col_ind_C = (int*)dcsr_col_ind_C_managed.get(); T* dcsr_val_C = (T*)dcsr_val_C_managed.get(); int* dnnz_per_row = (int*)dnnz_per_row_managed.get(); int* dnnz_C = (int*)dnnz_C_managed.get(); if(!dcsr_row_ptr_A || !dcsr_col_ind_A || !dcsr_val_A || !dcsr_row_ptr_C || !dcsr_col_ind_C || !dcsr_val_C || !dnnz_per_row || !dnnz_C) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dcsr_row_ptr_A || !dcsr_col_ind_A || !dcsr_val_A || " "!dcsr_row_ptr_C || !dcsr_col_ind_C || !dcsr_val_C || " "!dnnz_per_row || !dnnz_C"); return HIPSPARSE_STATUS_ALLOC_FAILED; } status = hipsparseXcsr2csr_compress(handle, m, n, csr_descr, dcsr_val_A, dcsr_col_ind_A, dcsr_row_ptr_A, safe_size, dnnz_per_row, dcsr_val_C, dcsr_col_ind_C, dcsr_row_ptr_C, tol); if(m < 0 || n < 0) { verify_hipsparse_status_invalid_size(status, "Error: m < 0 || n < 0"); } else if(testing_real(tol) < testing_real(make_DataType(0))) { verify_hipsparse_status_invalid_value(status, "Error: real(tol) < 0"); } else { verify_hipsparse_status_success(status, "m >= 0 && n >= 0"); } return HIPSPARSE_STATUS_SUCCESS; } // Host CSR matrix std::vector hcsr_row_ptr_A; std::vector hcsr_col_ind_A; std::vector hcsr_val_A; // Sample initial COO matrix on CPU int hnnz_A; srand(12345ULL); if(binfile != "") { if(read_bin_matrix( binfile.c_str(), m, n, hnnz_A, hcsr_row_ptr_A, hcsr_col_ind_A, hcsr_val_A, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", binfile.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else if(argus.laplacian) { m = n = gen_2d_laplacian( argus.laplacian, hcsr_row_ptr_A, hcsr_col_ind_A, hcsr_val_A, idx_base); hnnz_A = hcsr_row_ptr_A[m]; } else { std::vector hcoo_row_ind; if(filename != "") { if(read_mtx_matrix(filename.c_str(), m, n, hnnz_A, hcoo_row_ind, hcsr_col_ind_A, hcsr_val_A, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { double scale = 0.02; if(m > 1000 || n > 1000) { scale = 2.0 / std::max(m, n); } hnnz_A = m * scale * n; gen_matrix_coo(m, n, hnnz_A, hcoo_row_ind, hcsr_col_ind_A, hcsr_val_A, idx_base); } // Convert COO to CSR hcsr_row_ptr_A.resize(m + 1, 0); for(int i = 0; i < hnnz_A; ++i) { ++hcsr_row_ptr_A[hcoo_row_ind[i] + 1 - idx_base]; } hcsr_row_ptr_A[0] = idx_base; for(int i = 0; i < m; ++i) { hcsr_row_ptr_A[i + 1] += hcsr_row_ptr_A[i]; } } // 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(); if(!dcsr_row_ptr_A || !dcsr_col_ind_A || !dcsr_val_A || !dcsr_row_ptr_C || !dnnz_per_row) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dcsr_row_ptr_A || !dcsr_col_ind_A || !dcsr_val_A || " "!dcsr_row_ptr_C || !dnnz_per_row"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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(); if(!dcsr_col_ind_C || !dcsr_val_C) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dcsr_col_ind_C || !dcsr_val_C"); return HIPSPARSE_STATUS_ALLOC_FAILED; } 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()); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSR2CSR_COMPRESS_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_csr2dense.hpp000066400000000000000000000035431447644345400234260ustar00rootroot00000000000000/* ************************************************************************ * 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_CSR2DENSE_HPP #define TESTING_CSR2DENSE_HPP #include "testing_csx2dense.hpp" template void testing_csr2dense_bad_arg(void) { static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_ROW; testing_csx2dense_bad_arg(hipsparseXcsr2dense); } template hipsparseStatus_t testing_csr2dense(Arguments argus) { static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_ROW; return testing_csx2dense(argus, hipsparseXcsr2dense, hipsparseXdense2csr); } #endif // TESTING_CSR2DENSE hipSPARSE-rocm-5.7.1/clients/include/testing_csr2gebsr.hpp000066400000000000000000000747641447644345400234470ustar00rootroot00000000000000/* ************************************************************************ * 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_CSR2GEBSR_HPP #define TESTING_CSR2GEBSR_HPP #include "hipsparse.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(void) { #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 = 100; 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(); auto bsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), 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(); if(!bsr_row_ptr || !bsr_col_ind || !bsr_val || !csr_row_ptr || !csr_col_ind || !csr_val) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } 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"); } { ARGSET; arg_p_buffer = nullptr; status = CALL_NNZ; verify_hipsparse_status_invalid_pointer(status, "Error: p_buffer 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"); } { ARGSET; arg_p_buffer = nullptr; status = CALL_FUNC; verify_hipsparse_status_invalid_pointer(status, "Error: p_buffer is nullptr"); } #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.idx_base; hipsparseIndexBase_t bsr_idx_base = argus.idx_base2; hipsparseDirection_t dir = argus.dirA; int row_block_dim = argus.row_block_dimA; int col_block_dim = argus.col_block_dimA; std::string binfile = ""; std::string filename = ""; hipsparseStatus_t status; // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu int safe_size = std::max(100, std::max(m, n)); if(m == -99 && n == -99 && argus.timing == 0) { binfile = argus.filename; m = n = safe_size; } if(argus.timing == 1) { 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) { #ifdef __HIP_PLATFORM_NVIDIA__ // Do not test cusparse with block dim 1 return HIPSPARSE_STATUS_SUCCESS; #endif } // Argument sanity check before allocating invalid memory if(m <= 0 || n <= 0 || row_block_dim <= 0 || col_block_dim <= 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // Do not test args in cusparse return HIPSPARSE_STATUS_SUCCESS; #endif auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), 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 dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), 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(); int* dbsr_col_ind = (int*)dbsr_col_ind_managed.get(); T* dbsr_val = (T*)dbsr_val_managed.get(); void* dbuffer = dbuffer_managed.get(); // row pointer must be valid CHECK_HIP_ERROR(hipMemset(dcsr_row_ptr, 0, sizeof(int) * (safe_size + 1))); if(!dcsr_row_ptr || !dcsr_col_ind || !dcsr_val || !dbsr_row_ptr || !dbsr_col_ind || !dbsr_val || !dbuffer) { verify_hipsparse_status_success( HIPSPARSE_STATUS_ALLOC_FAILED, "!dcsr_row_ptr || !dcsr_col_ind || !dcsr_val || " "!dbsr_row_ptr || !dbsr_col_ind || !dbsr_val || !dbuffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } size_t buffer_size; status = hipsparseXcsr2gebsr_bufferSize(handle, dir, m, n, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, row_block_dim, col_block_dim, &buffer_size); if(m < 0 || n < 0 || row_block_dim < 0 || col_block_dim < 0) { verify_hipsparse_status_invalid_size( status, "Error: m < 0 || n < 0 || row_block_dim < 0 || col_block_dim < 0"); } else { verify_hipsparse_status_success( status, "m >= 0 && n >= 0 && row_block_dim >= 0 && col_block_dim >= 0"); } int bsr_nnzb; status = hipsparseXcsr2gebsrNnz(handle, dir, m, n, csr_descr, dcsr_row_ptr, dcsr_col_ind, bsr_descr, dbsr_row_ptr, row_block_dim, col_block_dim, &bsr_nnzb, dbuffer); if(m < 0 || n < 0 || row_block_dim < 0 || col_block_dim < 0) { verify_hipsparse_status_invalid_size( status, "Error: m < 0 || n < 0 || row_block_dim < 0 || col_block_dim < 0"); } else { verify_hipsparse_status_success( status, "m >= 0 && n >= 0 && row_block_dim >= 0 && col_block_dim >= 0"); } status = 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); if(m < 0 || n < 0 || row_block_dim < 0 || col_block_dim < 0) { verify_hipsparse_status_invalid_size( status, "Error: m < 0 || n < 0 || row_block_dim < 0 || col_block_dim < 0"); } else { verify_hipsparse_status_success( status, "m >= 0 && n >= 0 && row_block_dim >= 0 && col_block_dim >= 0"); } return HIPSPARSE_STATUS_SUCCESS; } // Read or construct CSR matrix std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; int nnz; srand(12345ULL); if(binfile != "") { if(read_bin_matrix( binfile.c_str(), m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, csr_idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", binfile.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else if(argus.laplacian) { m = n = gen_2d_laplacian(argus.laplacian, hcsr_row_ptr, hcsr_col_ind, hcsr_val, csr_idx_base); nnz = hcsr_row_ptr[m]; } else { std::vector coo_row_ind; if(filename != "") { if(read_mtx_matrix( filename.c_str(), m, n, nnz, coo_row_ind, hcsr_col_ind, hcsr_val, csr_idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { double scale = 0.02; if(m > 1000 || n > 1000) { scale = 2.0 / std::max(m, n); } nnz = m * scale * n; nnz = std::max(nnz, 1); gen_matrix_coo(m, n, nnz, coo_row_ind, hcsr_col_ind, hcsr_val, csr_idx_base); } // Convert COO to CSR hcsr_row_ptr.resize(m + 1, 0); for(int i = 0; i < nnz; ++i) { ++hcsr_row_ptr[coo_row_ind[i] + 1 - csr_idx_base]; } hcsr_row_ptr[0] = csr_idx_base; for(int i = 0; i < m; ++i) { hcsr_row_ptr[i + 1] += hcsr_row_ptr[i]; } } int mb = (m + row_block_dim - 1) / row_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(); if(!dcsr_row_ptr || !dcsr_col_ind || !dcsr_val || !dbsr_row_ptr) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dcsr_row_ptr || !dcsr_col_ind || !dcsr_val || " "!dbsr_row_ptr"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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(); if(argus.unit_check) { // 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(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)); #if 0 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(hipsparseXcsr2gebsrNnz(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); #endif // 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(!dbsr_col_ind || !dbsr_val) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!bsr_col_ind || !bsr_val"); return HIPSPARSE_STATUS_ALLOC_FAILED; } 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()); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSR2GEBSR_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_csr2hyb.hpp000066400000000000000000000444411447644345400231140ustar00rootroot00000000000000/* ************************************************************************ * 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_CSR2HYB_HPP #define TESTING_CSR2HYB_HPP #include "hipsparse.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) struct test_hyb { 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 void testing_csr2hyb_bad_arg(void) { int m = 100; int n = 100; int safe_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; 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(); if(!csr_row_ptr || !csr_col_ind || !csr_val) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // Testing for(csr_row_ptr == nullptr) { int* csr_row_ptr_null = nullptr; status = hipsparseXcsr2hyb(handle, m, n, descr, csr_val, csr_row_ptr_null, csr_col_ind, hyb, 0, HIPSPARSE_HYB_PARTITION_AUTO); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr is nullptr"); } // Testing for(csr_col_ind == nullptr) { int* csr_col_ind_null = nullptr; status = hipsparseXcsr2hyb(handle, m, n, descr, csr_val, csr_row_ptr, csr_col_ind_null, hyb, 0, HIPSPARSE_HYB_PARTITION_AUTO); verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind is nullptr"); } // Testing for(csr_val == nullptr) { T* csr_val_null = nullptr; status = hipsparseXcsr2hyb(handle, m, n, descr, csr_val_null, csr_row_ptr, csr_col_ind, hyb, 0, HIPSPARSE_HYB_PARTITION_AUTO); verify_hipsparse_status_invalid_pointer(status, "Error: csr_val is nullptr"); } // Testing for(handle == nullptr) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXcsr2hyb(handle_null, m, n, descr, csr_val, csr_row_ptr, csr_col_ind, hyb, 0, HIPSPARSE_HYB_PARTITION_AUTO); verify_hipsparse_status_invalid_handle(status); } } template hipsparseStatus_t testing_csr2hyb(Arguments argus) { int m = argus.M; int n = argus.N; int safe_size = 100; hipsparseIndexBase_t idx_base = argus.idx_base; hipsparseHybPartition_t part = argus.part; int user_ell_width = argus.ell_width; std::string binfile = ""; std::string filename = ""; hipsparseStatus_t status; // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu if(m == -99 && n == -99 && argus.timing == 0) { binfile = argus.filename; m = n = safe_size; } if(argus.timing == 1) { filename = argus.filename; } double scale = 0.02; if(m > 1000 || n > 1000) { scale = 2.0 / std::max(m, n); } int nnz = m * scale * n; 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; // Argument sanity check before allocating invalid memory if(m <= 0 || n <= 0 || nnz <= 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 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(); if(!csr_row_ptr || !csr_col_ind || !csr_val) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!csr_row_ptr || !csr_col_ind || !csr_val"); return HIPSPARSE_STATUS_ALLOC_FAILED; } status = hipsparseXcsr2hyb( handle, m, n, descr, csr_val, csr_row_ptr, csr_col_ind, hyb, user_ell_width, part); if(m < 0 || n < 0) { verify_hipsparse_status_invalid_size(status, "Error: m < 0 || n < 0"); } else { verify_hipsparse_status_success(status, "m >= 0 && n >= 0"); } return HIPSPARSE_STATUS_SUCCESS; } // For testing, assemble a COO matrix and convert it to CSR first (on host) // Host structures std::vector hcsr_row_ptr; std::vector hcoo_row_ind; std::vector hcsr_col_ind; std::vector hcsr_val; // Sample initial COO matrix on CPU srand(12345ULL); if(binfile != "") { if(read_bin_matrix( binfile.c_str(), m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", binfile.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else if(argus.laplacian) { m = n = gen_2d_laplacian(argus.laplacian, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base); nnz = hcsr_row_ptr[m]; } else { if(filename != "") { if(read_mtx_matrix( filename.c_str(), m, n, nnz, hcoo_row_ind, hcsr_col_ind, hcsr_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { gen_matrix_coo(m, n, nnz, hcoo_row_ind, hcsr_col_ind, hcsr_val, idx_base); } // Convert COO to CSR hcsr_row_ptr.resize(m + 1, 0); for(int i = 0; i < nnz; ++i) { ++hcsr_row_ptr[hcoo_row_ind[i] + 1 - idx_base]; } hcsr_row_ptr[0] = idx_base; for(int i = 0; i < m; ++i) { hcsr_row_ptr[i + 1] += hcsr_row_ptr[i]; } } // 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(); if(!dcsr_row_ptr || !dcsr_col_ind || !dcsr_val) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dcsr_row_ptr || !dcsr_col_ind || !dcsr_val"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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 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 test_hyb* dhyb = (test_hyb*)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()); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSR2HYB_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_csrcolor.hpp000066400000000000000000000325471447644345400233720ustar00rootroot00000000000000/* ************************************************************************ * 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_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; if(!d_csr_row_ptr || !d_csr_col_ind || !d_csr_val) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } 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() { // Determine absolute path of test matrix // Matrices are stored at the same path in matrices directory std::string filename = get_filename("nos3.bin"); // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_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(read_bin_matrix(filename.c_str(), m, k, nnz, hrow_ptr, hcol_ind, hval, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", 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(); if(!dval || !drow_ptr || !dcol_ind || !dcoloring || !dreordering) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dval || !drow || !dcol || !dB || " "!dC_1 || !dC_2 || !d_alpha || !d_beta"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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); return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRCOLOR_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_csrgeam.hpp000066400000000000000000002010441447644345400231530ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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 = 100; 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), 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), 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), 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(); if(!dAval || !dAptr || !dAcol || !dBval || !dBptr || !dBcol || !dCval || !dCptr || !dCcol) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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) { int safe_size = 100; 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.idx_base; hipsparseIndexBase_t idx_base_B = argus.idx_base2; hipsparseIndexBase_t idx_base_C = argus.idx_base3; std::string binfile = ""; std::string filename = ""; hipsparseStatus_t status; // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu if(M == -99 && N == -99 && argus.timing == 0) { binfile = argus.filename; M = N = safe_size; } if(argus.timing == 1) { filename = argus.filename; } std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; std::unique_ptr test_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = test_descr_A->descr; std::unique_ptr test_descr_B(new descr_struct); hipsparseMatDescr_t descr_B = test_descr_B->descr; std::unique_ptr test_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = test_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)); // Determine number of non-zero elements double scale = 0.02; if(M > 1000 || N > 1000) { scale = 2.0 / std::max(M, N); } int nnz_A = M * scale * N; scale = 0.02; if(M > 1000 || N > 1000) { scale = 2.0 / std::max(M, N); } int nnz_B = M * scale * N; // Argument sanity check before allocating invalid memory if(M <= 0 || N <= 0 || nnz_A <= 0 || nnz_B <= 0) { auto dAptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), 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), 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), 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(); if(!dAval || !dAptr || !dAcol || !dBval || !dBptr || !dBcol || !dCval || !dCptr || !dCcol) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dAptr || !dAcol || !dAval || " "!dBptr || !dBcol || !dBval || " "!dCptr || !dCcol || !dCval"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // Test hipsparseXcsrgeamNnz int nnz_C; status = hipsparseXcsrgeamNnz(handle, M, N, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, descr_C, dCptr, &nnz_C); if(M < 0 || N < 0 || nnz_A < 0 || nnz_B < 0) { verify_hipsparse_status_invalid_size(status, "Error: M < 0 || N < 0 || nnz_A < 0 || nnz_B < 0"); } else { verify_hipsparse_status_success(status, "M >= 0 && N >= 0 && nnz_A >= 0 && nnz_B >= 0"); } // Test hipsparseXcsrgeam status = 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, dCptr, dCcol); if(M < 0 || N < 0 || nnz_A < 0 || nnz_B < 0) { verify_hipsparse_status_invalid_size(status, "Error: M < 0 || N < 0 || nnz_A < 0 || nnz_B < 0"); } else { verify_hipsparse_status_success(status, "M >= 0 && N >= 0 && nnz_A >= 0 && nnz_B >= 0"); } return HIPSPARSE_STATUS_SUCCESS; } // 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); if(binfile != "") { if(read_bin_matrix( binfile.c_str(), M, N, nnz_A, hcsr_row_ptr_A, hcsr_col_ind_A, hcsr_val_A, idx_base_A) != 0) { fprintf(stderr, "Cannot open [read] %s\n", binfile.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else if(argus.laplacian) { M = N = gen_2d_laplacian( argus.laplacian, hcsr_row_ptr_A, hcsr_col_ind_A, hcsr_val_A, idx_base_A); nnz_A = hcsr_row_ptr_A[M]; } else { std::vector hcoo_row_ind; if(filename != "") { if(read_mtx_matrix(filename.c_str(), M, N, nnz_A, hcoo_row_ind, hcsr_col_ind_A, hcsr_val_A, idx_base_A) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { gen_matrix_coo(M, N, nnz_A, hcoo_row_ind, hcsr_col_ind_A, hcsr_val_A, idx_base_A); } // Convert COO to CSR hcsr_row_ptr_A.resize(M + 1, 0); for(int i = 0; i < nnz_A; ++i) { ++hcsr_row_ptr_A[hcoo_row_ind[i] + 1 - idx_base_A]; } hcsr_row_ptr_A[0] = idx_base_A; for(int i = 0; i < M; ++i) { hcsr_row_ptr_A[i + 1] += hcsr_row_ptr_A[i]; } // TODO samples B matrix instead of squaring } // B = A 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(); if(!dAval || !dAptr || !dAcol || !dBval || !dBptr || !dBcol || !dCptr_1 || !dCptr_2) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dAval || !dAptr || !dAcol || " "!dBval || !dBptr || !dBcol || !dCptr_1 || !dCptr_2"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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)); // csrgeam nnz // 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(); if(!dCval_1 || !dCcol_1 || !dCval_2 || !dCcol_2) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dCval_1 || !dCcol_1 || !dCval_2 || !dCcol_2"); return HIPSPARSE_STATUS_ALLOC_FAILED; } if(argus.unit_check) { // 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)); // Compute csrgeam host solution std::vector hcsr_row_ptr_C_gold(M + 1); double cpu_time_used = get_time_us(); 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); 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 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(nnz_C_gold); std::vector hcsr_val_C_1(nnz_C_gold); std::vector hcsr_row_ptr_C_2(M + 1); std::vector hcsr_col_ind_C_2(nnz_C_gold); std::vector hcsr_val_C_2(nnz_C_gold); 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) * nnz_C_gold, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val_C_1.data(), dCval_1, sizeof(T) * nnz_C_gold, 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) * nnz_C_gold, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val_C_2.data(), dCval_2, sizeof(T) * nnz_C_gold, hipMemcpyDeviceToHost)); // 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()); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRGEAM_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_csrgeam2.hpp000066400000000000000000002201011447644345400232300ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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 = 100; 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), 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), 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), 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(); if(!dAval || !dAptr || !dAcol || !dBval || !dBptr || !dBcol || !dCval || !dCptr || !dCcol || !dbuffer) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int safe_size = 100; int M = argus.M; int N = argus.N; hipsparseIndexBase_t idx_base_A = argus.idx_base; hipsparseIndexBase_t idx_base_B = argus.idx_base2; hipsparseIndexBase_t idx_base_C = argus.idx_base3; std::string binfile = ""; std::string filename = ""; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseStatus_t status; size_t size; // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu if(M == -99 && N == -99 && argus.timing == 0) { binfile = argus.filename; M = N = safe_size; } if(argus.timing == 1) { filename = argus.filename; } std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; std::unique_ptr test_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = test_descr_A->descr; std::unique_ptr test_descr_B(new descr_struct); hipsparseMatDescr_t descr_B = test_descr_B->descr; std::unique_ptr test_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = test_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)); // Determine number of non-zero elements double scale = 0.02; if(M > 1000 || N > 1000) { scale = 2.0 / std::max(M, N); } int nnz_A = M * scale * N; scale = 0.02; if(M > 1000 || N > 1000) { scale = 2.0 / std::max(M, N); } int nnz_B = M * scale * N; // Argument sanity check before allocating invalid memory if(M <= 0 || N <= 0 || nnz_A <= 0 || nnz_B <= 0) { #ifdef __HIP_PLATFORM_NVIDIA__ return HIPSPARSE_STATUS_SUCCESS; #endif auto dAptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), 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), 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), 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(); if(!dAval || !dAptr || !dAcol || !dBval || !dBptr || !dBcol || !dCval || !dCptr || !dCcol || !dbuffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dAptr || !dAcol || !dAval || " "!dBptr || !dBcol || !dBval || " "!dCptr || !dCcol || !dCval || " "!dbuffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // hipsparseXcsrgeam2_bufferSizeExt must be successful, as there is no implementation // in rocsparse verify_hipsparse_status_success(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, dCval, dCptr, dCcol, &size), ""); // Test hipsparseXcsrgeam2Nnz int nnz_C; status = hipsparseXcsrgeam2Nnz(handle, M, N, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, descr_C, dCptr, &nnz_C, dbuffer); if(M < 0 || N < 0 || nnz_A < 0 || nnz_B < 0) { verify_hipsparse_status_invalid_size(status, "Error: M < 0 || N < 0 || nnz_A < 0 || nnz_B < 0"); } else { verify_hipsparse_status_success(status, "M >= 0 && N >= 0 && nnz_A >= 0 && nnz_B >= 0"); } // Test hipsparseXcsrgeam2 status = 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, dCptr, dCcol, dbuffer); if(M < 0 || N < 0 || nnz_A < 0 || nnz_B < 0) { verify_hipsparse_status_invalid_size(status, "Error: M < 0 || N < 0 || nnz_A < 0 || nnz_B < 0"); } else { verify_hipsparse_status_success(status, "M >= 0 && N >= 0 && nnz_A >= 0 && nnz_B >= 0"); } return HIPSPARSE_STATUS_SUCCESS; } // 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); if(binfile != "") { if(read_bin_matrix( binfile.c_str(), M, N, nnz_A, hcsr_row_ptr_A, hcsr_col_ind_A, hcsr_val_A, idx_base_A) != 0) { fprintf(stderr, "Cannot open [read] %s\n", binfile.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else if(argus.laplacian) { M = N = gen_2d_laplacian( argus.laplacian, hcsr_row_ptr_A, hcsr_col_ind_A, hcsr_val_A, idx_base_A); nnz_A = hcsr_row_ptr_A[M]; } else { std::vector hcoo_row_ind; if(filename != "") { if(read_mtx_matrix(filename.c_str(), M, N, nnz_A, hcoo_row_ind, hcsr_col_ind_A, hcsr_val_A, idx_base_A) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { gen_matrix_coo(M, N, nnz_A, hcoo_row_ind, hcsr_col_ind_A, hcsr_val_A, idx_base_A); } // Convert COO to CSR hcsr_row_ptr_A.resize(M + 1, 0); for(int i = 0; i < nnz_A; ++i) { ++hcsr_row_ptr_A[hcoo_row_ind[i] + 1 - idx_base_A]; } hcsr_row_ptr_A[0] = idx_base_A; for(int i = 0; i < M; ++i) { hcsr_row_ptr_A[i + 1] += hcsr_row_ptr_A[i]; } // TODO samples B matrix instead of squaring } // B = A so that we can compute the square of A 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(); int* dCcol_1 = nullptr; T* dCval_1 = nullptr; T* dalpha = (T*)dalpha_managed.get(); T* dbeta = (T*)dbeta_managed.get(); if(!dAval || !dAptr || !dAcol || !dBval || !dBptr || !dBcol || !dCptr_1 || !dCptr_2 || !dalpha || !dbeta) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dAval || !dAptr || !dAcol || " "!dBval || !dBptr || !dBcol || " "!dCptr_1 || !dCptr_2 || !dalpha || !dbeta"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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 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, dCval_1, dCptr_1, dCcol_1, &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(); if(!dbuffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dbuffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // csrgeam2 nnz // 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}; dCcol_1 = (int*)dCcol_1_managed.get(); dCval_1 = (T*)dCval_1_managed.get(); if(!dCval_1 || !dCcol_1) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dCval || !dCcol"); return HIPSPARSE_STATUS_ALLOC_FAILED; } if(argus.unit_check) { 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; T* dCval_2; dCcol_2 = (int*)dCcol_2_managed.get(); 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)); // 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); // 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 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(nnz_C_gold); std::vector hcsr_col_ind_C_2(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_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) * nnz_C_gold, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcsr_col_ind_C_2.data(), dCcol_2, sizeof(int) * nnz_C_gold, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val_C_1.data(), dCval_1, sizeof(T) * nnz_C_gold, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val_C_2.data(), dCval_2, sizeof(T) * nnz_C_gold, hipMemcpyDeviceToHost)); // 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()); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRGEAM2_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_csrgemm.hpp000066400000000000000000001413061447644345400231730ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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 = 100; int N = 100; int K = 100; int nnz_A = 100; int nnz_B = 100; hipsparseOperation_t trans_A = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t trans_B = HIPSPARSE_OPERATION_NON_TRANSPOSE; int safe_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_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), 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), 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), 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(); if(!dAval || !dAptr || !dAcol || !dBval || !dBptr || !dBcol || !dCval || !dCptr || !dCcol) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // testing hipsparseXcsrgemmNnz int nnz_C; // testing for(nullptr == dAptr) { int* dAptr_null = nullptr; status = hipsparseXcsrgemmNnz(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAptr_null, dAcol, descr_B, nnz_B, dBptr, dBcol, descr_C, dCptr, &nnz_C); verify_hipsparse_status_invalid_pointer(status, "Error: dAptr is nullptr"); } // testing for(nullptr == dAcol) { int* dAcol_null = nullptr; status = hipsparseXcsrgemmNnz(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAptr, dAcol_null, descr_B, nnz_B, dBptr, dBcol, descr_C, dCptr, &nnz_C); verify_hipsparse_status_invalid_pointer(status, "Error: dAcol is nullptr"); } // testing for(nullptr == dBptr) { int* dBptr_null = nullptr; status = hipsparseXcsrgemmNnz(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr_null, dBcol, descr_C, dCptr, &nnz_C); verify_hipsparse_status_invalid_pointer(status, "Error: dBptr is nullptr"); } // testing for(nullptr == dBcol) { int* dBcol_null = nullptr; status = hipsparseXcsrgemmNnz(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol_null, descr_C, dCptr, &nnz_C); verify_hipsparse_status_invalid_pointer(status, "Error: dBcol is nullptr"); } // testing for(nullptr == dCptr) { int* dCptr_null = nullptr; status = hipsparseXcsrgemmNnz(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, descr_C, dCptr_null, &nnz_C); verify_hipsparse_status_invalid_pointer(status, "Error: dCptr is nullptr"); } // testing for(nullptr == nnz_C) { int* nnz_C_null = nullptr; status = hipsparseXcsrgemmNnz(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, descr_C, dCptr, nnz_C_null); verify_hipsparse_status_invalid_pointer(status, "Error: nnz_C is nullptr"); } // testing for(nullptr == descr_A) { hipsparseMatDescr_t descr_A_null = nullptr; status = hipsparseXcsrgemmNnz(handle, trans_A, trans_B, M, N, K, descr_A_null, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, descr_C, dCptr, &nnz_C); verify_hipsparse_status_invalid_pointer(status, "Error: descr_A is nullptr"); } // testing for(nullptr == descr_B) { hipsparseMatDescr_t descr_B_null = nullptr; status = hipsparseXcsrgemmNnz(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B_null, nnz_B, dBptr, dBcol, descr_C, dCptr, &nnz_C); verify_hipsparse_status_invalid_pointer(status, "Error: descr_B is nullptr"); } // testing for(nullptr == descr_C) { hipsparseMatDescr_t descr_C_null = nullptr; status = hipsparseXcsrgemmNnz(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, descr_C_null, dCptr, &nnz_C); verify_hipsparse_status_invalid_pointer(status, "Error: descr_C is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXcsrgemmNnz(handle_null, 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_handle(status); } // testing hipsparseXcsrgemm // testing for(nullptr == dAval) { T* dAval_null = nullptr; status = hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAval_null, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol); verify_hipsparse_status_invalid_pointer(status, "Error: dAval is nullptr"); } // testing for(nullptr == dAptr) { int* dAptr_null = nullptr; status = hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAval, dAptr_null, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol); verify_hipsparse_status_invalid_pointer(status, "Error: dAptr is nullptr"); } // testing for(nullptr == dAcol) { int* dAcol_null = nullptr; status = hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAval, dAptr, dAcol_null, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol); verify_hipsparse_status_invalid_pointer(status, "Error: dAcol is nullptr"); } // testing for(nullptr == dBval) { T* dBval_null = nullptr; status = hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval_null, dBptr, dBcol, descr_C, dCval, dCptr, dCcol); verify_hipsparse_status_invalid_pointer(status, "Error: dBval is nullptr"); } // testing for(nullptr == dBptr) { int* dBptr_null = nullptr; status = hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr_null, dBcol, descr_C, dCval, dCptr, dCcol); verify_hipsparse_status_invalid_pointer(status, "Error: dBptr is nullptr"); } // testing for(nullptr == dBcol) { int* dBcol_null = nullptr; status = hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol_null, descr_C, dCval, dCptr, dCcol); verify_hipsparse_status_invalid_pointer(status, "Error: dBcol is nullptr"); } // testing for(nullptr == dCval) { T* dCval_null = nullptr; status = 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_null, dCptr, dCcol); verify_hipsparse_status_invalid_pointer(status, "Error: dCval is nullptr"); } // testing for(nullptr == dCptr) { int* dCptr_null = nullptr; status = 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_null, dCcol); verify_hipsparse_status_invalid_pointer(status, "Error: dCptr is nullptr"); } // testing for(nullptr == dCcol) { int* dCcol_null = nullptr; status = 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_null); verify_hipsparse_status_invalid_pointer(status, "Error: dCcol is nullptr"); } // testing for(nullptr == descr_A) { hipsparseMatDescr_t descr_A_null = nullptr; status = hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, descr_A_null, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol); verify_hipsparse_status_invalid_pointer(status, "Error: descr_A is nullptr"); } // testing for(nullptr == descr_B) { hipsparseMatDescr_t descr_B_null = nullptr; status = hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B_null, nnz_B, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol); verify_hipsparse_status_invalid_pointer(status, "Error: descr_B is nullptr"); } // testing for(nullptr == descr_C) { hipsparseMatDescr_t descr_C_null = nullptr; status = 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_null, dCval, dCptr, dCcol); verify_hipsparse_status_invalid_pointer(status, "Error: descr_C is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXcsrgemm(handle_null, 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); verify_hipsparse_status_invalid_handle(status); } #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) { int safe_size = 100; 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.idx_base; hipsparseIndexBase_t idx_base_B = argus.idx_base2; hipsparseIndexBase_t idx_base_C = argus.idx_base3; std::string binfile = ""; std::string filename = ""; hipsparseStatus_t status; // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu if(M == -99 && N == -99 && K == -99 && argus.timing == 0) { binfile = argus.filename; M = N = K = safe_size; } if(argus.timing == 1) { filename = argus.filename; } std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; std::unique_ptr test_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = test_descr_A->descr; std::unique_ptr test_descr_B(new descr_struct); hipsparseMatDescr_t descr_B = test_descr_B->descr; std::unique_ptr test_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = test_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)); // Determine number of non-zero elements double scale = 0.02; if(M > 1000 || K > 1000) { scale = 2.0 / std::max(M, K); } int nnz_A = M * scale * K; scale = 0.02; if(K > 1000 || N > 1000) { scale = 2.0 / std::max(K, N); } int nnz_B = K * scale * N; // Argument sanity check before allocating invalid memory if(M <= 0 || N <= 0 || K <= 0 || nnz_A <= 0 || nnz_B <= 0) { auto dAptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), 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), 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), 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(); if(!dAval || !dAptr || !dAcol || !dBval || !dBptr || !dBcol || !dCval || !dCptr || !dCcol) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dAptr || !dAcol || !dAval || " "!dBptr || !dBcol || !dBval || " "!dCptr || !dCcol || !dCval"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // Test hipsparseXcsrgemmNnz int nnz_C; status = hipsparseXcsrgemmNnz(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, descr_C, dCptr, &nnz_C); if(M < 0 || N < 0 || K < 0 || nnz_A < 0 || nnz_B < 0) { verify_hipsparse_status_invalid_size( status, "Error: M < 0 || N < 0 || K < 0 || nnz_A < 0 || nnz_B < 0"); } else { verify_hipsparse_status_success( status, "M >= 0 && N >= 0 && K >= 0 && nnz_A >= 0 && nnz_B >= 0"); } // Test hipsparseXcsrgemm status = 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); if(M < 0 || N < 0 || K < 0 || nnz_A < 0 || nnz_B < 0) { verify_hipsparse_status_invalid_size( status, "Error: M < 0 || N < 0 || K < 0 || nnz_A < 0 || nnz_B < 0"); } else { verify_hipsparse_status_success( status, "M >= 0 && N >= 0 && K >= 0 && nnz_A >= 0 && nnz_B >= 0"); } return HIPSPARSE_STATUS_SUCCESS; } // 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); if(binfile != "") { if(read_bin_matrix( binfile.c_str(), M, K, nnz_A, hcsr_row_ptr_A, hcsr_col_ind_A, hcsr_val_A, idx_base_A) != 0) { fprintf(stderr, "Cannot open [read] %s\n", binfile.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else if(argus.laplacian) { M = K = gen_2d_laplacian( argus.laplacian, hcsr_row_ptr_A, hcsr_col_ind_A, hcsr_val_A, idx_base_A); nnz_A = hcsr_row_ptr_A[M]; } else { std::vector hcoo_row_ind; if(filename != "") { if(read_mtx_matrix(filename.c_str(), M, K, nnz_A, hcoo_row_ind, hcsr_col_ind_A, hcsr_val_A, idx_base_A) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { gen_matrix_coo(M, K, nnz_A, hcoo_row_ind, hcsr_col_ind_A, hcsr_val_A, idx_base_A); } // Convert COO to CSR hcsr_row_ptr_A.resize(M + 1, 0); for(int i = 0; i < nnz_A; ++i) { ++hcsr_row_ptr_A[hcoo_row_ind[i] + 1 - idx_base_A]; } hcsr_row_ptr_A[0] = idx_base_A; for(int i = 0; i < M; ++i) { hcsr_row_ptr_A[i + 1] += hcsr_row_ptr_A[i]; } // TODO samples B matrix instead of squaring } // B = A^T so that we can compute the square of A N = M; 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(); if(!dAval || !dAptr || !dAcol || !dBval || !dBptr || !dBcol || !dCptr) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dAval || !dAptr || !dAcol || " "!dBval || !dBptr || !dBcol || !dCptr"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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(); if(!dCval || !dCcol) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dCval || !dCcol"); return HIPSPARSE_STATUS_ALLOC_FAILED; } 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(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)); // Compute csrgemm host solution std::vector hcsr_row_ptr_C_gold(M + 1); double cpu_time_used = get_time_us(); 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); 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 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(nnz_C_gold); std::vector hcsr_val_C(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.data(), dCval, sizeof(T) * nnz_C_gold, hipMemcpyDeviceToHost)); // 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()); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRGEMM_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_csrgemm2_a.hpp000066400000000000000000002357661447644345400235730ustar00rootroot00000000000000/* ************************************************************************ * 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_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 = 100; int N = 100; int K = 100; int nnz_A = 100; int nnz_B = 100; int safe_size = 100; T alpha = 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_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), 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), 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), 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(); if(!dAval || !dAptr || !dAcol || !dBval || !dBptr || !dBcol || !dCval || !dCptr || !dCcol || !dbuffer) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // Scenario: alpha != 0 and beta == 0 // testing hipsparseXcsrgemm2_bufferSizeExt // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXcsrgemm2_bufferSizeExt(handle_null, 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_handle(status); } // testing for(nullptr == alpha) { T* alpha_null = nullptr; status = hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, K, alpha_null, 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(status, "Error: alpha is nullptr"); } // testing for(nullptr == descr_A) { hipsparseMatDescr_t descr_A_null = nullptr; status = hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, K, &alpha, descr_A_null, 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(status, "Error: descr_A is nullptr"); } // testing for(nullptr == dAptr) { int* dAptr_null = nullptr; status = hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, K, &alpha, descr_A, nnz_A, dAptr_null, dAcol, descr_B, nnz_B, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (int*)nullptr, (int*)nullptr, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: dAptr is nullptr"); } // testing for(nullptr == dAcol) { int* dAcol_null = nullptr; status = hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, K, &alpha, descr_A, nnz_A, dAptr, dAcol_null, descr_B, nnz_B, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (int*)nullptr, (int*)nullptr, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: dAcol is nullptr"); } // testing for(nullptr == descr_B) { hipsparseMatDescr_t descr_B_null = nullptr; status = hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, K, &alpha, descr_A, nnz_A, dAptr, dAcol, descr_B_null, nnz_B, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (int*)nullptr, (int*)nullptr, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: descr_B is nullptr"); } // testing for(nullptr == dBptr) { int* dBptr_null = nullptr; status = hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, K, &alpha, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr_null, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (int*)nullptr, (int*)nullptr, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: dBptr is nullptr"); } // testing for(nullptr == dBcol) { int* dBcol_null = nullptr; status = hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, K, &alpha, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol_null, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (int*)nullptr, (int*)nullptr, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: dBcol is nullptr"); } // testing for(nullptr == info) { csrgemm2Info_t info_null = nullptr; status = 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_null, &size); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing for(nullptr == size) { size_t* size_null = nullptr; status = 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_null); verify_hipsparse_status_invalid_pointer(status, "Error: size is nullptr"); } // testing hipsparseXcsrgemm2Nnz // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXcsrgemm2Nnz(handle_null, 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_handle(status); } // testing for(nullptr == descr_A) { hipsparseMatDescr_t descr_A_null = nullptr; status = hipsparseXcsrgemm2Nnz(handle, M, N, K, descr_A_null, 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(status, "Error: descr_A is nullptr"); } // testing for(nullptr == dAptr) { int* dAptr_null = nullptr; status = hipsparseXcsrgemm2Nnz(handle, M, N, K, descr_A, nnz_A, dAptr_null, dAcol, descr_B, nnz_B, dBptr, dBcol, nullptr, 0, nullptr, nullptr, descr_C, dCptr, &nnz_C, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dAptr is nullptr"); } // testing for(nullptr == dAcol) { int* dAcol_null = nullptr; status = hipsparseXcsrgemm2Nnz(handle, M, N, K, descr_A, nnz_A, dAptr, dAcol_null, descr_B, nnz_B, dBptr, dBcol, nullptr, 0, nullptr, nullptr, descr_C, dCptr, &nnz_C, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dAcol is nullptr"); } // testing for(nullptr == descr_B) { hipsparseMatDescr_t descr_B_null = nullptr; status = hipsparseXcsrgemm2Nnz(handle, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B_null, nnz_B, dBptr, dBcol, nullptr, 0, nullptr, nullptr, descr_C, dCptr, &nnz_C, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_B is nullptr"); } // testing for(nullptr == dBptr) { int* dBptr_null = nullptr; status = hipsparseXcsrgemm2Nnz(handle, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr_null, dBcol, nullptr, 0, nullptr, nullptr, descr_C, dCptr, &nnz_C, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dBptr is nullptr"); } // testing for(nullptr == dBcol) { int* dBcol_null = nullptr; status = hipsparseXcsrgemm2Nnz(handle, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol_null, nullptr, 0, nullptr, nullptr, descr_C, dCptr, &nnz_C, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dBcol is nullptr"); } // testing for(nullptr == descr_C) { hipsparseMatDescr_t descr_C_null = nullptr; status = hipsparseXcsrgemm2Nnz(handle, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, nullptr, 0, nullptr, nullptr, descr_C_null, dCptr, &nnz_C, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_C is nullptr"); } // testing for(nullptr == dCptr) { int* dCptr_null = nullptr; status = hipsparseXcsrgemm2Nnz(handle, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, nullptr, 0, nullptr, nullptr, descr_C, dCptr_null, &nnz_C, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dCptr is nullptr"); } // testing for(nullptr == nnz_C) { int* nnz_C_null = nullptr; status = 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_null, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: nnz_C is nullptr"); } // testing for(nullptr == info) { csrgemm2Info_t info_null = nullptr; status = 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_null, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing for(nullptr == dbuffer) { void* dbuffer_null = nullptr; status = 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, dbuffer_null); verify_hipsparse_status_invalid_pointer(status, "Error: dbuffer is nullptr"); } // testing hipsparseXcsrgemm2 // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXcsrgemm2(handle_null, 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_handle(status); } // testing for(nullptr == alpha) { T* alpha_null = nullptr; status = hipsparseXcsrgemm2(handle, M, N, K, alpha_null, 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(status, "Error: alpha is nullptr"); } // testing for(nullptr == descr_A) { hipsparseMatDescr_t descr_A_null = nullptr; status = hipsparseXcsrgemm2(handle, M, N, K, &alpha, descr_A_null, 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(status, "Error: descr_A is nullptr"); } // testing for(nullptr == dAval) { T* dAval_null = nullptr; status = hipsparseXcsrgemm2(handle, M, N, K, &alpha, descr_A, nnz_A, dAval_null, 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(status, "Error: dAval is nullptr"); } // testing for(nullptr == dAptr) { int* dAptr_null = nullptr; status = hipsparseXcsrgemm2(handle, M, N, K, &alpha, descr_A, nnz_A, dAval, dAptr_null, 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(status, "Error: dAptr is nullptr"); } // testing for(nullptr == dAcol) { int* dAcol_null = nullptr; status = hipsparseXcsrgemm2(handle, M, N, K, &alpha, descr_A, nnz_A, dAval, dAptr, dAcol_null, 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(status, "Error: dAcol is nullptr"); } // testing for(nullptr == descr_B) { hipsparseMatDescr_t descr_B_null = nullptr; status = hipsparseXcsrgemm2(handle, M, N, K, &alpha, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B_null, 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(status, "Error: descr_B is nullptr"); } // testing for(nullptr == dBval) { T* dBval_null = nullptr; status = hipsparseXcsrgemm2(handle, M, N, K, &alpha, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval_null, 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(status, "Error: dBval is nullptr"); } // testing for(nullptr == dBptr) { int* dBptr_null = nullptr; status = hipsparseXcsrgemm2(handle, M, N, K, &alpha, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr_null, 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(status, "Error: dBptr is nullptr"); } // testing for(nullptr == dBcol) { int* dBcol_null = nullptr; status = hipsparseXcsrgemm2(handle, M, N, K, &alpha, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol_null, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (T*)nullptr, (int*)nullptr, (int*)nullptr, descr_C, dCval, dCptr, dCcol, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dBcol is nullptr"); } // testing for(nullptr == descr_C) { hipsparseMatDescr_t descr_C_null = nullptr; status = 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_null, dCval, dCptr, dCcol, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_C is nullptr"); } // testing for(nullptr == dCval) { T* dCval_null = nullptr; status = 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_null, dCptr, dCcol, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dCval is nullptr"); } // testing for(nullptr == dCptr) { int* dCptr_null = nullptr; status = 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_null, dCcol, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dCptr is nullptr"); } // testing for(nullptr == dCcol) { int* dCcol_null = nullptr; status = 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_null, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dCcol is nullptr"); } // testing for(nullptr == info) { csrgemm2Info_t info_null = nullptr; status = 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_null, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing for(nullptr == dbuffer) { void* dbuffer_null = nullptr; status = 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, dbuffer_null); verify_hipsparse_status_invalid_pointer(status, "Error: dbuffer is nullptr"); } #endif } template hipsparseStatus_t testing_csrgemm2_a(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int safe_size = 100; int M = argus.M; int N = argus.N; int K = argus.K; hipsparseIndexBase_t idx_base_A = argus.idx_base; hipsparseIndexBase_t idx_base_B = argus.idx_base2; hipsparseIndexBase_t idx_base_C = argus.idx_base3; std::string binfile = ""; std::string filename = ""; T alpha = make_DataType(argus.alpha); hipsparseStatus_t status; size_t size; T* h_alpha = α // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu if(M == -99 && N == -99 && K == -99 && argus.timing == 0) { binfile = argus.filename; M = N = K = safe_size; } if(argus.timing == 1) { filename = argus.filename; } std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; std::unique_ptr test_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = test_descr_A->descr; std::unique_ptr test_descr_B(new descr_struct); hipsparseMatDescr_t descr_B = test_descr_B->descr; std::unique_ptr test_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = test_descr_C->descr; std::unique_ptr test_descr_D(new descr_struct); hipsparseMatDescr_t descr_D = test_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)); // Determine number of non-zero elements double scale = 0.02; if(M > 1000 || K > 1000) { scale = 2.0 / std::max(M, K); } int nnz_A = M * scale * K; scale = 0.02; if(K > 1000 || N > 1000) { scale = 2.0 / std::max(K, N); } int nnz_B = K * scale * N; // Argument sanity check before allocating invalid memory if(M <= 0 || N <= 0 || K <= 0 || nnz_A <= 0 || nnz_B <= 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // do not test for zero return HIPSPARSE_STATUS_SUCCESS; #endif auto dAptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), 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), 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), 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(); if(!dAval || !dAptr || !dAcol || !dBval || !dBptr || !dBcol || !dCval || !dCptr || !dCcol || !dbuffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dAptr || !dAcol || !dAval || " "!dBptr || !dBcol || !dBval || " "!dCptr || !dCcol || !dCval || " "!dbuffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // Test hipsparseXcsrgemm2_bufferSizeExt status = 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, &size); if(M < 0 || N < 0 || K < 0 || nnz_A < 0 || nnz_B < 0) { verify_hipsparse_status_invalid_size( status, "Error: M < 0 || N < 0 || K < 0 || nnz_A < 0 || nnz_B < 0"); } else { verify_hipsparse_status_success( status, "M >= 0 && N >= 0 && K >= 0 && nnz_A >= 0 && nnz_B >= 0"); } // Test hipsparseXcsrgemm2Nnz int nnz_C; status = 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, &nnz_C, info, dbuffer); if(M < 0 || N < 0 || K < 0 || nnz_A < 0 || nnz_B < 0) { verify_hipsparse_status_invalid_size( status, "Error: M < 0 || N < 0 || K < 0 || nnz_A < 0 || nnz_B < 0"); } else { verify_hipsparse_status_success( status, "M >= 0 && N >= 0 && K >= 0 && nnz_A >= 0 && nnz_B >= 0"); } // Test hipsparseXcsrgemm2 status = 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); if(M < 0 || N < 0 || K < 0 || nnz_A < 0 || nnz_B < 0) { verify_hipsparse_status_invalid_size( status, "Error: M < 0 || N < 0 || K < 0 || nnz_A < 0 || nnz_B < 0"); } else { verify_hipsparse_status_success( status, "M >= 0 && N >= 0 && K >= 0 && nnz_A >= 0 && nnz_B >= 0"); } return HIPSPARSE_STATUS_SUCCESS; } // Host structures 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; std::vector hcsr_row_ptr_D; std::vector hcsr_col_ind_D; std::vector hcsr_val_D; // Initial Data on CPU srand(12345ULL); if(binfile != "") { if(read_bin_matrix( binfile.c_str(), M, K, nnz_A, hcsr_row_ptr_A, hcsr_col_ind_A, hcsr_val_A, idx_base_A) != 0) { fprintf(stderr, "Cannot open [read] %s\n", binfile.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else if(argus.laplacian) { M = K = gen_2d_laplacian( argus.laplacian, hcsr_row_ptr_A, hcsr_col_ind_A, hcsr_val_A, idx_base_A); nnz_A = hcsr_row_ptr_A[M]; } else { std::vector hcoo_row_ind; if(filename != "") { if(read_mtx_matrix(filename.c_str(), M, K, nnz_A, hcoo_row_ind, hcsr_col_ind_A, hcsr_val_A, idx_base_A) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { gen_matrix_coo(M, K, nnz_A, hcoo_row_ind, hcsr_col_ind_A, hcsr_val_A, idx_base_A); } // Convert COO to CSR hcsr_row_ptr_A.resize(M + 1, 0); for(int i = 0; i < nnz_A; ++i) { ++hcsr_row_ptr_A[hcoo_row_ind[i] + 1 - idx_base_A]; } hcsr_row_ptr_A[0] = idx_base_A; for(int i = 0; i < M; ++i) { hcsr_row_ptr_A[i + 1] += hcsr_row_ptr_A[i]; } // TODO samples B matrix instead of squaring } // B = A^T so that we can compute the square of A N = M; 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(); if(!dAval || !dAptr || !dAcol || !dBval || !dBptr || !dBcol || !dCptr || !dalpha) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dAval || !dAptr || !dAcol || " "!dBval || !dBptr || !dBcol || " "!dCptr || !dalpha"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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 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, &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(); if(!dbuffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dbuffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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(!dCval || !dCcol) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dCval || !dCcol"); return HIPSPARSE_STATUS_ALLOC_FAILED; } 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 = 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); 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 hipSPARSE-rocm-5.7.1/clients/include/testing_csrgemm2_b.hpp000066400000000000000000001720421447644345400235570ustar00rootroot00000000000000/* ************************************************************************ * 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_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 = 100; int N = 100; int nnz_D = 100; int safe_size = 100; 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), 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), 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(); if(!dDval || !dDptr || !dDcol || !dCval || !dCptr || !dCcol || !dbuffer) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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 for(nullptr == dbuffer) { 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, info, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: dbuffer 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"); } // testing for(nullptr == dbuffer) { 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, info, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: dbuffer is nullptr"); } #endif } template hipsparseStatus_t testing_csrgemm2_b(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int safe_size = 100; int M = argus.M; int N = argus.N; hipsparseIndexBase_t idx_base_C = argus.idx_base3; hipsparseIndexBase_t idx_base_D = argus.idx_base4; std::string binfile = ""; std::string filename = ""; T beta = make_DataType(argus.beta); hipsparseStatus_t status; size_t size; T* h_beta = β // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu if(M == -99 && N == -99 && argus.timing == 0) { binfile = argus.filename; M = N = safe_size; } if(argus.timing == 1) { filename = argus.filename; } std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; std::unique_ptr test_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = test_descr_A->descr; std::unique_ptr test_descr_B(new descr_struct); hipsparseMatDescr_t descr_B = test_descr_B->descr; std::unique_ptr test_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = test_descr_C->descr; std::unique_ptr test_descr_D(new descr_struct); hipsparseMatDescr_t descr_D = test_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)); // Determine number of non-zero elements double scale = 0.02; if(M > 1000 || N > 1000) { scale = 2.0 / std::max(M, N); } int nnz_D = M * scale * N; // Argument sanity check before allocating invalid memory if(M <= 0 || N <= 0 || nnz_D <= 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // do not test for zero return HIPSPARSE_STATUS_SUCCESS; #endif auto dDptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), 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), 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(); if(!dDval || !dDptr || !dDcol || !dCval || !dCptr || !dCcol || !dbuffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dDptr || !dDcol || !dDval || " "!dCptr || !dCcol || !dCval || " "!dbuffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // Test hipsparseXcsrgemm2_bufferSizeExt status = 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, &size); if(M < 0 || N < 0 || nnz_D < 0) { verify_hipsparse_status_invalid_size(status, "Error: M < 0 || N < 0 || nnz_D < 0"); } else { verify_hipsparse_status_success(status, "M >= 0 && N >= 0 && nnz_D >= 0"); } // Test hipsparseXcsrgemm2Nnz int nnz_C; status = hipsparseXcsrgemm2Nnz(handle, M, N, 0, descr_A, 0, nullptr, nullptr, descr_B, 0, nullptr, nullptr, descr_D, nnz_D, dDptr, dDcol, descr_C, dCptr, &nnz_C, info, dbuffer); if(M < 0 || N < 0 || nnz_D < 0) { verify_hipsparse_status_invalid_size(status, "Error: M < 0 || N < 0 || nnz_D < 0"); } else { verify_hipsparse_status_success(status, "M >= 0 && N >= 0 && nnz_D >= 0"); } // Test hipsparseXcsrgemm2 status = 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); if(M < 0 || N < 0 || nnz_D < 0) { verify_hipsparse_status_invalid_size(status, "Error: M < 0 || N < 0 || nnz_D < 0"); } else { verify_hipsparse_status_success(status, "M >= 0 && N >= 0 && nnz_D >= 0"); } return HIPSPARSE_STATUS_SUCCESS; } // Host structures 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; std::vector hcsr_row_ptr_D; std::vector hcsr_col_ind_D; std::vector hcsr_val_D; // Initial Data on CPU srand(12345ULL); if(binfile != "") { if(read_bin_matrix( binfile.c_str(), M, N, nnz_D, hcsr_row_ptr_D, hcsr_col_ind_D, hcsr_val_D, idx_base_D) != 0) { fprintf(stderr, "Cannot open [read] %s\n", binfile.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else if(argus.laplacian) { M = N = gen_2d_laplacian( argus.laplacian, hcsr_row_ptr_D, hcsr_col_ind_D, hcsr_val_D, idx_base_D); nnz_D = hcsr_row_ptr_D[M]; } else { std::vector hcoo_row_ind; if(filename != "") { if(read_mtx_matrix(filename.c_str(), M, N, nnz_D, hcoo_row_ind, hcsr_col_ind_D, hcsr_val_D, idx_base_D) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { gen_matrix_coo(M, N, nnz_D, hcoo_row_ind, hcsr_col_ind_D, hcsr_val_D, idx_base_D); } // Convert COO to CSR hcsr_row_ptr_D.resize(M + 1, 0); for(int i = 0; i < nnz_D; ++i) { ++hcsr_row_ptr_D[hcoo_row_ind[i] + 1 - idx_base_D]; } hcsr_row_ptr_D[0] = idx_base_D; for(int i = 0; i < M; ++i) { hcsr_row_ptr_D[i + 1] += hcsr_row_ptr_D[i]; } } // 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(); if(!dDval || !dDptr || !dDcol || !dCptr || !dbeta) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dDval || !dDptr || !dDcol || " "!dCptr || !dbeta"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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 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, &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(); if(!dbuffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dbuffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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(!dCval || !dCcol) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dCval || !dCcol"); return HIPSPARSE_STATUS_ALLOC_FAILED; } 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 = 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); 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 hipSPARSE-rocm-5.7.1/clients/include/testing_csric02.hpp000066400000000000000000000532761447644345400230130ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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; 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_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(); if(!dval || !dptr || !dcol || !dbuffer) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // testing hipsparseXcsric02_bufferSize int size; // testing for(nullptr == dptr) { int* dptr_null = nullptr; status = hipsparseXcsric02_bufferSize( handle, m, nnz, descr, dval, dptr_null, dcol, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: dptr is nullptr"); } // testing for(nullptr == dcol) { int* dcol_null = nullptr; status = hipsparseXcsric02_bufferSize( handle, m, nnz, descr, dval, dptr, dcol_null, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: dcol is nullptr"); } // testing for(nullptr == dval) { T* dval_null = nullptr; status = hipsparseXcsric02_bufferSize( handle, m, nnz, descr, dval_null, dptr, dcol, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: dval is nullptr"); } // testing for(nullptr == buffer_size) { int* size_null = nullptr; status = hipsparseXcsric02_bufferSize( handle, m, nnz, descr, dval, dptr, dcol, info, size_null); verify_hipsparse_status_invalid_pointer(status, "Error: size is nullptr"); } // testing for(nullptr == descr) { hipsparseMatDescr_t descr_null = nullptr; status = hipsparseXcsric02_bufferSize( handle, m, nnz, descr_null, dval, dptr, dcol, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); } // testing for(nullptr == info) { csric02Info_t info_null = nullptr; status = hipsparseXcsric02_bufferSize( handle, m, nnz, descr, dval, dptr, dcol, info_null, &size); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXcsric02_bufferSize( handle_null, m, nnz, descr, dval, dptr, dcol, info, &size); verify_hipsparse_status_invalid_handle(status); } // testing hipsparseXcsric02_analysis // testing for(nullptr == dptr) { int* dptr_null = nullptr; status = hipsparseXcsric02_analysis( handle, m, nnz, descr, dval, dptr_null, dcol, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dptr is nullptr"); } // testing for(nullptr == dcol) { int* dcol_null = nullptr; status = hipsparseXcsric02_analysis( handle, m, nnz, descr, dval, dptr, dcol_null, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dcol is nullptr"); } // testing for(nullptr == dval) { T* dval_null = nullptr; status = hipsparseXcsric02_analysis( handle, m, nnz, descr, dval_null, dptr, dcol, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dval is nullptr"); } // testing for(nullptr == dbuffer) { void* dbuffer_null = nullptr; status = hipsparseXcsric02_analysis( handle, m, nnz, descr, dval, dptr, dcol, info, policy, dbuffer_null); verify_hipsparse_status_invalid_pointer(status, "Error: dbuffer is nullptr"); } // testing for(nullptr == descr) { hipsparseMatDescr_t descr_null = nullptr; status = hipsparseXcsric02_analysis( handle, m, nnz, descr_null, dval, dptr, dcol, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); } // testing for(nullptr == info) { csric02Info_t info_null = nullptr; status = hipsparseXcsric02_analysis( handle, m, nnz, descr, dval, dptr, dcol, info_null, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXcsric02_analysis( handle_null, m, nnz, descr, dval, dptr, dcol, info, policy, dbuffer); verify_hipsparse_status_invalid_handle(status); } // testing hipsparseXcsric02 // testing for(nullptr == dptr) { int* dptr_null = nullptr; status = hipsparseXcsric02( handle, m, nnz, descr, dval, dptr_null, dcol, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dptr is nullptr"); } // testing for(nullptr == dcol) { int* dcol_null = nullptr; status = hipsparseXcsric02( handle, m, nnz, descr, dval, dptr, dcol_null, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dcol is nullptr"); } // testing for(nullptr == dval) { T* dval_null = nullptr; status = hipsparseXcsric02( handle, m, nnz, descr, dval_null, dptr, dcol, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dval is nullptr"); } // testing for(nullptr == dbuffer) { void* dbuffer_null = nullptr; status = hipsparseXcsric02( handle, m, nnz, descr, dval, dptr, dcol, info, policy, dbuffer_null); verify_hipsparse_status_invalid_pointer(status, "Error: dbuffer is nullptr"); } // testing for(nullptr == descr) { hipsparseMatDescr_t descr_null = nullptr; status = hipsparseXcsric02( handle, m, nnz, descr_null, dval, dptr, dcol, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); } // testing for(nullptr == info) { csric02Info_t info_null = nullptr; status = hipsparseXcsric02( handle, m, nnz, descr, dval, dptr, dcol, info_null, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXcsric02( handle_null, m, nnz, descr, dval, dptr, dcol, info, policy, dbuffer); verify_hipsparse_status_invalid_handle(status); } // testing hipsparseXcsric02_zeroPivot int position; // testing for(nullptr == position) { int* position_null = nullptr; status = hipsparseXcsric02_zeroPivot(handle, info, position_null); verify_hipsparse_status_invalid_pointer(status, "Error: position is nullptr"); } // testing for(nullptr == info) { csric02Info_t info_null = nullptr; status = hipsparseXcsric02_zeroPivot(handle, info_null, &position); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXcsric02_zeroPivot(handle_null, info, &position); verify_hipsparse_status_invalid_handle(status); } #endif } template hipsparseStatus_t testing_csric02(Arguments argus) { int safe_size = 100; int m = argus.M; hipsparseIndexBase_t idx_base = argus.idx_base; hipsparseSolvePolicy_t policy = HIPSPARSE_SOLVE_POLICY_USE_LEVEL; std::string binfile = ""; std::string filename = ""; hipsparseStatus_t status; int size; // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu if(m == -99 && argus.timing == 0) { binfile = argus.filename; m = safe_size; } if(argus.timing == 1) { filename = argus.filename; } std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; std::unique_ptr test_descr(new descr_struct); hipsparseMatDescr_t descr = test_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)); // Determine number of non-zero elements double scale = 0.02; if(m > 1000) { scale = 2.0 / m; } int nnz = m * scale * m; // Argument sanity check before allocating invalid memory if(m <= 0 || nnz <= 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // Do not test args in cusparse return HIPSPARSE_STATUS_SUCCESS; #endif 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 buffer_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* buffer = (void*)buffer_managed.get(); if(!dval || !dptr || !dcol || !buffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dptr || !dcol || !dval || !buffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // Test hipsparseXcsric02_bufferSize status = hipsparseXcsric02_bufferSize(handle, m, nnz, descr, dval, dptr, dcol, info, &size); if(m < 0 || nnz < 0) { verify_hipsparse_status_invalid_size(status, "Error: m < 0 || nnz < 0"); } else { verify_hipsparse_status_success(status, "m >= 0 && nnz >= 0"); } // Test hipsparseXcsric02_analysis status = hipsparseXcsric02_analysis( handle, m, nnz, descr, dval, dptr, dcol, info, policy, buffer); if(m < 0 || nnz < 0) { verify_hipsparse_status_invalid_size(status, "Error: m < 0 || nnz < 0"); } else { verify_hipsparse_status_success(status, "m >= 0 && nnz >= 0"); } // Test hipsparseXcsric02 status = hipsparseXcsric02(handle, m, nnz, descr, dval, dptr, dcol, info, policy, buffer); if(m < 0 || nnz < 0) { verify_hipsparse_status_invalid_size(status, "Error: m < 0 || nnz < 0"); } else { verify_hipsparse_status_success(status, "m >= 0 && nnz >= 0"); } // Test hipsparseXcsric02_zeroPivot int zero_pivot; CHECK_HIPSPARSE_ERROR(hipsparseXcsric02_zeroPivot(handle, info, &zero_pivot)); // Zero pivot should be -1 int res = -1; unit_check_general(1, 1, 1, &res, &zero_pivot); return HIPSPARSE_STATUS_SUCCESS; } // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Initial Data on CPU srand(12345ULL); if(binfile != "") { if(read_bin_matrix( binfile.c_str(), m, m, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", binfile.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else if(argus.laplacian) { m = gen_2d_laplacian(argus.laplacian, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base); nnz = hcsr_row_ptr[m]; } else { std::vector hcoo_row_ind; if(filename != "") { if(read_mtx_matrix( filename.c_str(), m, m, nnz, hcoo_row_ind, hcsr_col_ind, hcsr_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { gen_matrix_coo(m, m, nnz, hcoo_row_ind, hcsr_col_ind, hcsr_val, idx_base); } // Convert COO to CSR hcsr_row_ptr.resize(m + 1, 0); for(int i = 0; i < nnz; ++i) { ++hcsr_row_ptr[hcoo_row_ind[i] + 1 - idx_base]; } hcsr_row_ptr[0] = idx_base; for(int i = 0; i < m; ++i) { hcsr_row_ptr[i + 1] += hcsr_row_ptr[i]; } } // 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(); if(!dval_1 || !dval_2 || !dptr || !dcol || !d_analysis_pivot_2 || !d_solve_pivot_2) { verify_hipsparse_status_success( HIPSPARSE_STATUS_ALLOC_FAILED, "!dval_1 || !dval_2 || !dptr || !dcol || !d_analysis_pivot_2 || !d_solve_pivot_2"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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)); // Obtain csric02 buffer size CHECK_HIPSPARSE_ERROR( hipsparseXcsric02_bufferSize(handle, m, nnz, descr, dval_1, dptr, dcol, info, &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(); if(!dbuffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dbuffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } 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) { CHECK_HIP_ERROR(hipMemcpy(dval_2, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); hipsparseStatus_t status_analysis_1; hipsparseStatus_t status_analysis_2; hipsparseStatus_t status_solve_1; hipsparseStatus_t status_solve_2; // 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()); } } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRIC0_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_csrilu02.hpp000066400000000000000000000554231447644345400232050ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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; 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_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(); if(!dval || !dptr || !dcol || !dbuffer || !dboost_tol || !dboost_val) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // testing hipsparseXcsrilu02_bufferSize int size; // testing for(nullptr == dptr) { int* dptr_null = nullptr; status = hipsparseXcsrilu02_bufferSize( handle, m, nnz, descr, dval, dptr_null, dcol, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: dptr is nullptr"); } // testing for(nullptr == dcol) { int* dcol_null = nullptr; status = hipsparseXcsrilu02_bufferSize( handle, m, nnz, descr, dval, dptr, dcol_null, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: dcol is nullptr"); } // testing for(nullptr == dval) { T* dval_null = nullptr; status = hipsparseXcsrilu02_bufferSize( handle, m, nnz, descr, dval_null, dptr, dcol, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: dval is nullptr"); } // testing for(nullptr == buffer_size) { int* size_null = nullptr; status = hipsparseXcsrilu02_bufferSize( handle, m, nnz, descr, dval, dptr, dcol, info, size_null); verify_hipsparse_status_invalid_pointer(status, "Error: size is nullptr"); } // testing for(nullptr == descr) { hipsparseMatDescr_t descr_null = nullptr; status = hipsparseXcsrilu02_bufferSize( handle, m, nnz, descr_null, dval, dptr, dcol, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); } // testing for(nullptr == info) { csrilu02Info_t info_null = nullptr; status = hipsparseXcsrilu02_bufferSize( handle, m, nnz, descr, dval, dptr, dcol, info_null, &size); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXcsrilu02_bufferSize( handle_null, m, nnz, descr, dval, dptr, dcol, info, &size); verify_hipsparse_status_invalid_handle(status); } // testing hipsparseXcsrilu02_numericBoost // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXcsrilu02_numericBoost(handle_null, info, 1, dboost_tol, dboost_val); verify_hipsparse_status_invalid_handle(status); } // testing for(nullptr == info) { csrilu02Info_t info_null = nullptr; status = hipsparseXcsrilu02_numericBoost(handle, info_null, 1, dboost_tol, dboost_val); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing for(nullptr == dboost_tol) { double* boost_tol_null = nullptr; status = hipsparseXcsrilu02_numericBoost(handle, info, 1, boost_tol_null, dboost_val); verify_hipsparse_status_invalid_pointer(status, "Error: boost_tol is nullptr"); } // testing for(nullptr == dboost_val) { T* boost_val_null = nullptr; status = hipsparseXcsrilu02_numericBoost(handle, info, 1, dboost_tol, boost_val_null); verify_hipsparse_status_invalid_pointer(status, "Error: boost_val is nullptr"); } // testing hipsparseXcsrilu02_analysis // testing for(nullptr == dptr) { int* dptr_null = nullptr; status = hipsparseXcsrilu02_analysis( handle, m, nnz, descr, dval, dptr_null, dcol, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dptr is nullptr"); } // testing for(nullptr == dcol) { int* dcol_null = nullptr; status = hipsparseXcsrilu02_analysis( handle, m, nnz, descr, dval, dptr, dcol_null, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dcol is nullptr"); } // testing for(nullptr == dval) { T* dval_null = nullptr; status = hipsparseXcsrilu02_analysis( handle, m, nnz, descr, dval_null, dptr, dcol, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dval is nullptr"); } // testing for(nullptr == dbuffer) { void* dbuffer_null = nullptr; status = hipsparseXcsrilu02_analysis( handle, m, nnz, descr, dval, dptr, dcol, info, policy, dbuffer_null); verify_hipsparse_status_invalid_pointer(status, "Error: dbuffer is nullptr"); } // testing for(nullptr == descr) { hipsparseMatDescr_t descr_null = nullptr; status = hipsparseXcsrilu02_analysis( handle, m, nnz, descr_null, dval, dptr, dcol, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); } // testing for(nullptr == info) { csrilu02Info_t info_null = nullptr; status = hipsparseXcsrilu02_analysis( handle, m, nnz, descr, dval, dptr, dcol, info_null, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXcsrilu02_analysis( handle_null, m, nnz, descr, dval, dptr, dcol, info, policy, dbuffer); verify_hipsparse_status_invalid_handle(status); } // testing hipsparseXcsrilu02 // testing for(nullptr == dptr) { int* dptr_null = nullptr; status = hipsparseXcsrilu02( handle, m, nnz, descr, dval, dptr_null, dcol, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dptr is nullptr"); } // testing for(nullptr == dcol) { int* dcol_null = nullptr; status = hipsparseXcsrilu02( handle, m, nnz, descr, dval, dptr, dcol_null, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dcol is nullptr"); } // testing for(nullptr == dval) { T* dval_null = nullptr; status = hipsparseXcsrilu02( handle, m, nnz, descr, dval_null, dptr, dcol, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dval is nullptr"); } // testing for(nullptr == dbuffer) { void* dbuffer_null = nullptr; status = hipsparseXcsrilu02( handle, m, nnz, descr, dval, dptr, dcol, info, policy, dbuffer_null); verify_hipsparse_status_invalid_pointer(status, "Error: dbuffer is nullptr"); } // testing for(nullptr == descr) { hipsparseMatDescr_t descr_null = nullptr; status = hipsparseXcsrilu02( handle, m, nnz, descr_null, dval, dptr, dcol, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); } // testing for(nullptr == info) { csrilu02Info_t info_null = nullptr; status = hipsparseXcsrilu02( handle, m, nnz, descr, dval, dptr, dcol, info_null, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXcsrilu02( handle_null, m, nnz, descr, dval, dptr, dcol, info, policy, dbuffer); verify_hipsparse_status_invalid_handle(status); } // testing hipsparseXcsrilu02_zeroPivot int position; // testing for(nullptr == position) { int* position_null = nullptr; status = hipsparseXcsrilu02_zeroPivot(handle, info, position_null); verify_hipsparse_status_invalid_pointer(status, "Error: position is nullptr"); } // testing for(nullptr == info) { csrilu02Info_t info_null = nullptr; status = hipsparseXcsrilu02_zeroPivot(handle, info_null, &position); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXcsrilu02_zeroPivot(handle_null, info, &position); verify_hipsparse_status_invalid_handle(status); } #endif } template hipsparseStatus_t testing_csrilu02(Arguments argus) { int safe_size = 100; 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.idx_base; hipsparseSolvePolicy_t policy = HIPSPARSE_SOLVE_POLICY_USE_LEVEL; std::string binfile = ""; std::string filename = ""; hipsparseStatus_t status; int size; // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu if(m == -99 && argus.timing == 0) { binfile = argus.filename; m = safe_size; } if(argus.timing == 1) { filename = argus.filename; } std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; std::unique_ptr test_descr(new descr_struct); hipsparseMatDescr_t descr = test_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)); // Determine number of non-zero elements double scale = 0.02; if(m > 1000) { scale = 2.0 / m; } int nnz = m * scale * m; // Argument sanity check before allocating invalid memory if(m <= 0 || nnz <= 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // Do not test args in cusparse return HIPSPARSE_STATUS_SUCCESS; #endif 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 buffer_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* buffer = (void*)buffer_managed.get(); if(!dval || !dptr || !dcol || !buffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dptr || !dcol || !dval || !buffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // Test hipsparseXcsrilu02_bufferSize status = hipsparseXcsrilu02_bufferSize(handle, m, nnz, descr, dval, dptr, dcol, info, &size); if(m < 0 || nnz < 0) { verify_hipsparse_status_invalid_size(status, "Error: m < 0 || nnz < 0"); } else { verify_hipsparse_status_success(status, "m >= 0 && nnz >= 0"); } // Test hipsparseXcsrilu02_analysis status = hipsparseXcsrilu02_analysis( handle, m, nnz, descr, dval, dptr, dcol, info, policy, buffer); if(m < 0 || nnz < 0) { verify_hipsparse_status_invalid_size(status, "Error: m < 0 || nnz < 0"); } else { verify_hipsparse_status_success(status, "m >= 0 && nnz >= 0"); } // Test hipsparseXcsrilu02 status = hipsparseXcsrilu02(handle, m, nnz, descr, dval, dptr, dcol, info, policy, buffer); if(m < 0 || nnz < 0) { verify_hipsparse_status_invalid_size(status, "Error: m < 0 || nnz < 0"); } else { verify_hipsparse_status_success(status, "m >= 0 && nnz >= 0"); } // Test hipsparseXcsrilu02_zeroPivot int zero_pivot; CHECK_HIPSPARSE_ERROR(hipsparseXcsrilu02_zeroPivot(handle, info, &zero_pivot)); // Zero pivot should be -1 int res = -1; unit_check_general(1, 1, 1, &res, &zero_pivot); return HIPSPARSE_STATUS_SUCCESS; } // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Initial Data on CPU srand(12345ULL); if(binfile != "") { if(read_bin_matrix( binfile.c_str(), m, m, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", binfile.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else if(argus.laplacian) { m = gen_2d_laplacian(argus.laplacian, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base); nnz = hcsr_row_ptr[m]; } else { std::vector hcoo_row_ind; if(filename != "") { if(read_mtx_matrix( filename.c_str(), m, m, nnz, hcoo_row_ind, hcsr_col_ind, hcsr_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { gen_matrix_coo(m, m, nnz, hcoo_row_ind, hcsr_col_ind, hcsr_val, idx_base); } // Convert COO to CSR hcsr_row_ptr.resize(m + 1, 0); for(int i = 0; i < nnz; ++i) { ++hcsr_row_ptr[hcoo_row_ind[i] + 1 - idx_base]; } hcsr_row_ptr[0] = idx_base; for(int i = 0; i < m; ++i) { hcsr_row_ptr[i + 1] += hcsr_row_ptr[i]; } } // 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(); if(!dval1 || !dval2 || !dptr || !dcol || !d_position || !dboost_tol || !dboost_val) { verify_hipsparse_status_success( HIPSPARSE_STATUS_ALLOC_FAILED, "!dval1 || !dval2|| !dptr || !dcol || !d_position || !dboost_tol || !dboost_val"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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 CHECK_HIPSPARSE_ERROR( hipsparseXcsrilu02_bufferSize(handle, m, nnz, descr, dval1, dptr, dcol, info, &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(); if(!dbuffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dbuffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } 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 } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRILU0_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_csrilusv.hpp000066400000000000000000000516711447644345400234150ustar00rootroot00000000000000/* ************************************************************************ * 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_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.idx_base; std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; std::unique_ptr test_descr_M(new descr_struct); hipsparseMatDescr_t descr_M = test_descr_M->descr; std::unique_ptr test_csrilu02_info(new csrilu02_struct); csrilu02Info_t info_M = test_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(read_bin_matrix( argus.filename.c_str(), m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", argus.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(); if(!dval || !dptr || !dcol || !d_position) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dval || !dptr || !dcol || !d_position"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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(); if(!dbuffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dbuffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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 test_csrsv2_lower(new csrsv2_struct); std::unique_ptr test_csrsv2_upper(new csrsv2_struct); csrsv2Info_t info_L = test_csrsv2_lower->info; csrsv2Info_t info_U = test_csrsv2_upper->info; // Create matrix descriptors for csrsv std::unique_ptr test_descr_L(new descr_struct); hipsparseMatDescr_t descr_L = test_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 test_descr_U(new descr_struct); hipsparseMatDescr_t descr_U = test_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(); if(!dbuffer_sv) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dbuffer_sv"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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(); if(!dx || !dy_1 || !dy_2 || !dz_1 || !dz_2 || !d_alpha) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dx || !dy_1 || !dy_2 || !dz_1 || " "!dz_2 || !d_alpha"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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; 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 hipSPARSE-rocm-5.7.1/clients/include/testing_csrmm.hpp000066400000000000000000000547121447644345400226630ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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(void) { #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 = 0.6; T beta = 0.2; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; 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 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(); if(!dval || !dptr || !dcol || !dB || !dC) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // testing for(nullptr == dptr) { int* dptr_null = nullptr; status = hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &alpha, descr, dval, dptr_null, dcol, dB, ldb, &beta, dC, ldc); verify_hipsparse_status_invalid_pointer(status, "Error: dptr is nullptr"); } // testing for(nullptr == dcol) { int* dcol_null = nullptr; status = hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &alpha, descr, dval, dptr, dcol_null, dB, ldb, &beta, dC, ldc); verify_hipsparse_status_invalid_pointer(status, "Error: dcol is nullptr"); } // testing for(nullptr == dval) { T* dval_null = nullptr; status = hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &alpha, descr, dval_null, dptr, dcol, dB, ldb, &beta, dC, ldc); verify_hipsparse_status_invalid_pointer(status, "Error: dval is nullptr"); } // testing for(nullptr == dB) { T* dB_null = nullptr; status = hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &alpha, descr, dval, dptr, dcol, dB_null, ldb, &beta, dC, ldc); verify_hipsparse_status_invalid_pointer(status, "Error: dB is nullptr"); } // testing for(nullptr == dC) { T* dC_null = nullptr; status = hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &alpha, descr, dval, dptr, dcol, dB, ldb, &beta, dC_null, ldc); verify_hipsparse_status_invalid_pointer(status, "Error: dC is nullptr"); } // testing for(nullptr == d_alpha) { T* d_alpha_null = nullptr; status = hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, d_alpha_null, descr, dval, dptr, dcol, dB, ldb, &beta, dC, ldc); verify_hipsparse_status_invalid_pointer(status, "Error: alpha is nullptr"); } // testing for(nullptr == d_beta) { T* d_beta_null = nullptr; status = hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &alpha, descr, dval, dptr, dcol, dB, ldb, d_beta_null, dC, ldc); verify_hipsparse_status_invalid_pointer(status, "Error: beta is nullptr"); } // testing for(nullptr == descr) { hipsparseMatDescr_t descr_null = nullptr; status = hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &alpha, descr_null, dval, dptr, dcol, dB, ldb, &beta, dC, ldc); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXcsrmm2(handle_null, transA, transB, M, N, K, nnz, &alpha, descr, dval, dptr, dcol, dB, ldb, &beta, dC, ldc); verify_hipsparse_status_invalid_handle(status); } #endif } template hipsparseStatus_t testing_csrmm(Arguments argus) { int safe_size = 100; int M = argus.M; int N = argus.N; int K = argus.K; int ldb = argus.ldb; int ldc = argus.ldc; 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.idx_base; std::string binfile = ""; std::string filename = ""; hipsparseStatus_t status; // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu if(M == -99 && K == -99 && argus.timing == 0) { binfile = argus.filename; M = K = safe_size; } if(argus.timing == 1) { filename = argus.filename; } std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; std::unique_ptr test_descr(new descr_struct); hipsparseMatDescr_t descr = test_descr->descr; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); // Determine number of non-zero elements double scale = 0.02; if(M > 1000 || K > 1000) { scale = 2.0 / std::max(M, K); } int nnz = M * scale * K; // Argument sanity check before allocating invalid memory if(M <= 0 || N <= 0 || K <= 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // Do not test args in cusparse return HIPSPARSE_STATUS_SUCCESS; #endif 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(); if(!dval || !dptr || !dcol || !dB || !dC) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dptr || !dcol || !dval || !dB || !dC"); return HIPSPARSE_STATUS_ALLOC_FAILED; } CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); status = hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &h_alpha, descr, dval, dptr, dcol, dB, ldb, &h_beta, dC, ldc); if(M < 0 || N < 0 || K < 0) { verify_hipsparse_status_invalid_size(status, "Error: M < 0 || N < 0 || K < 0"); } else { verify_hipsparse_status_success(status, "M >= 0 && N >= 0 && K >= 0"); } return HIPSPARSE_STATUS_SUCCESS; } // Initialize random seed srand(12345ULL); // Host structures - CSR matrix A std::vector hcsr_row_ptrA; std::vector hcsr_col_indA; std::vector hcsr_valA; // Initial Data on CPU if(binfile != "") { if(read_bin_matrix( binfile.c_str(), M, K, nnz, hcsr_row_ptrA, hcsr_col_indA, hcsr_valA, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", binfile.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { std::vector hcoo_row_indA; if(filename != "") { if(read_mtx_matrix( filename.c_str(), M, K, nnz, hcoo_row_indA, hcsr_col_indA, hcsr_valA, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { gen_matrix_coo(M, K, nnz, hcoo_row_indA, hcsr_col_indA, hcsr_valA, idx_base); } // Convert COO to CSR hcsr_row_ptrA.resize(M + 1, 0); for(int i = 0; i < nnz; ++i) { ++hcsr_row_ptrA[hcoo_row_indA[i] + 1 - idx_base]; } hcsr_row_ptrA[0] = idx_base; for(int i = 0; i < M; ++i) { hcsr_row_ptrA[i + 1] += hcsr_row_ptrA[i]; } } // 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; ldb = B_m; 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(); if(!dcsr_valA || !dcsr_row_ptrA || !dcsr_col_indA || !dB || !dC_1 || !d_alpha || !d_beta) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dcsr_valA || !dcsr_row_ptrA || !dcsr_col_indA || !dB || " "!dC_1 || !d_alpha || !d_beta"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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)); // ROCSPARSE 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)); // ROCSPARSE 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, 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()); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRMM_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_csrmv.hpp000066400000000000000000000432221447644345400226660ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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(void) { #if(!defined(CUDART_VERSION)) int n = 100; int m = 100; int nnz = 100; int safe_size = 100; T alpha = 0.6; T beta = 0.2; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; 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 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(); if(!dval || !dptr || !dcol || !dx || !dy) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // testing for(nullptr == dptr) { int* dptr_null = nullptr; status = hipsparseXcsrmv( handle, transA, m, n, nnz, &alpha, descr, dval, dptr_null, dcol, dx, &beta, dy); verify_hipsparse_status_invalid_pointer(status, "Error: dptr is nullptr"); } // testing for(nullptr == dcol) { int* dcol_null = nullptr; status = hipsparseXcsrmv( handle, transA, m, n, nnz, &alpha, descr, dval, dptr, dcol_null, dx, &beta, dy); verify_hipsparse_status_invalid_pointer(status, "Error: dcol is nullptr"); } // testing for(nullptr == dval) { T* dval_null = nullptr; status = hipsparseXcsrmv( handle, transA, m, n, nnz, &alpha, descr, dval_null, dptr, dcol, dx, &beta, dy); verify_hipsparse_status_invalid_pointer(status, "Error: dval is nullptr"); } // testing for(nullptr == dx) { T* dx_null = nullptr; status = hipsparseXcsrmv( handle, transA, m, n, nnz, &alpha, descr, dval, dptr, dcol, dx_null, &beta, dy); verify_hipsparse_status_invalid_pointer(status, "Error: dx is nullptr"); } // testing for(nullptr == dy) { T* dy_null = nullptr; status = hipsparseXcsrmv( handle, transA, m, n, nnz, &alpha, descr, dval, dptr, dcol, dx, &beta, dy_null); verify_hipsparse_status_invalid_pointer(status, "Error: dy is nullptr"); } // testing for(nullptr == d_alpha) { T* d_alpha_null = nullptr; status = hipsparseXcsrmv( handle, transA, m, n, nnz, d_alpha_null, descr, dval, dptr, dcol, dx, &beta, dy); verify_hipsparse_status_invalid_pointer(status, "Error: alpha is nullptr"); } // testing for(nullptr == d_beta) { T* d_beta_null = nullptr; status = hipsparseXcsrmv( handle, transA, m, n, nnz, &alpha, descr, dval, dptr, dcol, dx, d_beta_null, dy); verify_hipsparse_status_invalid_pointer(status, "Error: beta is nullptr"); } // testing for(nullptr == descr) { hipsparseMatDescr_t descr_null = nullptr; status = hipsparseXcsrmv( handle, transA, m, n, nnz, &alpha, descr_null, dval, dptr, dcol, dx, &beta, dy); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXcsrmv( handle_null, transA, m, n, nnz, &alpha, descr, dval, dptr, dcol, dx, &beta, dy); verify_hipsparse_status_invalid_handle(status); } #endif } template hipsparseStatus_t testing_csrmv(Arguments argus) { int nrow = argus.M; int ncol = argus.N; int safe_size = std::max(100, std::max(nrow, ncol)); T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseIndexBase_t idx_base = argus.idx_base; std::string binfile = ""; std::string filename = ""; hipsparseStatus_t status; // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu if(nrow == -99 && ncol == -99 && argus.timing == 0) { binfile = argus.filename; nrow = ncol = safe_size; } if(argus.timing == 1) { filename = argus.filename; } std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; std::unique_ptr test_descr(new descr_struct); hipsparseMatDescr_t descr = test_descr->descr; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); // Determine number of non-zero elements double scale = 0.02; if(nrow > 1000 || ncol > 1000) { scale = 2.0 / std::max(nrow, ncol); } int nnz = nrow * scale * ncol; // Argument sanity check before allocating invalid memory if(nrow <= 0 || ncol <= 0 || nnz <= 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // Do not test args in cusparse return HIPSPARSE_STATUS_SUCCESS; #endif auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), 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(); // row pointer should be valid CHECK_HIP_ERROR(hipMemset(dptr, 0, sizeof(int) * (safe_size + 1))); if(!dval || !dptr || !dcol || !dx || !dy) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dptr || !dcol || !dval || !dx || !dy"); return HIPSPARSE_STATUS_ALLOC_FAILED; } CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); status = hipsparseXcsrmv( handle, transA, nrow, ncol, nnz, &h_alpha, descr, dval, dptr, dcol, dx, &h_beta, dy); if(nrow < 0 || ncol < 0 || nnz < 0) { verify_hipsparse_status_invalid_size(status, "Error: nrow < 0 || ncol < 0 || nnz < 0"); } else { verify_hipsparse_status_success(status, "nrow >= 0 && ncol >= 0 && nnz >= 0"); } return HIPSPARSE_STATUS_SUCCESS; } // Host structures std::vector hcsr_row_ptr; std::vector hcoo_row_ind; std::vector hcol_ind; std::vector hval; // Initial Data on CPU srand(12345ULL); if(binfile != "") { if(read_bin_matrix(binfile.c_str(), nrow, ncol, nnz, hcsr_row_ptr, hcol_ind, hval, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\ncol", binfile.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else if(argus.laplacian) { nrow = ncol = gen_2d_laplacian(argus.laplacian, hcsr_row_ptr, hcol_ind, hval, idx_base); nnz = hcsr_row_ptr[nrow]; } else { if(filename != "") { if(read_mtx_matrix( filename.c_str(), nrow, ncol, nnz, hcoo_row_ind, hcol_ind, hval, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { gen_matrix_coo(nrow, ncol, nnz, hcoo_row_ind, hcol_ind, hval, idx_base); } // Convert COO to CSR if(!argus.laplacian) { hcsr_row_ptr.resize(nrow + 1, 0); for(int i = 0; i < nnz; ++i) { ++hcsr_row_ptr[hcoo_row_ind[i] + 1 - idx_base]; } hcsr_row_ptr[0] = idx_base; for(int i = 0; i < nrow; ++i) { hcsr_row_ptr[i + 1] += hcsr_row_ptr[i]; } } } 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(); if(!dval || !dptr || !dcol || !dx || !dy_1 || !dy_2 || !d_alpha || !d_beta) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dval || !dptr || !dcol || !dx || " "!dy_1 || !dy_2 || !d_alpha || !d_beta"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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, 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)); if(argus.unit_check) { CHECK_HIP_ERROR(hipMemcpy(dy_2, hy_2.data(), sizeof(T) * m, hipMemcpyHostToDevice)); // ROCSPARSE 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)); // ROCSPARSE 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)); // CPU - do the csrmv row reduction in the same order as the GPU if(transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) { // Query for warpSize hipDeviceProp_t prop; hipGetDeviceProperties(&prop, 0); int WF_SIZE; int nnz_per_row = nnz / nrow; 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(int i = 0; i < nrow; ++i) { std::vector sum(WF_SIZE, make_DataType(0.0)); for(int 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]); } } } else { // Scale y with beta for(int i = 0; i < ncol; ++i) { hy_gold[i] = testing_mult(hy_gold[i], h_beta); } // Transposed SpMV for(int i = 0; i < nrow; ++i) { int row_begin = hcsr_row_ptr[i] - idx_base; int row_end = hcsr_row_ptr[i + 1] - idx_base; T row_val = testing_mult(h_alpha, hx[i]); for(int j = row_begin; j < row_end; ++j) { int col = hcol_ind[j] - idx_base; T val = (transA == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE) ? testing_conj(hval[j]) : hval[j]; hy_gold[col] = testing_fma(val, row_val, hy_gold[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()); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRMV_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_csrsm2.hpp000066400000000000000000001475011447644345400227520ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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(void) { #if(!defined(CUDART_VERSION)) int m = 100; int nrhs = 100; int nnz = 100; int safe_size = 100; T h_alpha = 0.6; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseSolvePolicy_t policy = HIPSPARSE_SOLVE_POLICY_USE_LEVEL; 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_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(); if(!dval || !dptr || !dcol || !dB || !dbuffer) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // testing hipsparseXcsrsm2_bufferSizeExt size_t size; // testing for(nullptr == alpha) { T* dalpha_null = nullptr; status = hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, dalpha_null, descr, dval, dptr, dcol, dB, safe_size, info, policy, &size); verify_hipsparse_status_invalid_pointer(status, "Error: dalpha is nullptr"); } // testing for(nullptr == dptr) { int* dptr_null = nullptr; status = hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr_null, dcol, dB, safe_size, info, policy, &size); verify_hipsparse_status_invalid_pointer(status, "Error: dptr is nullptr"); } // testing for(nullptr == dcol) { int* dcol_null = nullptr; status = hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol_null, dB, safe_size, info, policy, &size); verify_hipsparse_status_invalid_pointer(status, "Error: dcol is nullptr"); } // testing for(nullptr == dval) { T* dval_null = nullptr; status = hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval_null, dptr, dcol, dB, safe_size, info, policy, &size); verify_hipsparse_status_invalid_pointer(status, "Error: dval is nullptr"); } // testing for(nullptr == buffer_size) { size_t* size_null = nullptr; status = hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, info, policy, size_null); verify_hipsparse_status_invalid_pointer(status, "Error: size is nullptr"); } // testing for(nullptr == descr) { hipsparseMatDescr_t descr_null = nullptr; status = hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr_null, dval, dptr, dcol, dB, safe_size, info, policy, &size); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); } // testing for(nullptr == info) { csrsm2Info_t info_null = nullptr; status = hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, info_null, policy, &size); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing for(nullptr == B) { T* B_null = nullptr; status = hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, B_null, safe_size, info, policy, &size); verify_hipsparse_status_invalid_pointer(status, "Error: dB is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXcsrsm2_bufferSizeExt(handle_null, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, info, policy, &size); verify_hipsparse_status_invalid_handle(status); } // testing hipsparseXcsrsm2_analysis // testing for(nullptr == dalpha) { T* dalpha_null = nullptr; status = hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, dalpha_null, descr, dval, dptr, dcol, dB, safe_size, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dalpha is nullptr"); } // testing for(nullptr == dptr) { int* dptr_null = nullptr; status = hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr_null, dcol, dB, safe_size, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dptr is nullptr"); } // testing for(nullptr == dcol) { int* dcol_null = nullptr; status = hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol_null, dB, safe_size, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dcol is nullptr"); } // testing for(nullptr == dval) { T* dval_null = nullptr; status = hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval_null, dptr, dcol, dB, safe_size, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dval is nullptr"); } // testing for(nullptr == dbuffer) { void* dbuffer_null = nullptr; status = hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, info, policy, dbuffer_null); verify_hipsparse_status_invalid_pointer(status, "Error: dbuffer is nullptr"); } // testing for(nullptr == descr) { hipsparseMatDescr_t descr_null = nullptr; status = hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr_null, dval, dptr, dcol, dB, safe_size, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); } // testing for(nullptr == dB) { T* dB_null = nullptr; status = hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB_null, safe_size, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dB is nullptr"); } // testing for(nullptr == info) { csrsm2Info_t info_null = nullptr; status = hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, info_null, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXcsrsm2_analysis(handle_null, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, info, policy, dbuffer); verify_hipsparse_status_invalid_handle(status); } // testing rocsparse_csrsm2 // testing for(nullptr == dptr) { int* dptr_null = nullptr; status = hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr_null, dcol, dB, safe_size, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dptr is nullptr"); } // testing for(nullptr == dcol) { int* dcol_null = nullptr; status = hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol_null, dB, safe_size, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dcol is nullptr"); } // testing for(nullptr == dval) { T* dval_null = nullptr; status = hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval_null, dptr, dcol, dB, safe_size, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dval is nullptr"); } // testing for(nullptr == dB) { T* dB_null = nullptr; status = hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB_null, safe_size, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dB is nullptr"); } // testing for(nullptr == d_alpha) { T* d_alpha_null = nullptr; status = hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, d_alpha_null, descr, dval, dptr, dcol, dB, safe_size, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: alpha is nullptr"); } // testing for(nullptr == dbuffer) { void* dbuffer_null = nullptr; status = hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, info, policy, dbuffer_null); verify_hipsparse_status_invalid_pointer(status, "Error: dbuffer is nullptr"); } // testing for(nullptr == descr) { hipsparseMatDescr_t descr_null = nullptr; status = hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr_null, dval, dptr, dcol, dB, safe_size, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); } // testing for(nullptr == info) { csrsm2Info_t info_null = nullptr; status = hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, info_null, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXcsrsm2_solve(handle_null, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, info, policy, dbuffer); verify_hipsparse_status_invalid_handle(status); } // testing hipsparseXcsrsm2_zeroPivot int position; // testing for(nullptr == position) { int* position_null = nullptr; status = hipsparseXcsrsm2_zeroPivot(handle, info, position_null); verify_hipsparse_status_invalid_pointer(status, "Error: position is nullptr"); } // testing for(nullptr == info) { csrsm2Info_t info_null = nullptr; status = hipsparseXcsrsm2_zeroPivot(handle, info_null, &position); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXcsrsm2_zeroPivot(handle_null, info, &position); verify_hipsparse_status_invalid_handle(status); } #endif } template hipsparseStatus_t testing_csrsm2(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int safe_size = 100; int m = argus.M; int nrhs = argus.N; hipsparseIndexBase_t idx_base = argus.idx_base; 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 = HIPSPARSE_SOLVE_POLICY_USE_LEVEL; T h_alpha = make_DataType(argus.alpha); std::string binfile = ""; std::string filename = ""; hipsparseStatus_t status; size_t size; // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu if(m == -99 && argus.timing == 0) { binfile = argus.filename; m = safe_size; } if(argus.timing == 1) { filename = argus.filename; } std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; std::unique_ptr test_descr(new descr_struct); hipsparseMatDescr_t descr = test_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)); // Determine number of non-zero elements double scale = 0.02; if(m > 1000) { scale = 2.0 / m; } int nnz = m * scale * m; // Argument sanity check before allocating invalid memory if(m <= 0 || nrhs <= 0 || nnz <= 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // Do not test args in cusparse return HIPSPARSE_STATUS_SUCCESS; #endif 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 buffer_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* buffer = (void*)buffer_managed.get(); if(!dval || !dptr || !dcol || !dB || !buffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dptr || !dcol || !dval || " "!dB || !buffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // Test hipsparseXcsrsm2_bufferSize status = hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, info, policy, &size); if(m < 0 || nrhs < 0 || nnz < 0) { verify_hipsparse_status_invalid_size(status, "Error: m < 0 || nrhs < 0 || nnz < 0"); } else { verify_hipsparse_status_success(status, "m >= 0 && nrhs >= 0 && nnz >= 0"); } // Test hipsparseXcsrsm2_analysis status = hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, info, policy, buffer); if(m < 0 || nrhs < 0 || nnz < 0) { verify_hipsparse_status_invalid_size(status, "Error: m < 0 || nrhs < 0 || nnz < 0"); } else { verify_hipsparse_status_success(status, "m >= 0 && nrhs >= 0 && nnz >= 0"); } // Test hipsparseXcsrsm2_solve status = hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, info, policy, buffer); if(m < 0 || nrhs < 0 || nnz < 0) { verify_hipsparse_status_invalid_size(status, "Error: m < 0 || nrhs < 0 || nnz < 0"); } else { verify_hipsparse_status_success(status, "m >= 0 && nrhs >= 0 && nnz >= 0"); } // Test hipsparseXcsrsm2_zeroPivot int zero_pivot; CHECK_HIPSPARSE_ERROR(hipsparseXcsrsm2_zeroPivot(handle, info, &zero_pivot)); // Zero pivot should be -1 int res = -1; unit_check_general(1, 1, 1, &res, &zero_pivot); return HIPSPARSE_STATUS_SUCCESS; } // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Initial Data on CPU srand(12345ULL); if(binfile != "") { int n; if(read_bin_matrix( binfile.c_str(), m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", binfile.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else if(argus.laplacian) { m = gen_2d_laplacian(argus.laplacian, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base); nnz = hcsr_row_ptr[m]; } else { std::vector hcoo_row_ind; if(filename != "") { int n; if(read_mtx_matrix( filename.c_str(), m, n, nnz, hcoo_row_ind, hcsr_col_ind, hcsr_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { gen_matrix_coo(m, m, nnz, hcoo_row_ind, hcsr_col_ind, hcsr_val, idx_base); } // Convert COO to CSR hcsr_row_ptr.resize(m + 1, 0); for(int i = 0; i < nnz; ++i) { ++hcsr_row_ptr[hcoo_row_ind[i] + 1 - idx_base]; } hcsr_row_ptr[0] = idx_base; for(int i = 0; i < m; ++i) { hcsr_row_ptr[i + 1] += hcsr_row_ptr[i]; } } 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(); if(!dval || !dptr || !dcol || !dB_1 || !dB_2 || !d_alpha || !d_analysis_pivot_2 || !d_solve_pivot_2) { verify_hipsparse_status_success( HIPSPARSE_STATUS_ALLOC_FAILED, "!dval || !dptr || !dcol || " "!dB_1 || !dB_2 || !d_alpha || !d_analysis_pivot_2 || !d_solve_pivot_2"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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 CHECK_HIPSPARSE_ERROR(hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB_1, ldb, info, policy, &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(); if(!dbuffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dbuffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } 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(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"); } // 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_csrsm(m, nrhs, nnz, transA, transB, h_alpha, hcsr_row_ptr, hcsr_col_ind, hcsr_val, hB_gold, ldb, 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()); } } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRSM2_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_csrsort.hpp000066400000000000000000000362461447644345400232430ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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; 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; 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(); if(!csr_row_ptr || !csr_col_ind || !perm || !buffer) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // Testing csrsort_buffer_size for bad args // Testing for (csr_row_ptr == nullptr) { int* csr_row_ptr_null = nullptr; status = hipsparseXcsrsort_bufferSizeExt( handle, m, n, nnz, csr_row_ptr_null, csr_col_ind, &buffer_size); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr is nullptr"); } // Testing for (csr_col_ind == nullptr) { int* csr_col_ind_null = nullptr; status = hipsparseXcsrsort_bufferSizeExt( handle, m, n, nnz, csr_row_ptr, csr_col_ind_null, &buffer_size); verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind is nullptr"); } // Testing for (buffer_size == nullptr) { size_t* buffer_size_null = nullptr; status = hipsparseXcsrsort_bufferSizeExt( handle, m, n, nnz, csr_row_ptr, csr_col_ind, buffer_size_null); verify_hipsparse_status_invalid_pointer(status, "Error: buffer_size is nullptr"); } // Testing for (handle == nullptr) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXcsrsort_bufferSizeExt( handle_null, m, n, nnz, csr_row_ptr, csr_col_ind, &buffer_size); verify_hipsparse_status_invalid_handle(status); } // Testing csrsort for bad args // Testing for (csr_row_ptr == nullptr) { int* csr_row_ptr_null = nullptr; status = hipsparseXcsrsort( handle, m, n, nnz, descr, csr_row_ptr_null, csr_col_ind, perm, buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr is nullptr"); } // Testing for (csr_col_ind == nullptr) { int* csr_col_ind_null = nullptr; status = hipsparseXcsrsort( handle, m, n, nnz, descr, csr_row_ptr, csr_col_ind_null, perm, buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind is nullptr"); } // Testing for (buffer == nullptr) { int* buffer_null = nullptr; status = hipsparseXcsrsort( handle, m, n, nnz, descr, csr_row_ptr, csr_col_ind, perm, buffer_null); verify_hipsparse_status_invalid_pointer(status, "Error: buffer is nullptr"); } // Testing for (descr == nullptr) { hipsparseMatDescr_t descr_null = nullptr; status = hipsparseXcsrsort( handle, m, n, nnz, descr_null, csr_row_ptr, csr_col_ind, perm, buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); } // Testing for (handle == nullptr) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXcsrsort( handle_null, m, n, nnz, descr, csr_row_ptr, csr_col_ind, perm, buffer); verify_hipsparse_status_invalid_handle(status); } #endif } hipsparseStatus_t testing_csrsort(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int m = argus.M; int n = argus.N; int safe_size = 100; int permute = argus.temp; hipsparseIndexBase_t idx_base = argus.idx_base; std::string binfile = ""; std::string filename = ""; hipsparseStatus_t status; // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu if(m == -99 && n == -99 && argus.timing == 0) { binfile = argus.filename; m = n = safe_size; } if(argus.timing == 1) { filename = argus.filename; } size_t buffer_size = 0; double scale = 0.02; if(m > 1000 || n > 1000) { scale = 2.0 / std::max(m, n); } int nnz = m * scale * n; 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)); // Argument sanity check before allocating invalid memory if(m <= 0 || n <= 0 || nnz <= 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // Do not test args in cusparse return HIPSPARSE_STATUS_SUCCESS; #endif 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(); if(!csr_row_ptr || !csr_col_ind || !perm || !buffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!csr_row_ptr || !csr_col_ind || !perm || !buffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } status = hipsparseXcsrsort_bufferSizeExt( handle, m, n, nnz, csr_row_ptr, csr_col_ind, &buffer_size); if(m < 0 || n < 0 || nnz < 0) { verify_hipsparse_status_invalid_size(status, "Error: m < 0 || n < 0 || nnz < 0"); } else { verify_hipsparse_status_success(status, "m >= 0 && n >= 0 && nnz >= 0"); // Buffer size should be 4 size_t four = 4; unit_check_general(1, 1, 1, &four, &buffer_size); } status = hipsparseXcsrsort(handle, m, n, nnz, descr, csr_row_ptr, csr_col_ind, perm, buffer); if(m < 0 || n < 0 || nnz < 0) { verify_hipsparse_status_invalid_size(status, "Error: m < 0 || n < 0 || nnz < 0"); } else { verify_hipsparse_status_success(status, "m >= 0 && n >= 0 && nnz >= 0"); } return HIPSPARSE_STATUS_SUCCESS; } // For testing, assemble a COO matrix and convert it to CSR first (on host) // Host structures std::vector hcsr_row_ptr; std::vector hcoo_row_ind; std::vector hcsr_col_ind; std::vector hcsr_val; // Sample initial COO matrix on CPU srand(12345ULL); if(binfile != "") { if(read_bin_matrix( binfile.c_str(), m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", binfile.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else if(argus.laplacian) { m = n = gen_2d_laplacian(argus.laplacian, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base); nnz = hcsr_row_ptr[m]; } else { if(filename != "") { if(read_mtx_matrix( filename.c_str(), m, n, nnz, hcoo_row_ind, hcsr_col_ind, hcsr_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { gen_matrix_coo(m, n, nnz, hcoo_row_ind, hcsr_col_ind, hcsr_val, idx_base); } // Convert COO to CSR hcsr_row_ptr.resize(m + 1, 0); for(int i = 0; i < nnz; ++i) { ++hcsr_row_ptr[hcoo_row_ind[i] + 1 - idx_base]; } hcsr_row_ptr[0] = idx_base; for(int i = 0; i < m; ++i) { hcsr_row_ptr[i + 1] += hcsr_row_ptr[i]; } } // 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; if(!dcsr_row_ptr || !dcsr_col_ind || !dcsr_val || !dcsr_val_sorted || (permute && !dperm)) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dcsr_row_ptr || !dcsr_col_ind || !dcsr_val || " "!dcsr_val_sorted || (permute && !dperm)"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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)); if(argus.unit_check) { // Obtain buffer size CHECK_HIPSPARSE_ERROR(hipsparseXcsrsort_bufferSizeExt( handle, m, n, nnz, dcsr_row_ptr, dcsr_col_ind, &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(!dbuffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dbuffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } if(permute) { // Initialize perm with identity permutation CHECK_HIPSPARSE_ERROR(hipsparseCreateIdentityPermutation(handle, nnz, dperm)); } // 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()); } } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRSORT_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_csrsv2.hpp000066400000000000000000000753231447644345400227650ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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(void) { #if(!defined(CUDART_VERSION)) int m = 100; int nnz = 100; int safe_size = 100; T h_alpha = 0.6; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseSolvePolicy_t policy = HIPSPARSE_SOLVE_POLICY_USE_LEVEL; 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_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(); if(!dval || !dptr || !dcol || !dx || !dy || !dbuffer) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // testing hipsparseXcsrsv2_bufferSize int size; // testing for(nullptr == dptr) { int* dptr_null = nullptr; status = hipsparseXcsrsv2_bufferSize( handle, transA, m, nnz, descr, dval, dptr_null, dcol, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: dptr is nullptr"); } // testing for(nullptr == dcol) { int* dcol_null = nullptr; status = hipsparseXcsrsv2_bufferSize( handle, transA, m, nnz, descr, dval, dptr, dcol_null, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: dcol is nullptr"); } // testing for(nullptr == dval) { T* dval_null = nullptr; status = hipsparseXcsrsv2_bufferSize( handle, transA, m, nnz, descr, dval_null, dptr, dcol, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: dval is nullptr"); } // testing for(nullptr == buffer_size) { int* size_null = nullptr; status = hipsparseXcsrsv2_bufferSize( handle, transA, m, nnz, descr, dval, dptr, dcol, info, size_null); verify_hipsparse_status_invalid_pointer(status, "Error: size is nullptr"); } // testing for(nullptr == descr) { hipsparseMatDescr_t descr_null = nullptr; status = hipsparseXcsrsv2_bufferSize( handle, transA, m, nnz, descr_null, dval, dptr, dcol, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); } // testing for(nullptr == info) { csrsv2Info_t info_null = nullptr; status = hipsparseXcsrsv2_bufferSize( handle, transA, m, nnz, descr, dval, dptr, dcol, info_null, &size); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXcsrsv2_bufferSize( handle_null, transA, m, nnz, descr, dval, dptr, dcol, info, &size); verify_hipsparse_status_invalid_handle(status); } // testing hipsparseXcsrsv2_analysis // testing for(nullptr == dptr) { int* dptr_null = nullptr; status = hipsparseXcsrsv2_analysis( handle, transA, m, nnz, descr, dval, dptr_null, dcol, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dptr is nullptr"); } // testing for(nullptr == dcol) { int* dcol_null = nullptr; status = hipsparseXcsrsv2_analysis( handle, transA, m, nnz, descr, dval, dptr, dcol_null, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dcol is nullptr"); } // testing for(nullptr == dval) { T* dval_null = nullptr; status = hipsparseXcsrsv2_analysis( handle, transA, m, nnz, descr, dval_null, dptr, dcol, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dval is nullptr"); } // testing for(nullptr == dbuffer) { void* dbuffer_null = nullptr; status = hipsparseXcsrsv2_analysis( handle, transA, m, nnz, descr, dval, dptr, dcol, info, policy, dbuffer_null); verify_hipsparse_status_invalid_pointer(status, "Error: dbuffer is nullptr"); } // testing for(nullptr == descr) { hipsparseMatDescr_t descr_null = nullptr; status = hipsparseXcsrsv2_analysis( handle, transA, m, nnz, descr_null, dval, dptr, dcol, info, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); } // testing for(nullptr == info) { csrsv2Info_t info_null = nullptr; status = hipsparseXcsrsv2_analysis( handle, transA, m, nnz, descr, dval, dptr, dcol, info_null, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXcsrsv2_analysis( handle_null, transA, m, nnz, descr, dval, dptr, dcol, info, policy, dbuffer); verify_hipsparse_status_invalid_handle(status); } // testing rocsparse_csrsv2 // testing for(nullptr == dptr) { int* dptr_null = nullptr; status = hipsparseXcsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr, dval, dptr_null, dcol, info, dx, dy, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dptr is nullptr"); } // testing for(nullptr == dcol) { int* dcol_null = nullptr; status = hipsparseXcsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol_null, info, dx, dy, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dcol is nullptr"); } // testing for(nullptr == dval) { T* dval_null = nullptr; status = hipsparseXcsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr, dval_null, dptr, dcol, info, dx, dy, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dval is nullptr"); } // testing for(nullptr == dx) { T* dx_null = nullptr; status = hipsparseXcsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, info, dx_null, dy, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dx is nullptr"); } // testing for(nullptr == dy) { T* dy_null = nullptr; status = hipsparseXcsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, info, dx, dy_null, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dy is nullptr"); } // testing for(nullptr == d_alpha) { T* d_alpha_null = nullptr; status = hipsparseXcsrsv2_solve(handle, transA, m, nnz, d_alpha_null, descr, dval, dptr, dcol, info, dx, dy, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: alpha is nullptr"); } // testing for(nullptr == dbuffer) { void* dbuffer_null = nullptr; status = hipsparseXcsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, info, dx, dy, policy, dbuffer_null); verify_hipsparse_status_invalid_pointer(status, "Error: dbuffer is nullptr"); } // testing for(nullptr == descr) { hipsparseMatDescr_t descr_null = nullptr; status = hipsparseXcsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr_null, dval, dptr, dcol, info, dx, dy, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); } // testing for(nullptr == info) { csrsv2Info_t info_null = nullptr; status = hipsparseXcsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, info_null, dx, dy, policy, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXcsrsv2_solve(handle_null, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, info, dx, dy, policy, dbuffer); verify_hipsparse_status_invalid_handle(status); } // testing hipsparseXcsrsv2_zeroPivot int position; // testing for(nullptr == position) { int* position_null = nullptr; status = hipsparseXcsrsv2_zeroPivot(handle, info, position_null); verify_hipsparse_status_invalid_pointer(status, "Error: position is nullptr"); } // testing for(nullptr == info) { csrsv2Info_t info_null = nullptr; status = hipsparseXcsrsv2_zeroPivot(handle, info_null, &position); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXcsrsv2_zeroPivot(handle_null, info, &position); verify_hipsparse_status_invalid_handle(status); } #endif } template hipsparseStatus_t testing_csrsv2(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int safe_size = 100; int m = argus.M; hipsparseIndexBase_t idx_base = argus.idx_base; hipsparseOperation_t trans = argus.transA; hipsparseDiagType_t diag_type = argus.diag_type; hipsparseFillMode_t fill_mode = argus.fill_mode; hipsparseSolvePolicy_t policy = HIPSPARSE_SOLVE_POLICY_USE_LEVEL; T h_alpha = make_DataType(argus.alpha); std::string binfile = ""; std::string filename = ""; hipsparseStatus_t status; int size; // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu if(m == -99 && argus.timing == 0) { binfile = argus.filename; m = safe_size; } if(argus.timing == 1) { filename = argus.filename; } std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; std::unique_ptr test_descr(new descr_struct); hipsparseMatDescr_t descr = test_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)); // Determine number of non-zero elements double scale = 0.02; if(m > 1000) { scale = 2.0 / m; } int nnz = m * scale * m; // Argument sanity check before allocating invalid memory if(m <= 0 || nnz <= 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // Do not test args in cusparse return HIPSPARSE_STATUS_SUCCESS; #endif 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 buffer_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* buffer = (void*)buffer_managed.get(); if(!dval || !dptr || !dcol || !dx || !dy || !buffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dptr || !dcol || !dval || " "!dx || !dy || !buffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // Test hipsparseXcsrsv2_bufferSize status = hipsparseXcsrsv2_bufferSize( handle, trans, m, nnz, descr, dval, dptr, dcol, info, &size); if(m < 0 || nnz < 0) { verify_hipsparse_status_invalid_size(status, "Error: m < 0 || nnz < 0"); } else { verify_hipsparse_status_success(status, "m >= 0 && nnz >= 0"); } // Test hipsparseXcsrsv2_analysis status = hipsparseXcsrsv2_analysis( handle, trans, m, nnz, descr, dval, dptr, dcol, info, policy, buffer); if(m < 0 || nnz < 0) { verify_hipsparse_status_invalid_size(status, "Error: m < 0 || nnz < 0"); } else { verify_hipsparse_status_success(status, "m >= 0 && nnz >= 0"); } // Test hipsparseXcsrsv2_solve status = hipsparseXcsrsv2_solve( handle, trans, m, nnz, &h_alpha, descr, dval, dptr, dcol, info, dx, dy, policy, buffer); if(m < 0 || nnz < 0) { verify_hipsparse_status_invalid_size(status, "Error: m < 0 || nnz < 0"); } else { verify_hipsparse_status_success(status, "m >= 0 && nnz >= 0"); } // Test hipsparseXcsrsv2_zeroPivot int zero_pivot; CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_zeroPivot(handle, info, &zero_pivot)); // Zero pivot should be -1 int res = -1; unit_check_general(1, 1, 1, &res, &zero_pivot); return HIPSPARSE_STATUS_SUCCESS; } // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Initial Data on CPU srand(12345ULL); if(binfile != "") { int n; if(read_bin_matrix( binfile.c_str(), m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", binfile.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else if(argus.laplacian) { m = gen_2d_laplacian(argus.laplacian, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base); nnz = hcsr_row_ptr[m]; } else { std::vector hcoo_row_ind; if(filename != "") { int n; if(read_mtx_matrix( filename.c_str(), m, n, nnz, hcoo_row_ind, hcsr_col_ind, hcsr_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { gen_matrix_coo(m, m, nnz, hcoo_row_ind, hcsr_col_ind, hcsr_val, idx_base); } // Convert COO to CSR hcsr_row_ptr.resize(m + 1, 0); for(int i = 0; i < nnz; ++i) { ++hcsr_row_ptr[hcoo_row_ind[i] + 1 - idx_base]; } hcsr_row_ptr[0] = idx_base; for(int i = 0; i < m; ++i) { hcsr_row_ptr[i + 1] += hcsr_row_ptr[i]; } } 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(); if(!dval || !dptr || !dcol || !dx || !dy_1 || !dy_2 || !d_alpha || !d_position) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dval || !dptr || !dcol || !dx || " "!dy_1 || !dy_2 || !d_alpha || !d_position"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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 CHECK_HIPSPARSE_ERROR( hipsparseXcsrsv2_bufferSize(handle, trans, m, nnz, descr, dval, dptr, dcol, info, &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(); if(!dbuffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dbuffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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)); // ROCSPARSE 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); // ROCSPARSE 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; 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()); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRSV2_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_csru2csr.hpp000066400000000000000000000403671447644345400233110ustar00rootroot00000000000000/* ************************************************************************ * 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_CSRU2CSR_HPP #define TESTING_CSRU2CSR_HPP #include "hipsparse.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include using namespace hipsparse; using namespace hipsparse_test; void testing_csru2csr_bad_arg(void) { 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(); if(!csr_row_ptr || !csr_col_ind || !csr_val || !buffer) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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 } template hipsparseStatus_t testing_csru2csr(void) { // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; std::unique_ptr test_descr(new descr_struct); hipsparseMatDescr_t descr = test_descr->descr; std::unique_ptr test_info(new csru2csr_struct); csru2csrInfo_t info = test_info->info; // Sample test matrix srand(12345ULL); int m = 51314; int n = 12963; int nnz = 309274; // Sample random COO matrix std::vector hcoo_row_ind; std::vector hcsr_row_ptr(m + 1, 0); std::vector hcsr_col_ind_gold; std::vector hcsr_val_gold; gen_matrix_coo( m, n, nnz, hcoo_row_ind, hcsr_col_ind_gold, hcsr_val_gold, HIPSPARSE_INDEX_BASE_ZERO); // Convert COO to CSR for(int i = 0; i < nnz; ++i) { ++hcsr_row_ptr[hcoo_row_ind[i] + 1]; } hcsr_row_ptr[0] = 0; for(int i = 0; i < m; ++i) { hcsr_row_ptr[i + 1] += hcsr_row_ptr[i]; } // 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]; int row_end = hcsr_row_ptr[i + 1]; 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]; 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; 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(); if(!dcsr_row_ptr || !dcsr_col_ind || !dcsr_val) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dcsr_row_ptr || !dcsr_col_ind || !dcsr_val"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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(!dbuffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dbuffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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()); return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRU2CSR_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_csx2dense.hpp000066400000000000000000000327741447644345400234440ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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 = 10; static constexpr int N = 10; static constexpr int LD = M; 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_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), 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(); if(!d_dense_val || !d_nnzPerRowColumn || !d_csx_row_col_ptr || !d_csx_col_row_ind || !d_csx_val) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // // Testing invalid handle. // status = csx2dense(nullptr, 0, 0, nullptr, (const T*)nullptr, nullptr, nullptr, (T*)nullptr, 0); verify_hipsparse_status_invalid_handle(status); // // Testing invalid pointers. // status = csx2dense( handle, M, N, nullptr, d_csx_val, d_csx_row_col_ptr, d_csx_col_row_ind, d_dense_val, LD); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected."); status = csx2dense(handle, M, N, descr, (const T*)nullptr, d_csx_row_col_ptr, d_csx_col_row_ind, d_dense_val, LD); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected."); status = csx2dense(handle, M, N, descr, d_csx_val, nullptr, d_csx_col_row_ind, d_dense_val, LD); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected."); status = csx2dense(handle, M, N, descr, d_csx_val, d_csx_row_col_ptr, nullptr, d_dense_val, LD); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected."); status = csx2dense( handle, M, N, descr, d_csx_val, d_csx_row_col_ptr, d_csx_col_row_ind, (T*)nullptr, LD); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected."); // // Testing invalid size on M // status = csx2dense( handle, -1, N, descr, d_csx_val, d_csx_row_col_ptr, d_csx_col_row_ind, d_dense_val, LD); verify_hipsparse_status_invalid_size(status, "Error: an invalid size must be detected."); // // Testing invalid size on N // status = csx2dense( handle, M, -1, descr, d_csx_val, d_csx_row_col_ptr, d_csx_col_row_ind, d_dense_val, LD); verify_hipsparse_status_invalid_size(status, "Error: an invalid size must be detected."); // // Testing invalid size on LD // status = csx2dense( handle, M, -1, descr, d_csx_val, d_csx_row_col_ptr, d_csx_col_row_ind, d_dense_val, M - 1); verify_hipsparse_status_invalid_size(status, "Error: an invalid size must be detected."); #endif } template hipsparseStatus_t testing_csx2dense(const Arguments& argus, FUNC1& csx2dense, FUNC2& dense2csx) { int M = argus.M; int N = argus.N; int LD = argus.lda; hipsparseIndexBase_t idx_base = argus.idx_base; 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; CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); if(M <= 0 || N <= 0 || LD < M) { hipsparseStatus_t expected_status = (((M == 0 && N >= 0) || (M >= 0 && N == 0)) && (LD >= M)) ? HIPSPARSE_STATUS_SUCCESS : HIPSPARSE_STATUS_INVALID_VALUE; status = csx2dense(handle, M, N, descr, (const T*)nullptr, nullptr, nullptr, (T*)nullptr, LD); verify_hipsparse_status(status, expected_status, (expected_status == HIPSPARSE_STATUS_SUCCESS) ? "Error: call with zero sizes must be succesfull." : "Error: An invalid size must be detected."); return HIPSPARSE_STATUS_SUCCESS; } 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. // int MN = DIMDIR; 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) * MN), 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(); if(!d_nnzPerRowColumn || !d_dense_val) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!d_nnzPerRowColumn || !d_dense_val"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // // 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, 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(); if(!d_csx_row_col_ptr || !d_csx_val || !d_csx_col_row_ind) { CHECK_HIP_ERROR(hipErrorOutOfMemory); return HIPSPARSE_STATUS_ALLOC_FAILED; } std::vector cpu_csx_row_col_ptr(DIMDIR + 1); std::vector cpu_csx_val(nnz); std::vector cpu_csx_col_row_ind(nnz); if(!cpu_csx_row_col_ptr.data() || !cpu_csx_val.data() || !cpu_csx_col_row_ind.data()) { CHECK_HIP_ERROR(hipErrorOutOfMemory); return HIPSPARSE_STATUS_ALLOC_FAILED; } // // Convert the dense matrix to a compressed sparse matrix. // if(DIRA == HIPSPARSE_DIRECTION_ROW) { CHECK_HIPSPARSE_ERROR(dense2csx(handle, M, N, descr, d_dense_val, LD, d_nnzPerRowColumn, d_csx_val, d_csx_row_col_ptr, d_csx_col_row_ind)); } else { CHECK_HIPSPARSE_ERROR(dense2csx(handle, M, N, descr, d_dense_val, LD, d_nnzPerRowColumn, d_csx_val, d_csx_col_row_ind, d_csx_row_col_ptr)); } // // Copy on host. // CHECK_HIP_ERROR(hipMemcpy( cpu_csx_val.data(), d_csx_val, sizeof(T) * std::max(nnz, 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(cpu_csx_row_col_ptr.data(), d_csx_row_col_ptr, sizeof(int) * (DIMDIR + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(cpu_csx_col_row_ind.data(), d_csx_col_row_ind, sizeof(int) * std::max(nnz, 1), 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); if(DIRA == HIPSPARSE_DIRECTION_ROW) { CHECK_HIPSPARSE_ERROR(csx2dense(handle, M, N, descr, d_csx_val, d_csx_row_col_ptr, d_csx_col_row_ind, d_dense_val, LD)); } else { CHECK_HIPSPARSE_ERROR(csx2dense(handle, M, N, descr, d_csx_val, 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; } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSX2DENSE_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_dense2csc.hpp000066400000000000000000000035211447644345400234030ustar00rootroot00000000000000/* ************************************************************************ * 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_DENSE2CSC_HPP #define TESTING_DENSE2CSC_HPP #include "testing_dense2csx.hpp" template void testing_dense2csc_bad_arg(void) { static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_COLUMN; testing_dense2csx_bad_arg(hipsparseXdense2csc); } template hipsparseStatus_t testing_dense2csc(Arguments argus) { static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_COLUMN; return testing_dense2csx(argus, hipsparseXdense2csc); } #endif // TESTING_DENSE2CSC hipSPARSE-rocm-5.7.1/clients/include/testing_dense2csr.hpp000066400000000000000000000035131447644345400234230ustar00rootroot00000000000000/* ************************************************************************ * 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_DENSE2CSR_HPP #define TESTING_DENSE2CSR_HPP #include "testing_dense2csx.hpp" template void testing_dense2csr_bad_arg(void) { static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_ROW; testing_dense2csx_bad_arg(hipsparseXdense2csr); } template hipsparseStatus_t testing_dense2csr(Arguments argus) { static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_ROW; return testing_dense2csx(argus, hipsparseXdense2csr); } #endif // TESTING_DENSE2CSR hipSPARSE-rocm-5.7.1/clients/include/testing_dense2csx.hpp000066400000000000000000000344321447644345400234350ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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 = 10; static constexpr int N = 10; static constexpr int LD = M; 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_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), 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(); if(!d_dense_val || !d_nnzPerRowColumn || !d_csx_row_col_ptr || !d_csx_col_row_ind || !d_csx_val) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // // Testing invalid handle. // status = dense2csx( nullptr, 0, 0, nullptr, (const T*)nullptr, 0, nullptr, (T*)nullptr, nullptr, nullptr); verify_hipsparse_status_invalid_handle(status); // // Testing invalid pointers. // status = dense2csx(handle, M, N, nullptr, d_dense_val, LD, d_nnzPerRowColumn, d_csx_val, d_csx_row_col_ptr, d_csx_col_row_ind); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected."); status = dense2csx(handle, M, N, descr, nullptr, LD, d_nnzPerRowColumn, d_csx_val, d_csx_row_col_ptr, d_csx_col_row_ind); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected."); status = dense2csx(handle, M, N, descr, d_dense_val, LD, nullptr, d_csx_val, d_csx_row_col_ptr, d_csx_col_row_ind); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected."); status = dense2csx(handle, M, N, descr, d_dense_val, LD, d_nnzPerRowColumn, nullptr, d_csx_row_col_ptr, d_csx_col_row_ind); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected."); status = dense2csx(handle, M, N, descr, d_dense_val, LD, d_nnzPerRowColumn, d_csx_val, nullptr, d_csx_col_row_ind); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected."); status = dense2csx(handle, M, N, descr, d_dense_val, LD, d_nnzPerRowColumn, d_csx_val, d_csx_row_col_ptr, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected."); // // Testing invalid size on M // status = dense2csx(handle, -1, N, descr, d_dense_val, LD, d_nnzPerRowColumn, d_csx_val, d_csx_row_col_ptr, d_csx_col_row_ind); verify_hipsparse_status_invalid_size(status, "Error: An invalid size must be detected."); // // Testing invalid size on N // status = dense2csx(handle, M, -1, descr, d_dense_val, LD, d_nnzPerRowColumn, d_csx_val, d_csx_row_col_ptr, d_csx_col_row_ind); verify_hipsparse_status_invalid_size(status, "Error: An invalid size must be detected."); // // Testing invalid size on LD // status = 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); verify_hipsparse_status_invalid_size(status, "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.idx_base; 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; CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); if(M <= 0 || N <= 0 || LD < M) { hipsparseStatus_t expected_status = (((M == 0 && N >= 0) || (M >= 0 && N == 0)) && (LD >= M)) ? HIPSPARSE_STATUS_SUCCESS : HIPSPARSE_STATUS_INVALID_VALUE; status = dense2csx( handle, M, N, descr, (const T*)nullptr, LD, nullptr, (T*)nullptr, nullptr, nullptr); verify_hipsparse_status(status, expected_status, (expected_status == HIPSPARSE_STATUS_SUCCESS) ? "Error: call with zero sizes must be succesfull." : "Error: An invalid size must be detected."); return HIPSPARSE_STATUS_SUCCESS; } int DIMDIR = (HIPSPARSE_DIRECTION_ROW == DIRA) ? M : N; std::vector h_dense_val(LD * N); std::vector h_nnzPerRowColumn(DIMDIR); std::vector hd_nnzPerRowColumn(DIMDIR); std::vector h_nnzTotalDevHostPtr(1); std::vector hd_nnzTotalDevHostPtr(1); // // Create the dense matrix. // int MN = DIMDIR; 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) * MN), 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(); int* d_nnzTotalDevHostPtr = (int*)nnzTotalDevHostPtr_managed.get(); if(!d_nnzPerRowColumn || !d_nnzTotalDevHostPtr || !d_dense_val) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!h_nnzPerRowColumn || !d_nnzPerRowColumn || !d_dense_val"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // // 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, 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(); if(!d_csx_row_col_ptr || !d_csx_val || !d_csx_col_row_ind) { CHECK_HIP_ERROR(hipErrorOutOfMemory); return HIPSPARSE_STATUS_ALLOC_FAILED; } std::vector cpu_csx_row_col_ptr(DIMDIR + 1); std::vector cpu_csx_val(nnz); std::vector cpu_csx_col_row_ind(nnz); if(!cpu_csx_row_col_ptr.data() || !cpu_csx_val.data() || !cpu_csx_col_row_ind.data()) { CHECK_HIP_ERROR(hipErrorOutOfMemory); return HIPSPARSE_STATUS_ALLOC_FAILED; } 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()); if(DIRA == HIPSPARSE_DIRECTION_ROW) { CHECK_HIPSPARSE_ERROR(dense2csx(handle, M, N, descr, d_dense_val, LD, d_nnzPerRowColumn, d_csx_val, d_csx_row_col_ptr, d_csx_col_row_ind)); } else { CHECK_HIPSPARSE_ERROR(dense2csx(handle, M, N, descr, d_dense_val, LD, d_nnzPerRowColumn, d_csx_val, 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; } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_DENSE2CSX_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_dense_to_sparse_coo.hpp000066400000000000000000000246061447644345400255560ustar00rootroot00000000000000/* ************************************************************************ * 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 "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(int64_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(); int64_t* dcoo_row_ind = (int64_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(); if(!ddense_val || !dcoo_row_ind || !dcoo_col_ind || !dcoo_val || !dbuf) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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(void) { #if(!defined(CUDART_VERSION)) hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseDenseToSparseAlg_t alg = HIPSPARSE_DENSETOSPARSE_ALG_DEFAULT; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; // Index and data type hipsparseIndexType_t typeI = (typeid(I) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipDataType typeT = (typeid(T) == typeid(float)) ? HIP_R_32F : ((typeid(T) == typeid(double)) ? HIP_R_64F : ((typeid(T) == typeid(hipComplex) ? HIP_C_32F : HIP_C_64F))); // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; I m = 100; I n = 100; I ld = m; // Host structures std::vector hdense_val(ld * n); for(int i = 0; i < ld; ++i) { for(int j = 0; j < n; ++j) { hdense_val[j * ld + i] = make_DataType(-1); } } srand(0); gen_dense_random_sparsity_pattern(m, n, hdense_val.data(), ld, 0.2); // allocate memory on device auto ddense_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * ld * n), device_free}; T* ddense = (T*)ddense_managed.get(); if(!ddense) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!ddense"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // Copy host dense matrix to device CHECK_HIP_ERROR( hipMemcpy(ddense, hdense_val.data(), sizeof(T) * ld * n, 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(); if(!drow || !dcol || !dval) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!drow || !dcol || !dval"); return HIPSPARSE_STATUS_ALLOC_FAILED; } CHECK_HIPSPARSE_ERROR(hipsparseCooSetPointers(matB, drow, dcol, dval)); 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)); // Query for warpSize hipDeviceProp_t prop; hipGetDeviceProperties(&prop, 0); std::vector hcoo_row_ind_cpu(nnz); std::vector hcoo_col_ind_cpu(nnz); std::vector hcoo_val_cpu(nnz); 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++; } } } 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()); 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 hipSPARSE-rocm-5.7.1/clients/include/testing_dense_to_sparse_csc.hpp000066400000000000000000000270001447644345400255350ustar00rootroot00000000000000/* ************************************************************************ * 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 "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_64I; 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(int64_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(); int64_t* dcsc_col_ptr = (int64_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(); if(!ddense_val || !dcsc_col_ptr || !dcsc_row_ind || !dcsc_val || !dbuf) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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(void) { #if(!defined(CUDART_VERSION)) hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseDenseToSparseAlg_t alg = HIPSPARSE_DENSETOSPARSE_ALG_DEFAULT; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; // Index and data type hipsparseIndexType_t typeI = (typeid(I) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipsparseIndexType_t typeJ = (typeid(J) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipDataType typeT = (typeid(T) == typeid(float)) ? HIP_R_32F : ((typeid(T) == typeid(double)) ? HIP_R_64F : ((typeid(T) == typeid(hipComplex) ? HIP_C_32F : HIP_C_64F))); // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; J m = 100; J n = 100; I ld = m; // Host structures std::vector hdense_val(ld * n); for(int i = 0; i < ld; ++i) { for(int j = 0; j < n; ++j) { hdense_val[j * ld + i] = make_DataType(-1); } } srand(0); gen_dense_random_sparsity_pattern(m, n, hdense_val.data(), ld, 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) * ld * n), device_free}; I* dptr = (I*)dptr_managed.get(); T* ddense = (T*)ddense_managed.get(); if(!dptr || !ddense) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dptr || !ddense"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // Copy host dense matrix to device CHECK_HIP_ERROR( hipMemcpy(ddense, hdense_val.data(), sizeof(T) * ld * n, 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(); if(!drow || !dval) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!drow || !dval"); return HIPSPARSE_STATUS_ALLOC_FAILED; } CHECK_HIPSPARSE_ERROR(hipsparseCscSetPointers(matB, dptr, drow, dval)); 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)); // Query for warpSize hipDeviceProp_t prop; hipGetDeviceProperties(&prop, 0); 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); 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]++; } } } 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]; } 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++; } } } 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()); 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 hipSPARSE-rocm-5.7.1/clients/include/testing_dense_to_sparse_csr.hpp000066400000000000000000000270221447644345400255600ustar00rootroot00000000000000/* ************************************************************************ * 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 "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_64I; 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(int64_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(); int64_t* dcsr_row_ptr = (int64_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(); if(!ddense_val || !dcsr_row_ptr || !dcsr_col_ind || !dcsr_val || !dbuf) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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(void) { #if(!defined(CUDART_VERSION)) hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseDenseToSparseAlg_t alg = HIPSPARSE_DENSETOSPARSE_ALG_DEFAULT; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; // Index and data type hipsparseIndexType_t typeI = (typeid(I) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipsparseIndexType_t typeJ = (typeid(J) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipDataType typeT = (typeid(T) == typeid(float)) ? HIP_R_32F : ((typeid(T) == typeid(double)) ? HIP_R_64F : ((typeid(T) == typeid(hipComplex) ? HIP_C_32F : HIP_C_64F))); // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; J m = 100; J n = 100; I ld = m; // Host structures std::vector hdense_val(ld * n); for(int i = 0; i < ld; ++i) { for(int j = 0; j < n; ++j) { hdense_val[j * ld + i] = make_DataType(-1); } } srand(0); gen_dense_random_sparsity_pattern(m, n, hdense_val.data(), ld, 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) * ld * n), device_free}; I* dptr = (I*)dptr_managed.get(); T* ddense = (T*)ddense_managed.get(); if(!dptr || !ddense) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dptr || !ddense"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // Copy host dense matrix to device CHECK_HIP_ERROR( hipMemcpy(ddense, hdense_val.data(), sizeof(T) * ld * n, 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(); if(!dcol || !dval) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dcol || !dval"); return HIPSPARSE_STATUS_ALLOC_FAILED; } CHECK_HIPSPARSE_ERROR(hipsparseCsrSetPointers(matB, dptr, dcol, dval)); 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)); // Query for warpSize hipDeviceProp_t prop; hipGetDeviceProperties(&prop, 0); 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); 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]++; } } } 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]; } 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++; } } } 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()); 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 hipSPARSE-rocm-5.7.1/clients/include/testing_dnvec_descr.hpp000066400000000000000000000106401447644345400240110ustar00rootroot00000000000000/* ************************************************************************ * 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) || CUDART_VERSION > 10010 \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) 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(); if(!val_data) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } 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 #if(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_pointer(hipsparseDestroyDnVec(nullptr), "Error: x is nullptr"); #else verify_hipsparse_status_success(hipsparseDestroyDnVec(nullptr), "Success"); #endif // 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 hipSPARSE-rocm-5.7.1/clients/include/testing_dotci.hpp000066400000000000000000000203431447644345400226350ustar00rootroot00000000000000/* ************************************************************************ * 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_DOTCI_HPP #define TESTING_DOTCI_HPP #include "hipsparse.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(void) { #if(!defined(CUDART_VERSION)) int nnz = 100; int safe_size = 100; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseStatus_t status; 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(!dx_ind || !dx_val || !dy) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } T result; // testing for (nullptr == dx_val) { T* dx_val_null = nullptr; status = hipsparseXdotci(handle, nnz, dx_val_null, dx_ind, dy, &result, idx_base); verify_hipsparse_status_invalid_pointer(status, "Error: x_val is nullptr"); } // testing for (nullptr == dx_ind) { int* dx_ind_null = nullptr; status = hipsparseXdotci(handle, nnz, dx_val, dx_ind_null, dy, &result, idx_base); verify_hipsparse_status_invalid_pointer(status, "Error: x_ind is nullptr"); } // testing for (nullptr == dy) { T* dy_null = nullptr; status = hipsparseXdotci(handle, nnz, dx_val, dx_ind, dy_null, &result, idx_base); verify_hipsparse_status_invalid_pointer(status, "Error: y is nullptr"); } // testing for (nullptr == result) { T* result_null = nullptr; status = hipsparseXdotci(handle, nnz, dx_val, dx_ind, dy, result_null, idx_base); verify_hipsparse_status_invalid_pointer(status, "Error: result is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXdotci(handle_null, nnz, dx_val, dx_ind, dy, &result, idx_base); verify_hipsparse_status_invalid_handle(status); } #endif } template hipsparseStatus_t testing_dotci(Arguments argus) { int N = argus.N; int nnz = argus.nnz; int safe_size = 100; hipsparseIndexBase_t idx_base = argus.idx_base; hipsparseStatus_t status; std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; // Argument sanity check before allocating invalid memory if(nnz <= 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // Do not test args in cusparse return HIPSPARSE_STATUS_SUCCESS; #endif auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dx_val_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* dx_ind = (int*)dx_ind_managed.get(); T* dx_val = (T*)dx_val_managed.get(); T* dy = (T*)dy_managed.get(); if(!dx_ind || !dx_val || !dy) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dx_ind || !dx_val || !dy"); return HIPSPARSE_STATUS_ALLOC_FAILED; } T result; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); status = hipsparseXdotci(handle, nnz, dx_val, dx_ind, dy, &result, idx_base); if(nnz < 0) { verify_hipsparse_status_invalid_size(status, "Error: nnz < 0"); } else { verify_hipsparse_status_success(status, "nnz == 0"); } return HIPSPARSE_STATUS_SUCCESS; } // 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(); if(!dx_ind || !dx_val || !dy || !dresult_2) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dx_ind || !dx_val || !dy || !dresult_2"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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) { // ROCSPARSE 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)); // ROCSPARSE 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); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_DOTCI_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_doti.hpp000066400000000000000000000202611447644345400224710ustar00rootroot00000000000000/* ************************************************************************ * 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_DOTI_HPP #define TESTING_DOTI_HPP #include "hipsparse.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(void) { #if(!defined(CUDART_VERSION)) int nnz = 100; int safe_size = 100; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseStatus_t status; 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(!dx_ind || !dx_val || !dy) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } T result; // testing for (nullptr == dx_val) { T* dx_val_null = nullptr; status = hipsparseXdoti(handle, nnz, dx_val_null, dx_ind, dy, &result, idx_base); verify_hipsparse_status_invalid_pointer(status, "Error: x_val is nullptr"); } // testing for (nullptr == dx_ind) { int* dx_ind_null = nullptr; status = hipsparseXdoti(handle, nnz, dx_val, dx_ind_null, dy, &result, idx_base); verify_hipsparse_status_invalid_pointer(status, "Error: x_ind is nullptr"); } // testing for (nullptr == dy) { T* dy_null = nullptr; status = hipsparseXdoti(handle, nnz, dx_val, dx_ind, dy_null, &result, idx_base); verify_hipsparse_status_invalid_pointer(status, "Error: y is nullptr"); } // testing for (nullptr == result) { T* result_null = nullptr; status = hipsparseXdoti(handle, nnz, dx_val, dx_ind, dy, result_null, idx_base); verify_hipsparse_status_invalid_pointer(status, "Error: result is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXdoti(handle_null, nnz, dx_val, dx_ind, dy, &result, idx_base); verify_hipsparse_status_invalid_handle(status); } #endif } template hipsparseStatus_t testing_doti(Arguments argus) { int N = argus.N; int nnz = argus.nnz; int safe_size = 100; hipsparseIndexBase_t idx_base = argus.idx_base; hipsparseStatus_t status; std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; // Argument sanity check before allocating invalid memory if(nnz <= 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // Do not test args in cusparse return HIPSPARSE_STATUS_SUCCESS; #endif auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dx_val_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* dx_ind = (int*)dx_ind_managed.get(); T* dx_val = (T*)dx_val_managed.get(); T* dy = (T*)dy_managed.get(); if(!dx_ind || !dx_val || !dy) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dx_ind || !dx_val || !dy"); return HIPSPARSE_STATUS_ALLOC_FAILED; } T result; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); status = hipsparseXdoti(handle, nnz, dx_val, dx_ind, dy, &result, idx_base); if(nnz < 0) { verify_hipsparse_status_invalid_size(status, "Error: nnz < 0"); } else { verify_hipsparse_status_success(status, "nnz == 0"); } return HIPSPARSE_STATUS_SUCCESS; } // 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(); if(!dx_ind || !dx_val || !dy || !dresult_2) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dx_ind || !dx_val || !dy || !dresult_2"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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) { // ROCSPARSE 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)); // ROCSPARSE 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); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_DOTI_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_gather.hpp000066400000000000000000000141411447644345400230040ustar00rootroot00000000000000/* ************************************************************************ * 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 "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(); if(!dx_ind || !dx_val || !dy) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) int64_t size = 15332; int64_t nnz = 500; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; // Index and data type hipsparseIndexType_t idxType = (typeid(I) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipDataType dataType = (typeid(T) == typeid(float)) ? HIP_R_32F : ((typeid(T) == typeid(double)) ? HIP_R_64F : ((typeid(T) == typeid(hipComplex) ? HIP_C_32F : HIP_C_64F))); // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_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(); if(!dx_ind || !dx_val || !dy) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dx_ind || !dx_val || !dy"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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)); // 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()); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpVec(x)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GATHER_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_gebsr2csr.hpp000066400000000000000000000610221447644345400234260ustar00rootroot00000000000000/* ************************************************************************ * 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_GEBSR2CSR_HPP #define TESTING_GEBSR2CSR_HPP #include "hipsparse.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(void) { #if(!defined(CUDART_VERSION)) int m = 100; int n = 100; int safe_size = 100; 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; hipsparseStatus_t status; 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), 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), 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(); if(!bsr_row_ptr || !bsr_col_ind || !bsr_val || !csr_row_ptr || !csr_col_ind || !csr_val) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // Testing hipsparseXgebsr2csr() // Test invalid handle status = 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_handle(status); // Test invalid pointers status = 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); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_descr is nullptr"); status = 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); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_val is nullptr"); status = 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); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_row_ptr is nullptr"); status = 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); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_col_ind is nullptr"); status = 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); verify_hipsparse_status_invalid_pointer(status, "Error: csr_descr is nullptr"); status = 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); verify_hipsparse_status_invalid_pointer(status, "Error: csr_val is nullptr"); status = 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); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr is nullptr"); status = 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); verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind is nullptr"); // Test invalid sizes status = 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); verify_hipsparse_status_invalid_size(status, "Error: m is invalid"); status = 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); verify_hipsparse_status_invalid_size(status, "Error: n is invalid"); status = 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); verify_hipsparse_status_invalid_size(status, "Error: row_block_dim is invalid"); status = 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); verify_hipsparse_status_invalid_size(status, "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.idx_base; hipsparseIndexBase_t bsr_idx_base = argus.idx_base2; hipsparseDirection_t dir = argus.dirA; std::string binfile = ""; std::string filename = ""; hipsparseStatus_t status; // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu int safe_size = std::max(100, std::max(m, n)); if(m == -99 && n == -99 && argus.timing == 0) { binfile = argus.filename; m = n = safe_size; } if(argus.timing == 1) { filename = argus.filename; } int mb = -1; int nb = -1; if(row_block_dim > 0 && col_block_dim > 0) { mb = m * row_block_dim; nb = n * col_block_dim; } 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); // Argument sanity check before allocating invalid memory if(mb <= 0 || nb <= 0 || row_block_dim <= 0 || col_block_dim <= 0) { auto dbsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), 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 dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcsr_val_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(); 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(); // row pointer must be valid CHECK_HIP_ERROR(hipMemset(dbsr_row_ptr, 0, sizeof(int) * (safe_size + 1))); if(!dbsr_row_ptr || !dbsr_col_ind || !dbsr_val || !dcsr_row_ptr || !dcsr_col_ind || !dcsr_val) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dbsr_row_ptr || !dbsr_col_ind || !dbsr_val || " "!dcsr_row_ptr || !dcsr_col_ind || !dcsr_val"); return HIPSPARSE_STATUS_ALLOC_FAILED; } status = 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); if(mb < 0 || nb < 0 || row_block_dim < 0 || col_block_dim < 0) { verify_hipsparse_status_invalid_size( status, "Error: mb < 0 || nb < 0 || row_block_dim < 0 || col_block_dim < 0"); } else { verify_hipsparse_status_success( status, "mb >= 0 && nb >= 0 && row_block_dim >= 0 && col_block_dim >= 0"); } return HIPSPARSE_STATUS_SUCCESS; } // Read or construct CSR matrix std::vector bsr_row_ptr; std::vector bsr_col_ind; std::vector bsr_val; int nnzb; srand(12345ULL); if(binfile != "") { if(read_bin_matrix( binfile.c_str(), mb, nb, nnzb, bsr_row_ptr, bsr_col_ind, bsr_val, bsr_idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", binfile.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else if(argus.laplacian) { mb = nb = gen_2d_laplacian(argus.laplacian, bsr_row_ptr, bsr_col_ind, bsr_val, bsr_idx_base); nnzb = bsr_row_ptr[m]; } else { std::vector coo_row_ind; if(filename != "") { if(read_mtx_matrix( filename.c_str(), mb, nb, nnzb, coo_row_ind, bsr_col_ind, bsr_val, bsr_idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { double scale = 0.02; if(m > 1000 || n > 1000) { scale = 2.0 / std::max(mb, nb); } nnzb = mb * scale * nb; gen_matrix_coo(mb, nb, nnzb, coo_row_ind, bsr_col_ind, bsr_val, bsr_idx_base); } // Convert COO to CSR bsr_row_ptr.resize(mb + 1, 0); for(int i = 0; i < nnzb; ++i) { ++bsr_row_ptr[coo_row_ind[i] + 1 - bsr_idx_base]; } bsr_row_ptr[0] = bsr_idx_base; for(int i = 0; i < mb; ++i) { bsr_row_ptr[i + 1] += bsr_row_ptr[i]; } } m = mb * row_block_dim; n = nb * col_block_dim; int 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(); if(!dbsr_row_ptr || !dbsr_col_ind || !dbsr_val || !dcsr_row_ptr || !dcsr_col_ind || !dcsr_val) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dbsr_row_ptr || !dbsr_col_ind || !dbsr_val || " "!dcsr_row_ptr || !dcsr_col_ind || !dcsr_val"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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) { // DEVICE 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()); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GEBSR2CSR_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_gebsr2gebsc.hpp000066400000000000000000001013411447644345400237210ustar00rootroot00000000000000/* ************************************************************************ * 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_GEBSR2GEBSC_HPP #define TESTING_GEBSR2GEBSC_HPP #include "hipsparse.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(void) { #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 = 100; auto bsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), 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), 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(); if(!bsr_row_ptr || !bsr_col_ind || !bsr_val || !bsc_row_ind || !bsc_col_ptr || !bsc_val) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } 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) { hipsparseStatus_t status; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; hipsparseAction_t action = argus.action; hipsparseIndexBase_t base = argus.idx_base; // Argument sanity check before allocating invalid memory if((argus.M <= 0 && argus.M != -99) || (argus.N <= 0 && argus.M != -99) || argus.row_block_dimA <= 0 || argus.col_block_dimA <= 0) { #if(defined(CUDART_VERSION)) if(argus.row_block_dimA == 0 || argus.col_block_dimA == 0) { return HIPSPARSE_STATUS_SUCCESS; } #endif int M = argus.M; int N = argus.N; int row_block_dim = argus.row_block_dimA; int col_block_dim = argus.col_block_dimA; static const size_t safe_size = 100; // Allocate memory on device DEVICE_ALLOC(T, dbuffer, safe_size); if(!dbuffer) { return HIPSPARSE_STATUS_ALLOC_FAILED; } size_t buffer_size; status = hipsparseXgebsr2gebsc_bufferSize(handle, M, N, safe_size, (const T*)nullptr, nullptr, nullptr, row_block_dim, col_block_dim, &buffer_size); if(M < 0 || N < 0 || row_block_dim < 0 || col_block_dim < 0) { verify_hipsparse_status_invalid_size( status, "Error: M < 0 || N < 0 || row_block_dim < 0 || col_block_dim < 0"); } else { verify_hipsparse_status_success( status, "NOT(M < 0 || N < 0 || row_block_dim < 0 || col_block_dim < 0)"); } status = hipsparseXgebsr2gebsc(handle, M, N, safe_size, (const T*)nullptr, nullptr, nullptr, row_block_dim, col_block_dim, (T*)nullptr, nullptr, nullptr, action, base, dbuffer); if(M < 0 || N < 0 || row_block_dim < 0 || col_block_dim < 0) { verify_hipsparse_status_invalid_size( status, "Error: M < 0 || N < 0 || row_block_dim < 0 || col_block_dim < 0"); } else { verify_hipsparse_status_success( status, "NOT(M < 0 || N < 0 || row_block_dim < 0 || col_block_dim < 0)"); } return HIPSPARSE_STATUS_SUCCESS; } // // Build the gebsr matrix. // int bsr_mb = -1; int bsr_nb = -1; int bsr_nnzb = -1; int bsr_row_block_dim = -1; int bsr_col_block_dim = -1; std::vector hbsr_row_ptr; std::vector hbsr_col_ind; std::vector hbsr_val; { int m = argus.M; int n = argus.N; bsr_row_block_dim = argus.row_block_dimA; bsr_col_block_dim = argus.col_block_dimA; std::string binfile = ""; std::string filename = ""; // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu if(m == -99 && n == -99 && argus.timing == 0) { int safe_size = 100; binfile = argus.filename; m = n = safe_size; } if(argus.timing == 1) { filename = argus.filename; } // Read or construct CSR matrix std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; int nnz; srand(12345ULL); if(binfile != "") { if(read_bin_matrix( binfile.c_str(), m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", binfile.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else if(argus.laplacian) { m = n = gen_2d_laplacian(argus.laplacian, hcsr_row_ptr, hcsr_col_ind, hcsr_val, base); nnz = hcsr_row_ptr[m]; } else { std::vector coo_row_ind; if(filename != "") { if(read_mtx_matrix( filename.c_str(), m, n, nnz, coo_row_ind, hcsr_col_ind, hcsr_val, base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { double scale = 0.02; if(m > 1000 || n > 1000) { scale = 2.0 / std::max(m, n); } nnz = m * scale * n; nnz = std::max(nnz, 1); gen_matrix_coo(m, n, nnz, coo_row_ind, hcsr_col_ind, hcsr_val, base); } // Convert COO to CSR hcsr_row_ptr.resize(m + 1, 0); for(int i = 0; i < nnz; ++i) { ++hcsr_row_ptr[coo_row_ind[i] + 1 - base]; } hcsr_row_ptr[0] = base; for(int i = 0; i < m; ++i) { hcsr_row_ptr[i + 1] += hcsr_row_ptr[i]; } } // // Now convert the CSR matrix to a GEBSR matrix. // bsr_mb = m; bsr_nb = n; bsr_nnzb = nnz; size_t nvalues = bsr_nnzb * bsr_row_block_dim * bsr_col_block_dim; hbsr_val.resize(nvalues); for(size_t i = 0; i < nvalues; ++i) { hbsr_val[i] = random_generator(); } hbsr_row_ptr = hcsr_row_ptr; hbsr_col_ind = hcsr_col_ind; } DEVICE_ALLOC(int, dbsr_row_ptr, (bsr_mb + 1)); DEVICE_ALLOC(int, dbsr_col_ind, bsr_nnzb); DEVICE_ALLOC(T, dbsr_val, (bsr_nnzb * bsr_row_block_dim * bsr_col_block_dim)); // Copy data from host to device CHECK_HIP_ERROR(hipMemcpy( dbsr_row_ptr, hbsr_row_ptr.data(), sizeof(int) * (bsr_mb + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy( dbsr_col_ind, hbsr_col_ind.data(), sizeof(int) * bsr_nnzb, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dbsr_val, hbsr_val.data(), sizeof(T) * bsr_nnzb * bsr_row_block_dim * bsr_col_block_dim, hipMemcpyHostToDevice)); // // Obtain required buffer size (from host) // size_t buffer_size; CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2gebsc_bufferSize(handle, bsr_mb, bsr_nb, bsr_nnzb, dbsr_val, dbsr_row_ptr, dbsr_col_ind, bsr_row_block_dim, bsr_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, bsr_nnzb); DEVICE_ALLOC(int, dbsc_col_ptr, (bsr_nb + 1)); DEVICE_ALLOC(T, dbsc_val, (bsr_nnzb * bsr_row_block_dim * bsr_col_block_dim)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2gebsc(handle, bsr_mb, bsr_nb, bsr_nnzb, dbsr_val, dbsr_row_ptr, dbsr_col_ind, bsr_row_block_dim, bsr_col_block_dim, dbsc_val, dbsc_row_ind, dbsc_col_ptr, action, base, dbuffer)); // // Transfer to host. // std::vector hbsc_from_device_row_ind(bsr_nnzb); std::vector hbsc_from_device_col_ptr(bsr_nb + 1); std::vector hbsc_from_device_val(bsr_nnzb * bsr_row_block_dim * bsr_col_block_dim); CHECK_HIP_ERROR(hipMemcpy(hbsc_from_device_col_ptr.data(), dbsc_col_ptr, sizeof(int) * (bsr_nb + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsc_from_device_row_ind.data(), dbsc_row_ind, sizeof(int) * bsr_nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsc_from_device_val.data(), dbsc_val, sizeof(T) * bsr_nnzb * bsr_row_block_dim * bsr_col_block_dim, hipMemcpyDeviceToHost)); // // Allocate host bsc matrix. // std::vector hbsc_row_ind(bsr_nnzb); std::vector hbsc_col_ptr(bsr_nb + 1); std::vector hbsc_val(bsr_nnzb * bsr_row_block_dim * bsr_col_block_dim); host_gebsr_to_gebsc(bsr_mb, bsr_nb, bsr_nnzb, hbsr_row_ptr, hbsr_col_ind, hbsr_val, bsr_row_block_dim, bsr_col_block_dim, hbsc_row_ind, hbsc_col_ptr, hbsc_val, action, base); unit_check_general(1, bsr_nb + 1, 1, hbsc_from_device_col_ptr.data(), hbsc_col_ptr.data()); unit_check_general(1, bsr_nnzb, 1, hbsc_from_device_row_ind.data(), hbsc_row_ind.data()); if(action == HIPSPARSE_ACTION_NUMERIC) { unit_check_general(1, bsr_nnzb * bsr_row_block_dim * bsr_col_block_dim, 1, hbsc_from_device_val.data(), hbsc_val.data()); } } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GEBSR2GEBSC_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_gebsr2gebsr.hpp000066400000000000000000001776331447644345400237610ustar00rootroot00000000000000/* ************************************************************************ * 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_GEBSR2GEBSR_HPP #define TESTING_GEBSR2GEBSR_HPP #include "hipsparse.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(void) { #if(!defined(CUDART_VERSION)) int mb = 100; int nb = 100; int nnzb = 100; int safe_size = 100; 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), 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), 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(); if(!bsr_row_ptr_A || !bsr_col_ind_A || !bsr_val_A || !bsr_row_ptr_C || !bsr_col_ind_C || !bsr_val_C || !temp_buffer) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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"); 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, &nnz_total_dev_host_ptr, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer 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"); 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, col_block_dim_C, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: temp_buffer 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.idx_base; hipsparseIndexBase_t idx_base_C = argus.idx_base2; hipsparseDirection_t dir = argus.dirA; std::string binfile = ""; std::string filename = ""; hipsparseStatus_t status; // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu int safe_size = 100; if(m == -99 && n == -99 && argus.timing == 0) { binfile = argus.filename; m = n = safe_size; } if(argus.timing == 1) { filename = argus.filename; } int mb = -1; int nb = -1; if(row_block_dim_A > 0 && col_block_dim_A > 0) { mb = (m + row_block_dim_A - 1) / row_block_dim_A; nb = (n + col_block_dim_A - 1) / col_block_dim_A; } 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); // Argument sanity check before allocating invalid memory if(mb <= 0 || nb <= 0 || row_block_dim_A <= 0 || col_block_dim_A <= 0 || row_block_dim_C <= 0 || col_block_dim_C <= 0) { auto dtemp_buffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; T* dtemp_buffer = (T*)dtemp_buffer_managed.get(); if(!dtemp_buffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dtemp_buffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, safe_size, descr_A, (const T*)nullptr, nullptr, nullptr, row_block_dim_A, col_block_dim_A, descr_C, (T*)nullptr, nullptr, nullptr, row_block_dim_C, col_block_dim_C, dtemp_buffer); if(mb < 0 || nb < 0 || row_block_dim_A <= 0 || col_block_dim_A <= 0 || row_block_dim_C <= 0 || col_block_dim_C <= 0) { verify_hipsparse_status_invalid_size( status, "Error: mb < 0 || nb < 0 || row_block_dim_A <= 0 || col_block_dim_A <= 0 || " "row_block_dim_C <= 0 || col_block_dim_C <= 0"); } else { verify_hipsparse_status_success( status, "mb >= 0 && nb >= 0 && row_block_dim_A > 0 && col_block_dim_A > 0 && " "row_block_dim_C > 0 && col_block_dim_C > 0"); } return HIPSPARSE_STATUS_SUCCESS; } // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; int nnz; // Initial Data on CPU srand(12345ULL); if(binfile != "") { if(read_bin_matrix( binfile.c_str(), m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base_A) != 0) { fprintf(stderr, "Cannot open [read] %s\n", binfile.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else if(argus.laplacian) { m = n = gen_2d_laplacian(argus.laplacian, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base_A); nnz = hcsr_row_ptr[m]; } else { std::vector coo_row_ind; if(filename != "") { if(read_mtx_matrix( filename.c_str(), m, n, nnz, coo_row_ind, hcsr_col_ind, hcsr_val, idx_base_A) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { double scale = 0.02; if(m > 1000 || n > 1000) { scale = 2.0 / std::max(m, n); } nnz = m * scale * n; gen_matrix_coo(m, n, nnz, coo_row_ind, hcsr_col_ind, hcsr_val, idx_base_A); } // Convert COO to CSR hcsr_row_ptr.resize(m + 1, 0); for(int i = 0; i < nnz; ++i) { ++hcsr_row_ptr[coo_row_ind[i] + 1 - idx_base_A]; } hcsr_row_ptr[0] = idx_base_A; for(int i = 0; i < m; ++i) { hcsr_row_ptr[i + 1] += hcsr_row_ptr[i]; } } // mb and nb can be modified if reading from a file mb = (m + row_block_dim_A - 1) / row_block_dim_A; 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; // 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(); if(!dcsr_val || !dcsr_row_ptr || !dcsr_col_ind || !dbsr_row_ptr_A) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dval || !dptr || !dcol || !dbsr_row_ptr_A"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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(); if(!dbuffer_conversion) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dbuffer_conversion"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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(); if(!dbsr_col_ind_A || !dbsr_val_A || !dbsr_row_ptr_C) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dbsr_col_ind_A || !dbsr_val_A || !dbsr_row_ptr_C"); return HIPSPARSE_STATUS_ALLOC_FAILED; } 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(); if(!dbuffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dbuffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } if(argus.unit_check) { // 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)); // 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(!dbsr_col_ind_C || !dbsr_val_C) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!bsr_col_ind_C || !bsr_val_C"); return HIPSPARSE_STATUS_ALLOC_FAILED; } 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()); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GEBSR2GEBSR_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_gemmi.hpp000066400000000000000000000672441447644345400226440ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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(void) { #if(!defined(CUDART_VERSION)) int safe_size = 100; T alpha = 0.6; T beta = 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(); if(!dval || !dptr || !drow || !dA || !dC) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } 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 safe_size = 100; int M = argus.M; int N = argus.N; int K = argus.K; int lda = argus.lda; int ldc = argus.ldc; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); std::string binfile = ""; std::string filename = ""; hipsparseStatus_t status; // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu if(K == -99 && N == -99 && argus.timing == 0) { binfile = argus.filename; K = N = safe_size; } if(argus.timing == 1) { filename = argus.filename; } std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; // Determine number of non-zero elements double scale = 0.02; if(K > 1000 || N > 1000) { scale = 2.0 / std::max(K, N); } int nnz = K * scale * N; #ifdef __HIP_PLATFORM_NVIDIA__ // Do not test args in cusparse if(M <= 0 || N <= 0 || K <= 0) { return HIPSPARSE_STATUS_SUCCESS; } #endif // Argument sanity check before allocating invalid memory if(M <= 0 || N <= 0 || K < 0) { 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(); if(!dval || !dptr || !drow || !dA || !dC) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dptr || !drow || !dval || !dA || !dC"); return HIPSPARSE_STATUS_ALLOC_FAILED; } CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); status = hipsparseXgemmi( handle, M, N, K, nnz, &h_alpha, dA, lda, dval, dptr, drow, &h_beta, dC, ldc); if(M < 0 || N < 0 || K < 0 || nnz < 0) { verify_hipsparse_status_invalid_size(status, "Error: M < 0 || N < 0 || K < 0 || nnz < 0"); } else { verify_hipsparse_status_success(status, "M >= 0 && N >= 0 && K >= 0 && nnz >= 0"); } return HIPSPARSE_STATUS_SUCCESS; } // Initialize random seed srand(12345ULL); // Host structures - CSC matrix A std::vector hcsc_col_ptrB; std::vector hcsc_row_indB; std::vector hcsc_valB; // Initial Data on CPU if(binfile != "") { if(read_bin_matrix(binfile.c_str(), N, K, nnz, hcsc_col_ptrB, hcsc_row_indB, hcsc_valB, HIPSPARSE_INDEX_BASE_ZERO) != 0) { fprintf(stderr, "Cannot open [read] %s\n", binfile.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else if(argus.laplacian) { N = K = gen_2d_laplacian( argus.laplacian, hcsc_col_ptrB, hcsc_row_indB, hcsc_valB, HIPSPARSE_INDEX_BASE_ZERO); nnz = hcsc_col_ptrB[N]; } else { std::vector hcoo_row_indA; if(filename != "") { if(read_mtx_matrix(filename.c_str(), N, K, nnz, hcoo_row_indA, hcsc_row_indB, hcsc_valB, HIPSPARSE_INDEX_BASE_ZERO) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { gen_matrix_coo( N, K, nnz, hcoo_row_indA, hcsc_row_indB, hcsc_valB, HIPSPARSE_INDEX_BASE_ZERO); } // Convert COO to CSC hcsc_col_ptrB.resize(N + 1, 0); for(int i = 0; i < nnz; ++i) { ++hcsc_col_ptrB[hcoo_row_indA[i] + 1]; } hcsc_col_ptrB[0] = 0; for(int i = 0; i < N; ++i) { hcsc_col_ptrB[i + 1] += hcsc_col_ptrB[i]; } } lda = std::max(1, M); 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 + 1)), device_free}; auto dcsc_valB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * (nnz + 1)), device_free}; auto dA_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * (Annz + 1)), 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(); if(!dcsc_valB || !dcsc_col_ptrB || !dcsc_row_indB || !dA || !dC_1 || !d_alpha || !d_beta) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dcsc_valB || !dcsc_col_ptrB || !dcsc_row_indB || !dA || " "!dC_1 || !d_alpha || !d_beta"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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)); // ROCSPARSE 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)); // ROCSPARSE 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()); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GEMMI_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_gemvi.hpp000066400000000000000000000237501447644345400226470ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include using namespace hipsparse; using namespace hipsparse_test; void testing_gemvi_bad_arg(void) { 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; float alpha = 0.6; float beta = 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(float) * m * n), device_free}; auto x_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * 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(float) * m), device_free}; float* A = (float*)A_managed.get(); float* x = (float*)x_managed.get(); int* xInd = (int*)xInd_managed.get(); float* y = (float*)y_managed.get(); if(!A || !xInd || !x || !y) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // cusparse has error checks for this function at all #if(!defined(CUDART_VERSION)) // gemvi bufferSize - buffer size is currently not doing anything // int 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"); // gemvi void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, 100)); verify_hipsparse_status_invalid_handle(hipsparseSgemvi( nullptr, opType, m, n, &alpha, A, lda, nnz, x, xInd, &beta, y, idxBase, buffer)); verify_hipsparse_status_invalid_pointer( hipsparseSgemvi( handle, opType, m, n, nullptr, A, lda, nnz, x, xInd, &beta, y, idxBase, buffer), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSgemvi( handle, opType, m, n, &alpha, nullptr, lda, nnz, x, xInd, &beta, y, idxBase, buffer), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSgemvi( handle, opType, m, n, &alpha, A, lda, nnz, nullptr, xInd, &beta, y, idxBase, buffer), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSgemvi( handle, opType, m, n, &alpha, A, lda, nnz, x, nullptr, &beta, y, idxBase, buffer), "Error: xInd is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSgemvi( handle, opType, m, n, &alpha, A, lda, nnz, x, xInd, nullptr, y, idxBase, buffer), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSgemvi( handle, opType, m, n, &alpha, A, lda, nnz, x, xInd, &beta, nullptr, idxBase, buffer), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSgemvi( handle, opType, m, n, &alpha, A, lda, nnz, x, xInd, &beta, y, idxBase, nullptr), "Error: buffer is nullptr"); verify_hipsparse_status_invalid_size( hipsparseSgemvi( handle, opType, -1, n, &alpha, A, lda, nnz, x, xInd, &beta, y, idxBase, buffer), "Error: m is invalid"); verify_hipsparse_status_invalid_size( hipsparseSgemvi( handle, opType, m, -1, &alpha, A, lda, nnz, x, xInd, &beta, y, idxBase, buffer), "Error: n is invalid"); verify_hipsparse_status_invalid_size( hipsparseSgemvi( handle, opType, m, n, &alpha, A, -1, nnz, x, xInd, &beta, y, idxBase, buffer), "Error: lda is invalid"); verify_hipsparse_status_invalid_size( hipsparseSgemvi( handle, opType, m, n, &alpha, A, lda, -1, x, xInd, &beta, y, idxBase, buffer), "Error: nnz is invalid"); verify_hipsparse_status_invalid_size( hipsparseSgemvi( 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(void) { int m = 1291; int n = 724; int nnz = 237; static constexpr hipsparseOperation_t opType = HIPSPARSE_OPERATION_NON_TRANSPOSE; int lda = m; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; T alpha = make_DataType(0.6); T beta = make_DataType(3.2); // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_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(); if(!dx_ind || !dx_val || !dy || !dA) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dx_ind || !dx_val || !dy || !dA"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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, opType, m, n, nnz, &bufferSize)); CHECK_HIP_ERROR(hipMalloc(&externalBuffer, bufferSize)); // gemvi CHECK_HIPSPARSE_ERROR(hipsparseXgemvi(handle, opType, m, n, &alpha, dA, lda, nnz, dx_val, dx_ind, &beta, dy, idxBase, externalBuffer)); CHECK_HIP_ERROR(hipFree(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] * 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()); return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GEMVI_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_gpsv_interleaved_batch.hpp000066400000000000000000000252731447644345400262440ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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(); if(!dds || !ddl || !dd || !ddu || !ddw || !dx || !dbuf) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } 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(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; int algo = 0; int m = 512; int batch_count = 512; // 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(); if(!dds || !ddl || !dd || !ddu || !ddw || !dx) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dds || !ddl || !dd || !ddu || !ddw || !dx"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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)); 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()); CHECK_HIP_ERROR(hipFree(buffer)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GPSV_INTERLEAVED_BATCH_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_gthr.hpp000066400000000000000000000160341447644345400225010ustar00rootroot00000000000000/* ************************************************************************ * 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_GTHR_HPP #define TESTING_GTHR_HPP #include "hipsparse.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(void) { int nnz = 100; int safe_size = 100; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseStatus_t status; 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(!dx_ind || !dx_val || !dy) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } #if(!defined(CUDART_VERSION)) // testing for(nullptr == dx_ind) { int* dx_ind_null = nullptr; status = hipsparseXgthr(handle, nnz, dy, dx_val, dx_ind_null, idx_base); verify_hipsparse_status_invalid_pointer(status, "Error: x_ind is nullptr"); } // testing for(nullptr == dx_val) { T* dx_val_null = nullptr; status = hipsparseXgthr(handle, nnz, dy, dx_val_null, dx_ind, idx_base); verify_hipsparse_status_invalid_pointer(status, "Error: x_val is nullptr"); } // testing for(nullptr == dy) { T* dy_null = nullptr; status = hipsparseXgthr(handle, nnz, dy_null, dx_val, dx_ind, idx_base); verify_hipsparse_status_invalid_pointer(status, "Error: y is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXgthr(handle_null, nnz, dy, dx_val, dx_ind, idx_base); verify_hipsparse_status_invalid_handle(status); } #endif } template hipsparseStatus_t testing_gthr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int N = argus.N; int nnz = argus.nnz; int safe_size = 100; hipsparseIndexBase_t idx_base = argus.idx_base; hipsparseStatus_t status; std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; // Argument sanity check before allocating invalid memory if(nnz <= 0) { auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dx_val_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* dx_ind = (int*)dx_ind_managed.get(); T* dx_val = (T*)dx_val_managed.get(); T* dy = (T*)dy_managed.get(); if(!dx_ind || !dx_val || !dy) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dx_ind || !dx_val || !dy"); return HIPSPARSE_STATUS_ALLOC_FAILED; } CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); status = hipsparseXgthr(handle, nnz, dy, dx_val, dx_ind, idx_base); if(nnz < 0) { verify_hipsparse_status_invalid_size(status, "Error: nnz < 0"); } else { verify_hipsparse_status_success(status, "nnz == 0"); } return HIPSPARSE_STATUS_SUCCESS; } // 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(); if(!dx_ind || !dx_val || !dy) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dx_ind || !dx_val || !dy"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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) { // ROCSPARSE 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()); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GTHR_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_gthrz.hpp000066400000000000000000000165131447644345400226750ustar00rootroot00000000000000/* ************************************************************************ * 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_GTHRZ_HPP #define TESTING_GTHRZ_HPP #include "hipsparse.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(void) { int nnz = 100; int safe_size = 100; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseStatus_t status; 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(!dx_ind || !dx_val || !dy) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } #if(!defined(CUDART_VERSION)) // testing for(nullptr == dx_ind) { int* dx_ind_null = nullptr; status = hipsparseXgthrz(handle, nnz, dy, dx_val, dx_ind_null, idx_base); verify_hipsparse_status_invalid_pointer(status, "Error: x_ind is nullptr"); } // testing for(nullptr == dx_val) { T* dx_val_null = nullptr; status = hipsparseXgthrz(handle, nnz, dy, dx_val_null, dx_ind, idx_base); verify_hipsparse_status_invalid_pointer(status, "Error: x_val is nullptr"); } // testing for(nullptr == dy) { T* dy_null = nullptr; status = hipsparseXgthrz(handle, nnz, dy_null, dx_val, dx_ind, idx_base); verify_hipsparse_status_invalid_pointer(status, "Error: y is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXgthrz(handle_null, nnz, dy, dx_val, dx_ind, idx_base); verify_hipsparse_status_invalid_handle(status); } #endif } template hipsparseStatus_t testing_gthrz(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int N = argus.N; int nnz = argus.nnz; int safe_size = 100; hipsparseIndexBase_t idx_base = argus.idx_base; hipsparseStatus_t status; std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; // Argument sanity check before allocating invalid memory if(nnz <= 0) { auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dx_val_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* dx_ind = (int*)dx_ind_managed.get(); T* dx_val = (T*)dx_val_managed.get(); T* dy = (T*)dy_managed.get(); if(!dx_ind || !dx_val || !dy) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dx_ind || !dx_val || !dy"); return HIPSPARSE_STATUS_ALLOC_FAILED; } CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); status = hipsparseXgthrz(handle, nnz, dy, dx_val, dx_ind, idx_base); if(nnz < 0) { verify_hipsparse_status_invalid_size(status, "Error: nnz < 0"); } else { verify_hipsparse_status_success(status, "nnz == 0"); } return HIPSPARSE_STATUS_SUCCESS; } // 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(); if(!dx_ind || !dx_val || !dy) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dx_ind || !dx_val || !dy"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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) { // ROCSPARSE 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()); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GTHRZ_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_gtsv.hpp000066400000000000000000000176771447644345400225360ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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(); if(!ddl || !dd || !ddu || !dB || !dbuf) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } 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(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; int m = 512; int n = 512; 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(); if(!ddl || !dd || !ddu || !dB) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!ddl || !dd || !ddu || !dB"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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)); 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()); CHECK_HIP_ERROR(hipFree(buffer)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GTSV2_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_gtsv2_nopivot.hpp000066400000000000000000000201561447644345400243600ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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(); if(!ddl || !dd || !ddu || !dB || !dbuf) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } 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"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsv2_nopivot(handle, m, n, ddl, dd, ddu, dB, ldb, nullptr), "Error: bsize is nullptr"); #endif } template hipsparseStatus_t testing_gtsv2_nopivot(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; int m = 512; int n = 512; 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(); if(!ddl || !dd || !ddu || !dB) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!ddl || !dd || !ddu || !dB"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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)); 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()); CHECK_HIP_ERROR(hipFree(buffer)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GTSV2_NOPIVOT_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_gtsv2_strided_batch.hpp000066400000000000000000000230051447644345400254550ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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(); if(!ddl || !dd || !ddu || !dx || !dbuf) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } 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"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsv2StridedBatch( handle, m, ddl, dd, ddu, dx, batch_count, batch_stride, nullptr), "Error: bsize is nullptr"); #endif } template hipsparseStatus_t testing_gtsv2_strided_batch(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; int m = 512; int batch_count = 512; 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(); if(!ddl || !dd || !ddu || !dx) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!ddl || !dd || !ddu || !dx"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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)); 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()); CHECK_HIP_ERROR(hipFree(buffer)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GTSV2_NOPIVOT_STRIDED_BATCH_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_gtsv_interleaved_batch.hpp000066400000000000000000000213061447644345400262410ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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(); if(!ddl || !dd || !ddu || !dx || !dbuf) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } 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(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; int algo = 0; int m = 512; int batch_count = 512; // 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(); if(!ddl || !dd || !ddu || !dx) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!ddl || !dd || !ddu || !dx"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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)); 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()); CHECK_HIP_ERROR(hipFree(buffer)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GTSV_INTERLEAVED_BATCH_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_hyb2csr.hpp000066400000000000000000000314421447644345400231110ustar00rootroot00000000000000/* ************************************************************************ * 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_HYB2CSR_HPP #define TESTING_HYB2CSR_HPP #include "hipsparse.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; struct test_hyb { 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 void testing_hyb2csr_bad_arg(void) { #if(!defined(CUDART_VERSION)) int safe_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; std::unique_ptr unique_ptr_hyb(new hyb_struct); hipsparseHybMat_t hyb = unique_ptr_hyb->hyb; test_hyb* dhyb = (test_hyb*)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(); if(!csr_row_ptr || !csr_col_ind || !csr_val) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // Testing hipsparseXhyb2csr() // Testing for (csr_row_ptr == nullptr) { int* csr_row_ptr_null = nullptr; status = hipsparseXhyb2csr(handle, descr, hyb, csr_val, csr_row_ptr_null, csr_col_ind); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr is nullptr"); } // Testing for (csr_col_ind == nullptr) { int* csr_col_ind_null = nullptr; status = hipsparseXhyb2csr(handle, descr, hyb, csr_val, csr_row_ptr, csr_col_ind_null); verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind is nullptr"); } // Testing for (csr_val == nullptr) { T* csr_val_null = nullptr; status = hipsparseXhyb2csr(handle, descr, hyb, csr_val_null, csr_row_ptr, csr_col_ind); verify_hipsparse_status_invalid_pointer(status, "Error: csr_val is nullptr"); } // Testing for (descr == nullptr) { hipsparseMatDescr_t descr_null = nullptr; status = hipsparseXhyb2csr(handle, descr_null, hyb, csr_val, csr_row_ptr, csr_col_ind); verify_hipsparse_status_invalid_pointer(status, "Error: csr_val is nullptr"); } // Testing for (hyb == nullptr) { hipsparseHybMat_t* hyb_null = nullptr; status = hipsparseXhyb2csr(handle, descr, hyb_null, csr_val, csr_row_ptr, csr_col_ind); verify_hipsparse_status_invalid_pointer(status, "Error: csr_val is nullptr"); } // Testing for (handle == nullptr) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXhyb2csr(handle_null, descr, hyb, csr_val, csr_row_ptr, csr_col_ind); verify_hipsparse_status_invalid_handle(status); } #endif } template hipsparseStatus_t testing_hyb2csr(Arguments argus) { int m = argus.M; int n = argus.N; int safe_size = 100; hipsparseIndexBase_t idx_base = argus.idx_base; std::string binfile = ""; std::string filename = ""; hipsparseStatus_t status; // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu if(m == -99 && n == -99 && argus.timing == 0) { binfile = argus.filename; m = n = safe_size; } if(argus.timing == 1) { filename = argus.filename; } double scale = 0.02; if(m > 1000 || n > 1000) { scale = 2.0 / std::max(m, n); } int nnz = m * scale * n; 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)); // Argument sanity check before allocating invalid memory if(m <= 0 || n <= 0 || nnz <= 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // Do not test args in cusparse return HIPSPARSE_STATUS_SUCCESS; #endif test_hyb* dhyb = (test_hyb*)hyb; dhyb->m = m; dhyb->n = n; 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(); if(!csr_row_ptr || !csr_col_ind || !csr_val) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!csr_row_ptr || !csr_col_ind || !csr_val"); return HIPSPARSE_STATUS_ALLOC_FAILED; } status = hipsparseXhyb2csr(handle, descr, hyb, csr_val, csr_row_ptr, csr_col_ind); if(m < 0 || n < 0 || nnz < 0) { verify_hipsparse_status_invalid_size(status, "Error: m < 0 || n < 0 || nnz < 0"); } else { verify_hipsparse_status_success(status, "m >= 0 && n >= 0 && nnz >= 0"); } return HIPSPARSE_STATUS_SUCCESS; } // Host structures std::vector hcsr_row_ptr_gold; std::vector hcsr_col_ind_gold; std::vector hcsr_val_gold; // Sample initial COO matrix on CPU srand(12345ULL); if(binfile != "") { if(read_bin_matrix(binfile.c_str(), m, n, nnz, hcsr_row_ptr_gold, hcsr_col_ind_gold, hcsr_val_gold, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", binfile.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else if(argus.laplacian) { m = n = gen_2d_laplacian( argus.laplacian, hcsr_row_ptr_gold, hcsr_col_ind_gold, hcsr_val_gold, idx_base); nnz = hcsr_row_ptr_gold[m]; } else { std::vector hcoo_row_ind; if(filename != "") { if(read_mtx_matrix(filename.c_str(), m, n, nnz, hcoo_row_ind, hcsr_col_ind_gold, hcsr_val_gold, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { gen_matrix_coo(m, n, nnz, hcoo_row_ind, hcsr_col_ind_gold, hcsr_val_gold, idx_base); } // Convert COO to CSR hcsr_row_ptr_gold.resize(m + 1, 0); 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]; } } // 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(); if(!dcsr_row_ptr || !dcsr_col_ind || !dcsr_val) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dcsr_row_ptr || !dcsr_col_ind || !dcsr_val"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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()); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_HYB2CSR_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_hybmv.hpp000066400000000000000000000415461447644345400226700ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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) 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 void testing_hybmv_bad_arg(void) { int safe_size = 100; T alpha = 0.6; T beta = 0.2; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; 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_hyb(new hyb_struct); hipsparseHybMat_t hyb = unique_ptr_hyb->hyb; 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(); if(!dx || !dy) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // testing for(nullptr == dx) { T* dx_null = nullptr; status = hipsparseXhybmv(handle, transA, &alpha, descr, hyb, dx_null, &beta, dy); verify_hipsparse_status_invalid_pointer(status, "Error: dx is nullptr"); } // testing for(nullptr == dy) { T* dy_null = nullptr; status = hipsparseXhybmv(handle, transA, &alpha, descr, hyb, dx, &beta, dy_null); verify_hipsparse_status_invalid_pointer(status, "Error: dy is nullptr"); } // testing for(nullptr == d_alpha) { T* d_alpha_null = nullptr; status = hipsparseXhybmv(handle, transA, d_alpha_null, descr, hyb, dx, &beta, dy); verify_hipsparse_status_invalid_pointer(status, "Error: alpha is nullptr"); } // testing for(nullptr == d_beta) { T* d_beta_null = nullptr; status = hipsparseXhybmv(handle, transA, &alpha, descr, hyb, dx, d_beta_null, dy); verify_hipsparse_status_invalid_pointer(status, "Error: beta is nullptr"); } // testing for(nullptr == hyb) { hipsparseHybMat_t hyb_null = nullptr; status = hipsparseXhybmv(handle, transA, &alpha, descr, hyb_null, dx, &beta, dy); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); } // testing for(nullptr == descr) { hipsparseMatDescr_t descr_null = nullptr; status = hipsparseXhybmv(handle, transA, &alpha, descr_null, hyb, dx, &beta, dy); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); } // testing for(nullptr == handle) { hipsparseHandle_t handle_null = nullptr; status = hipsparseXhybmv(handle_null, transA, &alpha, descr, hyb, dx, &beta, dy); verify_hipsparse_status_invalid_handle(status); } } template hipsparseStatus_t testing_hybmv(Arguments argus) { int safe_size = 100; 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.idx_base; hipsparseHybPartition_t part = argus.part; int user_ell_width = argus.ell_width; std::string binfile = ""; std::string filename = ""; hipsparseStatus_t status; T zero = make_DataType(0.0); T one = make_DataType(1.0); // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu if(m == -99 && n == -99 && argus.timing == 0) { binfile = argus.filename; m = n = safe_size; } if(argus.timing == 1) { filename = argus.filename; } std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; std::unique_ptr test_descr(new descr_struct); hipsparseMatDescr_t descr = test_descr->descr; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); std::unique_ptr test_hyb(new hyb_struct); hipsparseHybMat_t hyb = test_hyb->hyb; // Determine number of non-zero elements double scale = 0.02; if(m > 1000 || n > 1000) { scale = 2.0 / std::max(m, n); } int nnz = m * scale * n; // Argument sanity check before allocating invalid memory if(m <= 0 || n <= 0 || nnz <= 0) { 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(); if(!dval || !dptr || !dcol || !dx || !dy) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dptr || !dcol || !dval || !dx || !dy"); return HIPSPARSE_STATUS_ALLOC_FAILED; } CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); status = hipsparseXcsr2hyb(handle, m, n, descr, dval, dptr, dcol, hyb, user_ell_width, part); if(m < 0 || n < 0 || nnz < 0) { verify_hipsparse_status_invalid_size(status, "Error: m < 0 || n < 0 || nnz < 0"); } // hybmv should be able to deal with m <= 0 || n <= 0 || nnz <= 0 even if csr2hyb fails // because hyb structures is allocated with n = m = 0 - so nothing should happen status = hipsparseXhybmv(handle, transA, &h_alpha, descr, hyb, dx, &h_beta, dy); verify_hipsparse_status_success(status, "m >= 0 && n >= 0 && nnz >= 0"); return HIPSPARSE_STATUS_SUCCESS; } // Host structures std::vector hcsr_row_ptr; std::vector hcoo_row_ind; std::vector hcol_ind; std::vector hval; // Initial Data on CPU srand(12345ULL); if(binfile != "") { if(read_bin_matrix(binfile.c_str(), m, n, nnz, hcsr_row_ptr, hcol_ind, hval, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", binfile.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else if(argus.laplacian) { m = n = gen_2d_laplacian(argus.laplacian, hcsr_row_ptr, hcol_ind, hval, idx_base); nnz = hcsr_row_ptr[m]; } else { if(filename != "") { if(read_mtx_matrix(filename.c_str(), m, n, nnz, hcoo_row_ind, hcol_ind, hval, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { gen_matrix_coo(m, n, nnz, hcoo_row_ind, hcol_ind, hval, idx_base); } // Convert COO to CSR hcsr_row_ptr.resize(m + 1, 0); for(int i = 0; i < nnz; ++i) { ++hcsr_row_ptr[hcoo_row_ind[i] + 1 - idx_base]; } hcsr_row_ptr[0] = idx_base; for(int i = 0; i < m; ++i) { hcsr_row_ptr[i + 1] += hcsr_row_ptr[i]; } } 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(); if(!dval || !dptr || !dcol || !dx || !dy_1 || !dy_2 || !d_alpha || !d_beta) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dval || !dptr || !dcol || !dx || " "!dy_1 || !dy_2 || !d_alpha || !d_beta"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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 = (2 * nnz - 1) / m + 1; // Limit ELL user width if(part == HIPSPARSE_HYB_PARTITION_USER) { user_ell_width = user_ell_width * nnz / m; user_ell_width = std::min(width_limit, user_ell_width); } // Convert CSR to HYB 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)); // ROCSPARSE 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)); // ROCSPARSE 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()); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_HYBMV_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_identity.hpp000066400000000000000000000102731447644345400233650ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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) { 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(); if(!p) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } #if(!defined(CUDART_VERSION)) 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) { int n = argus.N; int safe_size = 100; hipsparseStatus_t status; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Argument sanity check before allocating invalid memory if(n <= 0) { auto p_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; int* p = (int*)p_managed.get(); if(!p) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!p"); return HIPSPARSE_STATUS_ALLOC_FAILED; } status = hipsparseCreateIdentityPermutation(handle, n, p); if(n < 0) { verify_hipsparse_status_invalid_size(status, "Error: n < 0"); } else { verify_hipsparse_status_success(status, "n >= 0"); } return HIPSPARSE_STATUS_SUCCESS; } // 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(!dp) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!p"); return HIPSPARSE_STATUS_ALLOC_FAILED; } 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()); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_IDENTITY_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_nnz.hpp000066400000000000000000000323151447644345400223420ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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; 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 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(!d_nnzPerRowColumn || !d_A || !d_nnzTotalDevHostPtr) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } #if(!defined(CUDART_VERSION)) // // Testing invalid handle. // status = hipsparseXnnz( nullptr, dirA, M, N, descrA, (const T*)d_A, lda, d_nnzPerRowColumn, d_nnzTotalDevHostPtr); verify_hipsparse_status_invalid_handle(status); // // Testing invalid pointers. // status = hipsparseXnnz( handle, dirA, M, N, nullptr, (const T*)d_A, lda, d_nnzPerRowColumn, d_nnzTotalDevHostPtr); verify_hipsparse_status_invalid_pointer(status, "Error: descrA as invalid pointer must be detected."); status = hipsparseXnnz(handle, dirA, M, N, descrA, (const T*)nullptr, lda, d_nnzPerRowColumn, d_nnzTotalDevHostPtr); verify_hipsparse_status_invalid_pointer(status, "Error: A as invalid pointer must be detected."); status = hipsparseXnnz( handle, dirA, M, N, descrA, (const T*)d_A, lda, nullptr, d_nnzTotalDevHostPtr); verify_hipsparse_status_invalid_pointer( status, "Error: nnzPerRowColumn as invalid pointer must be detected."); status = hipsparseXnnz(handle, dirA, M, N, descrA, (const T*)d_A, lda, d_nnzPerRowColumn, nullptr); verify_hipsparse_status_invalid_pointer( status, "Error: nnzTotalDevHostPtr as invalid pointer must be detected."); #endif // // Testing invalid direction // try { status = 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(...) { } // // Testing invalid size on M // status = hipsparseXnnz( handle, dirA, -1, N, descrA, (const T*)d_A, lda, d_nnzPerRowColumn, d_nnzTotalDevHostPtr); verify_hipsparse_status_invalid_size(status, "Error: M < 0 must be detected."); // // Testing invalid size on N // status = hipsparseXnnz( handle, dirA, M, -1, descrA, (const T*)d_A, lda, d_nnzPerRowColumn, d_nnzTotalDevHostPtr); verify_hipsparse_status_invalid_size(status, "Error: N < 0 must be detected."); // // Testing invalid size on lda // status = hipsparseXnnz( handle, dirA, M, N, descrA, (const T*)d_A, M - 1, d_nnzPerRowColumn, d_nnzTotalDevHostPtr); verify_hipsparse_status_invalid_size(status, "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; 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 descrA = unique_ptr_descr->descr; if(M <= 0 || N <= 0 || lda < M) { // cusparse returns internal error for this case #if(defined(CUDART_VERSION)) if((M == 0 || N == 0) && lda >= M) { return HIPSPARSE_STATUS_SUCCESS; } #endif status = hipsparseXnnz(handle, dirA, M, N, descrA, (const T*)nullptr, lda, nullptr, nullptr); if(((M == 0 && N >= 0) || (M >= 0 && N == 0)) && (lda >= M)) { verify_hipsparse_status_success(status, "Error: M or N = 0 must be successful."); } else { verify_hipsparse_status_invalid_size( status, "Error: M is negative or N is negative or lda < M must be detected."); } if(HIPSPARSE_STATUS_SUCCESS == status) { int h_nnz = 77; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); status = hipsparseXnnz( handle, dirA, M, N, descrA, (const T*)nullptr, lda, nullptr, nullptr); verify_hipsparse_status_success(status, "Error: M or N = 0 must be successful."); status = hipsparseXnnz( handle, dirA, M, N, descrA, (const T*)nullptr, lda, nullptr, &h_nnz); verify_hipsparse_status_success(status, "Error: M or N = 0 must be successful."); if(0 != h_nnz) { verify_hipsparse_status_success( status, "Error: h_nnz must be zero with a non-null pointer and the pointer mode host."); } h_nnz = 139; auto nnz_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; int* d_nnz = (int*)nnz_managed.get(); CHECK_HIP_ERROR(hipMemcpy((int*)d_nnz, &h_nnz, sizeof(int) * 1, hipMemcpyHostToDevice)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); status = hipsparseXnnz( handle, dirA, M, N, descrA, (const T*)nullptr, lda, nullptr, nullptr); verify_hipsparse_status_success(status, "Error: M or N = 0 must be successful."); status = hipsparseXnnz( handle, dirA, M, N, descrA, (const T*)nullptr, lda, nullptr, (int*)d_nnz); verify_hipsparse_status_success(status, "Error: M or N = 0 must be successful."); CHECK_HIP_ERROR(hipMemcpy(&h_nnz, (int*)d_nnz, sizeof(int) * 1, hipMemcpyDeviceToHost)); status = (0 == h_nnz) ? HIPSPARSE_STATUS_SUCCESS : HIPSPARSE_STATUS_INTERNAL_ERROR; if(0 != h_nnz) { verify_hipsparse_status_success( status, "Error: h_nnz must be zero with the pointer mode device."); } } return HIPSPARSE_STATUS_SUCCESS; } // // 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(); if(!d_nnzPerRowColumn || !d_nnzTotalDevHostPtr || !d_A) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!h_nnzPerRowColumn || !d_nnzPerRowColumn || !d_A"); return HIPSPARSE_STATUS_ALLOC_FAILED; } 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, 0.2); // // Transfer. // CHECK_HIP_ERROR(hipMemcpy(d_A, h_A.data(), sizeof(T) * lda * N, hipMemcpyHostToDevice)); // // Unit check. // 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()); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_NNZ_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_prune_csr2csr.hpp000066400000000000000000001222741447644345400243330ustar00rootroot00000000000000/* ************************************************************************ * 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_PRUNE_CSR2CSR_HPP #define TESTING_PRUNE_CSR2CSR_HPP #include "hipsparse.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(void) { size_t safe_size = 100; int M = 10; int N = 10; int nnz_A = 10; 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_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), 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), 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(); if(!csr_row_ptr_A || !csr_col_ind_A || !csr_val_A || !csr_row_ptr_C || !csr_col_ind_C || !csr_val_C || !temp_buffer) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } #if(!defined(CUDART_VERSION)) // 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"); 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, &nnz_total_dev_host_ptr, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer 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"); 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, csr_col_ind_C, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer is nullptr"); #endif } template hipsparseStatus_t testing_prune_csr2csr(Arguments argus) { int M = argus.M; int N = argus.N; T threshold = static_cast(argus.threshold); hipsparseIndexBase_t csr_idx_base_A = argus.idx_base; hipsparseIndexBase_t csr_idx_base_C = argus.idx_base2; std::string binfile = ""; std::string filename = ""; hipsparseStatus_t status; // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu if(M == -99 && N == -99 && argus.timing == 0) { int safe_size = 100; binfile = argus.filename; M = N = safe_size; } if(argus.timing == 1) { 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)); // Argument sanity check before allocating invalid memory if(M <= 0 || N <= 0) { size_t safe_size = 100; auto csr_row_ptr_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), 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), 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(); if(!csr_row_ptr_A || !csr_col_ind_A || !csr_val_A || !csr_row_ptr_C || !csr_col_ind_C || !csr_val_C || !temp_buffer) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return HIPSPARSE_STATUS_ALLOC_FAILED; } status = hipsparseXpruneCsr2csr(handle, M, N, safe_size, 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); if(M < 0 || N < 0) { verify_hipsparse_status_invalid_size(status, "Error: m < 0 || n < 0"); } else { verify_hipsparse_status_success(status, "m >= 0 && n >= 0"); } return HIPSPARSE_STATUS_SUCCESS; } // Read or construct CSR matrix std::vector h_nnz_total_dev_host_ptr(1); std::vector h_csr_row_ptr_A; std::vector h_csr_col_ind_A; std::vector h_csr_val_A; int nnz_A; srand(12345ULL); if(binfile != "") { if(read_bin_matrix(binfile.c_str(), M, N, nnz_A, h_csr_row_ptr_A, h_csr_col_ind_A, h_csr_val_A, csr_idx_base_A) != 0) { fprintf(stderr, "Cannot open [read] %s\n", binfile.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else if(argus.laplacian) { M = N = gen_2d_laplacian( argus.laplacian, h_csr_row_ptr_A, h_csr_col_ind_A, h_csr_val_A, csr_idx_base_A); nnz_A = h_csr_row_ptr_A[M]; } else { std::vector coo_row_ind; if(filename != "") { if(read_mtx_matrix(filename.c_str(), M, N, nnz_A, coo_row_ind, h_csr_col_ind_A, h_csr_val_A, csr_idx_base_A) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { double scale = 0.02; if(M > 1000 || N > 1000) { scale = 2.0 / std::max(M, N); } nnz_A = M * scale * N; gen_matrix_coo(M, N, nnz_A, coo_row_ind, h_csr_col_ind_A, h_csr_val_A, csr_idx_base_A); } // Convert COO to CSR h_csr_row_ptr_A.resize(M + 1, 0); for(int i = 0; i < nnz_A; ++i) { ++h_csr_row_ptr_A[coo_row_ind[i] + 1 - csr_idx_base_A]; } h_csr_row_ptr_A[0] = csr_idx_base_A; for(int i = 0; i < M; ++i) { h_csr_row_ptr_A[i + 1] += h_csr_row_ptr_A[i]; } } // 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(); if(!d_nnz_total_dev_host_ptr || !d_csr_row_ptr_C || !d_csr_row_ptr_A || !d_csr_col_ind_A || !d_csr_val_A) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!d_nnz_total_dev_host_ptr || !d_csr_row_ptr_C || " "!d_csr_row_ptr_A || !d_csr_col_ind_A || !d_csr_val_A"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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(); if(!d_temp_buffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!d_temp_buffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } auto d_threshold_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; T* d_threshold = (T*)d_threshold_managed.get(); if(!d_threshold) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!d_threshold"); return HIPSPARSE_STATUS_ALLOC_FAILED; } CHECK_HIP_ERROR(hipMemcpy(d_threshold, &threshold, sizeof(T), hipMemcpyHostToDevice)); 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)); if(argus.unit_check) { 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)); unit_check_general( 1, 1, 1, h_nnz_total_dev_host_ptr.data(), h_nnz_total_copied_from_device.data()); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); if(h_nnz_total_dev_host_ptr[0] > 0) { 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(!d_csr_col_ind_C || !d_csr_val_C) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!d_csr_col_ind_C || !d_csr_val_C"); return HIPSPARSE_STATUS_ALLOC_FAILED; } 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()); } } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_PRUNE_CSR2CSR_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_prune_csr2csr_by_percentage.hpp000066400000000000000000001454141447644345400272230ustar00rootroot00000000000000/* ************************************************************************ * 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_PRUNE_CSR2CSR_BY_PERCENTAGE_HPP #define TESTING_PRUNE_CSR2CSR_BY_PERCENTAGE_HPP #include "hipsparse.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(void) { size_t safe_size = 100; int M = 10; int N = 10; int nnz_A = 10; T percentage = static_cast(0); 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_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), 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), 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(); if(!csr_row_ptr_A || !csr_col_ind_A || !csr_val_A || !csr_row_ptr_C || !csr_col_ind_C || !csr_val_C || !temp_buffer) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } #if(!defined(CUDART_VERSION)) // 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) { int M = argus.M; int N = argus.N; T percentage = static_cast(argus.percentage); hipsparseIndexBase_t csr_idx_base_A = argus.idx_base; hipsparseIndexBase_t csr_idx_base_C = argus.idx_base2; std::string binfile = ""; std::string filename = ""; hipsparseStatus_t status; // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu if(M == -99 && N == -99 && argus.timing == 0) { int safe_size = 100; binfile = argus.filename; M = N = safe_size; } if(argus.timing == 1) { 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)); // Argument sanity check before allocating invalid memory if(M <= 0 || N <= 0 || percentage < static_cast(0) || percentage > static_cast(100)) { size_t safe_size = 100; auto csr_row_ptr_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), 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), 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(); if(!csr_row_ptr_A || !csr_col_ind_A || !csr_val_A || !csr_row_ptr_C || !csr_col_ind_C || !csr_val_C || !temp_buffer) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return HIPSPARSE_STATUS_ALLOC_FAILED; } status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, safe_size, 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); if(M < 0 || N < 0 || percentage < static_cast(0) || percentage > static_cast(100)) { verify_hipsparse_status_invalid_size( status, "Error: m < 0 || n < 0 || percentage < 0 || percentage > 100"); } else { verify_hipsparse_status_success( status, "m >= 0 && n >= 0 && percentage >= 0 || percentage <= 100"); } return HIPSPARSE_STATUS_SUCCESS; } // Read or construct CSR matrix std::vector h_nnz_total_dev_host_ptr(1); std::vector h_csr_row_ptr_A; std::vector h_csr_col_ind_A; std::vector h_csr_val_A; int nnz_A; srand(12345ULL); if(binfile != "") { if(read_bin_matrix(binfile.c_str(), M, N, nnz_A, h_csr_row_ptr_A, h_csr_col_ind_A, h_csr_val_A, csr_idx_base_A) != 0) { fprintf(stderr, "Cannot open [read] %s\n", binfile.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else if(argus.laplacian) { M = N = gen_2d_laplacian( argus.laplacian, h_csr_row_ptr_A, h_csr_col_ind_A, h_csr_val_A, csr_idx_base_A); nnz_A = h_csr_row_ptr_A[M]; } else { std::vector coo_row_ind; if(filename != "") { if(read_mtx_matrix(filename.c_str(), M, N, nnz_A, coo_row_ind, h_csr_col_ind_A, h_csr_val_A, csr_idx_base_A) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } } else { double scale = 0.02; if(M > 1000 || N > 1000) { scale = 2.0 / std::max(M, N); } nnz_A = M * scale * N; gen_matrix_coo(M, N, nnz_A, coo_row_ind, h_csr_col_ind_A, h_csr_val_A, csr_idx_base_A); } // Convert COO to CSR h_csr_row_ptr_A.resize(M + 1, 0); for(int i = 0; i < nnz_A; ++i) { ++h_csr_row_ptr_A[coo_row_ind[i] + 1 - csr_idx_base_A]; } h_csr_row_ptr_A[0] = csr_idx_base_A; for(int i = 0; i < M; ++i) { h_csr_row_ptr_A[i + 1] += h_csr_row_ptr_A[i]; } } // 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(); if(!d_nnz_total_dev_host_ptr || !d_csr_row_ptr_C || !d_csr_row_ptr_A || !d_csr_col_ind_A || !d_csr_val_A) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!d_nnz_total_dev_host_ptr || !d_csr_row_ptr_C || " "!d_csr_row_ptr_A || !d_csr_col_ind_A || !d_csr_val_A"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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(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(); if(!d_temp_buffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!d_temp_buffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } 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)); if(argus.unit_check) { 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)); unit_check_general( 1, 1, 1, h_nnz_total_dev_host_ptr.data(), h_nnz_total_copied_from_device.data()); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); if(h_nnz_total_dev_host_ptr[0] > 0) { 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(!d_csr_col_ind_C || !d_csr_val_C) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!d_csr_col_ind_C || !d_csr_val_C"); return HIPSPARSE_STATUS_ALLOC_FAILED; } 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()); } } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_PRUNE_CSR2CSR_BY_PERCENTAGE_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_prune_dense2csr.hpp000066400000000000000000000551651447644345400246460ustar00rootroot00000000000000/* ************************************************************************ * 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_PRUNE_DENSE2CSR_HPP #define TESTING_PRUNE_DENSE2CSR_HPP #include "hipsparse.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(void) { size_t safe_size = 100; int M = 10; int N = 10; 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), 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(); if(!csr_row_ptr || !csr_col_ind || !csr_val || !A || !temp_buffer) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } #if(!defined(CUDART_VERSION)) // 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"); status = hipsparseXpruneDense2csrNnz( handle, M, N, A, LDA, &threshold, descr, csr_row_ptr, &nnz_total_dev_host_ptr, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer size 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"); status = hipsparseXpruneDense2csr( handle, M, N, A, LDA, &threshold, descr, csr_val, csr_row_ptr, csr_col_ind, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer is nullptr"); #endif } template hipsparseStatus_t testing_prune_dense2csr(Arguments argus) { int M = argus.M; int N = argus.N; int LDA = argus.lda; T threshold = static_cast(argus.threshold); hipsparseIndexBase_t idx_base = argus.idx_base; 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; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); // Argument sanity check before allocating invalid memory if(M <= 0 || N <= 0 || LDA < M) { size_t safe_size = 100; 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 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(); if(!csr_row_ptr || !csr_col_ind || !csr_val || !A || !temp_buffer) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return HIPSPARSE_STATUS_ALLOC_FAILED; } status = hipsparseXpruneDense2csr(handle, M, N, A, LDA, &threshold, descr, csr_val, csr_row_ptr, csr_col_ind, temp_buffer); if(M < 0 || N < 0 || LDA < M) { verify_hipsparse_status_invalid_size(status, "Error: m < 0 || n < 0 || lda < m"); } else { verify_hipsparse_status_success(status, "m >= 0 && n >= 0 && lda >= m"); } return HIPSPARSE_STATUS_SUCCESS; } // 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(); if(!d_A || !d_nnz_total_dev_host_ptr || !d_csr_row_ptr) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!d_A || !d_nnz_total_dev_host_ptr || !d_csr_row_ptr"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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, 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(); if(!d_temp_buffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!d_temp_buffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } auto d_threshold_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; T* d_threshold = (T*)d_threshold_managed.get(); if(!d_threshold) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!d_threshold"); return HIPSPARSE_STATUS_ALLOC_FAILED; } 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)); if(argus.unit_check) { 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)); unit_check_general( 1, 1, 1, h_nnz_total_dev_host_ptr.data(), h_nnz_total_copied_from_device.data()); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); if(h_nnz_total_dev_host_ptr[0] > 0) { 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(!d_csr_col_ind || !d_csr_val) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!d_csr_col_ind || !d_csr_val"); return HIPSPARSE_STATUS_ALLOC_FAILED; } 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()); } } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_PRUNE_DENSE2CSR_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_prune_dense2csr_by_percentage.hpp000066400000000000000000000773471447644345400275430ustar00rootroot00000000000000/* ************************************************************************ * 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_PRUNE_DENSE2CSR_BY_PERCENTAGE_HPP #define TESTING_PRUNE_DENSE2CSR_BY_PERCENTAGE_HPP #include "hipsparse.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(void) { size_t safe_size = 100; int M = 10; int N = 10; int LDA = M; T percentage = 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; 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), 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(); if(!csr_row_ptr || !csr_col_ind || !csr_val || !A || !temp_buffer) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } #if(!defined(CUDART_VERSION)) // 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) { int M = argus.M; int N = argus.N; int LDA = argus.lda; T percentage = static_cast(argus.percentage); hipsparseIndexBase_t idx_base = argus.idx_base; 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; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); // Argument sanity check before allocating invalid memory if(M <= 0 || N <= 0 || LDA < M || percentage < 0.0 || percentage > 100.0) { // cusparse does not seem to check LDA < M #if(defined(CUDART_VERSION)) if(LDA < M) { return HIPSPARSE_STATUS_SUCCESS; } #endif size_t safe_size = 100; 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 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(); if(!csr_row_ptr || !csr_col_ind || !csr_val || !A || !temp_buffer) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return HIPSPARSE_STATUS_ALLOC_FAILED; } status = hipsparseXpruneDense2csrByPercentage(handle, M, N, A, LDA, percentage, descr, csr_val, csr_row_ptr, csr_col_ind, info, temp_buffer); if(M < 0 || N < 0 || LDA < M || percentage < 0.0 || percentage > 100.0) { verify_hipsparse_status_invalid_size( status, "Error: m < 0 || n < 0 || lda < m || percentage < 0.0 || percentage > 100.0"); } else { verify_hipsparse_status_success( status, "m >= 0 && n >= 0 && lda >= m && percentage >= 0.0 && percentage <= 100.0"); } return HIPSPARSE_STATUS_SUCCESS; } // 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(); if(!d_A || !d_nnz_total_dev_host_ptr || !d_csr_row_ptr) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!d_A || !d_nnz_total_dev_host_ptr || !d_csr_row_ptr"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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, 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(); if(!d_temp_buffer) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!d_temp_buffer"); return HIPSPARSE_STATUS_ALLOC_FAILED; } 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)); if(argus.unit_check) { 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)); unit_check_general( 1, 1, 1, h_nnz_total_dev_host_ptr.data(), h_nnz_total_copied_from_device.data()); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); if(h_nnz_total_dev_host_ptr[0] > 0) { 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(!d_csr_col_ind || !d_csr_val) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!d_csr_col_ind || !d_csr_val"); return HIPSPARSE_STATUS_ALLOC_FAILED; } 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()); } } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_PRUNE_DENSE2CSR_BY_PERCENTAGE_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_rot.hpp000066400000000000000000000224551447644345400223450ustar00rootroot00000000000000/* ************************************************************************ * 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 "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) 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(); if(!dx_ind || !dx_val || !dy) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) int64_t size = 15332; int64_t nnz = 500; T hc_coeff = make_DataType(1.5); T hs_coeff = make_DataType(2.0); hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; // Index and data type hipsparseIndexType_t idxType = (typeid(I) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipDataType dataType = (typeid(T) == typeid(float)) ? HIP_R_32F : ((typeid(T) == typeid(double)) ? HIP_R_64F : ((typeid(T) == typeid(hipComplex) ? HIP_C_32F : HIP_C_64F))); // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_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(); if(!dx_ind || !dx_val_1 || !dx_val_2 || !dy_1 || !dy_2 || !dc_coeff || !ds_coeff) { verify_hipsparse_status_success( HIPSPARSE_STATUS_ALLOC_FAILED, "!dx_ind || !dx_val_1 || !dx_val_2 || !dy_1 || !dy_2 || !dc_coeff || !ds_coeff"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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)); // Rot // 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()); 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 hipSPARSE-rocm-5.7.1/clients/include/testing_roti.hpp000066400000000000000000000231111447644345400225040ustar00rootroot00000000000000/* ************************************************************************ * 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_ROTI_HPP #define TESTING_ROTI_HPP #include "hipsparse.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(void) { 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(); if(!dx_ind || !dx_val || !dy) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } 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.alpha; T s = argus.beta; int safe_size = 100; hipsparseIndexBase_t idx_base = argus.idx_base; hipsparseStatus_t status; std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; // Argument sanity check before allocating invalid memory if(nnz <= 0) { auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dx_val_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* dx_ind = (int*)dx_ind_managed.get(); T* dx_val = (T*)dx_val_managed.get(); T* dy = (T*)dy_managed.get(); if(!dx_ind || !dx_val || !dy) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dx_ind || !dx_val || !dy"); return HIPSPARSE_STATUS_ALLOC_FAILED; } CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); status = hipsparseXroti(handle, nnz, dx_val, dx_ind, dy, &c, &s, idx_base); if(nnz < 0) { verify_hipsparse_status_invalid_size(status, "Error: nnz < 0"); } else { verify_hipsparse_status_success(status, "nnz == 0"); } return HIPSPARSE_STATUS_SUCCESS; } // 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(); if(!dx_ind || !dx_val_1 || !dx_val_2 || !dy_1 || !dy_2 || !dc || !ds) { verify_hipsparse_status_success( HIPSPARSE_STATUS_ALLOC_FAILED, "!dx_ind || !dx_val_1 || !dx_val_2 || !dy_1 || !dy_2 || !dc || !ds"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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)); // ROCSPARSE 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)); // ROCSPARSE 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()); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_ROTI_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_scatter.hpp000066400000000000000000000143631447644345400232050ustar00rootroot00000000000000/* ************************************************************************ * 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 "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(); if(!dx_ind || !dx_val || !dy) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) int64_t size = 15332; int64_t nnz = 500; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; // Index and data type hipsparseIndexType_t idxType = (typeid(I) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipDataType dataType = (typeid(T) == typeid(float)) ? HIP_R_32F : ((typeid(T) == typeid(double)) ? HIP_R_64F : ((typeid(T) == typeid(hipComplex) ? HIP_C_32F : HIP_C_64F))); // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_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(); if(!dx_ind || !dx_val || !dy) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dx_ind || !dx_val || !dy"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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)); // 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()); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpVec(x)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SCATTER_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_sctr.hpp000066400000000000000000000156501447644345400225130ustar00rootroot00000000000000/* ************************************************************************ * 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_SCTR_HPP #define TESTING_SCTR_HPP #include "hipsparse.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(void) { 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(!dx_ind || !dx_val || !dy) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } 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; int safe_size = 100; hipsparseIndexBase_t idx_base = argus.idx_base; hipsparseStatus_t status; std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; // Argument sanity check before allocating invalid memory if(nnz <= 0) { auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dx_val_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* dx_ind = (int*)dx_ind_managed.get(); T* dx_val = (T*)dx_val_managed.get(); T* dy = (T*)dy_managed.get(); if(!dx_ind || !dx_val || !dy) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dx_ind || !dx_val || !dy"); return HIPSPARSE_STATUS_ALLOC_FAILED; } CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); status = hipsparseXsctr(handle, nnz, dx_val, dx_ind, dy, idx_base); if(nnz < 0) { verify_hipsparse_status_invalid_size(status, "Error: nnz < 0"); } else { verify_hipsparse_status_success(status, "nnz == 0"); } return HIPSPARSE_STATUS_SUCCESS; } // 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(); if(!dx_ind || !dx_val || !dy) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dx_ind || !dx_val || !dy"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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) { // ROCSPARSE 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()); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SCTR_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_sddmm_coo.hpp000066400000000000000000000370171447644345400235050ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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) { #ifdef __HIP_PLATFORM_NVIDIA__ // do not test for bad args return; #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11022) 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 order = 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(); if(!dval || !drow || !dcol || !dB || !dA || !dbuf) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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, order), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&B, k, n, k, dB, dataType, order), "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() { // only csr format supported when using cusparse backend #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11022) 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_ZERO; hipsparseSDDMMAlg_t alg = HIPSPARSE_SDDMM_ALG_DEFAULT; // Matrices are stored at the same path in matrices directory std::string filename = get_filename("nos3.bin"); // Index and data type hipsparseIndexType_t typeI = (typeid(I) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipDataType typeT = (typeid(T) == typeid(float)) ? HIP_R_32F : ((typeid(T) == typeid(double)) ? HIP_R_64F : ((typeid(T) == typeid(hipComplex) ? HIP_C_32F : HIP_C_64F))); // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_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 m; I n; I nnz; if(read_bin_matrix(filename.c_str(), m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } I k = 5; I lda = m; I ldb = k; std::vector hrow_ind(nnz); // Convert to COO for(I i = 0; i < m; ++i) { for(I j = hcsr_row_ptr[i] - idx_base; j < hcsr_row_ptr[i + 1] - idx_base; ++j) { hrow_ind[j - idx_base] = i + idx_base; } } std::vector hA(m * k); std::vector hB(k * n); std::vector hval1(nnz); std::vector hval2(nnz); hipsparseInit(hA, m, k); hipsparseInit(hB, k, n); // 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) * m * k), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * k * 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 = (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(); if(!dval1 || !dval2 || !drow || !dcol || !dB || !dA || !d_alpha || !d_beta) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dval1 || !dval2 || !drow || !dcol || !dA || " "!dB || !d_alpha || !d_beta"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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) * m * k, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * k * n, 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, m, n, nnz, drow, dcol, dval1, typeI, idx_base, typeT)); CHECK_HIPSPARSE_ERROR( hipsparseCreateCoo(&C2, m, n, nnz, drow, dcol, dval2, typeI, idx_base, typeT)); // Create dense matrices hipsparseDnMatDescr_t A, B; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&A, m, k, lda, dA, typeT, order)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&B, k, n, ldb, dB, typeT, order)); // 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)); // ROCSPARSE 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)); CHECK_HIPSPARSE_ERROR( hipsparseSDDMM(handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); // ROCSPARSE 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)); CHECK_HIPSPARSE_ERROR( hipsparseSDDMM(handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); // copy output from device to CPU. CHECK_HIP_ERROR(hipMemcpy(hval1.data(), dval1, sizeof(T) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hval2.data(), dval2, sizeof(T) * nnz, hipMemcpyDeviceToHost)); // CPU const I incx = lda; const I incy = 1; for(I i = 0; i < m; ++i) { for(I at = hcsr_row_ptr[i] - idx_base; at < hcsr_row_ptr[i + 1] - idx_base; ++at) { I j = hcsr_col_ind[at] - idx_base; const T* x = &hA[i]; const T* y = &hB[ldb * j]; T sum = make_DataType(0.0); for(I k_ = 0; k_ < k; ++k_) { sum = testing_fma(x[incx * k_], y[incy * k_], sum); } hcsr_val[at] = testing_mult(hcsr_val[at], 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()); // 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 hipSPARSE-rocm-5.7.1/clients/include/testing_sddmm_coo_aos.hpp000066400000000000000000000365241447644345400243510ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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) { #ifdef __HIP_PLATFORM_NVIDIA__ // do not test for bad args return; #endif #if(!defined(CUDART_VERSION) || (CUDART_VERSION >= 11022 && CUDART_VERSION < 12000)) 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 order = 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(); if(!dval || !drowcol || !dB || !dA || !dbuf) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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, order), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&B, k, n, k, dB, dataType, order), "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() { // only csr format supported when using cusparse backend #if(!defined(CUDART_VERSION) || (CUDART_VERSION >= 11022 && CUDART_VERSION < 12000)) 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_ZERO; hipsparseSDDMMAlg_t alg = HIPSPARSE_SDDMM_ALG_DEFAULT; // Matrices are stored at the same path in matrices directory std::string filename = get_filename("nos3.bin"); // Index and data type hipsparseIndexType_t typeI = (typeid(I) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipDataType typeT = (typeid(T) == typeid(float)) ? HIP_R_32F : ((typeid(T) == typeid(double)) ? HIP_R_64F : ((typeid(T) == typeid(hipComplex) ? HIP_C_32F : HIP_C_64F))); // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_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 m; I n; I nnz; if(read_bin_matrix(filename.c_str(), m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } I k = 5; I lda = m; I ldb = k; 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; } } std::vector hA(m * k); std::vector hB(k * n); std::vector hval1(nnz); std::vector hval2(nnz); hipsparseInit(hA, m, k); hipsparseInit(hB, k, n); // 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) * m * k), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * k * 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* 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(); if(!dval1 || !dval2 || !drowcol || !dB || !dA || !d_alpha || !d_beta) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dval1 || !dval2 || !drow || !dcol || !dA || " "!dB || !d_alpha || !d_beta"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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) * m * k, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * k * n, 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, m, n, nnz, drowcol, dval1, typeI, idx_base, typeT)); CHECK_HIPSPARSE_ERROR( hipsparseCreateCooAoS(&C2, m, n, nnz, drowcol, dval2, typeI, idx_base, typeT)); // Create dense matrices hipsparseDnMatDescr_t A, B; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&A, m, k, lda, dA, typeT, order)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&B, k, n, ldb, dB, typeT, order)); // 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)); // ROCSPARSE 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)); CHECK_HIPSPARSE_ERROR( hipsparseSDDMM(handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); // ROCSPARSE 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)); CHECK_HIPSPARSE_ERROR( hipsparseSDDMM(handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); // copy output from device to CPU. CHECK_HIP_ERROR(hipMemcpy(hval1.data(), dval1, sizeof(T) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hval2.data(), dval2, sizeof(T) * nnz, hipMemcpyDeviceToHost)); // CPU const I incx = lda; const I incy = 1; for(I i = 0; i < m; ++i) { for(I at = hcsr_row_ptr[i] - idx_base; at < hcsr_row_ptr[i + 1] - idx_base; ++at) { I j = hcsr_col_ind[at] - idx_base; const T* x = &hA[i]; const T* y = &hB[ldb * j]; T sum = make_DataType(0.0); for(I k_ = 0; k_ < k; ++k_) { sum = testing_fma(x[incx * k_], y[incy * k_], sum); } hcsr_val[at] = testing_mult(hcsr_val[at], 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()); // 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 hipSPARSE-rocm-5.7.1/clients/include/testing_sddmm_csc.hpp000066400000000000000000000371531447644345400234760ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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) { #ifdef __HIP_PLATFORM_NVIDIA__ // do not test for bad args return; #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11022) 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 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; 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(); if(!dval || !dptr || !dcol || !dB || !dA || !dbuf) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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, order), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&B, k, n, k, dB, dataType, order), "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() { // only csr format supported when using cusparse backend #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11022) 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_ZERO; hipsparseSDDMMAlg_t alg = HIPSPARSE_SDDMM_ALG_DEFAULT; // Matrices are stored at the same path in matrices directory std::string filename = get_filename("nos3.bin"); // Index and data type hipsparseIndexType_t typeI = (typeid(I) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipsparseIndexType_t typeJ = (typeid(J) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipDataType typeT = (typeid(T) == typeid(float)) ? HIP_R_32F : ((typeid(T) == typeid(double)) ? HIP_R_64F : ((typeid(T) == typeid(hipComplex) ? HIP_C_32F : HIP_C_64F))); // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; // Host structures std::vector hcsc_col_ptr; std::vector hcsc_row_ind; std::vector hcsc_val; // Initial Data on CPU srand(12345ULL); J m; J n; I nnz; { J mm; J nn; if(read_bin_matrix( filename.c_str(), mm, nn, nnz, hcsc_col_ptr, hcsc_row_ind, hcsc_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } m = nn; n = mm; } J k = 5; J lda = m; J ldb = k; std::vector hA(m * k); std::vector hB(k * n); std::vector hval1(nnz); std::vector hval2(nnz); hipsparseInit(hA, m, k); hipsparseInit(hB, k, n); // allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (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) * m * k), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * k * 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* 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(); if(!dval1 || !dval2 || !dptr || !dind || !dB || !dA || !d_alpha || !d_beta) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dval1 || !dval2 || !dptr || !dind || !dA || " "!dB || !d_alpha || !d_beta"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsc_col_ptr.data(), sizeof(I) * (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) * m * k, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * k * n, 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, m, n, nnz, dptr, dind, dval1, typeI, typeJ, idx_base, typeT)); CHECK_HIPSPARSE_ERROR( hipsparseCreateCsc(&C2, m, n, nnz, dptr, dind, dval2, typeI, typeJ, idx_base, typeT)); // Create dense matrices hipsparseDnMatDescr_t A, B; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&A, m, k, lda, dA, typeT, order)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&B, k, n, ldb, dB, typeT, order)); // 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)); // ROCSPARSE 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)); CHECK_HIPSPARSE_ERROR( hipsparseSDDMM(handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); // ROCSPARSE 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)); CHECK_HIPSPARSE_ERROR( hipsparseSDDMM(handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); // copy output from device to CPU. CHECK_HIP_ERROR(hipMemcpy(hval1.data(), dval1, sizeof(T) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hval2.data(), dval2, sizeof(T) * nnz, hipMemcpyDeviceToHost)); // CPU const J incx = lda; const J incy = 1; for(J j = 0; j < n; ++j) { for(I at = hcsc_col_ptr[j] - idx_base; at < hcsc_col_ptr[j + 1] - idx_base; ++at) { J i = hcsc_row_ind[at] - idx_base; const T* x = &hA[i]; const T* y = &hB[ldb * j]; T sum = make_DataType(0.0); for(J k_ = 0; k_ < k; ++k_) { sum = testing_fma(x[incx * k_], y[incy * k_], sum); } hcsc_val[at] = testing_mult(hcsc_val[at], 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()); // 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 hipSPARSE-rocm-5.7.1/clients/include/testing_sddmm_csr.hpp000066400000000000000000000366771447644345400235270ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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) { #ifdef __HIP_PLATFORM_NVIDIA__ // do not test for bad args return; #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11022) 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 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; 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(); if(!dval || !dptr || !dcol || !dB || !dA || !dbuf) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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, order), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&B, k, n, k, dB, dataType, order), "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() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11022) 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_ZERO; hipsparseSDDMMAlg_t alg = HIPSPARSE_SDDMM_ALG_DEFAULT; // Matrices are stored at the same path in matrices directory std::string filename = get_filename("nos3.bin"); // Index and data type hipsparseIndexType_t typeI = (typeid(I) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipsparseIndexType_t typeJ = (typeid(J) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipDataType typeT = (typeid(T) == typeid(float)) ? HIP_R_32F : ((typeid(T) == typeid(double)) ? HIP_R_64F : ((typeid(T) == typeid(hipComplex) ? HIP_C_32F : HIP_C_64F))); // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Initial Data on CPU srand(12345ULL); J m; J n; I nnz; if(read_bin_matrix(filename.c_str(), m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } J k = 5; J lda = m; J ldb = k; std::vector hA(m * k); std::vector hB(k * n); std::vector hval1(nnz); std::vector hval2(nnz); hipsparseInit(hA, m, k); hipsparseInit(hB, k, n); // 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 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) * m * k), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * k * 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* 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(); if(!dval1 || !dval2 || !dptr || !dcol || !dB || !dA || !d_alpha || !d_beta) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dval1 || !dval2 || !dptr || !dcol || !dA || " "!dB || !d_alpha || !d_beta"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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(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) * m * k, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * k * n, 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, m, n, nnz, dptr, dcol, dval1, typeI, typeJ, idx_base, typeT)); CHECK_HIPSPARSE_ERROR( hipsparseCreateCsr(&C2, m, n, nnz, dptr, dcol, dval2, typeI, typeJ, idx_base, typeT)); // Create dense matrices hipsparseDnMatDescr_t A, B; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&A, m, k, lda, dA, typeT, order)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&B, k, n, ldb, dB, typeT, order)); // 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)); // ROCSPARSE 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)); CHECK_HIPSPARSE_ERROR( hipsparseSDDMM(handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); // ROCSPARSE 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)); CHECK_HIPSPARSE_ERROR( hipsparseSDDMM(handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); // copy output from device to CPU. CHECK_HIP_ERROR(hipMemcpy(hval1.data(), dval1, sizeof(T) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hval2.data(), dval2, sizeof(T) * nnz, hipMemcpyDeviceToHost)); // CPU const J incx = lda; const J incy = 1; for(J i = 0; i < m; ++i) { for(I at = hcsr_row_ptr[i] - idx_base; at < hcsr_row_ptr[i + 1] - idx_base; ++at) { J j = hcsr_col_ind[at] - idx_base; const T* x = &hA[i]; const T* y = &hB[ldb * j]; T sum = make_DataType(0.0); for(J k_ = 0; k_ < k; ++k_) { sum = testing_fma(x[incx * k_], y[incy * k_], sum); } hcsr_val[at] = testing_mult(hcsr_val[at], 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()); // 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 hipSPARSE-rocm-5.7.1/clients/include/testing_sparse_to_dense_coo.hpp000066400000000000000000000233351447644345400255540ustar00rootroot00000000000000/* ************************************************************************ * 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 "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(); if(!ddense_val || !dcoo_row_ind || !dcoo_col_ind || !dcoo_val || !dbuf) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseSparseToDenseAlg_t alg = HIPSPARSE_SPARSETODENSE_ALG_DEFAULT; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; // Matrices are stored at the same path in matrices directory std::string filename = get_filename("nos3.bin"); // Index and data type hipsparseIndexType_t typeI = (typeid(I) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipDataType typeT = (typeid(T) == typeid(float)) ? HIP_R_32F : ((typeid(T) == typeid(double)) ? HIP_R_64F : ((typeid(T) == typeid(hipComplex) ? HIP_C_32F : HIP_C_64F))); // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_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 m; I n; I nnz; if(read_bin_matrix(filename.c_str(), m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } I ld = m; // 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) * ld * n), 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(); if(!dval || !drow || !dcol || !ddense) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dval || !drow || !dcol || !ddense"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // Dense matrix std::vector hdense(ld * n); // 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)); CHECK_HIPSPARSE_ERROR(hipsparseSparseToDense(handle, matA, matB, alg, buffer)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hdense.data(), ddense, sizeof(T) * ld * n, hipMemcpyDeviceToHost)); // Query for warpSize hipDeviceProp_t prop; hipGetDeviceProperties(&prop, 0); std::vector hdense_cpu(ld * n); 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]; } unit_check_general(m, n, ld, hdense_cpu.data(), hdense.data()); 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 hipSPARSE-rocm-5.7.1/clients/include/testing_sparse_to_dense_csc.hpp000066400000000000000000000260671447644345400255510ustar00rootroot00000000000000/* ************************************************************************ * 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 "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_64I; 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(int64_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(); int64_t* dcsc_col_ptr = (int64_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(); if(!ddense_val || !dcsc_col_ptr || !dcsc_row_ind || !dcsc_val || !dbuf) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseSparseToDenseAlg_t alg = HIPSPARSE_SPARSETODENSE_ALG_DEFAULT; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; // Matrices are stored at the same path in matrices directory std::string filename = get_filename("nos3.bin"); // Index and data type hipsparseIndexType_t typeI = (typeid(I) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipsparseIndexType_t typeJ = (typeid(J) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipDataType typeT = (typeid(T) == typeid(float)) ? HIP_R_32F : ((typeid(T) == typeid(double)) ? HIP_R_64F : ((typeid(T) == typeid(hipComplex) ? HIP_C_32F : HIP_C_64F))); // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_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); J m; J n; I nnz; if(read_bin_matrix(filename.c_str(), m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } I ld = m; // 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) * ld * n), 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(); if(!dval || !dptr || !drow || !ddense) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dval || !dptr || !drow || !ddense"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // Dense matrix std::vector hdense(ld * n); // 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)); CHECK_HIPSPARSE_ERROR(hipsparseSparseToDense(handle, matA, matB, alg, buffer)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hdense.data(), ddense, sizeof(T) * ld * n, hipMemcpyDeviceToHost)); // Query for warpSize hipDeviceProp_t prop; hipGetDeviceProperties(&prop, 0); std::vector hdense_cpu(ld * n); 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]; } } unit_check_general(m, n, ld, hdense_cpu.data(), hdense.data()); 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 hipSPARSE-rocm-5.7.1/clients/include/testing_sparse_to_dense_csr.hpp000066400000000000000000000241701447644345400255610ustar00rootroot00000000000000/* ************************************************************************ * 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 "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_64I; 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(int64_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(); int64_t* dcsr_row_ptr = (int64_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(); if(!ddense_val || !dcsr_row_ptr || !dcsr_col_ind || !dcsr_val || !dbuf) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseSparseToDenseAlg_t alg = HIPSPARSE_SPARSETODENSE_ALG_DEFAULT; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; // Matrices are stored at the same path in matrices directory std::string filename = get_filename("nos3.bin"); // Index and data type hipsparseIndexType_t typeI = (typeid(I) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipsparseIndexType_t typeJ = (typeid(J) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipDataType typeT = (typeid(T) == typeid(float)) ? HIP_R_32F : ((typeid(T) == typeid(double)) ? HIP_R_64F : ((typeid(T) == typeid(hipComplex) ? HIP_C_32F : HIP_C_64F))); // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Initial Data on CPU srand(12345ULL); J m; J n; I nnz; if(read_bin_matrix(filename.c_str(), m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } I ld = m; // 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) * ld * n), 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(); if(!dval || !dptr || !dcol || !ddense) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dval || !dptr || !dcol || !ddense"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // Dense matrix std::vector hdense(ld * n); // 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)); CHECK_HIPSPARSE_ERROR(hipsparseSparseToDense(handle, matA, matB, alg, buffer)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hdense.data(), ddense, sizeof(T) * ld * n, hipMemcpyDeviceToHost)); // Query for warpSize hipDeviceProp_t prop; hipGetDeviceProperties(&prop, 0); std::vector hdense_cpu(ld * n); 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 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(m, n, ld, hdense_cpu.data(), hdense.data()); 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 hipSPARSE-rocm-5.7.1/clients/include/testing_spgemm_csr.hpp000066400000000000000000001223611447644345400236750ustar00rootroot00000000000000/* ************************************************************************ * 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_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(); if(!dcsr_row_ptr_A || !dcsr_col_ind_A || !dcsr_val_A || !dcsr_row_ptr_B || !dcsr_col_ind_B || !dcsr_val_B || !dcsr_row_ptr_C || !dcsr_col_ind_C || !dcsr_val_C || !dbuf) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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"); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMM_compute( handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, descr, nullptr, dbuf), "Error: bufferSize 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(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) T h_alpha = make_DataType(2.0); T h_beta = make_DataType(0.0); 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; hipsparseSpGEMMAlg_t alg = HIPSPARSE_SPGEMM_DEFAULT; // Matrices are stored at the same path in matrices directory std::string filename = get_filename("nos6.bin"); // Index and data type hipsparseIndexType_t typeI = (typeid(I) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipsparseIndexType_t typeJ = (typeid(J) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipDataType typeT = (typeid(T) == typeid(float)) ? HIP_R_32F : ((typeid(T) == typeid(double)) ? HIP_R_64F : ((typeid(T) == typeid(hipComplex) ? HIP_C_32F : HIP_C_64F))); // hipSPARSE handles std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_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); // Some sparse matrix A J m; J k; I nnz_A; if(read_bin_matrix( filename.c_str(), m, k, nnz_A, hcsr_row_ptr_A, hcsr_col_ind_A, hcsr_val_A, idxBaseA) != 0) { fprintf(stderr, "Cannot open [read] %s\n", 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_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) * (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_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(); if(!dcsr_row_ptr_A || !dcsr_col_ind_A || !dcsr_val_A || !dcsr_row_ptr_B || !dcsr_col_ind_B || !dcsr_val_B || !dcsr_row_ptr_C_1 || !dcsr_row_ptr_C_2 || !d_alpha || !d_beta) { verify_hipsparse_status_success( HIPSPARSE_STATUS_ALLOC_FAILED, "!dcsr_row_ptr_A || !dcsr_col_ind_A || !dcsr_val_A || " "!dcsr_row_ptr_B || !dcsr_col_ind_B || !dcsr_val_B || " "!dcsr_row_ptr_C_1 || !dcsr_row_ptr_C_2 || !d_alpha || !d_beta"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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)); // We can already free buffer1 CHECK_HIP_ERROR(hipFree(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)); // We can already free buffer2 CHECK_HIP_ERROR(hipFree(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(); if(!dcsr_col_ind_C_1 || !dcsr_val_C_1 || !dcsr_col_ind_C_2 || !dcsr_val_C_2) { verify_hipsparse_status_success( HIPSPARSE_STATUS_ALLOC_FAILED, "!dcsr_col_ind_C_1 || !dcsr_val_C_1 || !dcsr_col_ind_C_2 || !dcsr_val_C_2"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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 = 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); 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()); // Clean up CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(B)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(C1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(C2)); return HIPSPARSE_STATUS_SUCCESS; #endif } #endif // TESTING_SPGEMM_CSR_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_spgemmreuse_csr.hpp000066400000000000000000000676361447644345400247560ustar00rootroot00000000000000/* ************************************************************************ * 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_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}; 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(); if(!dcsr_row_ptr_A || !dcsr_col_ind_A || !dcsr_val_A || !dcsr_row_ptr_B || !dcsr_col_ind_B || !dcsr_val_B || !dcsr_row_ptr_C || !dcsr_col_ind_C || !dcsr_val_C || !dbuf) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11031) T h_alpha = make_DataType(2.0); T h_beta = make_DataType(0.0); 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; hipsparseSpGEMMAlg_t alg = HIPSPARSE_SPGEMM_DEFAULT; // Matrices are stored at the same path in matrices directory std::string filename = get_filename("nos6.bin"); // Index and data type hipsparseIndexType_t typeI = (typeid(I) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipsparseIndexType_t typeJ = (typeid(J) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipDataType typeT = (typeid(T) == typeid(float)) ? HIP_R_32F : ((typeid(T) == typeid(double)) ? HIP_R_64F : ((typeid(T) == typeid(hipComplex) ? HIP_C_32F : HIP_C_64F))); // hipSPARSE handles std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_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); // Some sparse matrix A J m; J k; I nnz_A; if(read_bin_matrix( filename.c_str(), m, k, nnz_A, hcsr_row_ptr_A, hcsr_col_ind_A, hcsr_val_A, idxBaseA) != 0) { fprintf(stderr, "Cannot open [read] %s\n", 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_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) * (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_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(); if(!dcsr_row_ptr_A || !dcsr_col_ind_A || !dcsr_val_A || !dcsr_row_ptr_B || !dcsr_col_ind_B || !dcsr_val_B || !dcsr_row_ptr_C_1 || !dcsr_row_ptr_C_2 || !d_alpha || !d_beta) { verify_hipsparse_status_success( HIPSPARSE_STATUS_ALLOC_FAILED, "!dcsr_row_ptr_A || !dcsr_col_ind_A || !dcsr_val_A || " "!dcsr_row_ptr_B || !dcsr_col_ind_B || !dcsr_val_B || " "!dcsr_row_ptr_C_1 || !dcsr_row_ptr_C_2 || !d_alpha || !d_beta"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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)); // Query SpGEMM work estimation buffer size_t bufferSize1; CHECK_HIPSPARSE_ERROR(hipsparseSpGEMMreuse_workEstimation( handle, transA, transB, A, B, C1, 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, C1, alg, descr, &bufferSize1, externalBuffer1)); // Query SpGEMM_nnz // SpGEMM work estimation size_t bufferSize2, bufferSize3, bufferSize4, bufferSize5; void *externalBuffer2 = nullptr, *externalBuffer3 = nullptr, *externalBuffer4 = nullptr, *externalBuffer5 = nullptr; CHECK_HIPSPARSE_ERROR(hipsparseSpGEMMreuse_nnz(handle, transA, transB, A, B, C1, 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_HIP_ERROR(hipMalloc(&externalBuffer2, bufferSize2)); CHECK_HIP_ERROR(hipMalloc(&externalBuffer3, bufferSize3)); CHECK_HIP_ERROR(hipMalloc(&externalBuffer4, bufferSize4)); CHECK_HIPSPARSE_ERROR(hipsparseSpGEMMreuse_nnz(handle, transA, transB, A, B, C1, 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_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)); nnz_C_2 = nnz_C_1; // 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(); if(!dcsr_col_ind_C_1 || !dcsr_val_C_1 || !dcsr_col_ind_C_2 || !dcsr_val_C_2) { verify_hipsparse_status_success( HIPSPARSE_STATUS_ALLOC_FAILED, "!dcsr_col_ind_C_1 || !dcsr_val_C_1 || !dcsr_col_ind_C_2 || !dcsr_val_C_2"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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(hipsparseSpGEMMreuse_copy( handle, transA, transB, A, B, C1, 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, C1, alg, descr, &bufferSize5, externalBuffer5)); externalBuffer3_managed.reset(nullptr); externalBuffer3 = nullptr; // Query SpGEMM compute buffer CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSpGEMMreuse_compute( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, descr)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIP_ERROR(hipMemcpy( dcsr_row_ptr_C_2, dcsr_row_ptr_C_1, sizeof(I) * (m + 1), hipMemcpyDeviceToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind_C_2, dcsr_col_ind_C_1, sizeof(J) * nnz_C_1, hipMemcpyDeviceToDevice)) CHECK_HIP_ERROR( hipMemcpy(dcsr_val_C_2, dcsr_val_C_1, sizeof(T) * nnz_C_1, hipMemcpyDeviceToDevice)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&C2, m, n, nnz_C_1, dcsr_row_ptr_C_2, dcsr_col_ind_C_2, dcsr_val_C_2, typeI, typeJ, idxBaseC, typeT)); CHECK_HIPSPARSE_ERROR(hipsparseSpGEMMreuse_compute( handle, transA, transB, d_alpha, A, B, d_beta, C1, 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_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 = 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); 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()); // Clean up CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(B)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(C1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(C2)); return HIPSPARSE_STATUS_SUCCESS; #endif } #endif // TESTING_SPGEMM_CSR_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_spmat_descr.hpp000066400000000000000000001232521447644345400240420ustar00rootroot00000000000000/* ************************************************************************ * 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 using namespace hipsparse_test; void testing_spmat_descr_bad_arg(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) 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(); if(!row_data || !col_data || !ind_data || !val_data) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } 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"); #if(!defined(CUDART_VERSION) || (CUDART_VERSION >= 10010 && CUDART_VERSION < 12000)) // 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"); #endif // 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 #if(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_pointer(hipsparseCreateBlockedEll(nullptr, rows, cols, ell_blocksize, ell_cols, col_data, val_data, colType, idxBase, dataType), "Error: A is nullptr"); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) 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"); #endif // hipsparseDestroySpMat #if(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_pointer(hipsparseDestroySpMat(nullptr), "Error: A is nullptr"); #else verify_hipsparse_status_success(hipsparseDestroySpMat(nullptr), "Success"); #endif // Create valid descriptors hipsparseSpMatDescr_t coo; hipsparseSpMatDescr_t coo_aos; hipsparseSpMatDescr_t csr; #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) hipsparseSpMatDescr_t bell; verify_hipsparse_status_success(hipsparseCreateBlockedEll(&bell, rows, cols, ell_blocksize, ell_cols, col_data, val_data, colType, idxBase, dataType), "Success"); #endif verify_hipsparse_status_success( hipsparseCreateCoo( &coo, rows, cols, nnz, row_data, col_data, val_data, rowType, idxBase, dataType), "Success"); #if(!defined(CUDART_VERSION) || (CUDART_VERSION >= 10010 && CUDART_VERSION < 12000)) verify_hipsparse_status_success( hipsparseCreateCooAoS( &coo_aos, rows, cols, nnz, ind_data, val_data, cooType, idxBase, dataType), "Success"); #endif verify_hipsparse_status_success(hipsparseCreateCsr(&csr, rows, cols, nnz, row_data, col_data, val_data, rowType, colType, idxBase, dataType), "Success"); #endif void* row_ptr; void* col_ptr; void* ind_ptr; void* val_ptr; // hipsparseCooGet #if(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_pointer(hipsparseCooGet(nullptr, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &idxBase, &dataType), "Error: A is nullptr"); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) 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"); #endif // hipsparseCooAoSGet #if(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_pointer( hipsparseCooAoSGet( nullptr, &rows, &cols, &nnz, &ind_ptr, &val_ptr, &cooType, &idxBase, &dataType), "Error: A is nullptr"); #endif #if(!defined(CUDART_VERSION) || (CUDART_VERSION >= 10010 && CUDART_VERSION < 12000)) 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"); #endif // hipsparseCsrGet #if(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_pointer(hipsparseCsrGet(nullptr, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &colType, &idxBase, &dataType), "Error: A is nullptr"); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) 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"); #if(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_pointer(hipsparseCsrGet(csr, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &colType, nullptr, &dataType), "Error: idxBase is nullptr"); #endif verify_hipsparse_status_invalid_pointer(hipsparseCsrGet(csr, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &colType, &idxBase, nullptr), "Error: dataType is nullptr"); #endif #if(!defined(CUDART_VERSION)) 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"); #endif // hipsparseCsrSetPointers #if(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_pointer( hipsparseCsrSetPointers(nullptr, row_data, col_data, val_data), "Error: A is nullptr"); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) 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"); #endif // hipsparseSpMatGetSize #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) 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"); #endif // hipsparseSpMatGetFormat #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetFormat(nullptr, &format), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetFormat(coo, nullptr), "Error: format is nullptr"); #endif // hipsparseSpMatGetIndexBase #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetIndexBase(nullptr, &idxBase), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetIndexBase(coo, nullptr), "Error: idxBase is nullptr"); #endif // hipsparseSpMatGetValues #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) 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"); #endif // hipsparseSpMatSetValues #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) 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"); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) 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"); #if(CUDART_VERSION < 12000) // 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"); #endif #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) // 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"); #endif // Destroy valid descriptors #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) verify_hipsparse_status_success(hipsparseDestroySpMat(coo), "Success"); verify_hipsparse_status_success(hipsparseDestroySpMat(coo_aos), "Success"); verify_hipsparse_status_success(hipsparseDestroySpMat(csr), "Success"); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) verify_hipsparse_status_success(hipsparseDestroySpMat(bell), "Success"); #endif } #endif // TESTING_SPMAT_DESCR_HPP hipSPARSE-rocm-5.7.1/clients/include/testing_spmm_batched_coo.hpp000066400000000000000000000375341447644345400250330ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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) { #ifdef __HIP_PLATFORM_NVIDIA__ // do not test for bad args return; #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) 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(); if(!dval || !drow || !dcol || !dB || !dC || !dbuf) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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() { #ifdef __HIP_PLATFORM_NVIDIA__ // do not test for bad args return HIPSPARSE_STATUS_SUCCESS; #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) 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_ZERO; 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 // Matrices are stored at the same path in matrices directory std::string filename = get_filename("nos3.bin"); // Index and data type hipsparseIndexType_t typeI = (typeid(I) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipDataType typeT = (typeid(T) == typeid(float)) ? HIP_R_32F : ((typeid(T) == typeid(double)) ? HIP_R_64F : ((typeid(T) == typeid(hipComplex) ? HIP_C_32F : HIP_C_64F))); // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; // Host structures std::vector hrow_ptr; std::vector hcol_ind; std::vector hval; // Initial Data on CPU srand(12345ULL); I m; I k; I nnz; if(read_bin_matrix(filename.c_str(), m, k, nnz, hrow_ptr, hcol_ind, hval, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", 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; } } I n = 5; I ldb = k; I ldc = m; I batch_stride_A = 0; I batch_stride_B = k * n; I batch_stride_C = m * n; std::vector hB(batch_count_B * k * n); std::vector hC_1(batch_count_C * m * n); std::vector hC_2(batch_count_C * m * n); std::vector hC_gold(batch_count_C * m * n); hipsparseInit(hB, batch_count_B * k * n, 1); hipsparseInit(hC_1, batch_count_C * m * n, 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) * 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) * batch_count_B * k * n), device_free}; auto dC_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * batch_count_C * m * n), device_free}; auto dC_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * batch_count_C * 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 = (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(); if(!dval || !drow || !dcol || !dB || !dC_1 || !dC_2 || !d_alpha || !d_beta) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dval || !drow || !dcol || !dB || " "!dC_1 || !dC_2 || !d_alpha || !d_beta"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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) * batch_count_B * k * n, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dC_1, hC_1.data(), sizeof(T) * batch_count_C * m * n, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dC_2, hC_2.data(), sizeof(T) * batch_count_C * 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)); // Create matrices hipsparseSpMatDescr_t A; CHECK_HIPSPARSE_ERROR( hipsparseCreateCoo(&A, m, k, nnz, drow, dcol, dval, 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)); 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)); // ROCSPARSE 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, B, &h_beta, C1, typeT, alg, buffer)); #endif CHECK_HIPSPARSE_ERROR( hipsparseSpMM(handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); // ROCSPARSE 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, B, d_beta, C2, typeT, alg, buffer)); #endif 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 * m * n, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hC_2.data(), dC_2, sizeof(T) * batch_count_C * m * n, hipMemcpyDeviceToHost)); // CPU double cpu_time_used = get_time_us(); host_coomm_batched(m, n, nnz, batch_count_A, batch_stride_A, transB, h_alpha, hrow_ind.data(), hcol_ind.data(), hval.data(), hB.data(), ldb, batch_count_B, batch_stride_B, h_beta, hC_gold.data(), ldc, batch_count_C, batch_stride_C, order, idx_base); cpu_time_used = get_time_us() - cpu_time_used; unit_check_near(1, batch_count_C * m * n, 1, hC_gold.data(), hC_1.data()); unit_check_near(1, batch_count_C * m * n, 1, hC_gold.data(), hC_2.data()); 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 hipSPARSE-rocm-5.7.1/clients/include/testing_spmm_batched_csc.hpp000066400000000000000000000410741447644345400250150ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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) { #ifdef __HIP_PLATFORM_NVIDIA__ // do not test for bad args return; #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) 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(); if(!dval || !dptr || !drow || !dB || !dC || !dbuf) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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() { #ifdef __HIP_PLATFORM_NVIDIA__ // do not test for bad args return HIPSPARSE_STATUS_SUCCESS; #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) T h_alpha = make_DataType(1.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_ZERO; 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 // Matrices are stored at the same path in matrices directory std::string filename = get_filename("nos3.bin"); // Index and data type hipsparseIndexType_t typeI = (typeid(I) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipsparseIndexType_t typeJ = (typeid(J) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipDataType typeT = (typeid(T) == typeid(float)) ? HIP_R_32F : ((typeid(T) == typeid(double)) ? HIP_R_64F : ((typeid(T) == typeid(hipComplex) ? HIP_C_32F : HIP_C_64F))); // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; // Host structures std::vector hcsc_col_ptr; std::vector hcsc_row_ind; std::vector hcsc_val; // Initial Data on CPU srand(12345ULL); J m; J k; I nnz; if(read_bin_matrix(filename.c_str(), k, m, nnz, hcsc_col_ptr, hcsc_row_ind, hcsc_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } J n = 5; J ldb = k; J ldc = m; J offsets_batch_stride_A = 0; I rows_values_batch_stride_A = 0; I batch_stride_B = k * n; I batch_stride_C = m * n; std::vector hB(batch_count_B * k * n); std::vector hC_1(batch_count_C * m * n); std::vector hC_2(batch_count_C * m * n); std::vector hC_gold(batch_count_C * m * n); hipsparseInit(hB, batch_count_B * k * n, 1); hipsparseInit(hC_1, batch_count_C * m * n, 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) * (k + 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 dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * batch_count_B * k * n), device_free}; auto dC_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * batch_count_C * m * n), device_free}; auto dC_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * batch_count_C * 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* 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(); if(!dval || !dptr || !drow || !dB || !dC_1 || !dC_2 || !d_alpha || !d_beta) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dval || !dptr || !drow || !dB || " "!dC_1 || !dC_2 || !d_alpha || !d_beta"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsc_col_ptr.data(), sizeof(I) * (k + 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)); CHECK_HIP_ERROR( hipMemcpy(dB, hB.data(), sizeof(T) * batch_count_B * k * n, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dC_1, hC_1.data(), sizeof(T) * batch_count_C * m * n, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dC_2, hC_2.data(), sizeof(T) * batch_count_C * 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)); // Create matrices hipsparseSpMatDescr_t A; CHECK_HIPSPARSE_ERROR( hipsparseCreateCsc(&A, m, k, nnz, dptr, drow, dval, typeI, typeJ, 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)); 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)); // ROCSPARSE 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, B, &h_beta, C1, typeT, alg, buffer)); #endif CHECK_HIPSPARSE_ERROR( hipsparseSpMM(handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); // ROCSPARSE 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, B, d_beta, C2, typeT, alg, buffer)); #endif 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 * m * n, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hC_2.data(), dC_2, sizeof(T) * batch_count_C * m * n, hipMemcpyDeviceToHost)); // CPU double cpu_time_used = get_time_us(); host_cscmm_batched(m, n, k, batch_count_A, offsets_batch_stride_A, rows_values_batch_stride_A, transA, transB, h_alpha, hcsc_col_ptr.data(), hcsc_row_ind.data(), hcsc_val.data(), hB.data(), ldb, batch_count_B, batch_stride_B, h_beta, hC_gold.data(), ldc, batch_count_C, batch_stride_C, order, idx_base); cpu_time_used = get_time_us() - cpu_time_used; unit_check_near(1, batch_count_C * m * n, 1, hC_gold.data(), hC_1.data()); unit_check_near(1, batch_count_C * m * n, 1, hC_gold.data(), hC_2.data()); 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 hipSPARSE-rocm-5.7.1/clients/include/testing_spmm_batched_csr.hpp000066400000000000000000000412671447644345400250400ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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) { #ifdef __HIP_PLATFORM_NVIDIA__ // do not test for bad args return; #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) 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(); if(!dval || !dptr || !dcol || !dB || !dC || !dbuf) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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() { #ifdef __HIP_PLATFORM_NVIDIA__ // do not test for bad args return HIPSPARSE_STATUS_SUCCESS; #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) T h_alpha = make_DataType(1.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_ZERO; 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 // Matrices are stored at the same path in matrices directory std::string filename = get_filename("nos3.bin"); // Index and data type hipsparseIndexType_t typeI = (typeid(I) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipsparseIndexType_t typeJ = (typeid(J) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipDataType typeT = (typeid(T) == typeid(float)) ? HIP_R_32F : ((typeid(T) == typeid(double)) ? HIP_R_64F : ((typeid(T) == typeid(hipComplex) ? HIP_C_32F : HIP_C_64F))); // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Initial Data on CPU srand(12345ULL); J m; J k; I nnz; if(read_bin_matrix(filename.c_str(), m, k, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } J n = 5; J ldb = k; J ldc = m; J offsets_batch_stride_A = 0; I columns_values_batch_stride_A = 0; I batch_stride_B = k * n; I batch_stride_C = m * n; std::vector hB(batch_count_B * k * n); std::vector hC_1(batch_count_C * m * n); std::vector hC_2(batch_count_C * m * n); std::vector hC_gold(batch_count_C * m * n); hipsparseInit(hB, batch_count_B * k * n, 1); hipsparseInit(hC_1, batch_count_C * m * n, 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) * (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) * batch_count_B * k * n), device_free}; auto dC_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * batch_count_C * m * n), device_free}; auto dC_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * batch_count_C * 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* 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(); if(!dval || !dptr || !dcol || !dB || !dC_1 || !dC_2 || !d_alpha || !d_beta) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dval || !dptr || !dcol || !dB || " "!dC_1 || !dC_2 || !d_alpha || !d_beta"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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) * batch_count_B * k * n, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dC_1, hC_1.data(), sizeof(T) * batch_count_C * m * n, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dC_2, hC_2.data(), sizeof(T) * batch_count_C * 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)); // Create matrices hipsparseSpMatDescr_t A; CHECK_HIPSPARSE_ERROR( hipsparseCreateCsr(&A, m, k, nnz, dptr, dcol, dval, typeI, typeJ, 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)); 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)); // ROCSPARSE 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, B, &h_beta, C1, typeT, alg, buffer)); #endif CHECK_HIPSPARSE_ERROR( hipsparseSpMM(handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); // ROCSPARSE 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, B, d_beta, C2, typeT, alg, buffer)); #endif 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 * m * n, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hC_2.data(), dC_2, sizeof(T) * batch_count_C * m * n, hipMemcpyDeviceToHost)); // CPU double cpu_time_used = get_time_us(); host_csrmm_batched(m, n, k, batch_count_A, offsets_batch_stride_A, columns_values_batch_stride_A, transA, transB, h_alpha, hcsr_row_ptr.data(), hcsr_col_ind.data(), hcsr_val.data(), hB.data(), ldb, batch_count_B, batch_stride_B, h_beta, hC_gold.data(), ldc, batch_count_C, batch_stride_C, order, idx_base, false); cpu_time_used = get_time_us() - cpu_time_used; unit_check_near(1, batch_count_C * m * n, 1, hC_gold.data(), hC_1.data()); unit_check_near(1, batch_count_C * m * n, 1, hC_gold.data(), hC_2.data()); 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 hipSPARSE-rocm-5.7.1/clients/include/testing_spmm_bell.hpp000066400000000000000000000452711447644345400235140ustar00rootroot00000000000000/* ************************************************************************ * 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_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) { #ifdef __HIP_PLATFORM_NVIDIA__ // do not test for bad args return; #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) 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(); if(!dval || !dind || !dB || !dC || !dbuf) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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 = (typeid(I) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipDataType typeT = (typeid(T) == typeid(float)) ? HIP_R_32F : ((typeid(T) == typeid(double)) ? HIP_R_64F : ((typeid(T) == typeid(hipComplex) ? HIP_C_32F : HIP_C_64F))); // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_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(m * n); 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(); if(!dval || !drow_ptr || !dcol_ind || !dB || !dC_1 || !dC_2 || !d_alpha || !d_beta || !dbell_ind || !dbell_val) { verify_hipsparse_status_success( HIPSPARSE_STATUS_ALLOC_FAILED, "!dval || !drow_ptr || !dcol_ind || !dB || " "!dC_1 || !dC_2 || !d_alpha || !d_beta || !dbell_ind || !dbell_val"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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)); // ROCSPARSE 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)); // ROCSPARSE 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 hipSPARSE-rocm-5.7.1/clients/include/testing_spmm_coo.hpp000066400000000000000000000375231447644345400233570ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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) { #ifdef __HIP_PLATFORM_NVIDIA__ // do not test for bad args return; #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) 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(); if(!dval || !drow || !dcol || !dB || !dC || !dbuf) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) 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_ZERO; // // ! // #if(CUDART_VERSION >= 11003) hipsparseSpMMAlg_t alg = HIPSPARSE_SPMM_COO_ALG1; #else hipsparseSpMMAlg_t alg = HIPSPARSE_MM_ALG_DEFAULT; #endif // Matrices are stored at the same path in matrices directory std::string filename = get_filename("nos3.bin"); // Index and data type hipsparseIndexType_t typeI = (typeid(I) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipDataType typeT = (typeid(T) == typeid(float)) ? HIP_R_32F : ((typeid(T) == typeid(double)) ? HIP_R_64F : ((typeid(T) == typeid(hipComplex) ? HIP_C_32F : HIP_C_64F))); // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; // Host structures std::vector hrow_ptr; std::vector hcol_ind; std::vector hval; // Initial Data on CPU srand(12345ULL); I m; I k; I nnz; if(read_bin_matrix(filename.c_str(), m, k, nnz, hrow_ptr, hcol_ind, hval, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", 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; } } I n = 5; I ldb = k; I ldc = m; std::vector hB(k * n); std::vector hC_1(m * n); std::vector hC_2(m * n); std::vector hC_gold(m * n); hipsparseInit(hB, k, n); hipsparseInit(hC_1, m, n); // 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), 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) * 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 = (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(); if(!dval || !drow || !dcol || !dB || !dC_1 || !dC_2 || !d_alpha || !d_beta) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dval || !drow || !dcol || !dB || " "!dC_1 || !dC_2 || !d_alpha || !d_beta"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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) * 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)); // Create matrices hipsparseSpMatDescr_t A; CHECK_HIPSPARSE_ERROR( hipsparseCreateCoo(&A, m, k, nnz, drow, dcol, dval, 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; 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)); // ROCSPARSE 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, B, &h_beta, C1, typeT, alg, buffer)); #endif CHECK_HIPSPARSE_ERROR( hipsparseSpMM(handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); // ROCSPARSE 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, B, d_beta, C2, typeT, alg, buffer)); #endif 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) * m * n, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hC_2.data(), dC_2, sizeof(T) * m * n, hipMemcpyDeviceToHost)); // CPU host_coomm(m, n, nnz, transB, h_alpha, hrow_ind.data(), hcol_ind.data(), hval.data(), hB.data(), ldb, h_beta, hC_gold.data(), ldc, order, idx_base); 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)); 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 hipSPARSE-rocm-5.7.1/clients/include/testing_spmm_csc.hpp000066400000000000000000000400011447644345400233300ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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) { #ifdef __HIP_PLATFORM_NVIDIA__ // do not test for bad args return; #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) 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(); if(!dval || !dptr || !drow || !dB || !dC || !dbuf) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11061) 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_ZERO; // // ! // #if(CUDART_VERSION >= 11003) hipsparseSpMMAlg_t alg = HIPSPARSE_SPMM_CSR_ALG1; #else hipsparseSpMMAlg_t alg = HIPSPARSE_MM_ALG_DEFAULT; #endif // Matrices are stored at the same path in matrices directory std::string filename = get_filename("nos3.bin"); // Index and data type hipsparseIndexType_t typeI = (typeid(I) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipsparseIndexType_t typeJ = (typeid(J) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipDataType typeT = (typeid(T) == typeid(float)) ? HIP_R_32F : ((typeid(T) == typeid(double)) ? HIP_R_64F : ((typeid(T) == typeid(hipComplex) ? HIP_C_32F : HIP_C_64F))); // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; // Host structures std::vector hcsc_col_ptr; std::vector hcsc_row_ind; std::vector hcsc_val; // Initial Data on CPU srand(12345ULL); J m; J k; I nnz; if(read_bin_matrix(filename.c_str(), k, m, nnz, hcsc_col_ptr, hcsc_row_ind, hcsc_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } J n = 5; J ldb = k; J ldc = m; std::vector hB(k * n); std::vector hC_1(m * n); std::vector hC_2(m * n); std::vector hC_gold(m * n); hipsparseInit(hB, k, n); hipsparseInit(hC_1, m, n); // 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) * (k + 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 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* 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(); if(!dval || !dptr || !drow || !dB || !dC_1 || !dC_2 || !d_alpha || !d_beta) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dval || !dptr || !drow || !dB || " "!dC_1 || !dC_2 || !d_alpha || !d_beta"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsc_col_ptr.data(), sizeof(I) * (k + 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)); 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)); // Create matrices hipsparseSpMatDescr_t A; CHECK_HIPSPARSE_ERROR( hipsparseCreateCsc(&A, m, k, nnz, dptr, drow, dval, typeI, typeJ, 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; 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)); // ROCSPARSE 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, B, &h_beta, C1, typeT, alg, buffer)); #endif CHECK_HIPSPARSE_ERROR( hipsparseSpMM(handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); // ROCSPARSE 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, B, d_beta, C2, typeT, alg, buffer)); #endif 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) * m * n, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hC_2.data(), dC_2, sizeof(T) * m * n, hipMemcpyDeviceToHost)); // CPU double cpu_time_used = get_time_us(); host_cscmm(m, n, k, transA, transB, h_alpha, hcsc_col_ptr.data(), hcsc_row_ind.data(), hcsc_val.data(), hB.data(), ldb, h_beta, hC_gold.data(), ldc, order, idx_base); cpu_time_used = get_time_us() - cpu_time_used; 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)); 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 hipSPARSE-rocm-5.7.1/clients/include/testing_spmm_csr.hpp000066400000000000000000000400271447644345400233570ustar00rootroot00000000000000/* ************************************************************************ * 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 "hipsparse.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) { #ifdef __HIP_PLATFORM_NVIDIA__ // do not test for bad args return; #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) 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(); if(!dval || !dptr || !dcol || !dB || !dC || !dbuf) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) 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_ZERO; // // ! // #if(CUDART_VERSION >= 11003) hipsparseSpMMAlg_t alg = HIPSPARSE_SPMM_CSR_ALG1; #else hipsparseSpMMAlg_t alg = HIPSPARSE_MM_ALG_DEFAULT; #endif // Matrices are stored at the same path in matrices directory std::string filename = get_filename("nos3.bin"); // Index and data type hipsparseIndexType_t typeI = (typeid(I) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipsparseIndexType_t typeJ = (typeid(J) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipDataType typeT = (typeid(T) == typeid(float)) ? HIP_R_32F : ((typeid(T) == typeid(double)) ? HIP_R_64F : ((typeid(T) == typeid(hipComplex) ? HIP_C_32F : HIP_C_64F))); // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Initial Data on CPU srand(12345ULL); J m; J k; I nnz; if(read_bin_matrix(filename.c_str(), m, k, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } J n = 5; J ldb = k; J ldc = m; std::vector hB(k * n); std::vector hC_1(m * n); std::vector hC_2(m * n); std::vector hC_gold(m * n); hipsparseInit(hB, k, n); hipsparseInit(hC_1, m, n); // 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) * (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) * 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* 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(); if(!dval || !dptr || !dcol || !dB || !dC_1 || !dC_2 || !d_alpha || !d_beta) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dval || !dptr || !dcol || !dB || " "!dC_1 || !dC_2 || !d_alpha || !d_beta"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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) * 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)); // Create matrices hipsparseSpMatDescr_t A; CHECK_HIPSPARSE_ERROR( hipsparseCreateCsr(&A, m, k, nnz, dptr, dcol, dval, typeI, typeJ, 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; 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)); // ROCSPARSE 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, B, &h_beta, C1, typeT, alg, buffer)); #endif CHECK_HIPSPARSE_ERROR( hipsparseSpMM(handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); // ROCSPARSE 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, B, d_beta, C2, typeT, alg, buffer)); #endif 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) * m * n, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hC_2.data(), dC_2, sizeof(T) * m * n, hipMemcpyDeviceToHost)); // CPU double cpu_time_used = get_time_us(); host_csrmm(m, n, k, transA, transB, h_alpha, hcsr_row_ptr.data(), hcsr_col_ind.data(), hcsr_val.data(), hB.data(), ldb, h_beta, hC_gold.data(), ldc, order, idx_base, false); cpu_time_used = get_time_us() - cpu_time_used; 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)); 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 hipSPARSE-rocm-5.7.1/clients/include/testing_spmv_coo.hpp000066400000000000000000000330531447644345400233620ustar00rootroot00000000000000/* ************************************************************************ * 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 "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 < 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_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(); if(!dval || !drow || !dcol || !dx || !dy || !dbuf) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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(void) { #if(!defined(CUDART_VERSION) || (CUDART_VERSION > 10010 && CUDART_VERSION < 12000) \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1 && CUDART_VERSION < 12000)) T h_alpha = make_DataType(2.0); T h_beta = make_DataType(1.0); hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; #if(!defined(CUDART_VERSION)) hipsparseSpMVAlg_t alg = HIPSPARSE_COOMV_ALG; #else #if(CUDART_VERSION >= 12000) hipsparseSpMVAlg_t alg = HIPSPARSE_SPMV_COO_ALG1; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 12000) hipsparseSpMVAlg_t alg = HIPSPARSE_COOMV_ALG; #endif #endif // Matrices are stored at the same path in matrices directory std::string filename = get_filename("nos3.bin"); // Index and data type hipsparseIndexType_t typeI = (typeid(I) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipDataType typeT = (typeid(T) == typeid(float)) ? HIP_R_32F : ((typeid(T) == typeid(double)) ? HIP_R_64F : ((typeid(T) == typeid(hipComplex) ? HIP_C_32F : HIP_C_64F))); // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; // Host structures std::vector hrow_ptr; std::vector hcol_ind; std::vector hval; // Initial Data on CPU srand(12345ULL); I m; I n; I nnz; if(read_bin_matrix(filename.c_str(), m, n, nnz, hrow_ptr, hcol_ind, hval, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", 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(); if(!dval || !drow || !dcol || !dx || !dy_1 || !dy_2 || !d_alpha || !d_beta) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dval || !drow || !dcol || !dx || " "!dy_1 || !dy_2 || !d_alpha || !d_beta"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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)); // ROCSPARSE 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)); // ROCSPARSE 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] = hy_gold[i] * h_beta; } 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()); 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 hipSPARSE-rocm-5.7.1/clients/include/testing_spmv_coo_aos.hpp000066400000000000000000000320011447644345400242140ustar00rootroot00000000000000/* ************************************************************************ * 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 "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(); if(!dval || !dind || !dx || !dy || !dbuf) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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(void) { #if(!defined(CUDART_VERSION) || (CUDART_VERSION > 10010 && CUDART_VERSION < 12000) \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1 && CUDART_VERSION < 12000)) T h_alpha = make_DataType(2.0); T h_beta = make_DataType(1.0); hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseSpMVAlg_t alg = HIPSPARSE_COOMV_ALG; // Matrices are stored at the same path in matrices directory std::string filename = get_filename("nos3.bin"); // Index and data type hipsparseIndexType_t typeI = (typeid(I) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipDataType typeT = (typeid(T) == typeid(float)) ? HIP_R_32F : ((typeid(T) == typeid(double)) ? HIP_R_64F : ((typeid(T) == typeid(hipComplex) ? HIP_C_32F : HIP_C_64F))); // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; // Host structures std::vector hrow_ptr; std::vector hcol_ind; std::vector hval; // Initial Data on CPU srand(12345ULL); I m; I n; I nnz; if(read_bin_matrix(filename.c_str(), m, n, nnz, hrow_ptr, hcol_ind, hval, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", 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(); if(!dval || !dind || !dx || !dy_1 || !dy_2 || !d_alpha || !d_beta) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dval || !dind || !dx || " "!dy_1 || !dy_2 || !d_alpha || !d_beta"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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)); // ROCSPARSE 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)); // ROCSPARSE 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] = hy_gold[i] * h_beta; } 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()); 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 hipSPARSE-rocm-5.7.1/clients/include/testing_spmv_csr.hpp000066400000000000000000000403061447644345400233700ustar00rootroot00000000000000/* ************************************************************************ * 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 "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 < 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 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(); if(!dval || !dptr || !dcol || !dx || !dy || !dbuf) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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(void) { #if(!defined(CUDART_VERSION) || (CUDART_VERSION > 10010 && CUDART_VERSION < 12000) \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1 && CUDART_VERSION < 12000)) T h_alpha = make_DataType(2.0); T h_beta = make_DataType(1.0); hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; #if(!defined(CUDART_VERSION)) hipsparseSpMVAlg_t alg = HIPSPARSE_CSRMV_ALG2; #else #if(CUDART_VERSION >= 12000) hipsparseSpMVAlg_t alg = HIPSPARSE_SPMV_CSR_ALG2; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 12000) hipsparseSpMVAlg_t alg = HIPSPARSE_CSRMV_ALG2; #endif #endif // Matrices are stored at the same path in matrices directory std::string filename = get_filename("nos3.bin"); // Index and data type hipsparseIndexType_t typeI = (typeid(I) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipsparseIndexType_t typeJ = (typeid(J) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipDataType typeT = (typeid(T) == typeid(float)) ? HIP_R_32F : ((typeid(T) == typeid(double)) ? HIP_R_64F : ((typeid(T) == typeid(hipComplex) ? HIP_C_32F : HIP_C_64F))); // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; // Host structures std::vector hcsr_row_ptr; std::vector hcol_ind; std::vector hval; // Initial Data on CPU srand(12345ULL); J m; J n; I nnz; if(read_bin_matrix(filename.c_str(), m, n, nnz, hcsr_row_ptr, hcol_ind, hval, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", 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(); if(!dval || !dptr || !dcol || !dx || !dy_1 || !dy_2 || !d_alpha || !d_beta) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dval || !dptr || !dcol || !dx || " "!dy_1 || !dy_2 || !d_alpha || !d_beta"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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)); // ROCSPARSE 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)); // ROCSPARSE 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; 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()); 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 hipSPARSE-rocm-5.7.1/clients/include/testing_spsm_coo.hpp000066400000000000000000000363101447644345400233560ustar00rootroot00000000000000/* ************************************************************************ * 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 "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) { #ifdef __HIP_PLATFORM_NVIDIA__ // do not test for bad args return; #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11031) 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(); if(!dval || !drow || !dcol || !dB || !dC || !dbuf) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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, 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, 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"); #if(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_pointer( hipsparseSpSM_solve(handle, transA, transB, &alpha, A, B, C, dataType, alg, descr, nullptr), "Error: dbuf is nullptr"); #endif // 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(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11031) T h_alpha = make_DataType(2.3); hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseDiagType_t diag = HIPSPARSE_DIAG_TYPE_NON_UNIT; hipsparseFillMode_t uplo = HIPSPARSE_FILL_MODE_LOWER; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; hipsparseSpSMAlg_t alg = HIPSPARSE_SPSM_ALG_DEFAULT; std::string filename = get_filename("nos3.bin"); // Index and data type hipsparseIndexType_t typeI = (typeid(I) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipDataType typeT = (typeid(T) == typeid(float)) ? HIP_R_32F : ((typeid(T) == typeid(double)) ? HIP_R_64F : ((typeid(T) == typeid(hipComplex) ? HIP_C_32F : HIP_C_64F))); // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; // Host structures std::vector hrow_ptr; std::vector hcol_ind; std::vector hval; // Initial Data on CPU srand(12345ULL); I m; I n; I nnz; I k = 16; if(read_bin_matrix(filename.c_str(), m, n, nnz, hrow_ptr, hcol_ind, hval, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", 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 hB(m * k); std::vector hC_1(m * k); std::vector hC_2(m * k); std::vector hC_gold(m * k); hipsparseInit(hB, 1, m * k); 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) * m * k), device_free}; auto dC_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * k), device_free}; auto dC_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * k), 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(); if(!dval || !drow || !dcol || !dB || !dC_1 || !dC_2 || !d_alpha) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dval || !drow || !dcol || !dB || " "!dC_1 || !dC_2 || !d_alpha"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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) * m * k, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_1, hC_1.data(), sizeof(T) * m * k, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_2, hC_2.data(), sizeof(T) * m * k, 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, m, k, m, dB, typeT, order)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C1, m, k, m, dC_1, typeT, order)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C2, m, k, m, dC_2, typeT, order)); 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)); // 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) * m * k, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hC_2.data(), dC_2, sizeof(T) * m * k, hipMemcpyDeviceToHost)); I struct_pivot = -1; I numeric_pivot = -1; host_coosm(m, k, nnz, transA, transB, h_alpha, hrow_ind, hcol_ind, hval, hC_gold, m, diag, uplo, idx_base, &struct_pivot, &numeric_pivot); if(struct_pivot == -1 && numeric_pivot == -1) { unit_check_near(1, m * k, 1, hC_gold.data(), hC_1.data()); unit_check_near(1, m * k, 1, hC_gold.data(), hC_2.data()); } 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 hipSPARSE-rocm-5.7.1/clients/include/testing_spsm_csr.hpp000066400000000000000000000362371447644345400233750ustar00rootroot00000000000000/* ************************************************************************ * 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 "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) { #ifdef __HIP_PLATFORM_NVIDIA__ // do not test for bad args return; #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11031) 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(); if(!dval || !dptr || !dcol || !dB || !dC || !dbuf) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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, 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, 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"); #if(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_pointer( hipsparseSpSM_solve(handle, transA, transB, &alpha, A, B, C, dataType, alg, descr, nullptr), "Error: dbuf is nullptr"); #endif // 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(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11031) T h_alpha = make_DataType(2.3); hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseDiagType_t diag = HIPSPARSE_DIAG_TYPE_NON_UNIT; hipsparseFillMode_t uplo = HIPSPARSE_FILL_MODE_LOWER; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; hipsparseSpSMAlg_t alg = HIPSPARSE_SPSM_ALG_DEFAULT; std::string filename = get_filename("nos3.bin"); // Index and data type hipsparseIndexType_t typeI = (typeid(I) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipsparseIndexType_t typeJ = (typeid(J) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipDataType typeT = (typeid(T) == typeid(float)) ? HIP_R_32F : ((typeid(T) == typeid(double)) ? HIP_R_64F : ((typeid(T) == typeid(hipComplex) ? HIP_C_32F : HIP_C_64F))); // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; // Host structures std::vector hcsr_row_ptr; std::vector hcol_ind; std::vector hval; // Initial Data on CPU srand(12345ULL); J m; J n; I nnz; J k = 16; if(read_bin_matrix(filename.c_str(), m, n, nnz, hcsr_row_ptr, hcol_ind, hval, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hB(m * k); std::vector hC_1(m * k); std::vector hC_2(m * k); std::vector hC_gold(m * k); hipsparseInit(hB, 1, m * k); 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) * m * k), device_free}; auto dC_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * k), device_free}; auto dC_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * k), 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(); if(!dval || !dptr || !dcol || !dB || !dC_1 || !dC_2 || !d_alpha) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dval || !dptr || !dcol || !dB || " "!dC_1 || !dC_2 || !d_alpha"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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(dB, hB.data(), sizeof(T) * m * k, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_1, hC_1.data(), sizeof(T) * m * k, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_2, hC_2.data(), sizeof(T) * m * k, 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, n, nnz, dptr, dcol, dval, typeI, typeJ, idx_base, typeT)); // Create dense matrices hipsparseDnMatDescr_t B, C1, C2; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&B, m, k, m, dB, typeT, order)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C1, m, k, m, dC_1, typeT, order)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C2, m, k, m, dC_2, typeT, order)); 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)); // 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) * m * k, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hC_2.data(), dC_2, sizeof(T) * m * k, hipMemcpyDeviceToHost)); J struct_pivot = -1; J numeric_pivot = -1; host_csrsm(m, k, nnz, transA, transB, h_alpha, hcsr_row_ptr, hcol_ind, hval, hC_gold, m, diag, uplo, idx_base, &struct_pivot, &numeric_pivot); if(struct_pivot == -1 && numeric_pivot == -1) { unit_check_near(1, m * k, 1, hC_gold.data(), hC_1.data()); unit_check_near(1, m * k, 1, hC_gold.data(), hC_2.data()); } 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 hipSPARSE-rocm-5.7.1/clients/include/testing_spsv_coo.hpp000066400000000000000000000347771447644345400234060ustar00rootroot00000000000000/* ************************************************************************ * 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 "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) { #ifdef __HIP_PLATFORM_NVIDIA__ // do not test for bad args return; #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11030) 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(); if(!dval || !drow || !dcol || !dx || !dy || !dbuf) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_solve(handle, transA, nullptr, A, x, y, dataType, alg, descr, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_solve(handle, transA, &alpha, nullptr, x, y, dataType, alg, descr, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_solve(handle, transA, &alpha, A, nullptr, y, dataType, alg, descr, dbuf), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_solve(handle, transA, &alpha, A, x, nullptr, dataType, alg, descr, dbuf), "Error: y is nullptr"); #if(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_pointer( hipsparseSpSV_solve(handle, transA, &alpha, A, x, y, dataType, alg, descr, nullptr), "Error: dbuf 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(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11030) T h_alpha = make_DataType(2.3); hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseDiagType_t diag = HIPSPARSE_DIAG_TYPE_NON_UNIT; hipsparseFillMode_t uplo = HIPSPARSE_FILL_MODE_LOWER; hipsparseSpSVAlg_t alg = HIPSPARSE_SPSV_ALG_DEFAULT; std::string filename = get_filename("nos3.bin"); // Index and data type hipsparseIndexType_t typeI = (typeid(I) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipDataType typeT = (typeid(T) == typeid(float)) ? HIP_R_32F : ((typeid(T) == typeid(double)) ? HIP_R_64F : ((typeid(T) == typeid(hipComplex) ? HIP_C_32F : HIP_C_64F))); // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; // Host structures std::vector hrow_ptr; std::vector hcol_ind; std::vector hval; // Initial Data on CPU srand(12345ULL); I m; I n; I nnz; if(read_bin_matrix(filename.c_str(), m, n, nnz, hrow_ptr, hcol_ind, hval, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", 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(); if(!dval || !drow || !dcol || !dx || !dy_1 || !dy_2 || !d_alpha) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dval || !drow || !dcol || !dx || " "!dy_1 || !dy_2 || !d_alpha"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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)); // 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, buffer)); // 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, 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)); 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()); } 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 hipSPARSE-rocm-5.7.1/clients/include/testing_spsv_csr.hpp000066400000000000000000000347711447644345400234070ustar00rootroot00000000000000/* ************************************************************************ * 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 "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) { #ifdef __HIP_PLATFORM_NVIDIA__ // do not test for bad args return; #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11030) 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(); if(!dval || !dptr || !dcol || !dx || !dy || !dbuf) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_solve(handle, transA, nullptr, A, x, y, dataType, alg, descr, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_solve(handle, transA, &alpha, nullptr, x, y, dataType, alg, descr, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_solve(handle, transA, &alpha, A, nullptr, y, dataType, alg, descr, dbuf), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_solve(handle, transA, &alpha, A, x, nullptr, dataType, alg, descr, dbuf), "Error: y is nullptr"); #if(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_pointer( hipsparseSpSV_solve(handle, transA, &alpha, A, x, y, dataType, alg, descr, nullptr), "Error: dbuf 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(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11030) T h_alpha = make_DataType(2.3); hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseDiagType_t diag = HIPSPARSE_DIAG_TYPE_NON_UNIT; hipsparseFillMode_t uplo = HIPSPARSE_FILL_MODE_LOWER; hipsparseSpSVAlg_t alg = HIPSPARSE_SPSV_ALG_DEFAULT; std::string filename = get_filename("nos3.bin"); // Index and data type hipsparseIndexType_t typeI = (typeid(I) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipsparseIndexType_t typeJ = (typeid(J) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipDataType typeT = (typeid(T) == typeid(float)) ? HIP_R_32F : ((typeid(T) == typeid(double)) ? HIP_R_64F : ((typeid(T) == typeid(hipComplex) ? HIP_C_32F : HIP_C_64F))); // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; // Host structures std::vector hcsr_row_ptr; std::vector hcol_ind; std::vector hval; // Initial Data on CPU srand(12345ULL); J m; J n; I nnz; if(read_bin_matrix(filename.c_str(), m, n, nnz, hcsr_row_ptr, hcol_ind, hval, idx_base) != 0) { fprintf(stderr, "Cannot open [read] %s\n", 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(); if(!dval || !dptr || !dcol || !dx || !dy_1 || !dy_2 || !d_alpha) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dval || !dptr || !dcol || !dx || " "!dy_1 || !dy_2 || !d_alpha"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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) * 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)); // 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, buffer)); // 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, 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)); J struct_pivot = -1; J numeric_pivot = -1; host_csrsv(transA, m, nnz, h_alpha, hcsr_row_ptr.data(), hcol_ind.data(), hval.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()); } 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 hipSPARSE-rocm-5.7.1/clients/include/testing_spvec_descr.hpp000066400000000000000000000142271447644345400240370ustar00rootroot00000000000000/* ************************************************************************ * 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) || CUDART_VERSION > 10010 \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) 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(); if(!idx_data || !val_data) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } 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 #if(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_pointer(hipsparseDestroySpVec(nullptr), "Error: x is nullptr"); #else verify_hipsparse_status_success(hipsparseDestroySpVec(nullptr), "Success"); #endif // 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 hipSPARSE-rocm-5.7.1/clients/include/testing_spvv.hpp000066400000000000000000000242641447644345400225370ustar00rootroot00000000000000/* ************************************************************************ * 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 "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(); if(!dx_ind || !dx_val || !dy) { PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); return; } // 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(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION > 10010 \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) int64_t size = 15332; int64_t nnz = 500; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; // Index and data type hipsparseIndexType_t idxType = (typeid(I) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; hipDataType dataType = (typeid(T) == typeid(float)) ? HIP_R_32F : ((typeid(T) == typeid(double)) ? HIP_R_64F : ((typeid(T) == typeid(hipComplex) ? HIP_C_32F : HIP_C_64F))); // hipSPARSE handle std::unique_ptr test_handle(new handle_struct); hipsparseHandle_t handle = test_handle->handle; // Host structures std::vector hx_ind(nnz); std::vector hx_val(nnz); std::vector hy(size); T hresult_N; T hresult_C; T hresult_N_gold; T hresult_C_gold; // 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_C_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_C = (T*)dresult_C_managed.get(); if(!dx_ind || !dx_val || !dy || !dresult_C) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dx_ind || !dx_val || !dy || !dresult_2"); return HIPSPARSE_STATUS_ALLOC_FAILED; } // 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)); // SpVV_bufferSize size_t bufferSize; void* externalBuffer; // SpVV non-transpose pointer-mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSpVV_bufferSize( handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, x, y, &hresult_N, dataType, &bufferSize)); CHECK_HIP_ERROR(hipMalloc(&externalBuffer, bufferSize)); CHECK_HIPSPARSE_ERROR(hipsparseSpVV( handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, x, y, &hresult_N, dataType, externalBuffer)); CHECK_HIP_ERROR(hipFree(externalBuffer)); // SpVV conjugate-transpose pointer-mode device if(dataType == HIP_C_32F || dataType == HIP_C_64F) { CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSpVV_bufferSize(handle, HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE, x, y, dresult_C, dataType, &bufferSize)); CHECK_HIP_ERROR(hipMalloc(&externalBuffer, bufferSize)); CHECK_HIPSPARSE_ERROR(hipsparseSpVV(handle, HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE, x, y, dresult_C, dataType, externalBuffer)); CHECK_HIP_ERROR(hipFree(externalBuffer)); // Copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(&hresult_C, dresult_C, sizeof(T), hipMemcpyDeviceToHost)); } // CPU non-transpose hresult_N_gold = make_DataType(0); for(I i = 0; i < nnz; ++i) { hresult_N_gold = hresult_N_gold + testing_mult(hy[hx_ind[i] - idxBase], hx_val[i]); } // Verify results against host unit_check_general(1, 1, 1, &hresult_N_gold, &hresult_N); // CPU transpose if(dataType == HIP_C_32F || dataType == HIP_C_64F) { hresult_C_gold = make_DataType(0); for(I i = 0; i < nnz; ++i) { hresult_C_gold = hresult_C_gold + testing_mult(testing_conj(hx_val[i]), hy[hx_ind[i] - idxBase]); } // Verify results against host unit_check_general(1, 1, 1, &hresult_C_gold, &hresult_C); } CHECK_HIPSPARSE_ERROR(hipsparseDestroySpVec(x)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPVV_HPP hipSPARSE-rocm-5.7.1/clients/include/unit.hpp000066400000000000000000000043241447644345400207560ustar00rootroot00000000000000/* ************************************************************************ * 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 hipSPARSE-rocm-5.7.1/clients/include/utility.hpp000066400000000000000000005771161447644345400215200ustar00rootroot00000000000000/* ************************************************************************ * 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 TESTING_UTILITY_HPP #define TESTING_UTILITY_HPP #include "hipsparse.h" #include #include #include #include #include #include #include #include #include #include #include #ifdef GOOGLE_TEST #include "gtest/gtest.h" #endif #ifdef _OPENMP #include #endif std::string hipsparse_exepath(); /*!\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, float sparsity_ratio = 0.3) { 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); } } } /* ============================================================================================ */ /*! \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 */ static inline void read_mtx_value(std::istringstream& is, int& row, int& col, float& val) { is >> row >> col >> val; } static inline void read_mtx_value(std::istringstream& is, int& row, int& col, double& val) { is >> row >> col >> val; } static inline void read_mtx_value(std::istringstream& is, int& row, int& col, hipComplex& val) { float real; float imag; is >> row >> col >> real >> imag; val = make_DataType(real, imag); } static inline void read_mtx_value(std::istringstream& is, int& row, int& col, hipDoubleComplex& val) { double real; double imag; is >> row >> col >> real >> imag; val = make_DataType(real, imag); } template int read_mtx_matrix(const char* filename, int& nrow, int& ncol, int& 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 int snnz; sscanf(line, "%d %d %d", &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 int idx = 0; while(fgets(line, 1024, f)) { if(idx >= nnz) { return true; } int irow; int 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 true; } 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(int i = 0; i < nnz; ++i) { perm[i] = i; } std::sort(perm.begin(), perm.end(), [&](const int& a, const int& 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; } }); for(int 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 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(m * n); 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 = sorted_A[pos]; 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_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, T beta, T* C, J ldc, hipsparseOrder_t order, 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 = order == 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 && order == HIPSPARSE_ORDER_COL) || (transB == HIPSPARSE_OPERATION_TRANSPOSE && order != HIPSPARSE_ORDER_COL) || (transB == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE && order != 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 = (order == 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++) { 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; 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 && order == HIPSPARSE_ORDER_COL) || (transB == HIPSPARSE_OPERATION_TRANSPOSE && order != HIPSPARSE_ORDER_COL) || (transB == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE && order != HIPSPARSE_ORDER_COL)) { idx_B = (i + j * ldb); } else { idx_B = (j + i * ldb); } J idx_C = (order == 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, T beta, T* C, J ldc, J batch_count_C, I batch_stride_C, hipsparseOrder_t order, 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, beta, C + batch_stride_C * i, ldc, order, 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, beta, C + batch_stride_C * i, ldc, order, 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, beta, C + batch_stride_C * i, ldc, order, 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, T beta, T* C, J ldc, hipsparseOrder_t order, 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, beta, C, ldc, order, 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, beta, C, ldc, order, 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, beta, C, ldc, order, 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, T beta, T* C, J ldc, J batch_count_C, I batch_stride_C, hipsparseOrder_t order, 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, beta, C, ldc, batch_count_C, batch_stride_C, order, 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, beta, C, ldc, batch_count_C, batch_stride_C, order, 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, beta, C, ldc, batch_count_C, batch_stride_C, order, base, true); } } } template void host_coomm(I M, I N, I nnz, 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, T beta, T* C, I ldc, hipsparseOrder_t order, hipsparseIndexBase_t base) { if(order == HIPSPARSE_ORDER_COL) { 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 = i + j * ldc; C[idx_C] = testing_mult(beta, C[idx_C]); } } } else { for(I i = 0; i < M; ++i) { #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(I j = 0; j < N; j++) { I idx_C = 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 == HIPSPARSE_ORDER_COL ? row + j * ldc : row * ldc + j; I idx_B = 0; if((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE && order == HIPSPARSE_ORDER_COL) || (transB != HIPSPARSE_OPERATION_NON_TRANSPOSE && order != HIPSPARSE_ORDER_COL)) { idx_B = (col + j * ldb); } else { idx_B = (j + col * ldb); } if(transB == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE) { C[idx_C] = testing_fma(val, testing_conj(B[idx_B]), C[idx_C]); } else { C[idx_C] = testing_fma(val, B[idx_B], C[idx_C]); } } } } template void host_coomm_batched(I M, I N, I nnz, I batch_count_A, I batch_stride_A, 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, T beta, T* C, I ldc, I batch_count_C, I batch_stride_C, hipsparseOrder_t order, 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, nnz, transB, alpha, coo_row_ind_A, coo_col_ind_A, coo_val_A, B + batch_stride_B * i, ldb, beta, C + batch_stride_C * i, ldc, order, base); } } else if(Ci_Ai_B) { for(I i = 0; i < batch_count_C; i++) { host_coomm(M, N, nnz, 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, beta, C + batch_stride_C * i, ldc, order, base); } } else if(Ci_Ai_Bi) { for(I i = 0; i < batch_count_C; i++) { host_coomm(M, N, nnz, 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, beta, C + batch_stride_C * i, ldc, order, 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 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, hipsparseDiagType_t diag_type, hipsparseIndexBase_t base, J* struct_pivot, J* numeric_pivot) { // Get device properties int dev; hipDeviceProp_t prop; hipGetDevice(&dev); 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) ? 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) ? 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, hipsparseDiagType_t diag_type, hipsparseIndexBase_t base, J* struct_pivot, J* numeric_pivot) { // Get device properties int dev; hipDeviceProp_t prop; hipGetDevice(&dev); 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) ? 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) ? 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 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; hipGetDevice(&dev); 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; hipGetDevice(&dev); 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_csrsm(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, 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, diag_type, base, struct_pivot, numeric_pivot); } else { host_ussolve(M, nrhs, transB, alpha, csr_row_ptr, csr_col_ind, csr_val, B, ldb, 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, diag_type, base, struct_pivot, numeric_pivot); } else { host_lssolve(M, nrhs, transB, alpha, csrt_row_ptr, csrt_col_ind, csrt_val, B, ldb, 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_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, std::vector& B, I ldb, 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_csrsm(M, nrhs, nnz, transA, transB, alpha, csr_row_ptr, coo_col_ind, coo_val, B, ldb, 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 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 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 /* ============================================================================================ */ /*! \brief Class used to parse command arguments in both client & gtest */ // has to compile with option "-std=c++11", and this hipsparse library uses c++11 everywhere // c++11 allows intilization of member of a struct class Arguments { public: int M = 128; int N = 128; int K = 128; int nnz = 32; int block_dim = 1; int row_block_dimA = 1; int row_block_dimB = 1; int col_block_dimA = 1; int col_block_dimB = 1; int lda{}; int ldb{}; int ldc{}; double alpha = 1.0; double alphai = 0.0; double beta = 0.0; double betai = 0.0; double threshold = 0.0; double percentage = 0.0; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexBase_t idx_base2 = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexBase_t idx_base3 = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexBase_t idx_base4 = HIPSPARSE_INDEX_BASE_ZERO; hipsparseAction_t action = HIPSPARSE_ACTION_NUMERIC; hipsparseHybPartition_t part = HIPSPARSE_HYB_PARTITION_AUTO; hipsparseDiagType_t diag_type = HIPSPARSE_DIAG_TYPE_NON_UNIT; hipsparseFillMode_t fill_mode = HIPSPARSE_FILL_MODE_LOWER; hipsparseDirection_t dirA = HIPSPARSE_DIRECTION_ROW; int norm_check = 0; int unit_check = 1; int timing = 0; int iters = 10; int laplacian = 0; int ell_width = 0; int temp = 0; int numericboost{}; double boosttol{}; double boostval{}; double boostvali{}; std::string filename = ""; Arguments& operator=(const Arguments& rhs) { this->M = rhs.M; this->N = rhs.N; this->K = rhs.K; this->nnz = rhs.nnz; this->block_dim = rhs.block_dim; this->row_block_dimA = rhs.row_block_dimA; this->row_block_dimB = rhs.row_block_dimB; this->col_block_dimA = rhs.col_block_dimA; this->col_block_dimB = rhs.col_block_dimB; this->lda = rhs.lda; this->ldb = rhs.ldb; this->ldc = rhs.ldc; this->alpha = rhs.alpha; this->alphai = rhs.alphai; this->beta = rhs.beta; this->betai = rhs.betai; this->threshold = rhs.threshold; this->percentage = rhs.percentage; this->transA = rhs.transA; this->transB = rhs.transB; this->idx_base = rhs.idx_base; this->idx_base2 = rhs.idx_base2; this->idx_base3 = rhs.idx_base3; this->idx_base4 = rhs.idx_base4; this->action = rhs.action; this->part = rhs.part; this->diag_type = rhs.diag_type; this->fill_mode = rhs.fill_mode; this->dirA = rhs.dirA; this->norm_check = rhs.norm_check; this->unit_check = rhs.unit_check; this->timing = rhs.timing; this->iters = rhs.iters; this->laplacian = rhs.laplacian; this->ell_width = rhs.ell_width; this->temp = rhs.temp; this->numericboost = rhs.numericboost; this->boosttol = rhs.boosttol; this->boostval = rhs.boostval; this->boostvali = rhs.boostvali; this->filename = rhs.filename; return *this; } }; const char* get_hipsparse_clients_matrices_dir(); inline std::string get_filename(const std::string& bin_file) { const char* matrices_dir = get_hipsparse_clients_matrices_dir(); if(matrices_dir == nullptr) { matrices_dir = getenv("HIPSPARSE_CLIENTS_MATRICES_DIR"); } if(matrices_dir != nullptr) { return std::string(matrices_dir) + "/" + bin_file; } else { return hipsparse_exepath() + "../matrices/" + bin_file; } } #endif // TESTING_UTILITY_HPP hipSPARSE-rocm-5.7.1/clients/samples/000077500000000000000000000000001447644345400173045ustar00rootroot00000000000000hipSPARSE-rocm-5.7.1/clients/samples/CMakeLists.txt000066400000000000000000000065661447644345400220610ustar00rootroot00000000000000# ######################################################################## # 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. # # ######################################################################## set(HIPSPARSE_CLIENTS_COMMON ../common/utility.cpp) # Function to add hipsparse examples function(add_hipsparse_example EXAMPLE_SOURCE) get_filename_component(EXAMPLE_TARGET ${EXAMPLE_SOURCE} NAME_WE) add_executable(${EXAMPLE_TARGET} ${EXAMPLE_SOURCE} ${HIPSPARSE_CLIENTS_COMMON}) get_filename_component(EXAMPLE_EXTENSION ${EXAMPLE_SOURCE} LAST_EXT) if("${EXAMPLE_EXTENSION}" STREQUAL ".f90") add_dependencies(${EXAMPLE_TARGET} hipsparse_fortran) endif() # Include common client headers target_include_directories(${EXAMPLE_TARGET} PRIVATE $) # Linker dependencies target_link_libraries(${EXAMPLE_TARGET} PRIVATE roc::hipsparse) if(NOT USE_CUDA) target_link_libraries(${EXAMPLE_TARGET} PRIVATE hip::host) else() target_compile_definitions(${EXAMPLE_TARGET} PRIVATE __HIP_PLATFORM_NVIDIA__) target_include_directories(${EXAMPLE_TARGET} PRIVATE ${HIP_INCLUDE_DIRS}) target_link_libraries(${EXAMPLE_TARGET} PRIVATE ${CUDA_LIBRARIES}) endif() set_target_properties(${EXAMPLE_TARGET} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/staging") endfunction() # Examples add_hipsparse_example(example_handle.cpp) if(NOT USE_CUDA OR (USE_CUDA AND CUDA_VERSION LESS 11)) add_hipsparse_example(example_csrmv.cpp) add_hipsparse_example(example_hybmv.cpp) endif() if (NOT WIN32) # Fortran examples if(TARGET hipsparse AND NOT USE_CUDA) # Compile Fortran examples only if built directly with package # else the Fortran module file is not generated add_hipsparse_example(example_fortran_auxiliary.f90) add_hipsparse_example(example_fortran_csrsv2.f90) add_hipsparse_example(example_fortran_bsric02.f90) add_hipsparse_example(example_fortran_csric02.f90) add_hipsparse_example(example_fortran_bsrilu02.f90) add_hipsparse_example(example_fortran_csrilu02.f90) add_hipsparse_example(example_fortran_csrsm2.f90) add_hipsparse_example(example_fortran_dotci.f90) add_hipsparse_example(example_fortran_roti.f90) add_hipsparse_example(example_fortran_spmv.f90) add_hipsparse_example(example_fortran_bsrmm.f90) endif() endif() hipSPARSE-rocm-5.7.1/clients/samples/example_csrmv.cpp000066400000000000000000000126521447644345400226630ustar00rootroot00000000000000/* ************************************************************************ * 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 "utility.hpp" #include #include #include #include #include int main(int argc, char* argv[]) { // Parse command line if(argc < 2) { fprintf(stderr, "%s [ ]\n", argv[0]); return -1; } int ndim = atoi(argv[1]); int trials = 200; int batch_size = 1; if(argc > 2) { trials = atoi(argv[2]); } if(argc > 3) { batch_size = atoi(argv[3]); } // hipSPARSE handle hipsparseHandle_t handle; hipsparseCreate(&handle); hipDeviceProp_t devProp; int device_id = 0; hipGetDevice(&device_id); hipGetDeviceProperties(&devProp, device_id); printf("Device: %s\n", devProp.name); // Generate problem std::vector hAptr; std::vector hAcol; std::vector hAval; int m = gen_2d_laplacian(ndim, hAptr, hAcol, hAval, HIPSPARSE_INDEX_BASE_ZERO); int n = m; int nnz = hAptr[m]; // Sample some random data srand(12345ULL); double halpha = static_cast(rand()) / RAND_MAX; double hbeta = 0.0; std::vector hx(n); hipsparseInit(hx, 1, n); // Matrix descriptor hipsparseMatDescr_t descrA; hipsparseCreateMatDescr(&descrA); // Offload data to device int* dAptr = NULL; int* dAcol = NULL; double* dAval = NULL; double* dx = NULL; double* dy = NULL; hipMalloc((void**)&dAptr, sizeof(int) * (m + 1)); hipMalloc((void**)&dAcol, sizeof(int) * nnz); hipMalloc((void**)&dAval, sizeof(double) * nnz); hipMalloc((void**)&dx, sizeof(double) * n); hipMalloc((void**)&dy, sizeof(double) * m); hipMemcpy(dAptr, hAptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice); hipMemcpy(dAcol, hAcol.data(), sizeof(int) * nnz, hipMemcpyHostToDevice); hipMemcpy(dAval, hAval.data(), sizeof(double) * nnz, hipMemcpyHostToDevice); hipMemcpy(dx, hx.data(), sizeof(double) * n, hipMemcpyHostToDevice); // Warm up for(int i = 0; i < 10; ++i) { // Call hipsparse csrmv hipsparseDcsrmv(handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, m, n, nnz, &halpha, descrA, dAval, dAptr, dAcol, dx, &hbeta, dy); } // Device synchronization hipDeviceSynchronize(); // Start time measurement double time = get_time_us(); // CSR matrix vector multiplication for(int i = 0; i < trials; ++i) { for(int j = 0; j < batch_size; ++j) { // Call hipsparse csrmv hipsparseDcsrmv(handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, m, n, nnz, &halpha, descrA, dAval, dAptr, dAcol, dx, &hbeta, dy); } // Device synchronization hipDeviceSynchronize(); } time = (get_time_us() - time) / (trials * batch_size * 1e3); double bandwidth = static_cast(sizeof(double) * (2 * m + nnz) + sizeof(int) * (m + 1 + nnz)) / time / 1e6; double gflops = static_cast(2 * nnz) / time / 1e6; printf("m\t\tn\t\tnnz\t\talpha\tbeta\tGFlops\tGB/s\tusec\n"); printf("%8d\t%8d\t%9d\t%0.2lf\t%0.2lf\t%0.2lf\t%0.2lf\t%0.2lf\n", m, n, nnz, halpha, hbeta, gflops, bandwidth, time); // Clear up on device hipFree(dAptr); hipFree(dAcol); hipFree(dAval); hipFree(dx); hipFree(dy); hipsparseDestroyMatDescr(descrA); hipsparseDestroy(handle); return 0; } hipSPARSE-rocm-5.7.1/clients/samples/example_fortran_auxiliary.f90000066400000000000000000000134631447644345400251100ustar00rootroot00000000000000!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! 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. ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! subroutine HIPSPARSE_CHECK(stat) use iso_c_binding implicit none integer(c_int) :: stat if(stat /= 0) then write(*,*) 'Error: hipsparse error' stop end if end subroutine HIPSPARSE_CHECK subroutine COMPARE_EQUAL(a, b) use iso_c_binding implicit none integer(c_int) :: a integer(c_int) :: b if(a /= b) then write(*,*) 'Error: hipsparse_error' stop end if end subroutine COMPARE_EQUAL program example_fortran_auxiliary use iso_c_binding use hipsparse implicit none type(c_ptr) :: handle type(c_ptr) :: descr_A type(c_ptr) :: descr_B integer :: version integer :: pointer_mode integer :: index_base integer :: mat_type integer :: fill_mode integer :: diag_type ! Create hipSPARSE handle call HIPSPARSE_CHECK(hipsparseCreate(handle)) ! Get hipSPARSE version call HIPSPARSE_CHECK(hipsparseGetVersion(handle, version)) ! Print version on screen write(*,fmt='(A,I0,A,I0,A,I0)') 'hipSPARSE version: ', version / 100000, '.', & mod(version / 100, 1000), '.', mod(version, 100) ! Pointer mode call HIPSPARSE_CHECK(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)) call HIPSPARSE_CHECK(hipsparseGetPointerMode(handle, pointer_mode)) call COMPARE_EQUAL(pointer_mode, HIPSPARSE_POINTER_MODE_HOST); call HIPSPARSE_CHECK(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)) call HIPSPARSE_CHECK(hipsparseGetPointerMode(handle, pointer_mode)) call COMPARE_EQUAL(pointer_mode, HIPSPARSE_POINTER_MODE_DEVICE); ! Matrix descriptor ! Create matrix descriptors call HIPSPARSE_CHECK(hipsparseCreateMatDescr(descr_A)) call HIPSPARSE_CHECK(hipsparseCreateMatDescr(descr_B)) ! Index base call HIPSPARSE_CHECK(hipsparseSetMatIndexBase(descr_A, HIPSPARSE_INDEX_BASE_ZERO)) index_base = hipsparseGetMatIndexBase(descr_A) call COMPARE_EQUAL(index_base, HIPSPARSE_INDEX_BASE_ZERO); call HIPSPARSE_CHECK(hipsparseSetMatIndexBase(descr_A, HIPSPARSE_INDEX_BASE_ONE)) index_base = hipsparseGetMatIndexBase(descr_A) call COMPARE_EQUAL(index_base, HIPSPARSE_INDEX_BASE_ONE); ! Matrix type call HIPSPARSE_CHECK(hipsparseSetMatType(descr_A, HIPSPARSE_MATRIX_TYPE_GENERAL)) mat_type = hipsparseGetMatType(descr_A) call COMPARE_EQUAL(mat_type, HIPSPARSE_MATRIX_TYPE_GENERAL); call HIPSPARSE_CHECK(hipsparseSetMatType(descr_A, HIPSPARSE_MATRIX_TYPE_SYMMETRIC)) mat_type = hipsparseGetMatType(descr_A) call COMPARE_EQUAL(mat_type, HIPSPARSE_MATRIX_TYPE_SYMMETRIC); call HIPSPARSE_CHECK(hipsparseSetMatType(descr_A, HIPSPARSE_MATRIX_TYPE_HERMITIAN)) mat_type = hipsparseGetMatType(descr_A) call COMPARE_EQUAL(mat_type, HIPSPARSE_MATRIX_TYPE_HERMITIAN); call HIPSPARSE_CHECK(hipsparseSetMatType(descr_A, HIPSPARSE_MATRIX_TYPE_TRIANGULAR)) mat_type = hipsparseGetMatType(descr_A) call COMPARE_EQUAL(mat_type, HIPSPARSE_MATRIX_TYPE_TRIANGULAR); ! Fill mode call HIPSPARSE_CHECK(hipsparseSetMatFillMode(descr_A, HIPSPARSE_FILL_MODE_LOWER)) fill_mode = hipsparseGetMatFillMode(descr_A) call COMPARE_EQUAL(fill_mode, HIPSPARSE_FILL_MODE_LOWER); call HIPSPARSE_CHECK(hipsparseSetMatFillMode(descr_A, HIPSPARSE_FILL_MODE_UPPER)) fill_mode = hipsparseGetMatFillMode(descr_A) call COMPARE_EQUAL(fill_mode, HIPSPARSE_FILL_MODE_UPPER); ! Diag type call HIPSPARSE_CHECK(hipsparseSetMatDiagType(descr_A, HIPSPARSE_DIAG_TYPE_NON_UNIT)) diag_type = hipsparseGetMatDiagType(descr_A) call COMPARE_EQUAL(diag_type, HIPSPARSE_DIAG_TYPE_NON_UNIT); call HIPSPARSE_CHECK(hipsparseSetMatDiagType(descr_A, HIPSPARSE_DIAG_TYPE_UNIT)) diag_type = hipsparseGetMatDiagType(descr_A) call COMPARE_EQUAL(diag_type, HIPSPARSE_DIAG_TYPE_UNIT); ! Copy matrix descriptor call HIPSPARSE_CHECK(hipsparseCopyMatDescr(descr_B, descr_A)) index_base = hipsparseGetMatIndexBase(descr_B) mat_type = hipsparseGetMatType(descr_B) fill_mode = hipsparseGetMatFillMode(descr_B) diag_type = hipsparseGetMatDiagType(descr_B) call COMPARE_EQUAL(index_base, HIPSPARSE_INDEX_BASE_ONE); call COMPARE_EQUAL(mat_type, HIPSPARSE_MATRIX_TYPE_TRIANGULAR); call COMPARE_EQUAL(fill_mode, HIPSPARSE_FILL_MODE_UPPER); call COMPARE_EQUAL(diag_type, HIPSPARSE_DIAG_TYPE_UNIT); ! Clear hipSPARSE call HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descr_A)) call HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descr_B)) call HIPSPARSE_CHECK(hipsparseDestroy(handle)) write(*,fmt='(A)') 'All tests passed.' end program example_fortran_auxiliary hipSPARSE-rocm-5.7.1/clients/samples/example_fortran_bsric02.f90000066400000000000000000000242171447644345400243440ustar00rootroot00000000000000!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! 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. ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! subroutine HIP_CHECK(stat) use iso_c_binding implicit none integer(c_int) :: stat if(stat /= 0) then write(*,*) 'Error: hip error' stop end if end subroutine HIP_CHECK subroutine HIPSPARSE_CHECK(stat) use iso_c_binding implicit none integer(c_int) :: stat if(stat /= 0) then write(*,*) 'Error: hipsparse error' stop end if end subroutine HIPSPARSE_CHECK program example_fortran_bsric0 use iso_c_binding use hipsparse implicit none interface function hipMalloc(ptr, size) & bind(c, name = 'hipMalloc') use iso_c_binding implicit none integer :: hipMalloc type(c_ptr) :: ptr integer(c_size_t), value :: size end function hipMalloc function hipFree(ptr) & bind(c, name = 'hipFree') use iso_c_binding implicit none integer :: hipFree type(c_ptr), value :: ptr end function hipFree function hipMemcpy(dst, src, size, kind) & bind(c, name = 'hipMemcpy') use iso_c_binding implicit none integer :: hipMemcpy type(c_ptr), value :: dst type(c_ptr), intent(in), value :: src integer(c_size_t), value :: size integer(c_int), value :: kind end function hipMemcpy function hipMemset(dst, val, size) & bind(c, name = 'hipMemset') use iso_c_binding implicit none integer :: hipMemset type(c_ptr), value :: dst integer(c_int), value :: val integer(c_size_t), value :: size end function hipMemset function hipDeviceSynchronize() & bind(c, name = 'hipDeviceSynchronize') use iso_c_binding implicit none integer :: hipDeviceSynchronize end function hipDeviceSynchronize function hipDeviceReset() & bind(c, name = 'hipDeviceReset') use iso_c_binding implicit none integer :: hipDeviceReset end function hipDeviceReset end interface integer, target :: h_bsr_row_ptr(4), h_bsr_col_ind(9) real(8), target :: h_bsr_val(36) type(c_ptr) :: d_bsr_row_ptr type(c_ptr) :: d_bsr_col_ind type(c_ptr) :: d_bsr_val type(c_ptr) :: temp_buffer integer :: i, j, k, s, t integer(c_int) :: Mb, Nb, nnzb, block_dim integer(c_int) :: dir integer(c_int) :: stat integer(c_int), target :: pivot integer(c_size_t), target :: buffer_size type(c_ptr) :: handle type(c_ptr) :: descr type(c_ptr) :: info integer :: version character(len=12) :: rev ! Input data ! ( 3 0 -1 -1 0 -1 ) ! ( 0 2 0 -1 0 0 ) ! ( -1 0 3 0 -1 0 ) ! A = ( -1 -1 0 2 0 -1 ) ! ( 0 0 -1 0 3 -1 ) ! ( -1 0 0 -1 -1 4 ) ! Number of rows and columns Mb = 3 Nb = 3 ! Number of non-zero entries nnzb = 9 ! BSR block dimension block_dim = 2 ! BSR block direction dir = 0 ! Fill BSR structure h_bsr_row_ptr = (/0, 3, 6, 9/) h_bsr_col_ind = (/0, 1, 2, 0, 1, 2, 0, 1, 2/) h_bsr_val = (/3, 0, 0, 2, -1, -1, 0, -1, 0, -1, 0, 0, & -1, 0, -1, -1, 3, 0, 0, 2, -1, 0, 0, -1, & 0, 0, -1, 0, -1, 0, 0, -1, 3, -1, -1, 4/) ! Allocate device memory call HIP_CHECK(hipMalloc(d_bsr_row_ptr, (int(Mb, c_size_t) + 1) * 4)) call HIP_CHECK(hipMalloc(d_bsr_col_ind, int(nnzb, c_size_t) * 4)) call HIP_CHECK(hipMalloc(d_bsr_val, int(nnzb * block_dim * block_dim, c_size_t) * 8)) ! Copy host data to device call HIP_CHECK(hipMemcpy(d_bsr_row_ptr, c_loc(h_bsr_row_ptr), (int(Mb, c_size_t) + 1) * 4, 1)) call HIP_CHECK(hipMemcpy(d_bsr_col_ind, c_loc(h_bsr_col_ind), int(nnzb, c_size_t) * 4, 1)) call HIP_CHECK(hipMemcpy(d_bsr_val, c_loc(h_bsr_val), int(nnzb * block_dim * block_dim, c_size_t) * 8, 1)) ! Create hipSPARSE handle call HIPSPARSE_CHECK(hipsparseCreate(handle)) ! Get hipSPARSE version call HIPSPARSE_CHECK(hipsparseGetVersion(handle, version)) ! Print version on screen write(*,fmt='(A,I0,A,I0,A,I0)') 'hipSPARSE version: ', version / 100000, '.', & mod(version / 100, 1000), '.', mod(version, 100) ! Create matrix descriptor call HIPSPARSE_CHECK(hipsparseCreateMatDescr(descr)) ! Matrix fill mode call HIPSPARSE_CHECK(hipsparseSetMatFillMode(descr, HIPSPARSE_FILL_MODE_LOWER)) ! Create matrix info structure call HIPSPARSE_CHECK(hipsparseCreateBsric02Info(info)) ! Obtain required buffer size call HIPSPARSE_CHECK(hipsparseDbsric02_bufferSize(handle, & dir, & Mb, & nnzb, & descr, & d_bsr_val, & d_bsr_row_ptr, & d_bsr_col_ind, & block_dim, & info, & c_loc(buffer_size))) ! Allocate temporary buffer write(*,fmt='(A,I0,A)') 'Allocating ', buffer_size / 1024, 'kB temporary storage buffer' call HIP_CHECK(hipMalloc(temp_buffer, buffer_size)) ! Perform analysis step call HIPSPARSE_CHECK(hipsparseDbsric02_analysis(handle, & dir, & Mb, & nnzb, & descr, & d_bsr_val, & d_bsr_row_ptr, & d_bsr_col_ind, & block_dim, & info, & HIPSPARSE_SOLVE_POLICY_USE_LEVEL, & temp_buffer)) ! Call dbsric0 to perform incomplete Cholesky factorization call HIPSPARSE_CHECK(hipsparseDbsric02(handle, & dir, & Mb, & nnzb, & descr, & d_bsr_val, & d_bsr_row_ptr, & d_bsr_col_ind, & block_dim, & info, & HIPSPARSE_SOLVE_POLICY_USE_LEVEL, & temp_buffer)) ! Check for zero pivots stat = hipsparseXbsric02_zeroPivot(handle, info, c_loc(pivot)) if(stat .eq. HIPSPARSE_STATUS_ZERO_PIVOT) then write(*,fmt='(A,I0)') 'Found zero pivot in matrix row ', pivot end if ! Print result call HIP_CHECK(hipMemcpy(c_loc(h_bsr_val), d_bsr_val, int(nnzb * block_dim * block_dim, c_size_t) * 8, 2)) write(*,fmt='(A)') "Incomplete Cholesky factorization:" do i = 1, Mb do s = 1, block_dim k = h_bsr_row_ptr(i) + 1 do j = 1, i if(j .eq. h_bsr_col_ind(k) + 1) then do t = 1, block_dim if(dir .eq. 0) then write(*,fmt='(A,F6.2)',advance='no') ' ', h_bsr_val(block_dim * block_dim * (k - 1) + & block_dim * (s - 1) + t) else write(*,fmt='(A,F6.2)',advance='no') ' ', h_bsr_val(block_dim * block_dim * (k - 1) + & block_dim * (t - 1) + s) end if end do k = k + 1 else do t = 1, block_dim write(*,fmt='(A,F6.2)',advance='no') ' ', 0.0 end do end if end do write(*,*) end do end do ! Clear hipSPARSE call HIPSPARSE_CHECK(hipsparseDestroyBsric02Info(info)) call HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descr)) call HIPSPARSE_CHECK(hipsparseDestroy(handle)) ! Clear device memory call HIP_CHECK(hipFree(d_bsr_row_ptr)) call HIP_CHECK(hipFree(d_bsr_col_ind)) call HIP_CHECK(hipFree(d_bsr_val)) call HIP_CHECK(hipFree(temp_buffer)) end program example_fortran_bsric0 hipSPARSE-rocm-5.7.1/clients/samples/example_fortran_bsrilu02.f90000066400000000000000000000242421447644345400245400ustar00rootroot00000000000000!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! 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. ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! subroutine HIP_CHECK(stat) use iso_c_binding implicit none integer(c_int) :: stat if(stat /= 0) then write(*,*) 'Error: hip error' stop end if end subroutine HIP_CHECK subroutine HIPSPARSE_CHECK(stat) use iso_c_binding implicit none integer(c_int) :: stat if(stat /= 0) then write(*,*) 'Error: hipsparse error' stop end if end subroutine HIPSPARSE_CHECK program example_fortran_bsrilu0 use iso_c_binding use hipsparse implicit none interface function hipMalloc(ptr, size) & bind(c, name = 'hipMalloc') use iso_c_binding implicit none integer :: hipMalloc type(c_ptr) :: ptr integer(c_size_t), value :: size end function hipMalloc function hipFree(ptr) & bind(c, name = 'hipFree') use iso_c_binding implicit none integer :: hipFree type(c_ptr), value :: ptr end function hipFree function hipMemcpy(dst, src, size, kind) & bind(c, name = 'hipMemcpy') use iso_c_binding implicit none integer :: hipMemcpy type(c_ptr), value :: dst type(c_ptr), intent(in), value :: src integer(c_size_t), value :: size integer(c_int), value :: kind end function hipMemcpy function hipMemset(dst, val, size) & bind(c, name = 'hipMemset') use iso_c_binding implicit none integer :: hipMemset type(c_ptr), value :: dst integer(c_int), value :: val integer(c_size_t), value :: size end function hipMemset function hipDeviceSynchronize() & bind(c, name = 'hipDeviceSynchronize') use iso_c_binding implicit none integer :: hipDeviceSynchronize end function hipDeviceSynchronize function hipDeviceReset() & bind(c, name = 'hipDeviceReset') use iso_c_binding implicit none integer :: hipDeviceReset end function hipDeviceReset end interface integer, target :: h_bsr_row_ptr(4), h_bsr_col_ind(9) real(8), target :: h_bsr_val(36) type(c_ptr) :: d_bsr_row_ptr type(c_ptr) :: d_bsr_col_ind type(c_ptr) :: d_bsr_val type(c_ptr) :: temp_buffer integer :: i, j, k, s, t integer(c_int) :: Mb, Nb, nnzb, block_dim integer(c_int) :: dir integer(c_int) :: stat integer(c_int), target :: pivot integer(c_size_t), target :: buffer_size type(c_ptr) :: handle type(c_ptr) :: descr type(c_ptr) :: info integer :: version character(len=12) :: rev ! Input data ! ( 3 0 -1 -1 0 -1 ) ! ( 0 2 0 -1 0 0 ) ! ( -1 0 3 0 -1 0 ) ! A = ( -1 -1 0 2 0 -1 ) ! ( 0 0 -1 0 3 -1 ) ! ( -1 0 0 -1 -1 4 ) ! Number of rows and columns Mb = 3 Nb = 3 ! Number of non-zero entries nnzb = 9 ! BSR block dimension block_dim = 2 ! BSR block direction dir = 0 ! Fill BSR structure h_bsr_row_ptr = (/0, 3, 6, 9/) h_bsr_col_ind = (/0, 1, 2, 0, 1, 2, 0, 1, 2/) h_bsr_val = (/3, 0, 0, 2, -1, -1, 0, -1, 0, -1, 0, 0, & -1, 0, -1, -1, 3, 0, 0, 2, -1, 0, 0, -1, & 0, 0, -1, 0, -1, 0, 0, -1, 3, -1, -1, 4/) ! Allocate device memory call HIP_CHECK(hipMalloc(d_bsr_row_ptr, (int(Mb, c_size_t) + 1) * 4)) call HIP_CHECK(hipMalloc(d_bsr_col_ind, int(nnzb, c_size_t) * 4)) call HIP_CHECK(hipMalloc(d_bsr_val, int(nnzb * block_dim * block_dim, c_size_t) * 8)) ! Copy host data to device call HIP_CHECK(hipMemcpy(d_bsr_row_ptr, c_loc(h_bsr_row_ptr), (int(Mb, c_size_t) + 1) * 4, 1)) call HIP_CHECK(hipMemcpy(d_bsr_col_ind, c_loc(h_bsr_col_ind), int(nnzb, c_size_t) * 4, 1)) call HIP_CHECK(hipMemcpy(d_bsr_val, c_loc(h_bsr_val), int(nnzb * block_dim * block_dim, c_size_t) * 8, 1)) ! Create hipSPARSE handle call HIPSPARSE_CHECK(hipsparseCreate(handle)) ! Get hipSPARSE version call HIPSPARSE_CHECK(hipsparseGetVersion(handle, version)) ! Print version on screen write(*,fmt='(A,I0,A,I0,A,I0)') 'hipSPARSE version: ', version / 100000, '.', & mod(version / 100, 1000), '.', mod(version, 100) ! Create matrix descriptor call HIPSPARSE_CHECK(hipsparseCreateMatDescr(descr)) ! Matrix fill mode call HIPSPARSE_CHECK(hipsparseSetMatFillMode(descr, HIPSPARSE_FILL_MODE_LOWER)) ! Create matrix info structure call HIPSPARSE_CHECK(hipsparseCreateBsrilu02Info(info)) ! Obtain required buffer size call HIPSPARSE_CHECK(hipsparseDbsrilu02_bufferSize(handle, & dir, & Mb, & nnzb, & descr, & d_bsr_val, & d_bsr_row_ptr, & d_bsr_col_ind, & block_dim, & info, & c_loc(buffer_size))) ! Allocate temporary buffer write(*,fmt='(A,I0,A)') 'Allocating ', buffer_size / 1024, 'kB temporary storage buffer' call HIP_CHECK(hipMalloc(temp_buffer, buffer_size)) ! Perform analysis step call HIPSPARSE_CHECK(hipsparseDbsrilu02_analysis(handle, & dir, & Mb, & nnzb, & descr, & d_bsr_val, & d_bsr_row_ptr, & d_bsr_col_ind, & block_dim, & info, & HIPSPARSE_SOLVE_POLICY_USE_LEVEL, & temp_buffer)) ! Call dbsrilu0 to perform incomplete LU factorization call HIPSPARSE_CHECK(hipsparseDbsrilu02(handle, & dir, & Mb, & nnzb, & descr, & d_bsr_val, & d_bsr_row_ptr, & d_bsr_col_ind, & block_dim, & info, & HIPSPARSE_SOLVE_POLICY_USE_LEVEL, & temp_buffer)) ! Check for zero pivots stat = hipsparseXbsrilu02_zeroPivot(handle, info, c_loc(pivot)) if(stat .eq. HIPSPARSE_STATUS_ZERO_PIVOT) then write(*,fmt='(A,I0)') 'Found zero pivot in matrix row ', pivot end if ! Print result call HIP_CHECK(hipMemcpy(c_loc(h_bsr_val), d_bsr_val, int(nnzb * block_dim * block_dim, c_size_t) * 8, 2)) write(*,fmt='(A)') "Incomplete LU factorization:" do i = 1, Mb do s = 1, block_dim k = h_bsr_row_ptr(i) + 1 do j = 1, i if(j .eq. h_bsr_col_ind(k) + 1) then do t = 1, block_dim if(dir .eq. 0) then write(*,fmt='(A,F6.2)',advance='no') ' ', h_bsr_val(block_dim * block_dim * (k - 1) + & block_dim * (s - 1) + t) else write(*,fmt='(A,F6.2)',advance='no') ' ', h_bsr_val(block_dim * block_dim * (k - 1) + & block_dim * (t - 1) + s) end if end do k = k + 1 else do t = 1, block_dim write(*,fmt='(A,F6.2)',advance='no') ' ', 0.0 end do end if end do write(*,*) end do end do ! Clear hipSPARSE call HIPSPARSE_CHECK(hipsparseDestroyBsrilu02Info(info)) call HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descr)) call HIPSPARSE_CHECK(hipsparseDestroy(handle)) ! Clear device memory call HIP_CHECK(hipFree(d_bsr_row_ptr)) call HIP_CHECK(hipFree(d_bsr_col_ind)) call HIP_CHECK(hipFree(d_bsr_val)) call HIP_CHECK(hipFree(temp_buffer)) end program example_fortran_bsrilu0 hipSPARSE-rocm-5.7.1/clients/samples/example_fortran_bsrmm.f90000066400000000000000000000205351447644345400242170ustar00rootroot00000000000000!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! 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. ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! subroutine HIP_CHECK(stat) use iso_c_binding implicit none integer(c_int) :: stat if(stat /= 0) then write(*,*) 'Error: hip error' stop end if end subroutine HIP_CHECK subroutine HIPSPARSE_CHECK(stat) use iso_c_binding implicit none integer(c_int) :: stat if(stat /= 0) then write(*,*) 'Error: hipsparse error' stop end if end subroutine HIPSPARSE_CHECK program example_fortran_bsrmm use iso_c_binding use hipsparse implicit none interface function hipMalloc(ptr, size) & bind(c, name = 'hipMalloc') use iso_c_binding implicit none integer :: hipMalloc type(c_ptr) :: ptr integer(c_size_t), value :: size end function hipMalloc function hipFree(ptr) & bind(c, name = 'hipFree') use iso_c_binding implicit none integer :: hipFree type(c_ptr), value :: ptr end function hipFree function hipMemcpy(dst, src, size, kind) & bind(c, name = 'hipMemcpy') use iso_c_binding implicit none integer :: hipMemcpy type(c_ptr), value :: dst type(c_ptr), intent(in), value :: src integer(c_size_t), value :: size integer(c_int), value :: kind end function hipMemcpy function hipMemset(dst, val, size) & bind(c, name = 'hipMemset') use iso_c_binding implicit none integer :: hipMemset type(c_ptr), value :: dst integer(c_int), value :: val integer(c_size_t), value :: size end function hipMemset function hipDeviceSynchronize() & bind(c, name = 'hipDeviceSynchronize') use iso_c_binding implicit none integer :: hipDeviceSynchronize end function hipDeviceSynchronize function hipDeviceReset() & bind(c, name = 'hipDeviceReset') use iso_c_binding implicit none integer :: hipDeviceReset end function hipDeviceReset end interface integer, target :: h_bsr_row_ptr(3), h_bsr_col_ind(4) real(8), target :: h_bsr_val(16), h_B(6 * 10), h_C(4 * 10) type(c_ptr) :: d_bsr_row_ptr type(c_ptr) :: d_bsr_col_ind type(c_ptr) :: d_bsr_val type(c_ptr) :: d_B type(c_ptr) :: d_C integer :: i, j integer(c_int) :: M, Mb, N, K, Kb, nnzb, block_dim real(c_double), target :: alpha, beta type(c_ptr) :: handle type(c_ptr) :: descr integer :: version character(len=12) :: rev ! Input data ! ( 1 2 0 3 0 0 ) ! A = ( 0 4 5 0 0 0 ) ! ( 0 0 0 7 8 0 ) ! ( 0 0 1 2 4 1 ) ! ( 9 11 13 15 17 10 12 14 16 18 ) ! ( 8 10 1 10 6 11 7 3 12 17 ) ! B = ( 11 11 0 4 6 12 2 9 13 2 ) ! ( 15 3 2 3 8 1 2 4 6 6 ) ! ( 2 5 7 0 1 15 9 4 10 1 ) ! ( 7 12 12 1 12 5 1 11 1 14 ) ! Number of rows and columns block_dim = 2 Mb = 2 Kb = 3 N = 10 M = Mb * block_dim K = Kb * block_dim ! Number of non-zero blocks nnzb = 4 ! Fill BSR structure h_bsr_row_ptr = (/0, 2, 4/) h_bsr_col_ind = (/0, 1, 1, 2/) h_bsr_val = (/1, 2, 0, 4, 0, 3, 5, 0, 0, 7, 1, 2, 8, 0, 4, 1/) ! Scalar alpha and beta alpha = 1.0 beta = 0.0 ! Fill B in column-major h_B = (/9, 8, 11, 15, 2, 7, & 11, 10, 11, 3, 5, 12, & 13, 1, 0, 2, 7, 12, & 15, 10, 4, 3, 0, 1, & 17, 6, 6, 8, 1, 12, & 10, 11, 12, 1, 15, 5, & 12, 7, 2, 2, 9, 1, & 14, 3, 9, 4, 4, 11, & 16, 12, 13, 6, 10, 1, & 18, 17, 2, 6, 1, 14/) ! Fill C in column-major h_C = (/0, 0, 0, 0, & 0, 0, 0, 0, & 0, 0, 0, 0, & 0, 0, 0, 0, & 0, 0, 0, 0, & 0, 0, 0, 0, & 0, 0, 0, 0, & 0, 0, 0, 0, & 0, 0, 0, 0, & 0, 0, 0, 0/) ! Allocate device memory call HIP_CHECK(hipMalloc(d_bsr_row_ptr, (int(Mb, c_size_t) + 1) * 4)) call HIP_CHECK(hipMalloc(d_bsr_col_ind, int(nnzb, c_size_t) * 4)) call HIP_CHECK(hipMalloc(d_bsr_val, int(nnzb * block_dim * block_dim, c_size_t) * 8)) call HIP_CHECK(hipMalloc(d_B, int(K * N, c_size_t) * 8)) call HIP_CHECK(hipMalloc(d_C, int(M * N, c_size_t) * 8)) ! Copy host data to device call HIP_CHECK(hipMemcpy(d_bsr_row_ptr, c_loc(h_bsr_row_ptr), (int(Mb, c_size_t) + 1) * 4, 1)) call HIP_CHECK(hipMemcpy(d_bsr_col_ind, c_loc(h_bsr_col_ind), int(nnzb, c_size_t) * 4, 1)) call HIP_CHECK(hipMemcpy(d_bsr_val, c_loc(h_bsr_val), int(nnzb * block_dim * block_dim, c_size_t) * 8, 1)) call HIP_CHECK(hipMemcpy(d_B, c_loc(h_B), int(K * N, c_size_t) * 8, 1)) call HIP_CHECK(hipMemcpy(d_C, c_loc(h_C), int(M * N, c_size_t) * 8, 1)) ! Create hipSPARSE handle call HIPSPARSE_CHECK(hipsparseCreate(handle)) ! Get hipSPARSE version call HIPSPARSE_CHECK(hipsparseGetVersion(handle, version)) ! Print version on screen write(*,fmt='(A,I0,A,I0,A,I0)') 'hipSPARSE version: ', version / 100000, '.', & mod(version / 100, 1000), '.', mod(version, 100) ! Create matrix descriptor call HIPSPARSE_CHECK(hipsparseCreateMatDescr(descr)) ! Perform the matrix multiplication call HIPSPARSE_CHECK(hipsparseDbsrmm(handle, & HIPSPARSE_DIRECTION_ROW, & HIPSPARSE_OPERATION_NON_TRANSPOSE, & HIPSPARSE_OPERATION_NON_TRANSPOSE, & Mb, & N, & Kb, & nnzb, & c_loc(alpha), & descr, & d_bsr_val, & d_bsr_row_ptr, & d_bsr_col_ind, & block_dim, & d_B, & K, & c_loc(beta), & d_C, & M)) ! Print result call HIP_CHECK(hipMemcpy(c_loc(h_C), d_C, int(M * N, c_size_t) * 8, 2)) ! Note: C in column major ordering do i = 1, M do j = 1, N write(*,fmt='(A,F6.2)',advance='no') ' ', h_C(M * (j - 1) + i) end do write(*,*) end do ! Clear hipSPARSE call HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descr)) call HIPSPARSE_CHECK(hipsparseDestroy(handle)) ! Clear device memory call HIP_CHECK(hipFree(d_bsr_row_ptr)) call HIP_CHECK(hipFree(d_bsr_col_ind)) call HIP_CHECK(hipFree(d_bsr_val)) call HIP_CHECK(hipFree(d_B)) call HIP_CHECK(hipFree(d_C)) end program example_fortran_bsrmm hipSPARSE-rocm-5.7.1/clients/samples/example_fortran_csric02.f90000066400000000000000000000215401447644345400243410ustar00rootroot00000000000000!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! 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. ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! subroutine HIP_CHECK(stat) use iso_c_binding implicit none integer(c_int) :: stat if(stat /= 0) then write(*,*) 'Error: hip error' stop end if end subroutine HIP_CHECK subroutine HIPSPARSE_CHECK(stat) use iso_c_binding implicit none integer(c_int) :: stat if(stat /= 0) then write(*,*) 'Error: hipsparse error' stop end if end subroutine HIPSPARSE_CHECK program example_fortran_csric0 use iso_c_binding use hipsparse implicit none interface function hipMalloc(ptr, size) & bind(c, name = 'hipMalloc') use iso_c_binding implicit none integer :: hipMalloc type(c_ptr) :: ptr integer(c_size_t), value :: size end function hipMalloc function hipFree(ptr) & bind(c, name = 'hipFree') use iso_c_binding implicit none integer :: hipFree type(c_ptr), value :: ptr end function hipFree function hipMemcpy(dst, src, size, kind) & bind(c, name = 'hipMemcpy') use iso_c_binding implicit none integer :: hipMemcpy type(c_ptr), value :: dst type(c_ptr), intent(in), value :: src integer(c_size_t), value :: size integer(c_int), value :: kind end function hipMemcpy function hipMemset(dst, val, size) & bind(c, name = 'hipMemset') use iso_c_binding implicit none integer :: hipMemset type(c_ptr), value :: dst integer(c_int), value :: val integer(c_size_t), value :: size end function hipMemset function hipDeviceSynchronize() & bind(c, name = 'hipDeviceSynchronize') use iso_c_binding implicit none integer :: hipDeviceSynchronize end function hipDeviceSynchronize function hipDeviceReset() & bind(c, name = 'hipDeviceReset') use iso_c_binding implicit none integer :: hipDeviceReset end function hipDeviceReset end interface integer, target :: h_csr_row_ptr(7), h_csr_col_ind(20) real(8), target :: h_csr_val(20) type(c_ptr) :: d_csr_row_ptr type(c_ptr) :: d_csr_col_ind type(c_ptr) :: d_csr_val type(c_ptr) :: temp_buffer integer :: i, j, k integer(c_int) :: M, N, nnz integer(c_int) :: stat integer(c_int), target :: pivot integer(c_size_t), target :: buffer_size type(c_ptr) :: handle type(c_ptr) :: descr type(c_ptr) :: info integer :: version ! Input data ! ( 3 0 -1 -1 0 -1 ) ! ( 0 2 0 -1 0 0 ) ! ( -1 0 3 0 -1 0 ) ! A = ( -1 -1 0 2 0 -1 ) ! ( 0 0 -1 0 3 -1 ) ! ( -1 0 0 -1 -1 4 ) ! Number of rows and columns M = 6 N = 6 ! Number of non-zero entries nnz = 20 ! Fill CSR structure h_csr_row_ptr = (/0, 4, 6, 9, 13, 16, 20/) h_csr_col_ind = (/0, 2, 3, 5, 1, 3, 0, 2, 4, 0, 1, 3, 5, 2, 4, 5, 0, 3, 4, 5/) h_csr_val = (/3, -1, -1, -1, 2, -1, -1, 3, -1, -1, -1, 2, -1, -1, 3, -1, -1, -1, -1, 4/) ! Allocate device memory call HIP_CHECK(hipMalloc(d_csr_row_ptr, (int(M, c_size_t) + 1) * 4)) call HIP_CHECK(hipMalloc(d_csr_col_ind, int(nnz, c_size_t) * 4)) call HIP_CHECK(hipMalloc(d_csr_val, int(nnz, c_size_t) * 8)) ! Copy host data to device call HIP_CHECK(hipMemcpy(d_csr_row_ptr, c_loc(h_csr_row_ptr), (int(M, c_size_t) + 1) * 4, 1)) call HIP_CHECK(hipMemcpy(d_csr_col_ind, c_loc(h_csr_col_ind), int(nnz, c_size_t) * 4, 1)) call HIP_CHECK(hipMemcpy(d_csr_val, c_loc(h_csr_val), int(nnz, c_size_t) * 8, 1)) ! Create hipSPARSE handle call HIPSPARSE_CHECK(hipsparseCreate(handle)) ! Get hipSPARSE version call HIPSPARSE_CHECK(hipsparseGetVersion(handle, version)) ! Print version on screen write(*,fmt='(A,I0,A,I0,A,I0)') 'hipSPARSE version: ', version / 100000, '.', & mod(version / 100, 1000), '.', mod(version, 100) ! Create matrix descriptor call HIPSPARSE_CHECK(hipsparseCreateMatDescr(descr)) ! Matrix fill mode call HIPSPARSE_CHECK(hipsparseSetMatFillMode(descr, HIPSPARSE_FILL_MODE_LOWER)) ! Create matrix info structure call HIPSPARSE_CHECK(hipsparseCreateCsric02Info(info)) ! Obtain required buffer size call HIPSPARSE_CHECK(hipsparseDcsric02_bufferSizeExt(handle, & M, & nnz, & descr, & d_csr_val, & d_csr_row_ptr, & d_csr_col_ind, & info, & c_loc(buffer_size))) ! Allocate temporary buffer write(*,fmt='(A,I0,A)') 'Allocating ', buffer_size / 1024, 'kB temporary storage buffer' call HIP_CHECK(hipMalloc(temp_buffer, buffer_size)) ! Perform analysis step call HIPSPARSE_CHECK(hipsparseDcsric02_analysis(handle, & M, & nnz, & descr, & d_csr_val, & d_csr_row_ptr, & d_csr_col_ind, & info, & HIPSPARSE_SOLVE_POLICY_USE_LEVEL, & temp_buffer)) ! Call dcsric0 to perform incomplete Cholesky factorization call HIPSPARSE_CHECK(hipsparseDcsric02(handle, & M, & nnz, & descr, & d_csr_val, & d_csr_row_ptr, & d_csr_col_ind, & info, & HIPSPARSE_SOLVE_POLICY_USE_LEVEL, & temp_buffer)) ! Check for zero pivots stat = hipsparseXcsric02_zeroPivot(handle, info, c_loc(pivot)) if(stat .eq. HIPSPARSE_STATUS_ZERO_PIVOT) then write(*,fmt='(A,I0)') 'Found zero pivot in matrix row ', pivot end if ! Print result call HIP_CHECK(hipMemcpy(c_loc(h_csr_val), d_csr_val, int(nnz, c_size_t) * 8, 2)) write(*,fmt='(A)') "Incomplete Cholesky factorization:" do i = 1, M k = h_csr_row_ptr(i) + 1 do j = 1, i if(j .eq. h_csr_col_ind(k) + 1) then write(*,fmt='(A,F6.2)',advance='no') ' ', h_csr_val(k) k = k + 1 else write(*,fmt='(A,F6.2)',advance='no') ' ', 0.0 end if end do write(*,*) end do ! Clear hipSPARSE call HIPSPARSE_CHECK(hipsparseDestroyCsric02Info(info)) call HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descr)) call HIPSPARSE_CHECK(hipsparseDestroy(handle)) ! Clear device memory call HIP_CHECK(hipFree(d_csr_row_ptr)) call HIP_CHECK(hipFree(d_csr_col_ind)) call HIP_CHECK(hipFree(d_csr_val)) call HIP_CHECK(hipFree(temp_buffer)) end program example_fortran_csric0 hipSPARSE-rocm-5.7.1/clients/samples/example_fortran_csrilu02.f90000066400000000000000000000214151447644345400245400ustar00rootroot00000000000000!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! 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. ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! subroutine HIP_CHECK(stat) use iso_c_binding implicit none integer(c_int) :: stat if(stat /= 0) then write(*,*) 'Error: hip error' stop end if end subroutine HIP_CHECK subroutine HIPSPARSE_CHECK(stat) use iso_c_binding implicit none integer(c_int) :: stat if(stat /= 0) then write(*,*) 'Error: hipsparse error' stop end if end subroutine HIPSPARSE_CHECK program example_fortran_csrilu0 use iso_c_binding use hipsparse implicit none interface function hipMalloc(ptr, size) & bind(c, name = 'hipMalloc') use iso_c_binding implicit none integer :: hipMalloc type(c_ptr) :: ptr integer(c_size_t), value :: size end function hipMalloc function hipFree(ptr) & bind(c, name = 'hipFree') use iso_c_binding implicit none integer :: hipFree type(c_ptr), value :: ptr end function hipFree function hipMemcpy(dst, src, size, kind) & bind(c, name = 'hipMemcpy') use iso_c_binding implicit none integer :: hipMemcpy type(c_ptr), value :: dst type(c_ptr), intent(in), value :: src integer(c_size_t), value :: size integer(c_int), value :: kind end function hipMemcpy function hipMemset(dst, val, size) & bind(c, name = 'hipMemset') use iso_c_binding implicit none integer :: hipMemset type(c_ptr), value :: dst integer(c_int), value :: val integer(c_size_t), value :: size end function hipMemset function hipDeviceSynchronize() & bind(c, name = 'hipDeviceSynchronize') use iso_c_binding implicit none integer :: hipDeviceSynchronize end function hipDeviceSynchronize function hipDeviceReset() & bind(c, name = 'hipDeviceReset') use iso_c_binding implicit none integer :: hipDeviceReset end function hipDeviceReset end interface integer, target :: h_csr_row_ptr(7), h_csr_col_ind(20) real(8), target :: h_csr_val(20) type(c_ptr) :: d_csr_row_ptr type(c_ptr) :: d_csr_col_ind type(c_ptr) :: d_csr_val type(c_ptr) :: temp_buffer integer :: i, j, k integer(c_int) :: M, N, nnz integer(c_int) :: stat integer(c_int), target :: pivot integer(c_size_t), target :: buffer_size type(c_ptr) :: handle type(c_ptr) :: descr type(c_ptr) :: info integer :: version ! Input data ! ( 3 0 -1 -1 0 -1 ) ! ( 0 2 0 -1 0 0 ) ! ( -1 0 3 0 -1 0 ) ! A = ( -1 -1 0 2 0 -1 ) ! ( 0 0 -1 0 3 -1 ) ! ( -1 0 0 -1 -1 4 ) ! Number of rows and columns M = 6 N = 6 ! Number of non-zero entries nnz = 20 ! Fill CSR structure h_csr_row_ptr = (/0, 4, 6, 9, 13, 16, 20/) h_csr_col_ind = (/0, 2, 3, 5, 1, 3, 0, 2, 4, 0, 1, 3, 5, 2, 4, 5, 0, 3, 4, 5/) h_csr_val = (/3, -1, -1, -1, 2, -1, -1, 3, -1, -1, -1, 2, -1, -1, 3, -1, -1, -1, -1, 4/) ! Allocate device memory call HIP_CHECK(hipMalloc(d_csr_row_ptr, (int(M, c_size_t) + 1) * 4)) call HIP_CHECK(hipMalloc(d_csr_col_ind, int(nnz, c_size_t) * 4)) call HIP_CHECK(hipMalloc(d_csr_val, int(nnz, c_size_t) * 8)) ! Copy host data to device call HIP_CHECK(hipMemcpy(d_csr_row_ptr, c_loc(h_csr_row_ptr), (int(M, c_size_t) + 1) * 4, 1)) call HIP_CHECK(hipMemcpy(d_csr_col_ind, c_loc(h_csr_col_ind), int(nnz, c_size_t) * 4, 1)) call HIP_CHECK(hipMemcpy(d_csr_val, c_loc(h_csr_val), int(nnz, c_size_t) * 8, 1)) ! Create hipSPARSE handle call HIPSPARSE_CHECK(hipsparseCreate(handle)) ! Get hipSPARSE version call HIPSPARSE_CHECK(hipsparseGetVersion(handle, version)) ! Print version on screen write(*,fmt='(A,I0,A,I0,A,I0)') 'hipSPARSE version: ', version / 100000, '.', & mod(version / 100, 1000), '.', mod(version, 100) ! Create matrix descriptor call HIPSPARSE_CHECK(hipsparseCreateMatDescr(descr)) ! Create matrix info structure call HIPSPARSE_CHECK(hipsparseCreateCsrilu02Info(info)) ! Obtain required buffer size call HIPSPARSE_CHECK(hipsparseDcsrilu02_bufferSizeExt(handle, & M, & nnz, & descr, & d_csr_val, & d_csr_row_ptr, & d_csr_col_ind, & info, & c_loc(buffer_size))) ! Allocate temporary buffer write(*,fmt='(A,I0,A)') 'Allocating ', buffer_size / 1024, 'kB temporary storage buffer' call HIP_CHECK(hipMalloc(temp_buffer, buffer_size)) ! Perform analysis step call HIPSPARSE_CHECK(hipsparseDcsrilu02_analysis(handle, & M, & nnz, & descr, & d_csr_val, & d_csr_row_ptr, & d_csr_col_ind, & info, & HIPSPARSE_SOLVE_POLICY_USE_LEVEL, & temp_buffer)) ! Call dcsrilu0 to perform incomplete LU factorization call HIPSPARSE_CHECK(hipsparseDcsrilu02(handle, & M, & nnz, & descr, & d_csr_val, & d_csr_row_ptr, & d_csr_col_ind, & info, & HIPSPARSE_SOLVE_POLICY_USE_LEVEL, & temp_buffer)) ! Check for zero pivots stat = hipsparseXcsrilu02_zeroPivot(handle, info, c_loc(pivot)) if(stat .eq. HIPSPARSE_STATUS_ZERO_PIVOT) then write(*,fmt='(A,I0)') 'Found zero pivot in matrix row ', pivot end if ! Print result call HIP_CHECK(hipMemcpy(c_loc(h_csr_val), d_csr_val, int(nnz, c_size_t) * 8, 2)) write(*,fmt='(A)') "Incomplete LU factorization:" do i = 1, M k = h_csr_row_ptr(i) + 1 do j = 1, M if(j .eq. h_csr_col_ind(k) + 1) then write(*,fmt='(A,F6.2)',advance='no') ' ', h_csr_val(k) k = k + 1 else write(*,fmt='(A,F6.2)',advance='no') ' ', 0.0 end if end do write(*,*) end do ! Clear hipSPARSE call HIPSPARSE_CHECK(hipsparseDestroyCsrilu02Info(info)) call HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descr)) call HIPSPARSE_CHECK(hipsparseDestroy(handle)) ! Clear device memory call HIP_CHECK(hipFree(d_csr_row_ptr)) call HIP_CHECK(hipFree(d_csr_col_ind)) call HIP_CHECK(hipFree(d_csr_val)) call HIP_CHECK(hipFree(temp_buffer)) end program example_fortran_csrilu0 hipSPARSE-rocm-5.7.1/clients/samples/example_fortran_csrsm2.f90000066400000000000000000000247021447644345400243100ustar00rootroot00000000000000!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! 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. ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! subroutine HIP_CHECK(stat) use iso_c_binding implicit none integer(c_int) :: stat if(stat /= 0) then write(*,*) 'Error: hip error' stop end if end subroutine HIP_CHECK subroutine HIPSPARSE_CHECK(stat) use iso_c_binding implicit none integer(c_int) :: stat if(stat /= 0) then write(*,*) 'Error: hipsparse error' stop end if end subroutine HIPSPARSE_CHECK program example_fortran_csrsm use iso_c_binding use hipsparse implicit none interface function hipMalloc(ptr, size) & bind(c, name = 'hipMalloc') use iso_c_binding implicit none integer :: hipMalloc type(c_ptr) :: ptr integer(c_size_t), value :: size end function hipMalloc function hipFree(ptr) & bind(c, name = 'hipFree') use iso_c_binding implicit none integer :: hipFree type(c_ptr), value :: ptr end function hipFree function hipMemcpy(dst, src, size, kind) & bind(c, name = 'hipMemcpy') use iso_c_binding implicit none integer :: hipMemcpy type(c_ptr), value :: dst type(c_ptr), intent(in), value :: src integer(c_size_t), value :: size integer(c_int), value :: kind end function hipMemcpy function hipMemset(dst, val, size) & bind(c, name = 'hipMemset') use iso_c_binding implicit none integer :: hipMemset type(c_ptr), value :: dst integer(c_int), value :: val integer(c_size_t), value :: size end function hipMemset function hipDeviceSynchronize() & bind(c, name = 'hipDeviceSynchronize') use iso_c_binding implicit none integer :: hipDeviceSynchronize end function hipDeviceSynchronize function hipDeviceReset() & bind(c, name = 'hipDeviceReset') use iso_c_binding implicit none integer :: hipDeviceReset end function hipDeviceReset end interface integer, target :: h_csr_row_ptr(4), h_csr_col_ind(6) real(8), target :: h_csr_val(6), h_B(12) type(c_ptr) :: d_csr_row_ptr type(c_ptr) :: d_csr_col_ind type(c_ptr) :: d_csr_val type(c_ptr) :: d_B type(c_ptr) :: temp_buffer integer :: i, j integer(c_int) :: M, N, nnz integer(c_int) :: ldb, nrhs integer(c_int) :: stat integer(c_int), target :: pivot integer(c_size_t), target :: buffer_size real(c_double), target :: alpha type(c_ptr) :: handle type(c_ptr) :: descr type(c_ptr) :: info integer :: version ! Input data ! ( 1 0 0 ) ! A = ( 2 3 0 ) ! ( 4 5 6 ) ! Number of rows and columns M = 3 N = 3 ! Number of non-zero entries nnz = 6 ! Fill CSR structure h_csr_row_ptr = (/0, 1, 3, 6/) h_csr_col_ind = (/0, 0, 1, 0, 1, 2/) h_csr_val = (/1, 2, 3, 4, 5, 6/) ! Scalar alpha alpha = 1.0 ! B (nrhs rhs vectors) ldb = m nrhs = 4 h_B = (/1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12/) ! Allocate device memory call HIP_CHECK(hipMalloc(d_csr_row_ptr, (int(M, c_size_t) + 1) * 4)) call HIP_CHECK(hipMalloc(d_csr_col_ind, int(nnz, c_size_t) * 4)) call HIP_CHECK(hipMalloc(d_csr_val, int(nnz, c_size_t) * 8)) call HIP_CHECK(hipMalloc(d_B, int(M * nrhs, c_size_t) * 8)) ! Copy host data to device call HIP_CHECK(hipMemcpy(d_csr_row_ptr, c_loc(h_csr_row_ptr), (int(M, c_size_t) + 1) * 4, 1)) call HIP_CHECK(hipMemcpy(d_csr_col_ind, c_loc(h_csr_col_ind), int(nnz, c_size_t) * 4, 1)) call HIP_CHECK(hipMemcpy(d_csr_val, c_loc(h_csr_val), int(nnz, c_size_t) * 8, 1)) call HIP_CHECK(hipMemcpy(d_B, c_loc(h_B), int(M * nrhs, c_size_t) * 8, 1)) ! Create hipSPARSE handle call HIPSPARSE_CHECK(hipsparseCreate(handle)) ! Get hipSPARSE version call HIPSPARSE_CHECK(hipsparseGetVersion(handle, version)) ! Print version on screen write(*,fmt='(A,I0,A,I0,A,I0)') 'hipSPARSE version: ', version / 100000, '.', & mod(version / 100, 1000), '.', mod(version, 100) ! Create matrix descriptor call HIPSPARSE_CHECK(hipsparseCreateMatDescr(descr)) ! Matrix fill mode call HIPSPARSE_CHECK(hipsparseSetMatFillMode(descr, HIPSPARSE_FILL_MODE_LOWER)) ! Matrix diagonal type call HIPSPARSE_CHECK(hipsparseSetMatDiagType(descr, HIPSPARSE_DIAG_TYPE_NON_UNIT)) ! Create matrix info structure call HIPSPARSE_CHECK(hipsparseCreateCsrsm2Info(info)) ! Obtain required buffer size call HIPSPARSE_CHECK(hipsparseDcsrsm2_bufferSizeExt(handle, & 0, & HIPSPARSE_OPERATION_NON_TRANSPOSE, & HIPSPARSE_OPERATION_NON_TRANSPOSE, & M, & nrhs, & nnz, & c_loc(alpha), & descr, & d_csr_val, & d_csr_row_ptr, & d_csr_col_ind, & d_B, & ldb, & info, & HIPSPARSE_SOLVE_POLICY_USE_LEVEL, & c_loc(buffer_size))) ! Allocate temporary buffer write(*,fmt='(A,I0,A)') 'Allocating ', buffer_size / 1024, 'kB temporary storage buffer' call HIP_CHECK(hipMalloc(temp_buffer, buffer_size)) ! Perform analysis step call HIPSPARSE_CHECK(hipsparseDcsrsm2_analysis(handle, & 0, & HIPSPARSE_OPERATION_NON_TRANSPOSE, & HIPSPARSE_OPERATION_NON_TRANSPOSE, & M, & nrhs, & nnz, & c_loc(alpha), & descr, & d_csr_val, & d_csr_row_ptr, & d_csr_col_ind, & d_B, & ldb, & info, & HIPSPARSE_SOLVE_POLICY_USE_LEVEL, & temp_buffer)) ! Call dcsrsm to perform lower triangular solve Ly = x call HIPSPARSE_CHECK(hipsparseDcsrsm2_solve(handle, & 0, & HIPSPARSE_OPERATION_NON_TRANSPOSE, & HIPSPARSE_OPERATION_NON_TRANSPOSE, & M, & nrhs, & nnz, & c_loc(alpha), & descr, & d_csr_val, & d_csr_row_ptr, & d_csr_col_ind, & d_B, & ldb, & info, & HIPSPARSE_SOLVE_POLICY_USE_LEVEL, & temp_buffer)) ! Check for zero pivots stat = hipsparseXcsrsm2_zeroPivot(handle, info, c_loc(pivot)) if(stat .eq. HIPSPARSE_STATUS_ZERO_PIVOT) then write(*,fmt='(A,I0)') 'Found zero pivot in matrix row ', pivot end if ! Print result call HIP_CHECK(hipMemcpy(c_loc(h_B), d_B, int(m * nrhs, c_size_t) * 8, 2)) do i = 0, nrhs - 1 write(*,fmt='(A,I0,A)', advance='no') 'B(', i + 1, '):' do j = 1, M write(*,fmt='(A,F0.5)', advance='no') ' ', h_B(i * ldb + j) end do write(*,*) end do ! Clear hipSPARSE call HIPSPARSE_CHECK(hipsparseDestroyCsrsm2Info(info)) call HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descr)) call HIPSPARSE_CHECK(hipsparseDestroy(handle)) ! Clear device memory call HIP_CHECK(hipFree(d_csr_row_ptr)) call HIP_CHECK(hipFree(d_csr_col_ind)) call HIP_CHECK(hipFree(d_csr_val)) call HIP_CHECK(hipFree(d_B)) call HIP_CHECK(hipFree(temp_buffer)) end program example_fortran_csrsm hipSPARSE-rocm-5.7.1/clients/samples/example_fortran_csrsv2.f90000066400000000000000000000224021447644345400243140ustar00rootroot00000000000000!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! 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. ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! subroutine HIP_CHECK(stat) use iso_c_binding implicit none integer(c_int) :: stat if(stat /= 0) then write(*,*) 'Error: hip error' stop end if end subroutine HIP_CHECK subroutine HIPSPARSE_CHECK(stat) use iso_c_binding implicit none integer(c_int) :: stat if(stat /= 0) then write(*,*) 'Error: hipsparse error' stop end if end subroutine HIPSPARSE_CHECK program example_fortran_csrsv use iso_c_binding use hipsparse implicit none interface function hipMalloc(ptr, size) & bind(c, name = 'hipMalloc') use iso_c_binding implicit none integer :: hipMalloc type(c_ptr) :: ptr integer(c_size_t), value :: size end function hipMalloc function hipFree(ptr) & bind(c, name = 'hipFree') use iso_c_binding implicit none integer :: hipFree type(c_ptr), value :: ptr end function hipFree function hipMemcpy(dst, src, size, kind) & bind(c, name = 'hipMemcpy') use iso_c_binding implicit none integer :: hipMemcpy type(c_ptr), value :: dst type(c_ptr), intent(in), value :: src integer(c_size_t), value :: size integer(c_int), value :: kind end function hipMemcpy function hipMemset(dst, val, size) & bind(c, name = 'hipMemset') use iso_c_binding implicit none integer :: hipMemset type(c_ptr), value :: dst integer(c_int), value :: val integer(c_size_t), value :: size end function hipMemset function hipDeviceSynchronize() & bind(c, name = 'hipDeviceSynchronize') use iso_c_binding implicit none integer :: hipDeviceSynchronize end function hipDeviceSynchronize function hipDeviceReset() & bind(c, name = 'hipDeviceReset') use iso_c_binding implicit none integer :: hipDeviceReset end function hipDeviceReset end interface integer, target :: h_csr_row_ptr(4), h_csr_col_ind(6) real(8), target :: h_csr_val(6), h_x(3), h_y(3), h_y_gold(3) type(c_ptr) :: d_csr_row_ptr type(c_ptr) :: d_csr_col_ind type(c_ptr) :: d_csr_val type(c_ptr) :: d_x type(c_ptr) :: d_y type(c_ptr) :: temp_buffer integer :: i integer(c_int) :: M, N, nnz integer(c_int) :: stat integer(c_int), target :: pivot integer(c_size_t), target :: buffer_size real(c_double), target :: alpha type(c_ptr) :: handle type(c_ptr) :: descr type(c_ptr) :: info integer :: version ! Input data ! ( 1 0 0 ) ! A = ( 2 3 0 ) ! ( 4 5 6 ) ! Number of rows and columns M = 3 N = 3 ! Number of non-zero entries nnz = 6 ! Fill CSR structure h_csr_row_ptr = (/0, 1, 3, 6/) h_csr_col_ind = (/0, 0, 1, 0, 1, 2/) h_csr_val = (/1, 2, 3, 4, 5, 6/) ! Scalar alpha alpha = 3.7 ! x vector h_x = (/1, 2, 3/) ! Allocate device memory call HIP_CHECK(hipMalloc(d_csr_row_ptr, (int(M, c_size_t) + 1) * 4)) call HIP_CHECK(hipMalloc(d_csr_col_ind, int(nnz, c_size_t) * 4)) call HIP_CHECK(hipMalloc(d_csr_val, int(nnz, c_size_t) * 8)) call HIP_CHECK(hipMalloc(d_x, int(N, c_size_t) * 8)) call HIP_CHECK(hipMalloc(d_y, int(M, c_size_t) * 8)) ! Copy host data to device call HIP_CHECK(hipMemcpy(d_csr_row_ptr, c_loc(h_csr_row_ptr), (int(M, c_size_t) + 1) * 4, 1)) call HIP_CHECK(hipMemcpy(d_csr_col_ind, c_loc(h_csr_col_ind), int(nnz, c_size_t) * 4, 1)) call HIP_CHECK(hipMemcpy(d_csr_val, c_loc(h_csr_val), int(nnz, c_size_t) * 8, 1)) call HIP_CHECK(hipMemcpy(d_x, c_loc(h_x), int(N, c_size_t) * 8, 1)) ! Create hipSPARSE handle call HIPSPARSE_CHECK(hipsparseCreate(handle)) ! Get hipSPARSE version call HIPSPARSE_CHECK(hipsparseGetVersion(handle, version)) ! Print version on screen write(*,fmt='(A,I0,A,I0,A,I0)') 'hipSPARSE version: ', version / 100000, '.', & mod(version / 100, 1000), '.', mod(version, 100) ! Create matrix descriptor call HIPSPARSE_CHECK(hipsparseCreateMatDescr(descr)) ! Matrix fill mode call HIPSPARSE_CHECK(hipsparseSetMatFillMode(descr, HIPSPARSE_FILL_MODE_LOWER)) ! Matrix diagonal type call HIPSPARSE_CHECK(hipsparseSetMatDiagType(descr, HIPSPARSE_DIAG_TYPE_NON_UNIT)) ! Create csrsv2 info structure call HIPSPARSE_CHECK(hipsparseCreateCsrsv2Info(info)) ! Obtain required buffer size call HIPSPARSE_CHECK(hipsparseDcsrsv2_bufferSizeExt(handle, & HIPSPARSE_OPERATION_NON_TRANSPOSE, & M, & nnz, & descr, & d_csr_val, & d_csr_row_ptr, & d_csr_col_ind, & info, & c_loc(buffer_size))) ! Allocate temporary buffer write(*,fmt='(A,I0,A)') 'Allocating ', buffer_size / 1024, 'kB temporary storage buffer' call HIP_CHECK(hipMalloc(temp_buffer, buffer_size)) ! Perform analysis step call HIPSPARSE_CHECK(hipsparseDcsrsv2_analysis(handle, & HIPSPARSE_OPERATION_NON_TRANSPOSE, & M, & nnz, & descr, & d_csr_val, & d_csr_row_ptr, & d_csr_col_ind, & info, & HIPSPARSE_SOLVE_POLICY_USE_LEVEL, & temp_buffer)) ! Call dcsrsv to perform lower triangular solve Ly = x call HIPSPARSE_CHECK(hipsparseDcsrsv2_solve(handle, & HIPSPARSE_OPERATION_NON_TRANSPOSE, & M, & nnz, & c_loc(alpha), & descr, & d_csr_val, & d_csr_row_ptr, & d_csr_col_ind, & info, & d_x, & d_y, & HIPSPARSE_SOLVE_POLICY_USE_LEVEL, & temp_buffer)) ! Check for zero pivots stat = hipsparseXcsrsv2_zeroPivot(handle, info, c_loc(pivot)) if(stat .eq. HIPSPARSE_STATUS_ZERO_PIVOT) then write(*,fmt='(A,I0)') 'Found zero pivot in matrix row ', pivot end if ! Print result call HIP_CHECK(hipMemcpy(c_loc(h_y), d_y, int(M, c_size_t) * 8, 2)) do i = 1, m write(*,fmt='(A,I0,A,F0.2)') 'y(', i, ') = ', h_y(i) end do ! Clear hipSPARSE call HIPSPARSE_CHECK(hipsparseDestroyCsrsv2Info(info)) call HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descr)) call HIPSPARSE_CHECK(hipsparseDestroy(handle)) ! Clear device memory call HIP_CHECK(hipFree(d_csr_row_ptr)) call HIP_CHECK(hipFree(d_csr_col_ind)) call HIP_CHECK(hipFree(d_csr_val)) call HIP_CHECK(hipFree(d_x)) call HIP_CHECK(hipFree(d_y)) call HIP_CHECK(hipFree(temp_buffer)) end program example_fortran_csrsv hipSPARSE-rocm-5.7.1/clients/samples/example_fortran_dotci.f90000066400000000000000000000135251447644345400242020ustar00rootroot00000000000000!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! 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. ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! subroutine HIP_CHECK(stat) use iso_c_binding implicit none integer(c_int) :: stat if(stat /= 0) then write(*,*) 'Error: hip error' stop end if end subroutine HIP_CHECK subroutine HIPSPARSE_CHECK(stat) use iso_c_binding implicit none integer(c_int) :: stat if(stat /= 0) then write(*,*) 'Error: hipsparse error' stop end if end subroutine HIPSPARSE_CHECK program example_fortran_roti use iso_c_binding use hipsparse implicit none interface function hipMalloc(ptr, size) & bind(c, name = 'hipMalloc') use iso_c_binding implicit none integer :: hipMalloc type(c_ptr) :: ptr integer(c_size_t), value :: size end function hipMalloc function hipFree(ptr) & bind(c, name = 'hipFree') use iso_c_binding implicit none integer :: hipFree type(c_ptr), value :: ptr end function hipFree function hipMemcpy(dst, src, size, kind) & bind(c, name = 'hipMemcpy') use iso_c_binding implicit none integer :: hipMemcpy type(c_ptr), value :: dst type(c_ptr), intent(in), value :: src integer(c_size_t), value :: size integer(c_int), value :: kind end function hipMemcpy function hipMemset(dst, val, size) & bind(c, name = 'hipMemset') use iso_c_binding implicit none integer :: hipMemset type(c_ptr), value :: dst integer(c_int), value :: val integer(c_size_t), value :: size end function hipMemset function hipDeviceSynchronize() & bind(c, name = 'hipDeviceSynchronize') use iso_c_binding implicit none integer :: hipDeviceSynchronize end function hipDeviceSynchronize function hipDeviceReset() & bind(c, name = 'hipDeviceReset') use iso_c_binding implicit none integer :: hipDeviceReset end function hipDeviceReset end interface integer, target :: h_xind(3) complex(8), target :: h_xval(3), h_y(9) complex(8), target :: h_dot type(c_ptr) :: d_xind type(c_ptr) :: d_xval type(c_ptr) :: d_y type(c_ptr) :: d_dot integer :: i integer(c_int) :: M, nnz type(c_ptr) :: handle integer :: version ! Input data ! Number of rows M = 9 ! Number of non-zero entries nnz = 3 ! Fill structures h_xind = (/0, 3, 5/) h_xval = (/cmplx(1, 4), cmplx(2, 5), cmplx(3, 6)/) h_y = (/cmplx(1, -9), cmplx(2, -8), cmplx(3, -7), cmplx(4, -6), cmplx(5, -5), & cmplx(6, -4), cmplx(7, -3), cmplx(8, -2), cmplx(9, -1)/) ! Allocate device memory call HIP_CHECK(hipMalloc(d_xind, (int(nnz, c_size_t) + 1) * 4)) call HIP_CHECK(hipMalloc(d_xval, int(nnz, c_size_t) * 16)) call HIP_CHECK(hipMalloc(d_y, int(M, c_size_t) * 16)) call HIP_CHECK(hipMalloc(d_dot, int(16, c_size_t))) ! Copy host data to device call HIP_CHECK(hipMemcpy(d_xind, c_loc(h_xind), (int(nnz, c_size_t) + 1) * 4, 1)) call HIP_CHECK(hipMemcpy(d_xval, c_loc(h_xval), int(nnz, c_size_t) * 16, 1)) call HIP_CHECK(hipMemcpy(d_y, c_loc(h_y), int(M, c_size_t) * 16, 1)) ! Create hipSPARSE handle call HIPSPARSE_CHECK(hipsparseCreate(handle)) call HIPSPARSE_CHECK(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)) ! Get hipSPARSE version call HIPSPARSE_CHECK(hipsparseGetVersion(handle, version)) ! Print version on screen write(*,fmt='(A,I0,A,I0,A,I0)') 'hipSPARSE version: ', version / 100000, '.', & mod(version / 100, 1000), '.', mod(version, 100) ! Call zdotci call HIPSPARSE_CHECK(hipsparseZdotci(handle, & nnz, & d_xval, & d_xind, & d_y, & d_dot, & HIPSPARSE_INDEX_BASE_ZERO)) ! Copy result back to host call HIP_CHECK(hipMemcpy(c_loc(h_dot), d_dot, int(16, c_size_t), 2)) ! Print result write(*,fmt='(A,F0.0,F0.0,A)') 'Dot product: ', h_dot, 'i' ! Clear hipSPARSE call HIPSPARSE_CHECK(hipsparseDestroy(handle)) ! Clear device memory call HIP_CHECK(hipFree(d_xind)) call HIP_CHECK(hipFree(d_xval)) call HIP_CHECK(hipFree(d_y)) end program example_fortran_roti hipSPARSE-rocm-5.7.1/clients/samples/example_fortran_roti.f90000066400000000000000000000135521447644345400240550ustar00rootroot00000000000000!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! 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. ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! subroutine HIP_CHECK(stat) use iso_c_binding implicit none integer(c_int) :: stat if(stat /= 0) then write(*,*) 'Error: hip error' stop end if end subroutine HIP_CHECK subroutine HIPSPARSE_CHECK(stat) use iso_c_binding implicit none integer(c_int) :: stat if(stat /= 0) then write(*,*) 'Error: hipsparse error' stop end if end subroutine HIPSPARSE_CHECK program example_fortran_roti use iso_c_binding use hipsparse implicit none interface function hipMalloc(ptr, size) & bind(c, name = 'hipMalloc') use iso_c_binding implicit none integer :: hipMalloc type(c_ptr) :: ptr integer(c_size_t), value :: size end function hipMalloc function hipFree(ptr) & bind(c, name = 'hipFree') use iso_c_binding implicit none integer :: hipFree type(c_ptr), value :: ptr end function hipFree function hipMemcpy(dst, src, size, kind) & bind(c, name = 'hipMemcpy') use iso_c_binding implicit none integer :: hipMemcpy type(c_ptr), value :: dst type(c_ptr), intent(in), value :: src integer(c_size_t), value :: size integer(c_int), value :: kind end function hipMemcpy function hipMemset(dst, val, size) & bind(c, name = 'hipMemset') use iso_c_binding implicit none integer :: hipMemset type(c_ptr), value :: dst integer(c_int), value :: val integer(c_size_t), value :: size end function hipMemset function hipDeviceSynchronize() & bind(c, name = 'hipDeviceSynchronize') use iso_c_binding implicit none integer :: hipDeviceSynchronize end function hipDeviceSynchronize function hipDeviceReset() & bind(c, name = 'hipDeviceReset') use iso_c_binding implicit none integer :: hipDeviceReset end function hipDeviceReset end interface integer, target :: h_xind(3) real(4), target :: h_xval(3), h_y(9) type(c_ptr) :: d_xind type(c_ptr) :: d_xval type(c_ptr) :: d_y integer :: i integer(c_int) :: M, nnz real(c_float), target :: c real(c_float), target :: s type(c_ptr) :: handle integer :: version ! Input data ! Number of rows M = 9 ! Number of non-zero entries nnz = 3 ! Fill structures h_xind = (/0, 3, 5/) h_xval = (/1, 2, 3/) h_y = (/1, 2, 3, 4, 5, 6, 7, 8, 9/) ! c and s c = 3.7 s = 1.3 ! Allocate device memory call HIP_CHECK(hipMalloc(d_xind, (int(nnz, c_size_t) + 1) * 4)) call HIP_CHECK(hipMalloc(d_xval, int(nnz, c_size_t) * 8)) call HIP_CHECK(hipMalloc(d_y, int(M, c_size_t) * 8)) ! Copy host data to device call HIP_CHECK(hipMemcpy(d_xind, c_loc(h_xind), (int(nnz, c_size_t) + 1) * 4, 1)) call HIP_CHECK(hipMemcpy(d_xval, c_loc(h_xval), int(nnz, c_size_t) * 8, 1)) call HIP_CHECK(hipMemcpy(d_y, c_loc(h_y), int(M, c_size_t) * 8, 1)) ! Create hipSPARSE handle call HIPSPARSE_CHECK(hipsparseCreate(handle)) ! Get hipSPARSE version call HIPSPARSE_CHECK(hipsparseGetVersion(handle, version)) ! Print version on screen write(*,fmt='(A,I0,A,I0,A,I0)') 'hipSPARSE version: ', version / 100000, '.', & mod(version / 100, 1000), '.', mod(version, 100) ! Call sroti call HIPSPARSE_CHECK(hipsparseSroti(handle, & nnz, & d_xval, & d_xind, & d_y, & c_loc(c), & c_loc(s), & HIPSPARSE_INDEX_BASE_ZERO)) ! Print result call HIP_CHECK(hipMemcpy(c_loc(h_xval), d_xval, int(nnz, c_size_t) * 8, 2)) call HIP_CHECK(hipMemcpy(c_loc(h_y), d_y, int(M, c_size_t) * 8, 2)) do i = 1, nnz write(*,fmt='(A,I0,A,F0.2)') 'x(', h_xind(i), ') = ', h_xval(i) end do write(*,fmt='(A)',advance='no') 'y:' do i = 1, M write(*,fmt='(A,F0.2)',advance='no') ' ', h_y(i) end do write(*,*) ! Clear hipSPARSE call HIPSPARSE_CHECK(hipsparseDestroy(handle)) ! Clear device memory call HIP_CHECK(hipFree(d_xind)) call HIP_CHECK(hipFree(d_xval)) call HIP_CHECK(hipFree(d_y)) end program example_fortran_roti hipSPARSE-rocm-5.7.1/clients/samples/example_fortran_spmv.f90000066400000000000000000000426111447644345400240630ustar00rootroot00000000000000!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! 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. ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! subroutine HIP_CHECK(stat) use iso_c_binding implicit none integer(c_int) :: stat if(stat /= 0) then write(*,*) 'Error: hip error' stop end if end subroutine HIP_CHECK subroutine HIPSPARSE_CHECK(stat) use iso_c_binding implicit none integer(c_int) :: stat if(stat /= 0) then write(*,*) 'Error: hipsparse error' stop end if end subroutine HIPSPARSE_CHECK program example_fortran_spmv use iso_c_binding use hipsparse implicit none interface function hipMalloc(ptr, size) & bind(c, name = 'hipMalloc') use iso_c_binding implicit none integer :: hipMalloc type(c_ptr) :: ptr integer(c_size_t), value :: size end function hipMalloc function hipFree(ptr) & bind(c, name = 'hipFree') use iso_c_binding implicit none integer :: hipFree type(c_ptr), value :: ptr end function hipFree function hipMemcpy(dst, src, size, kind) & bind(c, name = 'hipMemcpy') use iso_c_binding implicit none integer :: hipMemcpy type(c_ptr), value :: dst type(c_ptr), intent(in), value :: src integer(c_size_t), value :: size integer(c_int), value :: kind end function hipMemcpy function hipMemset(dst, val, size) & bind(c, name = 'hipMemset') use iso_c_binding implicit none integer :: hipMemset type(c_ptr), value :: dst integer(c_int), value :: val integer(c_size_t), value :: size end function hipMemset function hipDeviceSynchronize() & bind(c, name = 'hipDeviceSynchronize') use iso_c_binding implicit none integer :: hipDeviceSynchronize end function hipDeviceSynchronize function hipDeviceReset() & bind(c, name = 'hipDeviceReset') use iso_c_binding implicit none integer :: hipDeviceReset end function hipDeviceReset end interface integer, dimension(:), allocatable, target :: h_csr_row_ptr, h_csr_col_ind real(8), dimension(:), allocatable, target :: h_csr_val, h_x, h_y, h_y_gold type(c_ptr) :: d_csr_row_ptr type(c_ptr) :: d_csr_col_ind type(c_ptr) :: d_csr_val type(c_ptr) :: d_x type(c_ptr) :: d_y type(c_ptr) :: d_bsr_row_ptr type(c_ptr) :: d_bsr_col_ind type(c_ptr) :: d_bsr_val integer(c_int) :: M, N, nnz integer(c_int) :: dim_x, dim_y integer(c_int) :: row, col integer(c_int) :: ix, iy, sx, sy real(c_double), target :: alpha real(c_double), target :: beta type(c_ptr) :: handle type(c_ptr) :: descr type(c_ptr) :: hyb type(c_ptr) :: d_nnzb type(c_ptr) :: d_alpha type(c_ptr) :: d_beta integer :: Mb, Nb, bsr_dim integer, target :: nnzb integer :: version integer i integer tbegin(8) integer tend(8) real(8) timing real(8) gflops real(8) gbyte real(8) acc ! Sample Laplacian on 2D domain dim_x = 3000 dim_y = 3000 ! Dimensions M = dim_x * dim_y N = dim_x * dim_y ! Allocate CSR arrays and vectors allocate(h_csr_row_ptr(M + 1), h_csr_col_ind(9 * M), h_csr_val(9 * M)) allocate(h_x(N)) allocate(h_y_gold(M)) allocate(h_y(M)) ! Initialize with 0 index base h_csr_row_ptr(1) = 0 nnz = 0 ! Fill host arrays do iy = 0, dim_y - 1 do ix = 0, dim_x - 1 row = iy * dim_x + ix do sy = -1, 1 if(iy + sy .gt. -1 .and. iy + sy .lt. dim_y) then do sx = -1, 1 if(ix + sx .gt. -1 .and. ix + sx .lt. dim_x) then col = row + sy * dim_x + sx h_csr_col_ind(nnz + 1) = col if(col .eq. row) then h_csr_val(nnz + 1) = 8 else h_csr_val(nnz + 1) = -1 endif nnz = nnz + 1 end if end do end if end do h_csr_row_ptr(row + 2) = nnz end do end do ! Initialize x and y h_x(1:N) = 1 ! Scalars alpha = 1 beta = 0 ! Print assembled matrix sizes write(*,fmt='(A,I0,A,I0,A,I0,A)') "2D Laplacian matrix: ", M, " x ", N, " with ", nnz, " non-zeros" ! Allocate device memory call HIP_CHECK(hipMalloc(d_csr_row_ptr, (int(M, c_size_t) + 1) * 4)) call HIP_CHECK(hipMalloc(d_csr_col_ind, int(nnz, c_size_t) * 4)) call HIP_CHECK(hipMalloc(d_csr_val, int(nnz, c_size_t) * 8)) call HIP_CHECK(hipMalloc(d_x, int(N, c_size_t) * 8)) call HIP_CHECK(hipMalloc(d_y, int(M, c_size_t) * 8)) ! Set y to zero call HIP_CHECK(hipMemset(d_y, 0, int(M, c_size_t) * 8)) ! Copy host data to device call HIP_CHECK(hipMemcpy(d_csr_row_ptr, c_loc(h_csr_row_ptr), (int(M, c_size_t) + 1) * 4, 1)) call HIP_CHECK(hipMemcpy(d_csr_col_ind, c_loc(h_csr_col_ind), int(nnz, c_size_t) * 4, 1)) call HIP_CHECK(hipMemcpy(d_csr_val, c_loc(h_csr_val), int(nnz, c_size_t) * 8, 1)) call HIP_CHECK(hipMemcpy(d_x, c_loc(h_x), int(N, c_size_t) * 8, 1)) ! Create hipSPARSE handle call HIPSPARSE_CHECK(hipsparseCreate(handle)) ! Get hipSPARSE version call HIPSPARSE_CHECK(hipsparseGetVersion(handle, version)) ! Print version on screen write(*,fmt='(A,I0,A,I0,A,I0)') 'hipSPARSE version: ', version / 100000, '.', & mod(version / 100, 1000), '.', mod(version, 100) ! Create matrix descriptor call HIPSPARSE_CHECK(hipsparseCreateMatDescr(descr)); ! Warm up call HIPSPARSE_CHECK(hipsparseDcsrmv(handle, & HIPSPARSE_OPERATION_NON_TRANSPOSE, & M, & N, & nnz, & c_loc(alpha), & descr, & d_csr_val, & d_csr_row_ptr, & d_csr_col_ind, & d_x, & c_loc(beta), & d_y)) ! Start time measurement call HIP_CHECK(hipDeviceSynchronize()) call date_and_time(values = tbegin) do i = 1, 200 call HIPSPARSE_CHECK(hipsparseDcsrmv(handle, & HIPSPARSE_OPERATION_NON_TRANSPOSE, & M, & N, & nnz, & c_loc(alpha), & descr, & d_csr_val, & d_csr_row_ptr, & d_csr_col_ind, & d_x, & c_loc(beta), & d_y)) end do call HIP_CHECK(hipDeviceSynchronize()) call date_and_time(values = tend) tbegin = tend - tbegin; timing = (0.001d0 * tbegin(8) + tbegin(7) + 60d0 * tbegin(6) + 3600d0 * tbegin(5)) / 200d0 * 1000d0 gbyte = ((M + N + nnz) * 8d0 + (M + 1 + nnz) * 4d0) / timing / 1000000d0 gflops = (2d0 * nnz) / timing / 1000000d0 write(*,fmt='(A,F0.2,A,F0.2,A,F0.2,A)') '[hipsparseDcsrmv] took ', & timing, ' msec; ', gbyte, ' GB/s; ', gflops, ' GFlop/s' ! Verify CSR result call HIP_CHECK(hipMemcpy(c_loc(h_y), d_y, int(M, c_size_t) * 8, 2)) do row = 1, M acc = beta * h_y_gold(row) do i = h_csr_row_ptr(row) + 1, h_csr_row_ptr(row + 1) col = h_csr_col_ind(i) + 1 acc = acc + h_csr_val(i) * h_x(col) end do h_y_gold(row) = alpha * acc if(h_y_gold(row) .ne. h_y(row)) then write(*,*) '[hipsparseDcsrmv] ERROR: ', h_y_gold(row), '!=', h_y(row) end if end do ! Convert to HYB call HIPSPARSE_CHECK(hipsparseCreateHybMat(hyb)) call HIPSPARSE_CHECK(hipsparseDcsr2hyb(handle, & M, & N, & descr, & d_csr_val, & d_csr_row_ptr, & d_csr_col_ind, & hyb, & 0, & HIPSPARSE_HYB_PARTITION_AUTO)) ! Warm up call HIPSPARSE_CHECK(hipsparseDhybmv(handle, & HIPSPARSE_OPERATION_NON_TRANSPOSE, & c_loc(alpha), & descr, & hyb, & d_x, & c_loc(beta), & d_y)) ! Start time measurement call HIP_CHECK(hipDeviceSynchronize()) call date_and_time(values = tbegin) do i = 1, 200 call HIPSPARSE_CHECK(hipsparseDhybmv(handle, & HIPSPARSE_OPERATION_NON_TRANSPOSE, & c_loc(alpha), & descr, & hyb, & d_x, & c_loc(beta), & d_y)) end do call HIP_CHECK(hipDeviceSynchronize()) call date_and_time(values = tend) tbegin = tend - tbegin; timing = (0.001d0 * tbegin(8) + tbegin(7) + 60d0 * tbegin(6) + 3600d0 * tbegin(5)) / 200d0 * 1000d0 gbyte = ((M + N + nnz) * 8d0 + (M + 1 + nnz) * 4d0) / timing / 1000000d0 gflops = (2d0 * nnz) / timing / 1000000d0 write(*,fmt='(A,F0.2,A,F0.2,A,F0.2,A)') '[hipsparseDhybmv] took ', & timing, ' msec; ', gbyte, ' GB/s; ', gflops, ' GFlop/s' ! Verify HYB result call HIP_CHECK(hipMemcpy(c_loc(h_y), d_y, int(M, c_size_t) * 8, 2)) do row = 1, M if(h_y_gold(row) .ne. h_y(row)) then write(*,*) '[hipsparseDhybmv] ERROR: ', h_y_gold(row), '!=', h_y(row) end if end do ! Free HYB structures call HIPSPARSE_CHECK(hipsparseDestroyHybMat(hyb)) ! Convert to BSR bsr_dim = 2 Mb = (M + bsr_dim - 1) / bsr_dim Nb = (N + bsr_dim - 1) / bsr_dim call HIP_CHECK(hipMalloc(d_bsr_row_ptr, (int(Mb, c_size_t) + 1) * 4)) call HIP_CHECK(hipMalloc(d_nnzb, int(4, c_size_t))) call HIP_CHECK(hipMalloc(d_alpha, int(8, c_size_t))) call HIP_CHECK(hipMalloc(d_beta, int(8, c_size_t))) call HIP_CHECK(hipMemcpy(d_alpha, c_loc(alpha), int(8, c_size_t), 1)) call HIP_CHECK(hipMemcpy(d_beta, c_loc(beta), int(8, c_size_t), 1)) ! Test device pointer mode call HIPSPARSE_CHECK(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)) call HIPSPARSE_CHECK(hipsparseXcsr2bsrNnz(handle, & HIPSPARSE_DIRECTION_COLUMN, & M, & N, & descr, & d_csr_row_ptr, & d_csr_col_ind, & bsr_dim, & descr, & d_bsr_row_ptr, & d_nnzb)) ! Copy device nnzb to host call HIP_CHECK(hipMemcpy(c_loc(nnzb), d_nnzb, int(4, c_size_t), 2)) call HIP_CHECK(hipMalloc(d_bsr_col_ind, int(nnzb, c_size_t) * 4)) call HIP_CHECK(hipMalloc(d_bsr_val, int(nnzb, c_size_t) * bsr_dim * bsr_dim * 8)) call HIPSPARSE_CHECK(hipsparseDcsr2bsr(handle, & HIPSPARSE_DIRECTION_COLUMN, & M, & N, & descr, & d_csr_val, & d_csr_row_ptr, & d_csr_col_ind, & bsr_dim, & descr, & d_bsr_val, & d_bsr_row_ptr, & d_bsr_col_ind)) ! Warm up call HIPSPARSE_CHECK(hipsparseDbsrmv(handle, & HIPSPARSE_DIRECTION_COLUMN, & HIPSPARSE_OPERATION_NON_TRANSPOSE, & Mb, & Nb, & nnzb, & d_alpha, & descr, & d_bsr_val, & d_bsr_row_ptr, & d_bsr_col_ind, & bsr_dim, & d_x, & d_beta, & d_y)) ! Start time measurement call HIP_CHECK(hipDeviceSynchronize()) call date_and_time(values = tbegin) do i = 1, 200 call HIPSPARSE_CHECK(hipsparseDbsrmv(handle, & HIPSPARSE_DIRECTION_COLUMN, & HIPSPARSE_OPERATION_NON_TRANSPOSE, & Mb, & Nb, & nnzb, & d_alpha, & descr, & d_bsr_val, & d_bsr_row_ptr, & d_bsr_col_ind, & bsr_dim, & d_x, & d_beta, & d_y)) end do call HIP_CHECK(hipDeviceSynchronize()) call date_and_time(values = tend) tbegin = tend - tbegin; timing = (0.001d0 * tbegin(8) + tbegin(7) + 60d0 * tbegin(6) + 3600d0 * tbegin(5)) / 200d0 * 1000d0 gbyte = ((M + N + nnz) * 8d0 + (M + 1 + nnz) * 4d0) / timing / 1000000d0 gflops = (2d0 * nnz) / timing / 1000000d0 write(*,fmt='(A,F0.2,A,F0.2,A,F0.2,A)') '[hipsparseDbsrmv] took ', & timing, ' msec; ', gbyte, ' GB/s; ', gflops, ' GFlop/s' ! Verify BSR result call HIP_CHECK(hipMemcpy(c_loc(h_y), d_y, int(M, c_size_t) * 8, 2)) do row = 1, M if(h_y_gold(row) .ne. h_y(row)) then write(*,*) '[hipsparseDbsrmv] ERROR: ', h_y_gold(row), '!=', h_y(row) end if end do ! Free BSR structures call HIP_CHECK(hipFree(d_bsr_row_ptr)) call HIP_CHECK(hipFree(d_bsr_col_ind)) call HIP_CHECK(hipFree(d_bsr_val)) ! Free host memory deallocate(h_csr_row_ptr, h_csr_col_ind, h_csr_val) deallocate(h_x, h_y) ! Free device memory call HIP_CHECK(hipFree(d_csr_val)) call HIP_CHECK(hipFree(d_csr_row_ptr)) call HIP_CHECK(hipFree(d_csr_col_ind)) call HIP_CHECK(hipFree(d_x)) call HIP_CHECK(hipFree(d_y)) ! Free hipSPARSE structures call HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descr)) call HIPSPARSE_CHECK(hipsparseDestroy(handle)) call HIP_CHECK(hipDeviceReset()) end program example_fortran_spmv hipSPARSE-rocm-5.7.1/clients/samples/example_handle.cpp000066400000000000000000000033541447644345400227630ustar00rootroot00000000000000/* ************************************************************************ * 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 #include int main(int argc, char* argv[]) { hipsparseHandle_t handle; hipsparseCreate(&handle); int version; hipsparseGetVersion(handle, &version); char rev[128]; hipsparseGetGitRevision(handle, rev); printf("hipSPARSE version %d.%d.%d-%s\n", version / 100000, version / 100 % 1000, version % 100, rev); hipsparseDestroy(handle); return 0; } hipSPARSE-rocm-5.7.1/clients/samples/example_hybmv.cpp000066400000000000000000000120311447644345400226450ustar00rootroot00000000000000/* ************************************************************************ * 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 "utility.hpp" #include #include #include #include #include int main(int argc, char* argv[]) { // Parse command line if(argc < 2) { fprintf(stderr, "%s [ ]\n", argv[0]); return -1; } int ndim = atoi(argv[1]); int trials = 200; int batch_size = 1; if(argc > 2) { trials = atoi(argv[2]); } if(argc > 3) { batch_size = atoi(argv[3]); } // hipSPARSE handle hipsparseHandle_t handle; hipsparseCreate(&handle); hipDeviceProp_t devProp; int device_id = 0; hipGetDevice(&device_id); hipGetDeviceProperties(&devProp, device_id); printf("Device: %s\n", devProp.name); // Generate problem in CSR format std::vector hAptr; std::vector hAcol; std::vector hAval; int m = gen_2d_laplacian(ndim, hAptr, hAcol, hAval, HIPSPARSE_INDEX_BASE_ZERO); int n = m; int nnz = hAptr[m]; // Sample some random data srand(12345ULL); double halpha = static_cast(rand()) / RAND_MAX; double hbeta = 0.0; std::vector hx(n); hipsparseInit(hx, 1, n); // Matrix descriptor hipsparseMatDescr_t descrA; hipsparseCreateMatDescr(&descrA); // Offload data to device int* dAptr = NULL; int* dAcol = NULL; double* dAval = NULL; double* dx = NULL; double* dy = NULL; hipMalloc((void**)&dAptr, sizeof(int) * (m + 1)); hipMalloc((void**)&dAcol, sizeof(int) * nnz); hipMalloc((void**)&dAval, sizeof(double) * nnz); hipMalloc((void**)&dx, sizeof(double) * n); hipMalloc((void**)&dy, sizeof(double) * m); hipMemcpy(dAptr, hAptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice); hipMemcpy(dAcol, hAcol.data(), sizeof(int) * nnz, hipMemcpyHostToDevice); hipMemcpy(dAval, hAval.data(), sizeof(double) * nnz, hipMemcpyHostToDevice); hipMemcpy(dx, hx.data(), sizeof(double) * n, hipMemcpyHostToDevice); // Convert CSR matrix to HYB format hipsparseHybMat_t hybA; hipsparseCreateHybMat(&hybA); hipsparseDcsr2hyb( handle, m, n, descrA, dAval, dAptr, dAcol, hybA, 0, HIPSPARSE_HYB_PARTITION_AUTO); // Clean up CSR structures hipFree(dAptr); hipFree(dAcol); hipFree(dAval); // Warm up for(int i = 0; i < 10; ++i) { // Call hipsparse hybmv hipsparseDhybmv( handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, &halpha, descrA, hybA, dx, &hbeta, dy); } // Device synchronization hipDeviceSynchronize(); // Start time measurement double time = get_time_us(); // HYB matrix vector multiplication for(int i = 0; i < trials; ++i) { for(int j = 0; j < batch_size; ++j) { // Call hipsparse hybmv hipsparseDhybmv( handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, &halpha, descrA, hybA, dx, &hbeta, dy); } // Device synchronization hipDeviceSynchronize(); } time = (get_time_us() - time) / (trials * batch_size * 1e3); double bandwidth = static_cast(sizeof(double) * (2 * m + nnz) + sizeof(int) * (nnz)) / time / 1e6; double gflops = static_cast(2 * nnz) / time / 1e6; printf("m\t\tn\t\tnnz\t\talpha\tbeta\tGFlops\tGB/s\tusec\n"); printf("%8d\t%8d\t%9d\t%0.2lf\t%0.2lf\t%0.2lf\t%0.2lf\t%0.2lf\n", m, n, nnz, halpha, hbeta, gflops, bandwidth, time); // Clear up on device hipsparseDestroyHybMat(hybA); hipsparseDestroyMatDescr(descrA); hipsparseDestroy(handle); return 0; } hipSPARSE-rocm-5.7.1/clients/tests/000077500000000000000000000000001447644345400170025ustar00rootroot00000000000000hipSPARSE-rocm-5.7.1/clients/tests/CMakeLists.txt000066400000000000000000000146371447644345400215550ustar00rootroot00000000000000# ######################################################################## # 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. # # ######################################################################## find_package(GTest REQUIRED) # # Client matrices. # if(NOT EXISTS "${CMAKE_MATRICES_DIR}") # # Download. # set(CMAKE_MATRICES_DIR ${PROJECT_BINARY_DIR}/matrices CACHE STRING "Matrices directory.") file(MAKE_DIRECTORY ${CMAKE_MATRICES_DIR}) if(NOT TARGET hipsparse) set(CONVERT_SOURCE ${CMAKE_SOURCE_DIR}/../deps/convert.cpp CACHE STRING "Convert tool mtx2csr.") include(${CMAKE_SOURCE_DIR}/../cmake/ClientMatrices.cmake) else() set(CONVERT_SOURCE ${CMAKE_SOURCE_DIR}/deps/convert.cpp CACHE STRING "Convert tool mtx2csr.") include(${CMAKE_SOURCE_DIR}/cmake/ClientMatrices.cmake) endif() else() # # Copy. # if(NOT CMAKE_MATRICES_DIR STREQUAL "${PROJECT_BINARY_DIR}/matrices") message("Copy matrix files from ${CMAKE_MATRICES_DIR} to ${PROJECT_BINARY_DIR}/matrices") execute_process(COMMAND cp -r ${CMAKE_MATRICES_DIR} ${PROJECT_BINARY_DIR}/matrices RESULT_VARIABLE STATUS WORKING_DIRECTORY ${CMAKE_MATRICES_DIR}) if(STATUS AND NOT STATUS EQUAL 0) message(FATAL_ERROR "Failed to copy matrix .bin files, aborting.") endif() endif() endif() set(HIPSPARSE_TEST_SOURCES hipsparse_gtest_main.cpp test_axpyi.cpp test_gthr.cpp test_gthrz.cpp test_roti.cpp test_sctr.cpp test_bsrmv.cpp test_bsrxmv.cpp test_bsrsv2.cpp test_csrsv2.cpp test_bsrmm.cpp test_bsrsm2.cpp test_csrsm2.cpp test_gemmi.cpp test_gemvi.cpp test_csrgeam2.cpp test_csrgemm2_a.cpp test_csrgemm2_b.cpp test_bsrilu02.cpp test_csrilu02.cpp test_bsric02.cpp test_csric02.cpp test_nnz.cpp test_csr2dense.cpp test_csc2dense.cpp test_dense2csr.cpp test_prune_dense2csr.cpp test_prune_dense2csr_by_percentage.cpp test_dense2csc.cpp test_csr2coo.cpp test_csr2bsr.cpp test_bsr2csr.cpp test_gebsr2csr.cpp test_csr2csr_compress.cpp test_prune_csr2csr.cpp test_prune_csr2csr_by_percentage.cpp test_coo2csr.cpp test_identity.cpp test_csrsort.cpp test_cscsort.cpp test_coosort.cpp test_csru2csr.cpp test_csrilusv.cpp test_gebsr2gebsr.cpp test_csr2gebsr.cpp test_gebsr2gebsc.cpp test_spmat_descr.cpp test_spvec_descr.cpp test_dnvec_descr.cpp test_spmv_coo.cpp test_spmv_coo_aos.cpp test_spmv_csr.cpp test_axpby.cpp test_gather.cpp test_scatter.cpp test_rot.cpp test_spvv.cpp test_dense_to_sparse_csr.cpp test_dense_to_sparse_csc.cpp test_dense_to_sparse_coo.cpp test_sparse_to_dense_csr.cpp test_sparse_to_dense_csc.cpp test_sparse_to_dense_coo.cpp test_spmm_csr.cpp test_spmm_batched_csr.cpp test_spmm_csc.cpp test_spmm_batched_csc.cpp test_spmm_coo.cpp test_spmm_batched_coo.cpp test_spmm_bell.cpp test_spgemm_csr.cpp test_spgemmreuse_csr.cpp test_sddmm_csr.cpp test_sddmm_csc.cpp test_sddmm_coo.cpp test_sddmm_coo_aos.cpp test_gpsv_interleaved_batch.cpp test_gtsv2_strided_batch.cpp test_gtsv.cpp test_gtsv2_nopivot.cpp test_gtsv_interleaved_batch.cpp test_csrcolor.cpp test_spsv_csr.cpp test_spsv_coo.cpp test_spsm_csr.cpp test_spsm_coo.cpp ) if(NOT USE_CUDA) list(APPEND HIPSPARSE_TEST_SOURCES test_doti.cpp test_dotci.cpp test_csr2csc.cpp test_csr2csc_ex2.cpp test_csrgemm.cpp test_csrgeam.cpp test_csrmv.cpp test_csrmm.cpp test_hybmv.cpp test_csr2hyb.cpp test_hyb2csr.cpp ) endif() set(HIPSPARSE_CLIENTS_COMMON ../common/arg_check.cpp ../common/unit.cpp ../common/utility.cpp ../common/hipsparse_template_specialization.cpp ) add_executable(hipsparse-test ${HIPSPARSE_TEST_SOURCES} ${HIPSPARSE_CLIENTS_COMMON}) # Set GOOGLE_TEST definition target_compile_definitions(hipsparse-test PRIVATE GOOGLE_TEST) # Target compile options target_compile_options(hipsparse-test PRIVATE -Wno-unused-command-line-argument -Wall) # Internal common header target_include_directories(hipsparse-test PRIVATE $) # Target link libraries target_link_libraries(hipsparse-test PRIVATE GTest::GTest roc::hipsparse) # Add OpenMP if available if(OPENMP_FOUND AND THREADS_FOUND) target_link_libraries(hipsparse-test PRIVATE OpenMP::OpenMP_CXX ${OpenMP_CXX_FLAGS}) endif() if(NOT USE_CUDA) target_link_libraries(hipsparse-test PRIVATE hip::host) else() target_compile_definitions(hipsparse-test PRIVATE __HIP_PLATFORM_NVIDIA__) target_include_directories(hipsparse-test PRIVATE ${HIP_INCLUDE_DIRS}) target_link_libraries(hipsparse-test PRIVATE ${CUDA_LIBRARIES}) endif() set_target_properties(hipsparse-test PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/staging") rocm_install(TARGETS hipsparse-test COMPONENT tests) if (WIN32) # for now adding in all .dll as dependency chain is not cmake based on win32 file( GLOB third_party_dlls LIST_DIRECTORIES OFF CONFIGURE_DEPENDS $ENV{HIP_DIR}/bin/*.dll $ENV{HIP_DIR}/bin/hipinfo.exe ${ROCSPARSE_PATH}/bin/librocsparse.dll ${CMAKE_SOURCE_DIR}/rtest.* C:/Windows/System32/libomp140*.dll ) foreach( file_i ${third_party_dlls}) add_custom_command( TARGET hipsparse-test POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy ${file_i} ${PROJECT_BINARY_DIR}/staging/ ) endforeach( file_i ) endif() add_test(hipsparse-test hipsparse-test) hipSPARSE-rocm-5.7.1/clients/tests/hipsparse_gtest_main.cpp000066400000000000000000000170541447644345400237250ustar00rootroot00000000000000/* ************************************************************************ * 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 "utility.hpp" #ifdef GOOGLE_TEST #include #endif #include #include using namespace testing; class ConfigurableEventListener : public TestEventListener { TestEventListener* eventListener; public: bool showTestCases; // Show the names of each test case. bool showTestNames; // Show the names of each test. bool showSuccesses; // Show each success. bool showInlineFailures; // Show each failure as it occurs. bool showEnvironment; // Show the setup of the global environment. explicit ConfigurableEventListener(TestEventListener* theEventListener) : eventListener(theEventListener) , showTestCases(true) , showTestNames(true) , showSuccesses(true) , showInlineFailures(true) , showEnvironment(true) { } ~ConfigurableEventListener() override { delete eventListener; } void OnTestProgramStart(const UnitTest& unit_test) override { eventListener->OnTestProgramStart(unit_test); } void OnTestIterationStart(const UnitTest& unit_test, int iteration) override { eventListener->OnTestIterationStart(unit_test, iteration); } void OnEnvironmentsSetUpStart(const UnitTest& unit_test) override { if(showEnvironment) { eventListener->OnEnvironmentsSetUpStart(unit_test); } } void OnEnvironmentsSetUpEnd(const UnitTest& unit_test) override { if(showEnvironment) { eventListener->OnEnvironmentsSetUpEnd(unit_test); } } void OnTestCaseStart(const TestCase& test_case) override { if(showTestCases) { eventListener->OnTestCaseStart(test_case); } } void OnTestStart(const TestInfo& test_info) override { if(showTestNames) { eventListener->OnTestStart(test_info); } } void OnTestPartResult(const TestPartResult& result) override { eventListener->OnTestPartResult(result); } void OnTestEnd(const TestInfo& test_info) override { if(test_info.result()->Failed() ? showInlineFailures : showSuccesses) { eventListener->OnTestEnd(test_info); } } void OnTestCaseEnd(const TestCase& test_case) override { if(showTestCases) { eventListener->OnTestCaseEnd(test_case); } } void OnEnvironmentsTearDownStart(const UnitTest& unit_test) override { if(showEnvironment) { eventListener->OnEnvironmentsTearDownStart(unit_test); } } void OnEnvironmentsTearDownEnd(const UnitTest& unit_test) override { if(showEnvironment) { eventListener->OnEnvironmentsTearDownEnd(unit_test); } } void OnTestIterationEnd(const UnitTest& unit_test, int iteration) override { eventListener->OnTestIterationEnd(unit_test, iteration); } void OnTestProgramEnd(const UnitTest& unit_test) override { eventListener->OnTestProgramEnd(unit_test); } }; /* ===================================================================== Main function: =================================================================== */ static const char* s_hipsparse_clients_matrices_dir = nullptr; const char* get_hipsparse_clients_matrices_dir() { return s_hipsparse_clients_matrices_dir; } int main(int argc, char** argv) { // Print version char version[256]; query_version(version); // Get device id from command line int device_id = 0; for(int i = 1; i < argc; ++i) { if(strcmp(argv[i], "--device") == 0 && argc > i + 1) { device_id = atoi(argv[i + 1]); } if(strcmp(argv[i], "--matrices-dir") == 0) { if(argc > i + 1) { s_hipsparse_clients_matrices_dir = argv[i + 1]; } else { fprintf(stderr, "missing argument from option --matrices-dir"); return -1; } } if(strcmp(argv[i], "--version") == 0) { printf("hipSPARSE version: %s\n", version); return 0; } if(strcmp(argv[i], "--help") == 0) { fprintf(stderr, "Usage: %s [--matrices-dir ] [--device ]\n", argv[0]); fprintf(stderr, "To specify the directory of matrix input files the user can export the " "environment variable HIPSPARSE_CLIENTS_MATRICES_DIR or uses the command line " "option '--matrices-dir'. If the command line option '--matrices-dir' is used " "then the environment variable HIPSPARSE_CLIENTS_MATRICES_DIR is ignored.\n"); return 0; } } // Device Query int device_count = query_device_property(); if(device_count <= device_id) { fprintf(stderr, "Error: invalid device ID. There may not be such device ID. Will exit\n"); return -1; } else { set_device(device_id); } printf("hipSPARSE version: %s\n", version); // Initialize google test InitGoogleTest(&argc, argv); // Remove the default listener auto& listeners = UnitTest::GetInstance()->listeners(); auto default_printer = listeners.Release(listeners.default_result_printer()); // Add our listener, by default everything is on (the same as using the default listener) // Here turning everything off so only the 3 lines for the result are visible // (plus any failures at the end), like: // [==========] Running 149 tests from 53 test cases. // [==========] 149 tests from 53 test cases ran. (1 ms total) // [ PASSED ] 149 tests. // auto listener = new ConfigurableEventListener(default_printer); auto gtest_listener = getenv("GTEST_LISTENER"); if(gtest_listener && !strcmp(gtest_listener, "NO_PASS_LINE_IN_LOG")) { listener->showTestNames = listener->showSuccesses = listener->showInlineFailures = false; } listeners.Append(listener); // Run all tests int ret = RUN_ALL_TESTS(); // Reset HIP device hipDeviceReset(); return ret; } hipSPARSE-rocm-5.7.1/clients/tests/test_axpby.cpp000066400000000000000000000041601447644345400216710ustar00rootroot00000000000000/* ************************************************************************ * 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_axpby.hpp" #include // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(axpby_bad_arg, axpby_float) { testing_axpby_bad_arg(); } TEST(axpby, axpby_i32_float) { hipsparseStatus_t status = testing_axpby(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(axpby, axpby_i64_double) { hipsparseStatus_t status = testing_axpby(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(axpby, axpby_i32_hipFloatComplex) { hipsparseStatus_t status = testing_axpby(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(axpby, axpby_i64_hipDoubleComplex) { hipsparseStatus_t status = testing_axpby(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_axpyi.cpp000066400000000000000000000072361447644345400217070ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_axpyi.hpp" #include "utility.hpp" #include #include typedef hipsparseIndexBase_t base; typedef std::tuple axpyi_tuple; int axpyi_N_range[] = {12000, 15332, 22031}; int axpyi_nnz_range[] = {-1, 0, 5, 10, 500, 1000, 7111, 10000}; std::vector axpyi_alpha_range = {1.0, 0.0}; base axpyi_idx_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; class parameterized_axpyi : public testing::TestWithParam { protected: parameterized_axpyi() {} virtual ~parameterized_axpyi() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_axpyi_arguments(axpyi_tuple tup) { Arguments arg; arg.N = std::get<0>(tup); arg.nnz = std::get<1>(tup); arg.alpha = std::get<2>(tup); arg.idx_base = std::get<3>(tup); arg.timing = 0; return arg; } // Only run tests for CUDA 11.1 or greater (removed in cusparse 12.0.0) #if(!defined(CUDART_VERSION) || (CUDART_VERSION >= 11010 && CUDART_VERSION < 12000)) TEST(axpyi_bad_arg, axpyi_float) { testing_axpyi_bad_arg(); } TEST_P(parameterized_axpyi, axpyi_float) { Arguments arg = setup_axpyi_arguments(GetParam()); hipsparseStatus_t status = testing_axpyi(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_axpyi, axpyi_double) { Arguments arg = setup_axpyi_arguments(GetParam()); hipsparseStatus_t status = testing_axpyi(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_axpyi, axpyi_float_complex) { Arguments arg = setup_axpyi_arguments(GetParam()); hipsparseStatus_t status = testing_axpyi(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_axpyi, axpyi_double_complex) { Arguments arg = setup_axpyi_arguments(GetParam()); hipsparseStatus_t status = testing_axpyi(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(axpyi, parameterized_axpyi, testing::Combine(testing::ValuesIn(axpyi_N_range), testing::ValuesIn(axpyi_nnz_range), testing::ValuesIn(axpyi_alpha_range), testing::ValuesIn(axpyi_idx_base_range))); hipSPARSE-rocm-5.7.1/clients/tests/test_bsr2csr.cpp000066400000000000000000000146201447644345400221300ustar00rootroot00000000000000/* ************************************************************************ * 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_bsr2csr.hpp" #include "utility.hpp" #include #include #include typedef std::tuple bsr2csr_tuple; typedef std:: tuple bsr2csr_bin_tuple; // Random matrices int bsr2csr_M_range[] = {0, 872, 13095, 21453}; int bsr2csr_N_range[] = {0, 623, 12766, 29285}; int bsr2csr_block_dim_range[] = {1, 2, 4, 7, 16}; hipsparseIndexBase_t bsr2csr_csr_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO}; hipsparseIndexBase_t bsr2csr_bsr_base_range[] = {HIPSPARSE_INDEX_BASE_ONE}; hipsparseDirection_t bsr2csr_dir_range[] = {HIPSPARSE_DIRECTION_ROW, HIPSPARSE_DIRECTION_COLUMN}; // Matrices from files (float and double) int bsr2csr_block_dim_range_bin[] = {5}; hipsparseIndexBase_t bsr2csr_csr_base_range_bin[] = {HIPSPARSE_INDEX_BASE_ONE}; hipsparseIndexBase_t bsr2csr_bsr_base_range_bin[] = {HIPSPARSE_INDEX_BASE_ONE}; hipsparseDirection_t bsr2csr_dir_range_bin[] = {HIPSPARSE_DIRECTION_ROW, HIPSPARSE_DIRECTION_COLUMN}; std::string bsr2csr_bin[] = {"nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin"}; class parameterized_bsr2csr : public testing::TestWithParam { protected: parameterized_bsr2csr() {} virtual ~parameterized_bsr2csr() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_bsr2csr_bin : public testing::TestWithParam { protected: parameterized_bsr2csr_bin() {} virtual ~parameterized_bsr2csr_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_bsr2csr_arguments(bsr2csr_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.block_dim = std::get<2>(tup); arg.idx_base = std::get<3>(tup); arg.idx_base2 = std::get<4>(tup); arg.dirA = std::get<5>(tup); arg.timing = 0; return arg; } Arguments setup_bsr2csr_arguments(bsr2csr_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = -99; arg.block_dim = std::get<0>(tup); arg.idx_base = std::get<1>(tup); arg.idx_base2 = std::get<2>(tup); arg.dirA = std::get<3>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<4>(tup); // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(bsr2csr_bad_arg, bsr2csr) { testing_bsr2csr_bad_arg(); } TEST_P(parameterized_bsr2csr, bsr2csr_float) { Arguments arg = setup_bsr2csr_arguments(GetParam()); hipsparseStatus_t status = testing_bsr2csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_bsr2csr, bsr2csr_double) { Arguments arg = setup_bsr2csr_arguments(GetParam()); hipsparseStatus_t status = testing_bsr2csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_bsr2csr, bsr2csr_float_complex) { Arguments arg = setup_bsr2csr_arguments(GetParam()); hipsparseStatus_t status = testing_bsr2csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_bsr2csr, bsr2csr_double_complex) { Arguments arg = setup_bsr2csr_arguments(GetParam()); hipsparseStatus_t status = testing_bsr2csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_bsr2csr_bin, bsr2csr_bin_float) { Arguments arg = setup_bsr2csr_arguments(GetParam()); hipsparseStatus_t status = testing_bsr2csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_bsr2csr_bin, bsr2csr_bin_double) { Arguments arg = setup_bsr2csr_arguments(GetParam()); hipsparseStatus_t status = testing_bsr2csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(bsr2csr, parameterized_bsr2csr, testing::Combine(testing::ValuesIn(bsr2csr_M_range), testing::ValuesIn(bsr2csr_N_range), testing::ValuesIn(bsr2csr_block_dim_range), testing::ValuesIn(bsr2csr_bsr_base_range), testing::ValuesIn(bsr2csr_csr_base_range), testing::ValuesIn(bsr2csr_dir_range))); INSTANTIATE_TEST_SUITE_P(bsr2csr_bin, parameterized_bsr2csr_bin, testing::Combine(testing::ValuesIn(bsr2csr_block_dim_range_bin), testing::ValuesIn(bsr2csr_bsr_base_range_bin), testing::ValuesIn(bsr2csr_csr_base_range_bin), testing::ValuesIn(bsr2csr_dir_range_bin), testing::ValuesIn(bsr2csr_bin))); hipSPARSE-rocm-5.7.1/clients/tests/test_bsric02.cpp000066400000000000000000000127111447644345400220130ustar00rootroot00000000000000/* ************************************************************************ * 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_bsric02.hpp" #include "utility.hpp" #include #include #include typedef hipsparseIndexBase_t base; typedef hipsparseDirection_t dir; typedef std::tuple bsric02_tuple; typedef std::tuple bsric02_bin_tuple; int bsric02_M_range[] = {-1, 50, 426}; int bsric02_dim_range[] = {-1, 3, 5, 9}; base bsric02_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; dir bsric02_dir_range[] = {HIPSPARSE_DIRECTION_ROW, HIPSPARSE_DIRECTION_COLUMN}; std::string bsric02_bin[] = {"nos4.bin", "nos6.bin", "nos7.bin"}; class parameterized_bsric02 : public testing::TestWithParam { protected: parameterized_bsric02() {} virtual ~parameterized_bsric02() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_bsric02_bin : public testing::TestWithParam { protected: parameterized_bsric02_bin() {} virtual ~parameterized_bsric02_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_bsric02_arguments(bsric02_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.block_dim = std::get<1>(tup); arg.dirA = std::get<2>(tup); arg.idx_base = std::get<3>(tup); arg.timing = 0; return arg; } Arguments setup_bsric02_arguments(bsric02_bin_tuple tup) { Arguments arg; arg.M = -99; arg.block_dim = std::get<0>(tup); arg.dirA = std::get<1>(tup); arg.idx_base = std::get<2>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<3>(tup); // Get current executables absolute path // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(bsric02_bad_arg, bsric02_float) { testing_bsric02_bad_arg(); } TEST_P(parameterized_bsric02, bsric02_float) { Arguments arg = setup_bsric02_arguments(GetParam()); hipsparseStatus_t status = testing_bsric02(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_bsric02, bsric02_double) { Arguments arg = setup_bsric02_arguments(GetParam()); hipsparseStatus_t status = testing_bsric02(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_bsric02, bsric02_float_complex) { Arguments arg = setup_bsric02_arguments(GetParam()); hipsparseStatus_t status = testing_bsric02(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_bsric02, bsric02_double_complex) { Arguments arg = setup_bsric02_arguments(GetParam()); hipsparseStatus_t status = testing_bsric02(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_bsric02_bin, bsric02_bin_float) { Arguments arg = setup_bsric02_arguments(GetParam()); hipsparseStatus_t status = testing_bsric02(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_bsric02_bin, bsric02_bin_double) { Arguments arg = setup_bsric02_arguments(GetParam()); hipsparseStatus_t status = testing_bsric02(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(bsric02, parameterized_bsric02, testing::Combine(testing::ValuesIn(bsric02_M_range), testing::ValuesIn(bsric02_dim_range), testing::ValuesIn(bsric02_dir_range), testing::ValuesIn(bsric02_idxbase_range))); INSTANTIATE_TEST_SUITE_P(bsric02_bin, parameterized_bsric02_bin, testing::Combine(testing::ValuesIn(bsric02_dim_range), testing::ValuesIn(bsric02_dir_range), testing::ValuesIn(bsric02_idxbase_range), testing::ValuesIn(bsric02_bin))); hipSPARSE-rocm-5.7.1/clients/tests/test_bsrilu02.cpp000066400000000000000000000154741447644345400222220ustar00rootroot00000000000000/* ************************************************************************ * 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_bsrilu02.hpp" #include "utility.hpp" #include #include typedef hipsparseIndexBase_t base; typedef hipsparseDirection_t dir; typedef std::tuple bsrilu02_tuple; typedef std::tuple bsrilu02_bin_tuple; int bsrilu02_M_range[] = {-1, 0, 50, 426}; int bsrilu02_dim_range[] = {-1, 0, 1, 3, 5, 9}; int bsrilu02_boost_range[] = {0}; double bsrilu02_boost_tol_range[] = {1.1}; double bsrilu02_boost_val_range[] = {0.3}; double bsrilu02_boost_vali_range[] = {0.2}; base bsrilu02_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; dir bsrilu02_dir_range[] = {HIPSPARSE_DIRECTION_ROW, HIPSPARSE_DIRECTION_COLUMN}; std::string bsrilu02_bin[] = {"nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin"}; class parameterized_bsrilu02 : public testing::TestWithParam { protected: parameterized_bsrilu02() {} virtual ~parameterized_bsrilu02() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_bsrilu02_bin : public testing::TestWithParam { protected: parameterized_bsrilu02_bin() {} virtual ~parameterized_bsrilu02_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_bsrilu02_arguments(bsrilu02_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.block_dim = std::get<1>(tup); arg.numericboost = std::get<2>(tup); arg.boosttol = std::get<3>(tup); arg.boostval = std::get<4>(tup); arg.boostvali = std::get<5>(tup); arg.dirA = std::get<6>(tup); arg.idx_base = std::get<7>(tup); arg.timing = 0; return arg; } Arguments setup_bsrilu02_arguments(bsrilu02_bin_tuple tup) { Arguments arg; arg.M = -99; arg.block_dim = std::get<0>(tup); arg.numericboost = std::get<1>(tup); arg.boosttol = std::get<2>(tup); arg.boostval = std::get<3>(tup); arg.boostvali = std::get<4>(tup); arg.dirA = std::get<5>(tup); arg.idx_base = std::get<6>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<7>(tup); // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(bsrilu02_bad_arg, bsrilu02_float) { testing_bsrilu02_bad_arg(); } TEST_P(parameterized_bsrilu02, bsrilu02_float) { Arguments arg = setup_bsrilu02_arguments(GetParam()); hipsparseStatus_t status = testing_bsrilu02(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_bsrilu02, bsrilu02_double) { Arguments arg = setup_bsrilu02_arguments(GetParam()); hipsparseStatus_t status = testing_bsrilu02(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_bsrilu02, bsrilu02_float_complex) { Arguments arg = setup_bsrilu02_arguments(GetParam()); hipsparseStatus_t status = testing_bsrilu02(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_bsrilu02, bsrilu02_double_complex) { Arguments arg = setup_bsrilu02_arguments(GetParam()); hipsparseStatus_t status = testing_bsrilu02(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_bsrilu02_bin, bsrilu02_bin_float) { Arguments arg = setup_bsrilu02_arguments(GetParam()); hipsparseStatus_t status = testing_bsrilu02(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_bsrilu02_bin, bsrilu02_bin_double) { Arguments arg = setup_bsrilu02_arguments(GetParam()); hipsparseStatus_t status = testing_bsrilu02(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(bsrilu02, parameterized_bsrilu02, testing::Combine(testing::ValuesIn(bsrilu02_M_range), testing::ValuesIn(bsrilu02_dim_range), testing::ValuesIn(bsrilu02_boost_range), testing::ValuesIn(bsrilu02_boost_tol_range), testing::ValuesIn(bsrilu02_boost_val_range), testing::ValuesIn(bsrilu02_boost_vali_range), testing::ValuesIn(bsrilu02_dir_range), testing::ValuesIn(bsrilu02_idxbase_range))); INSTANTIATE_TEST_SUITE_P(bsrilu02_bin, parameterized_bsrilu02_bin, testing::Combine(testing::ValuesIn(bsrilu02_dim_range), testing::ValuesIn(bsrilu02_boost_range), testing::ValuesIn(bsrilu02_boost_tol_range), testing::ValuesIn(bsrilu02_boost_val_range), testing::ValuesIn(bsrilu02_boost_vali_range), testing::ValuesIn(bsrilu02_dir_range), testing::ValuesIn(bsrilu02_idxbase_range), testing::ValuesIn(bsrilu02_bin))); hipSPARSE-rocm-5.7.1/clients/tests/test_bsrmm.cpp000066400000000000000000000173301447644345400216710ustar00rootroot00000000000000/* ************************************************************************ * 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_bsrmm.hpp" #include "utility.hpp" #include #include typedef hipsparseIndexBase_t base; typedef hipsparseDirection_t direction; typedef hipsparseOperation_t trans; typedef std::tuple bsrmm_tuple; typedef std::tuple bsrmm_bin_tuple; int bsrmm_M_range[] = {-1, 42, 2059}; int bsrmm_N_range[] = {-1, 7, 78}; int bsrmm_K_range[] = {-1, 50, 173, 1375}; int bsrmm_block_dim_range[] = {4, 7, 16}; double bsrmm_alpha_range[] = {-0.5}; double bsrmm_beta_range[] = {0.5}; direction bsrmm_dir_range[] = {HIPSPARSE_DIRECTION_ROW, HIPSPARSE_DIRECTION_COLUMN}; base bsrmm_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; trans bsrmm_transA_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE}; trans bsrmm_transB_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_TRANSPOSE}; int bsrmm_N_range_bin[] = {9, 17, 23}; int bsrmm_block_dim_range_bin[] = {5}; double bsrmm_alpha_range_bin[] = {0.75}; double bsrmm_beta_range_bin[] = {-0.5}; direction bsrmm_dir_range_bin[] = {HIPSPARSE_DIRECTION_COLUMN}; base bsrmm_idxbase_range_bin[] = {HIPSPARSE_INDEX_BASE_ONE}; trans bsrmm_transA_range_bin[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE}; trans bsrmm_transB_range_bin[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_TRANSPOSE}; std::string bsrmm_bin[] = {"rma10.bin", "scircuit.bin", "nos1.bin", "nos3.bin", "nos5.bin", "nos7.bin"}; class parameterized_bsrmm : public testing::TestWithParam { protected: parameterized_bsrmm() {} virtual ~parameterized_bsrmm() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_bsrmm_bin : public testing::TestWithParam { protected: parameterized_bsrmm_bin() {} virtual ~parameterized_bsrmm_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_bsrmm_arguments(bsrmm_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.K = std::get<2>(tup); arg.block_dim = std::get<3>(tup); arg.alpha = std::get<4>(tup); arg.beta = std::get<5>(tup); arg.dirA = std::get<6>(tup); arg.idx_base = std::get<7>(tup); arg.transA = std::get<8>(tup); arg.transB = std::get<9>(tup); arg.timing = 0; return arg; } Arguments setup_bsrmm_arguments(bsrmm_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = std::get<0>(tup); arg.K = -99; arg.block_dim = std::get<1>(tup); arg.alpha = std::get<2>(tup); arg.beta = std::get<3>(tup); arg.dirA = std::get<4>(tup); arg.idx_base = std::get<5>(tup); arg.transA = std::get<6>(tup); arg.transB = 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.filename = get_filename(bin_file); return arg; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(bsrmm_bad_arg, bsrmm_float) { testing_bsrmm_bad_arg(); } TEST_P(parameterized_bsrmm, bsrmm_float) { Arguments arg = setup_bsrmm_arguments(GetParam()); hipsparseStatus_t status = testing_bsrmm(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_bsrmm, bsrmm_double) { Arguments arg = setup_bsrmm_arguments(GetParam()); hipsparseStatus_t status = testing_bsrmm(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_bsrmm, bsrmm_float_complex) { Arguments arg = setup_bsrmm_arguments(GetParam()); hipsparseStatus_t status = testing_bsrmm(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_bsrmm, bsrmm_double_complex) { Arguments arg = setup_bsrmm_arguments(GetParam()); hipsparseStatus_t status = testing_bsrmm(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_bsrmm_bin, bsrmm_bin_float) { Arguments arg = setup_bsrmm_arguments(GetParam()); hipsparseStatus_t status = testing_bsrmm(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_bsrmm_bin, bsrmm_bin_double) { Arguments arg = setup_bsrmm_arguments(GetParam()); hipsparseStatus_t status = testing_bsrmm(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(bsrmm, parameterized_bsrmm, testing::Combine(testing::ValuesIn(bsrmm_M_range), testing::ValuesIn(bsrmm_N_range), testing::ValuesIn(bsrmm_K_range), testing::ValuesIn(bsrmm_block_dim_range), testing::ValuesIn(bsrmm_alpha_range), testing::ValuesIn(bsrmm_beta_range), testing::ValuesIn(bsrmm_dir_range), testing::ValuesIn(bsrmm_idxbase_range), testing::ValuesIn(bsrmm_transA_range), testing::ValuesIn(bsrmm_transB_range))); INSTANTIATE_TEST_SUITE_P(bsrmm_bin, parameterized_bsrmm_bin, testing::Combine(testing::ValuesIn(bsrmm_N_range_bin), testing::ValuesIn(bsrmm_block_dim_range_bin), testing::ValuesIn(bsrmm_alpha_range_bin), testing::ValuesIn(bsrmm_beta_range_bin), testing::ValuesIn(bsrmm_dir_range_bin), testing::ValuesIn(bsrmm_idxbase_range_bin), testing::ValuesIn(bsrmm_transA_range_bin), testing::ValuesIn(bsrmm_transB_range_bin), testing::ValuesIn(bsrmm_bin))); hipSPARSE-rocm-5.7.1/clients/tests/test_bsrmv.cpp000066400000000000000000000141461447644345400217040ustar00rootroot00000000000000/* ************************************************************************ * 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_bsrmv.hpp" #include "utility.hpp" #include #include #include typedef hipsparseIndexBase_t base; typedef hipsparseDirection_t dir; typedef std::tuple bsrmv_tuple; typedef std::tuple bsrmv_bin_tuple; int bsr_M_range[] = {-1, 0, 500, 7111}; int bsr_N_range[] = {-3, 0, 842, 4441}; int bsr_dim_range[] = {-1, 0, 1, 3, 5, 9}; std::vector bsr_alpha_range = {3.0}; std::vector bsr_beta_range = {1.0}; base bsr_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; dir bsr_dir_range[] = {HIPSPARSE_DIRECTION_ROW, HIPSPARSE_DIRECTION_COLUMN}; std::string bsr_bin[] = {"nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin"}; class parameterized_bsrmv : public testing::TestWithParam { protected: parameterized_bsrmv() {} virtual ~parameterized_bsrmv() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_bsrmv_bin : public testing::TestWithParam { protected: parameterized_bsrmv_bin() {} virtual ~parameterized_bsrmv_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_bsrmv_arguments(bsrmv_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.block_dim = std::get<4>(tup); arg.dirA = std::get<5>(tup); arg.idx_base = std::get<6>(tup); arg.timing = 0; return arg; } Arguments setup_bsrmv_arguments(bsrmv_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = -99; arg.alpha = std::get<0>(tup); arg.beta = std::get<1>(tup); arg.block_dim = std::get<2>(tup); arg.dirA = std::get<3>(tup); arg.idx_base = 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.filename = get_filename(bin_file); return arg; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(bsrmv_bad_arg, bsrmv_float) { testing_bsrmv_bad_arg(); } TEST_P(parameterized_bsrmv, bsrmv_float) { Arguments arg = setup_bsrmv_arguments(GetParam()); hipsparseStatus_t status = testing_bsrmv(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_bsrmv, bsrmv_double) { Arguments arg = setup_bsrmv_arguments(GetParam()); hipsparseStatus_t status = testing_bsrmv(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_bsrmv, bsrmv_float_complex) { Arguments arg = setup_bsrmv_arguments(GetParam()); hipsparseStatus_t status = testing_bsrmv(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_bsrmv, bsrmv_double_complex) { Arguments arg = setup_bsrmv_arguments(GetParam()); hipsparseStatus_t status = testing_bsrmv(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_bsrmv_bin, bsrmv_bin_float) { Arguments arg = setup_bsrmv_arguments(GetParam()); hipsparseStatus_t status = testing_bsrmv(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_bsrmv_bin, bsrmv_bin_double) { Arguments arg = setup_bsrmv_arguments(GetParam()); hipsparseStatus_t status = testing_bsrmv(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(bsrmv, parameterized_bsrmv, testing::Combine(testing::ValuesIn(bsr_M_range), testing::ValuesIn(bsr_N_range), testing::ValuesIn(bsr_alpha_range), testing::ValuesIn(bsr_beta_range), testing::ValuesIn(bsr_dim_range), testing::ValuesIn(bsr_dir_range), testing::ValuesIn(bsr_idxbase_range))); INSTANTIATE_TEST_SUITE_P(bsrmv_bin, parameterized_bsrmv_bin, testing::Combine(testing::ValuesIn(bsr_alpha_range), testing::ValuesIn(bsr_beta_range), testing::ValuesIn(bsr_dim_range), testing::ValuesIn(bsr_dir_range), testing::ValuesIn(bsr_idxbase_range), testing::ValuesIn(bsr_bin))); hipSPARSE-rocm-5.7.1/clients/tests/test_bsrsm2.cpp000066400000000000000000000041071447644345400217570ustar00rootroot00000000000000/* ************************************************************************ * 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_bsrsm2.hpp" #include // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(bsrsm2_bad_arg, bsrsm2_float) { testing_bsrsm2_bad_arg(); } TEST(bsrsm2, bsrsm2_float) { hipsparseStatus_t status = testing_bsrsm2(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(bsrsm2, bsrsm2_double) { hipsparseStatus_t status = testing_bsrsm2(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(bsrsm2, bsrsm2_hipComplex) { hipsparseStatus_t status = testing_bsrsm2(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(bsrsm2, bsrsm2_hipDoubleComplex) { hipsparseStatus_t status = testing_bsrsm2(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_bsrsv2.cpp000066400000000000000000000152521447644345400217730ustar00rootroot00000000000000/* ************************************************************************ * 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_bsrsv2.hpp" #include "utility.hpp" #include #include #include typedef hipsparseDirection_t dir; typedef hipsparseIndexBase_t base; typedef hipsparseOperation_t op; typedef hipsparseDiagType_t diag; typedef hipsparseFillMode_t fill; typedef std::tuple bsrsv2_tuple; typedef std::tuple bsrsv2_bin_tuple; int bsrsv2_M_range[] = {-1, 0, 647}; int bsrsv2_dim_range[] = {-1, 0, 1, 3, 9}; double bsrsv2_alpha_range[] = {2.3}; base bsrsv2_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; dir bsrsv2_dir_range[] = {HIPSPARSE_DIRECTION_ROW, HIPSPARSE_DIRECTION_COLUMN}; op bsrsv2_op_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_TRANSPOSE}; diag bsrsv2_diag_range[] = {HIPSPARSE_DIAG_TYPE_NON_UNIT}; fill bsrsv2_fill_range[] = {HIPSPARSE_FILL_MODE_LOWER, HIPSPARSE_FILL_MODE_UPPER}; std::string bsrsv2_bin[] = {"nos2.bin", "nos4.bin", "nos5.bin", "nos6.bin"}; class parameterized_bsrsv2 : public testing::TestWithParam { protected: parameterized_bsrsv2() {} virtual ~parameterized_bsrsv2() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_bsrsv2_bin : public testing::TestWithParam { protected: parameterized_bsrsv2_bin() {} virtual ~parameterized_bsrsv2_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_bsrsv2_arguments(bsrsv2_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.alpha = std::get<1>(tup); arg.idx_base = std::get<2>(tup); arg.block_dim = std::get<3>(tup); arg.dirA = std::get<4>(tup); arg.transA = std::get<5>(tup); arg.diag_type = std::get<6>(tup); arg.fill_mode = std::get<7>(tup); arg.timing = 0; return arg; } Arguments setup_bsrsv2_arguments(bsrsv2_bin_tuple tup) { Arguments arg; arg.M = -99; arg.alpha = std::get<0>(tup); arg.idx_base = std::get<1>(tup); arg.block_dim = std::get<2>(tup); arg.dirA = std::get<3>(tup); arg.transA = std::get<4>(tup); arg.diag_type = std::get<5>(tup); arg.fill_mode = std::get<6>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<7>(tup); // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(bsrsv2_bad_arg, bsrsv2_float) { testing_bsrsv2_bad_arg(); } TEST_P(parameterized_bsrsv2, bsrsv2_float) { Arguments arg = setup_bsrsv2_arguments(GetParam()); hipsparseStatus_t status = testing_bsrsv2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_bsrsv2, bsrsv2_double) { Arguments arg = setup_bsrsv2_arguments(GetParam()); hipsparseStatus_t status = testing_bsrsv2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_bsrsv2, bsrsv2_float_complex) { Arguments arg = setup_bsrsv2_arguments(GetParam()); hipsparseStatus_t status = testing_bsrsv2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_bsrsv2, bsrsv2_double_complex) { Arguments arg = setup_bsrsv2_arguments(GetParam()); hipsparseStatus_t status = testing_bsrsv2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_bsrsv2_bin, bsrsv2_bin_float) { Arguments arg = setup_bsrsv2_arguments(GetParam()); hipsparseStatus_t status = testing_bsrsv2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_bsrsv2_bin, bsrsv2_bin_double) { Arguments arg = setup_bsrsv2_arguments(GetParam()); hipsparseStatus_t status = testing_bsrsv2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(bsrsv2, parameterized_bsrsv2, testing::Combine(testing::ValuesIn(bsrsv2_M_range), testing::ValuesIn(bsrsv2_alpha_range), testing::ValuesIn(bsrsv2_idxbase_range), testing::ValuesIn(bsrsv2_dim_range), testing::ValuesIn(bsrsv2_dir_range), testing::ValuesIn(bsrsv2_op_range), testing::ValuesIn(bsrsv2_diag_range), testing::ValuesIn(bsrsv2_fill_range))); INSTANTIATE_TEST_SUITE_P(bsrsv2_bin, parameterized_bsrsv2_bin, testing::Combine(testing::ValuesIn(bsrsv2_alpha_range), testing::ValuesIn(bsrsv2_idxbase_range), testing::ValuesIn(bsrsv2_dim_range), testing::ValuesIn(bsrsv2_dir_range), testing::ValuesIn(bsrsv2_op_range), testing::ValuesIn(bsrsv2_diag_range), testing::ValuesIn(bsrsv2_fill_range), testing::ValuesIn(bsrsv2_bin))); hipSPARSE-rocm-5.7.1/clients/tests/test_bsrxmv.cpp000066400000000000000000000043301447644345400220660ustar00rootroot00000000000000/* ************************************************************************ * 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_bsrxmv.hpp" #include // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) 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) { hipsparseStatus_t status = testing_bsrxmv(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(bsrxmv, bsrxmv_double) { hipsparseStatus_t status = testing_bsrxmv(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(bsrxmv, bsrxmv_hipComplex) { hipsparseStatus_t status = testing_bsrxmv(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endifhipSPARSE-rocm-5.7.1/clients/tests/test_coo2csr.cpp000066400000000000000000000113011447644345400221130ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_coo2csr.hpp" #include "utility.hpp" #include #include #include typedef std::tuple coo2csr_tuple; typedef std::tuple coo2csr_bin_tuple; int coo2csr_M_range[] = {-1, 0, 10, 500, 872, 1000}; int coo2csr_N_range[] = {-3, 0, 33, 242, 623, 1000}; hipsparseIndexBase_t coo2csr_idx_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; std::string coo2csr_bin[] = {"rma10.bin", "mac_econ_fwd500.bin", "bibd_22_8.bin", "mc2depi.bin", "scircuit.bin", "ASIC_320k.bin", "bmwcra_1.bin", "nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin", "amazon0312.bin", "Chebyshev4.bin", "sme3Dc.bin", "webbase-1M.bin", "shipsec1.bin"}; class parameterized_coo2csr : public testing::TestWithParam { protected: parameterized_coo2csr() {} virtual ~parameterized_coo2csr() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_coo2csr_bin : public testing::TestWithParam { protected: parameterized_coo2csr_bin() {} virtual ~parameterized_coo2csr_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_coo2csr_arguments(coo2csr_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.idx_base = std::get<2>(tup); arg.timing = 0; return arg; } Arguments setup_coo2csr_arguments(coo2csr_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = -99; arg.idx_base = std::get<0>(tup); arg.timing = 0; std::string bin_file = std::get<1>(tup); arg.filename = get_filename(bin_file); return arg; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(coo2csr_bad_arg, coo2csr) { testing_coo2csr_bad_arg(); } TEST_P(parameterized_coo2csr, coo2csr) { Arguments arg = setup_coo2csr_arguments(GetParam()); hipsparseStatus_t status = testing_coo2csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_coo2csr_bin, coo2csr_bin) { Arguments arg = setup_coo2csr_arguments(GetParam()); hipsparseStatus_t status = testing_coo2csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(coo2csr, parameterized_coo2csr, testing::Combine(testing::ValuesIn(coo2csr_M_range), testing::ValuesIn(coo2csr_N_range), testing::ValuesIn(coo2csr_idx_base_range))); INSTANTIATE_TEST_SUITE_P(coo2csr_bin, parameterized_coo2csr_bin, testing::Combine(testing::ValuesIn(coo2csr_idx_base_range), testing::ValuesIn(coo2csr_bin))); hipSPARSE-rocm-5.7.1/clients/tests/test_coosort.cpp000066400000000000000000000122251447644345400222370ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_coosort.hpp" #include "utility.hpp" #include #include #include typedef std::tuple coosort_tuple; typedef std::tuple coosort_bin_tuple; int coosort_M_range[] = {-1, 0, 10, 500, 3872, 10000}; int coosort_N_range[] = {-3, 0, 33, 242, 1623, 10000}; hipsparseOperation_t coosort_trans[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_TRANSPOSE}; #if defined(__HIP_PLATFORM_AMD__) int coosort_perm[] = {0, 1}; #elif defined(__HIP_PLATFORM_NVIDIA__) // cusparse does not allow without permutation int coosort_perm[] = {1}; #endif hipsparseIndexBase_t coosort_base[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; std::string coosort_bin[] = {"mc2depi.bin", "scircuit.bin", "nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin", "shipsec1.bin"}; class parameterized_coosort : public testing::TestWithParam { protected: parameterized_coosort() {} virtual ~parameterized_coosort() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_coosort_bin : public testing::TestWithParam { protected: parameterized_coosort_bin() {} virtual ~parameterized_coosort_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_coosort_arguments(coosort_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.transA = std::get<2>(tup); arg.temp = std::get<3>(tup); arg.idx_base = std::get<4>(tup); arg.timing = 0; return arg; } Arguments setup_coosort_arguments(coosort_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = -99; arg.transA = std::get<0>(tup); arg.temp = std::get<1>(tup); arg.idx_base = 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.filename = get_filename(bin_file); return arg; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(coosort_bad_arg, coosort) { testing_coosort_bad_arg(); } TEST_P(parameterized_coosort, coosort) { Arguments arg = setup_coosort_arguments(GetParam()); hipsparseStatus_t status = testing_coosort(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_coosort_bin, coosort_bin) { Arguments arg = setup_coosort_arguments(GetParam()); hipsparseStatus_t status = testing_coosort(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(coosort, parameterized_coosort, testing::Combine(testing::ValuesIn(coosort_M_range), testing::ValuesIn(coosort_N_range), testing::ValuesIn(coosort_trans), testing::ValuesIn(coosort_perm), testing::ValuesIn(coosort_base))); INSTANTIATE_TEST_SUITE_P(coosort_bin, parameterized_coosort_bin, testing::Combine(testing::ValuesIn(coosort_trans), testing::ValuesIn(coosort_perm), testing::ValuesIn(coosort_base), testing::ValuesIn(coosort_bin))); hipSPARSE-rocm-5.7.1/clients/tests/test_csc2dense.cpp000066400000000000000000000074251447644345400224260ustar00rootroot00000000000000/* ************************************************************************ * 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_csc2dense.hpp" #include "utility.hpp" #include #include #include typedef hipsparseIndexBase_t base; typedef std::tuple csc2dense_tuple; int csc2dense_M_range[] = {-1, 0, 10, 500, 872, 1000}; int csc2dense_N_range[] = {-3, 0, 33, 242, 623, 1000}; int csc2dense_LD_range[] = {5, 500, 1000}; base csc2dense_idx_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; class parameterized_csc2dense : public testing::TestWithParam { protected: parameterized_csc2dense() {} virtual ~parameterized_csc2dense() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_csc2dense_arguments(csc2dense_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.lda = std::get<2>(tup); arg.idx_base = std::get<3>(tup); return arg; } // Only run tests for CUDA 11.1 or greater (removed in cusparse 12.0.0) #if(!defined(CUDART_VERSION) || (CUDART_VERSION >= 11010 & CUDART_VERSION < 12000)) TEST(csc2dense_bad_arg, csc2dense) { testing_csc2dense_bad_arg(); } TEST_P(parameterized_csc2dense, csc2dense_float) { Arguments arg = setup_csc2dense_arguments(GetParam()); hipsparseStatus_t status = testing_csc2dense(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csc2dense, csc2dense_double) { Arguments arg = setup_csc2dense_arguments(GetParam()); hipsparseStatus_t status = testing_csc2dense(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csc2dense, csc2dense_float_complex) { Arguments arg = setup_csc2dense_arguments(GetParam()); hipsparseStatus_t status = testing_csc2dense(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csc2dense, csc2dense_double_complex) { Arguments arg = setup_csc2dense_arguments(GetParam()); hipsparseStatus_t status = testing_csc2dense(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(csc2dense, parameterized_csc2dense, testing::Combine(testing::ValuesIn(csc2dense_M_range), testing::ValuesIn(csc2dense_N_range), testing::ValuesIn(csc2dense_LD_range), testing::ValuesIn(csc2dense_idx_base_range))); hipSPARSE-rocm-5.7.1/clients/tests/test_cscsort.cpp000066400000000000000000000120521447644345400222250ustar00rootroot00000000000000/* ************************************************************************ * 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. * * ************************************************************************ */ #include "testing_cscsort.hpp" #include "utility.hpp" #include #include #include typedef std::tuple cscsort_tuple; typedef std::tuple cscsort_bin_tuple; int cscsort_M_range[] = {-1, 0, 10, 500, 872, 1000}; int cscsort_N_range[] = {-3, 0, 33, 242, 623, 1000}; int cscsort_perm[] = {0, 1}; hipsparseIndexBase_t cscsort_base[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; std::string cscsort_bin[] = {"rma10.bin", "mac_econ_fwd500.bin", "bibd_22_8.bin", "mc2depi.bin", "scircuit.bin", "ASIC_320k.bin", "bmwcra_1.bin", "nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin", "amazon0312.bin", "Chebyshev4.bin", "sme3Dc.bin", "webbase-1M.bin", "shipsec1.bin"}; class parameterized_cscsort : public testing::TestWithParam { protected: parameterized_cscsort() {} virtual ~parameterized_cscsort() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_cscsort_bin : public testing::TestWithParam { protected: parameterized_cscsort_bin() {} virtual ~parameterized_cscsort_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_cscsort_arguments(cscsort_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.temp = std::get<2>(tup); arg.idx_base = std::get<3>(tup); arg.timing = 0; return arg; } Arguments setup_cscsort_arguments(cscsort_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = -99; arg.temp = std::get<0>(tup); arg.idx_base = std::get<1>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<2>(tup); // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(cscsort_bad_arg, cscsort) { testing_cscsort_bad_arg(); } TEST_P(parameterized_cscsort, cscsort) { Arguments arg = setup_cscsort_arguments(GetParam()); hipsparseStatus_t status = testing_cscsort(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_cscsort_bin, cscsort_bin) { Arguments arg = setup_cscsort_arguments(GetParam()); hipsparseStatus_t status = testing_cscsort(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(cscsort, parameterized_cscsort, testing::Combine(testing::ValuesIn(cscsort_M_range), testing::ValuesIn(cscsort_N_range), testing::ValuesIn(cscsort_perm), testing::ValuesIn(cscsort_base))); INSTANTIATE_TEST_SUITE_P(cscsort_bin, parameterized_cscsort_bin, testing::Combine(testing::ValuesIn(cscsort_perm), testing::ValuesIn(cscsort_base), testing::ValuesIn(cscsort_bin))); hipSPARSE-rocm-5.7.1/clients/tests/test_csr2bsr.cpp000066400000000000000000000152221447644345400221270ustar00rootroot00000000000000/* ************************************************************************ * 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_csr2bsr.hpp" #include "utility.hpp" #include #include #include typedef std::tuple csr2bsr_tuple; typedef std:: tuple csr2bsr_bin_tuple; // Random matrices int csr2bsr_M_range[] = {0, 872, 13095, 21453}; int csr2bsr_N_range[] = {0, 623, 12766, 29285}; int csr2bsr_block_dim_range[] = {1, 2, 4, 7, 16}; hipsparseIndexBase_t csr2bsr_csr_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO}; hipsparseIndexBase_t csr2bsr_bsr_base_range[] = {HIPSPARSE_INDEX_BASE_ONE}; hipsparseDirection_t csr2bsr_dir_range[] = {HIPSPARSE_DIRECTION_ROW, HIPSPARSE_DIRECTION_COLUMN}; // Matrices from files (float and double) int csr2bsr_block_dim_range_bin[] = {5}; hipsparseIndexBase_t csr2bsr_csr_base_range_bin[] = {HIPSPARSE_INDEX_BASE_ONE}; hipsparseIndexBase_t csr2bsr_bsr_base_range_bin[] = {HIPSPARSE_INDEX_BASE_ONE}; hipsparseDirection_t csr2bsr_dir_range_bin[] = {HIPSPARSE_DIRECTION_ROW, HIPSPARSE_DIRECTION_COLUMN}; std::string csr2bsr_bin[] = {"scircuit.bin", "nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin", "sme3Dc.bin"}; class parameterized_csr2bsr : public testing::TestWithParam { protected: parameterized_csr2bsr() {} virtual ~parameterized_csr2bsr() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_csr2bsr_bin : public testing::TestWithParam { protected: parameterized_csr2bsr_bin() {} virtual ~parameterized_csr2bsr_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_csr2bsr_arguments(csr2bsr_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.block_dim = std::get<2>(tup); arg.idx_base = std::get<3>(tup); arg.idx_base2 = std::get<4>(tup); arg.dirA = std::get<5>(tup); arg.timing = 0; return arg; } Arguments setup_csr2bsr_arguments(csr2bsr_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = -99; arg.block_dim = std::get<0>(tup); arg.idx_base = std::get<1>(tup); arg.idx_base2 = std::get<2>(tup); arg.dirA = std::get<3>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<4>(tup); // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(csr2bsr_bad_arg, csr2bsr) { testing_csr2bsr_bad_arg(); } TEST_P(parameterized_csr2bsr, csr2bsr_float) { Arguments arg = setup_csr2bsr_arguments(GetParam()); hipsparseStatus_t status = testing_csr2bsr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csr2bsr, csr2bsr_double) { Arguments arg = setup_csr2bsr_arguments(GetParam()); hipsparseStatus_t status = testing_csr2bsr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csr2bsr, csr2bsr_float_complex) { Arguments arg = setup_csr2bsr_arguments(GetParam()); hipsparseStatus_t status = testing_csr2bsr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csr2bsr, csr2bsr_double_complex) { Arguments arg = setup_csr2bsr_arguments(GetParam()); hipsparseStatus_t status = testing_csr2bsr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csr2bsr_bin, csr2bsr_bin_float) { Arguments arg = setup_csr2bsr_arguments(GetParam()); hipsparseStatus_t status = testing_csr2bsr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csr2bsr_bin, csr2bsr_bin_double) { Arguments arg = setup_csr2bsr_arguments(GetParam()); hipsparseStatus_t status = testing_csr2bsr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(csr2bsr, parameterized_csr2bsr, testing::Combine(testing::ValuesIn(csr2bsr_M_range), testing::ValuesIn(csr2bsr_N_range), testing::ValuesIn(csr2bsr_block_dim_range), testing::ValuesIn(csr2bsr_csr_base_range), testing::ValuesIn(csr2bsr_bsr_base_range), testing::ValuesIn(csr2bsr_dir_range))); INSTANTIATE_TEST_SUITE_P(csr2bsr_bin, parameterized_csr2bsr_bin, testing::Combine(testing::ValuesIn(csr2bsr_block_dim_range_bin), testing::ValuesIn(csr2bsr_csr_base_range_bin), testing::ValuesIn(csr2bsr_bsr_base_range_bin), testing::ValuesIn(csr2bsr_dir_range_bin), testing::ValuesIn(csr2bsr_bin))); hipSPARSE-rocm-5.7.1/clients/tests/test_csr2coo.cpp000066400000000000000000000114221447644345400221170ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_csr2coo.hpp" #include "utility.hpp" #include #include #include typedef std::tuple csr2coo_tuple; typedef std::tuple csr2coo_bin_tuple; int csr2coo_M_range[] = {-1, 0, 10, 500, 872, 1000}; int csr2coo_N_range[] = {-3, 0, 33, 242, 623, 1000}; hipsparseIndexBase_t csr2coo_idx_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; std::string csr2coo_bin[] = {"rma10.bin", "mac_econ_fwd500.bin", "bibd_22_8.bin", "mc2depi.bin", "scircuit.bin", "ASIC_320k.bin", "bmwcra_1.bin", "nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin", "amazon0312.bin", "Chebyshev4.bin", "sme3Dc.bin", "webbase-1M.bin", "shipsec1.bin"}; class parameterized_csr2coo : public testing::TestWithParam { protected: parameterized_csr2coo() {} virtual ~parameterized_csr2coo() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_csr2coo_bin : public testing::TestWithParam { protected: parameterized_csr2coo_bin() {} virtual ~parameterized_csr2coo_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_csr2coo_arguments(csr2coo_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.idx_base = std::get<2>(tup); arg.timing = 0; return arg; } Arguments setup_csr2coo_arguments(csr2coo_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = -99; arg.idx_base = std::get<0>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<1>(tup); // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(csr2coo_bad_arg, csr2coo) { testing_csr2coo_bad_arg(); } TEST_P(parameterized_csr2coo, csr2coo) { Arguments arg = setup_csr2coo_arguments(GetParam()); hipsparseStatus_t status = testing_csr2coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csr2coo_bin, csr2coo_bin) { Arguments arg = setup_csr2coo_arguments(GetParam()); hipsparseStatus_t status = testing_csr2coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(csr2coo, parameterized_csr2coo, testing::Combine(testing::ValuesIn(csr2coo_M_range), testing::ValuesIn(csr2coo_N_range), testing::ValuesIn(csr2coo_idx_base_range))); INSTANTIATE_TEST_SUITE_P(csr2coo_bin, parameterized_csr2coo_bin, testing::Combine(testing::ValuesIn(csr2coo_idx_base_range), testing::ValuesIn(csr2coo_bin))); hipSPARSE-rocm-5.7.1/clients/tests/test_csr2csc.cpp000066400000000000000000000133671447644345400221210ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_csr2csc.hpp" #include "utility.hpp" #include #include #include typedef std::tuple csr2csc_tuple; typedef std::tuple csr2csc_bin_tuple; int csr2csc_M_range[] = {-1, 0, 10, 500, 872, 1000}; int csr2csc_N_range[] = {-3, 0, 33, 242, 623, 1000}; hipsparseAction_t csr2csc_action_range[] = {HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_ACTION_SYMBOLIC}; hipsparseIndexBase_t csr2csc_csr_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; std::string csr2csc_bin[] = {"rma10.bin", "mc2depi.bin", "scircuit.bin", "nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin", "webbase-1M.bin", "shipsec1.bin"}; class parameterized_csr2csc : public testing::TestWithParam { protected: parameterized_csr2csc() {} virtual ~parameterized_csr2csc() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_csr2csc_bin : public testing::TestWithParam { protected: parameterized_csr2csc_bin() {} virtual ~parameterized_csr2csc_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_csr2csc_arguments(csr2csc_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.action = std::get<2>(tup); arg.idx_base = std::get<3>(tup); arg.timing = 0; return arg; } Arguments setup_csr2csc_arguments(csr2csc_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = -99; arg.action = std::get<0>(tup); arg.idx_base = std::get<1>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<2>(tup); // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(csr2csc_bad_arg, csr2csc) { testing_csr2csc_bad_arg(); } TEST_P(parameterized_csr2csc, csr2csc_float) { Arguments arg = setup_csr2csc_arguments(GetParam()); hipsparseStatus_t status = testing_csr2csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csr2csc, csr2csc_double) { Arguments arg = setup_csr2csc_arguments(GetParam()); hipsparseStatus_t status = testing_csr2csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csr2csc, csr2csc_float_complex) { Arguments arg = setup_csr2csc_arguments(GetParam()); hipsparseStatus_t status = testing_csr2csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csr2csc, csr2csc_double_complex) { Arguments arg = setup_csr2csc_arguments(GetParam()); hipsparseStatus_t status = testing_csr2csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csr2csc_bin, csr2csc_bin_float) { Arguments arg = setup_csr2csc_arguments(GetParam()); hipsparseStatus_t status = testing_csr2csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csr2csc_bin, csr2csc_bin_double) { Arguments arg = setup_csr2csc_arguments(GetParam()); hipsparseStatus_t status = testing_csr2csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(csr2csc, parameterized_csr2csc, testing::Combine(testing::ValuesIn(csr2csc_M_range), testing::ValuesIn(csr2csc_N_range), testing::ValuesIn(csr2csc_action_range), testing::ValuesIn(csr2csc_csr_base_range))); INSTANTIATE_TEST_SUITE_P(csr2csc_bin, parameterized_csr2csc_bin, testing::Combine(testing::ValuesIn(csr2csc_action_range), testing::ValuesIn(csr2csc_csr_base_range), testing::ValuesIn(csr2csc_bin))); hipSPARSE-rocm-5.7.1/clients/tests/test_csr2csc_ex2.cpp000066400000000000000000000140121447644345400226630ustar00rootroot00000000000000/* ************************************************************************ * 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. * * ************************************************************************ */ #include "testing_csr2csc_ex2.hpp" #include "utility.hpp" #include #include #include typedef std::tuple csr2csc_ex2_tuple; typedef std::tuple csr2csc_ex2_bin_tuple; int csr2csc_ex2_M_range[] = {-1, 0, 10, 500, 872, 1000}; int csr2csc_ex2_N_range[] = {-3, 0, 33, 242, 623, 1000}; hipsparseAction_t csr2csc_ex2_action_range[] = {HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_ACTION_SYMBOLIC}; hipsparseIndexBase_t csr2csc_ex2_csr_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; std::string csr2csc_ex2_bin[] = {"rma10.bin", "mc2depi.bin", "scircuit.bin", "nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin", "webbase-1M.bin", "shipsec1.bin"}; class parameterized_csr2csc_ex2 : public testing::TestWithParam { protected: parameterized_csr2csc_ex2() {} virtual ~parameterized_csr2csc_ex2() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_csr2csc_ex2_bin : public testing::TestWithParam { protected: parameterized_csr2csc_ex2_bin() {} virtual ~parameterized_csr2csc_ex2_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_csr2csc_ex2_arguments(csr2csc_ex2_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.action = std::get<2>(tup); arg.idx_base = std::get<3>(tup); arg.timing = 0; return arg; } Arguments setup_csr2csc_ex2_arguments(csr2csc_ex2_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = -99; arg.action = std::get<0>(tup); arg.idx_base = std::get<1>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<2>(tup); // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(csr2csc_ex2_bad_arg, csr2csc_ex2) { testing_csr2csc_ex2_bad_arg(); } TEST_P(parameterized_csr2csc_ex2, csr2csc_ex2_float) { Arguments arg = setup_csr2csc_ex2_arguments(GetParam()); hipsparseStatus_t status = testing_csr2csc_ex2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csr2csc_ex2, csr2csc_ex2_double) { Arguments arg = setup_csr2csc_ex2_arguments(GetParam()); hipsparseStatus_t status = testing_csr2csc_ex2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csr2csc_ex2, csr2csc_ex2_float_complex) { Arguments arg = setup_csr2csc_ex2_arguments(GetParam()); hipsparseStatus_t status = testing_csr2csc_ex2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csr2csc_ex2, csr2csc_ex2_double_complex) { Arguments arg = setup_csr2csc_ex2_arguments(GetParam()); hipsparseStatus_t status = testing_csr2csc_ex2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csr2csc_ex2_bin, csr2csc_ex2_bin_float) { Arguments arg = setup_csr2csc_ex2_arguments(GetParam()); hipsparseStatus_t status = testing_csr2csc_ex2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csr2csc_ex2_bin, csr2csc_ex2_bin_double) { Arguments arg = setup_csr2csc_ex2_arguments(GetParam()); hipsparseStatus_t status = testing_csr2csc_ex2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(csr2csc_ex2, parameterized_csr2csc_ex2, testing::Combine(testing::ValuesIn(csr2csc_ex2_M_range), testing::ValuesIn(csr2csc_ex2_N_range), testing::ValuesIn(csr2csc_ex2_action_range), testing::ValuesIn(csr2csc_ex2_csr_base_range))); INSTANTIATE_TEST_SUITE_P(csr2csc_ex2_bin, parameterized_csr2csc_ex2_bin, testing::Combine(testing::ValuesIn(csr2csc_ex2_action_range), testing::ValuesIn(csr2csc_ex2_csr_base_range), testing::ValuesIn(csr2csc_ex2_bin))); hipSPARSE-rocm-5.7.1/clients/tests/test_csr2csr_compress.cpp000066400000000000000000000135071447644345400240470ustar00rootroot00000000000000/* ************************************************************************ * 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_csr2csr_compress.hpp" #include "utility.hpp" #include #include #include typedef std::tuple csr2csr_compress_tuple; typedef std::tuple csr2csr_compress_bin_tuple; int csr2csr_compress_M_range[] = {-1, 10, 500, 872, 9375, 30327}; int csr2csr_compress_N_range[] = {-3, 33, 242, 623, 9184, 30645}; double csr2csr_compress_alpha_range[] = {-0.001, 0.0, 0.08736, 0.33333, 1.7}; hipsparseIndexBase_t csr2csr_compress_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; std::string csr2csr_compress_bin[] = {"nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin"}; class parameterized_csr2csr_compress : public testing::TestWithParam { protected: parameterized_csr2csr_compress() {} virtual ~parameterized_csr2csr_compress() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_csr2csr_compress_bin : public testing::TestWithParam { protected: parameterized_csr2csr_compress_bin() {} virtual ~parameterized_csr2csr_compress_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_csr2csr_compress_arguments(csr2csr_compress_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.alpha = std::get<2>(tup); arg.idx_base = std::get<3>(tup); arg.timing = 0; return arg; } Arguments setup_csr2csr_compress_arguments(csr2csr_compress_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = -99; arg.alpha = std::get<0>(tup); arg.idx_base = std::get<1>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<2>(tup); // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(csr2csr_compress_bad_arg, csr2csr_compress) { testing_csr2csr_compress_bad_arg(); } TEST_P(parameterized_csr2csr_compress, csr2csr_compress_float) { Arguments arg = setup_csr2csr_compress_arguments(GetParam()); hipsparseStatus_t status = testing_csr2csr_compress(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csr2csr_compress, csr2csr_compress_double) { Arguments arg = setup_csr2csr_compress_arguments(GetParam()); hipsparseStatus_t status = testing_csr2csr_compress(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csr2csr_compress, csr2csr_compress_float_complex) { Arguments arg = setup_csr2csr_compress_arguments(GetParam()); hipsparseStatus_t status = testing_csr2csr_compress(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csr2csr_compress, csr2csr_compress_double_complex) { Arguments arg = setup_csr2csr_compress_arguments(GetParam()); hipsparseStatus_t status = testing_csr2csr_compress(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csr2csr_compress_bin, csr2csr_compress_bin_float) { Arguments arg = setup_csr2csr_compress_arguments(GetParam()); hipsparseStatus_t status = testing_csr2csr_compress(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csr2csr_compress_bin, csr2csr_compress_bin_double) { Arguments arg = setup_csr2csr_compress_arguments(GetParam()); hipsparseStatus_t status = testing_csr2csr_compress(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(csr2csr_compress, parameterized_csr2csr_compress, testing::Combine(testing::ValuesIn(csr2csr_compress_M_range), testing::ValuesIn(csr2csr_compress_N_range), testing::ValuesIn(csr2csr_compress_alpha_range), testing::ValuesIn(csr2csr_compress_base_range))); INSTANTIATE_TEST_SUITE_P(csr2csr_compress_bin, parameterized_csr2csr_compress_bin, testing::Combine(testing::ValuesIn(csr2csr_compress_alpha_range), testing::ValuesIn(csr2csr_compress_base_range), testing::ValuesIn(csr2csr_compress_bin))); hipSPARSE-rocm-5.7.1/clients/tests/test_csr2dense.cpp000066400000000000000000000074251447644345400224450ustar00rootroot00000000000000/* ************************************************************************ * 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_csr2dense.hpp" #include "utility.hpp" #include #include #include typedef hipsparseIndexBase_t base; typedef std::tuple csr2dense_tuple; int csr2dense_M_range[] = {-1, 0, 10, 500, 872, 1000}; int csr2dense_N_range[] = {-3, 0, 33, 242, 623, 1000}; int csr2dense_LD_range[] = {5, 500, 1000}; base csr2dense_idx_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; class parameterized_csr2dense : public testing::TestWithParam { protected: parameterized_csr2dense() {} virtual ~parameterized_csr2dense() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_csr2dense_arguments(csr2dense_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.lda = std::get<2>(tup); arg.idx_base = std::get<3>(tup); return arg; } // Only run tests for CUDA 11.1 or greater (removed in cusparse 12.0.0) #if(!defined(CUDART_VERSION) || (CUDART_VERSION >= 11010 & CUDART_VERSION < 12000)) TEST(csr2dense_bad_arg, csr2dense) { testing_csr2dense_bad_arg(); } TEST_P(parameterized_csr2dense, csr2dense_float) { Arguments arg = setup_csr2dense_arguments(GetParam()); hipsparseStatus_t status = testing_csr2dense(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csr2dense, csr2dense_double) { Arguments arg = setup_csr2dense_arguments(GetParam()); hipsparseStatus_t status = testing_csr2dense(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csr2dense, csr2dense_float_complex) { Arguments arg = setup_csr2dense_arguments(GetParam()); hipsparseStatus_t status = testing_csr2dense(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csr2dense, csr2dense_double_complex) { Arguments arg = setup_csr2dense_arguments(GetParam()); hipsparseStatus_t status = testing_csr2dense(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(csr2dense, parameterized_csr2dense, testing::Combine(testing::ValuesIn(csr2dense_M_range), testing::ValuesIn(csr2dense_N_range), testing::ValuesIn(csr2dense_LD_range), testing::ValuesIn(csr2dense_idx_base_range))); hipSPARSE-rocm-5.7.1/clients/tests/test_csr2gebsr.cpp000066400000000000000000000165571447644345400224570ustar00rootroot00000000000000/* ************************************************************************ * 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_csr2gebsr.hpp" #include "utility.hpp" #include #include #include typedef std:: tuple csr2gebsr_tuple; typedef std:: tuple csr2gebsr_bin_tuple; // Random matrices int csr2gebsr_M_range[] = {-1, 0, 2, 13095}; int csr2gebsr_N_range[] = {-3, 0, 2, 12766}; int csr2gebsr_row_block_dim_range[] = {-1, 0, 1, 2, 7, 16}; int csr2gebsr_col_block_dim_range[] = {-1, 0, 1, 2}; hipsparseIndexBase_t csr2gebsr_csr_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO}; hipsparseIndexBase_t csr2gebsr_bsr_base_range[] = {HIPSPARSE_INDEX_BASE_ONE}; hipsparseDirection_t csr2gebsr_dir_range[] = {HIPSPARSE_DIRECTION_ROW, HIPSPARSE_DIRECTION_COLUMN}; // Matrices from files (float and double) int csr2gebsr_row_block_dim_range_bin[] = {5}; int csr2gebsr_col_block_dim_range_bin[] = {5}; hipsparseIndexBase_t csr2gebsr_csr_base_range_bin[] = {HIPSPARSE_INDEX_BASE_ONE}; hipsparseIndexBase_t csr2gebsr_bsr_base_range_bin[] = {HIPSPARSE_INDEX_BASE_ONE}; hipsparseDirection_t csr2gebsr_dir_range_bin[] = {HIPSPARSE_DIRECTION_ROW, HIPSPARSE_DIRECTION_COLUMN}; std::string csr2gebsr_bin[] = {"rma10.bin", "mac_econ_fwd500.bin", "scircuit.bin", "bmwcra_1.bin", "nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin"}; class parameterized_csr2gebsr : public testing::TestWithParam { protected: parameterized_csr2gebsr() {} virtual ~parameterized_csr2gebsr() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_csr2gebsr_bin : public testing::TestWithParam { protected: parameterized_csr2gebsr_bin() {} virtual ~parameterized_csr2gebsr_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_csr2gebsr_arguments(csr2gebsr_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.row_block_dimA = std::get<2>(tup); arg.col_block_dimA = std::get<3>(tup); arg.idx_base = std::get<4>(tup); arg.idx_base2 = std::get<5>(tup); arg.dirA = std::get<6>(tup); arg.timing = 0; return arg; } Arguments setup_csr2gebsr_arguments(csr2gebsr_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = -99; arg.row_block_dimA = std::get<0>(tup); arg.col_block_dimA = std::get<1>(tup); arg.idx_base = std::get<2>(tup); arg.idx_base2 = std::get<3>(tup); arg.dirA = 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.filename = get_filename(bin_file); return arg; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(csr2gebsr_bad_arg, csr2gebsr) { testing_csr2gebsr_bad_arg(); } TEST_P(parameterized_csr2gebsr, csr2gebsr_float) { Arguments arg = setup_csr2gebsr_arguments(GetParam()); hipsparseStatus_t status = testing_csr2gebsr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csr2gebsr, csr2gebsr_double) { Arguments arg = setup_csr2gebsr_arguments(GetParam()); hipsparseStatus_t status = testing_csr2gebsr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csr2gebsr, csr2gebsr_float_complex) { Arguments arg = setup_csr2gebsr_arguments(GetParam()); hipsparseStatus_t status = testing_csr2gebsr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csr2gebsr, csr2gebsr_double_complex) { Arguments arg = setup_csr2gebsr_arguments(GetParam()); hipsparseStatus_t status = testing_csr2gebsr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csr2gebsr_bin, csr2gebsr_bin_float) { Arguments arg = setup_csr2gebsr_arguments(GetParam()); hipsparseStatus_t status = testing_csr2gebsr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csr2gebsr_bin, csr2gebsr_bin_double) { Arguments arg = setup_csr2gebsr_arguments(GetParam()); hipsparseStatus_t status = testing_csr2gebsr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(csr2gebsr, parameterized_csr2gebsr, testing::Combine(testing::ValuesIn(csr2gebsr_M_range), testing::ValuesIn(csr2gebsr_N_range), testing::ValuesIn(csr2gebsr_row_block_dim_range), testing::ValuesIn(csr2gebsr_col_block_dim_range), testing::ValuesIn(csr2gebsr_bsr_base_range), testing::ValuesIn(csr2gebsr_csr_base_range), testing::ValuesIn(csr2gebsr_dir_range))); INSTANTIATE_TEST_SUITE_P(csr2gebsr_bin, parameterized_csr2gebsr_bin, testing::Combine(testing::ValuesIn(csr2gebsr_row_block_dim_range_bin), testing::ValuesIn(csr2gebsr_col_block_dim_range_bin), testing::ValuesIn(csr2gebsr_bsr_base_range_bin), testing::ValuesIn(csr2gebsr_csr_base_range_bin), testing::ValuesIn(csr2gebsr_dir_range_bin), testing::ValuesIn(csr2gebsr_bin))); hipSPARSE-rocm-5.7.1/clients/tests/test_csr2hyb.cpp000066400000000000000000000133241447644345400221240ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_csr2hyb.hpp" #include "utility.hpp" #include #include #include typedef std::tuple csr2hyb_tuple; typedef std::tuple csr2hyb_bin_tuple; int csr2hyb_M_range[] = {-1, 0, 10, 500, 872, 1000}; int csr2hyb_N_range[] = {-3, 0, 33, 242, 623, 1000}; hipsparseIndexBase_t csr2hyb_idx_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; hipsparseHybPartition_t csr2hyb_partition[] = {HIPSPARSE_HYB_PARTITION_AUTO, HIPSPARSE_HYB_PARTITION_MAX, HIPSPARSE_HYB_PARTITION_USER}; int csr2hyb_ELL_range[] = {-33, -1, 0, INT32_MAX}; std::string csr2hyb_bin[] = {"nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin"}; class parameterized_csr2hyb : public testing::TestWithParam { protected: parameterized_csr2hyb() {} virtual ~parameterized_csr2hyb() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_csr2hyb_bin : public testing::TestWithParam { protected: parameterized_csr2hyb_bin() {} virtual ~parameterized_csr2hyb_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_csr2hyb_arguments(csr2hyb_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.idx_base = std::get<2>(tup); arg.part = std::get<3>(tup); arg.ell_width = std::get<4>(tup); arg.timing = 0; return arg; } Arguments setup_csr2hyb_arguments(csr2hyb_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = -99; arg.idx_base = std::get<0>(tup); arg.part = std::get<1>(tup); arg.ell_width = 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.filename = get_filename(bin_file); return arg; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(csr2hyb_bad_arg, csr2hyb) { testing_csr2hyb_bad_arg(); } TEST_P(parameterized_csr2hyb, csr2hyb_float) { Arguments arg = setup_csr2hyb_arguments(GetParam()); hipsparseStatus_t status = testing_csr2hyb(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csr2hyb, csr2hyb_double) { Arguments arg = setup_csr2hyb_arguments(GetParam()); hipsparseStatus_t status = testing_csr2hyb(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csr2hyb, csr2hyb_float_complex) { Arguments arg = setup_csr2hyb_arguments(GetParam()); hipsparseStatus_t status = testing_csr2hyb(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csr2hyb, csr2hyb_double_complex) { Arguments arg = setup_csr2hyb_arguments(GetParam()); hipsparseStatus_t status = testing_csr2hyb(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csr2hyb_bin, csr2hyb_bin_float) { Arguments arg = setup_csr2hyb_arguments(GetParam()); hipsparseStatus_t status = testing_csr2hyb(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csr2hyb_bin, csr2hyb_bin_double) { Arguments arg = setup_csr2hyb_arguments(GetParam()); hipsparseStatus_t status = testing_csr2hyb(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(csr2hyb, parameterized_csr2hyb, testing::Combine(testing::ValuesIn(csr2hyb_M_range), testing::ValuesIn(csr2hyb_N_range), testing::ValuesIn(csr2hyb_idx_base_range), testing::ValuesIn(csr2hyb_partition), testing::ValuesIn(csr2hyb_ELL_range))); INSTANTIATE_TEST_SUITE_P(csr2hyb_bin, parameterized_csr2hyb_bin, testing::Combine(testing::ValuesIn(csr2hyb_idx_base_range), testing::ValuesIn(csr2hyb_partition), testing::ValuesIn(csr2hyb_ELL_range), testing::ValuesIn(csr2hyb_bin))); hipSPARSE-rocm-5.7.1/clients/tests/test_csrcolor.cpp000066400000000000000000000041151447644345400223740ustar00rootroot00000000000000/* ************************************************************************ * 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_csrcolor.hpp" #include #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(csrcolor_bad_arg, csrcolor_bad_arg_float) { testing_csrcolor_bad_arg(); } TEST(csrcolor, csrcolor_float) { hipsparseStatus_t status = testing_csrcolor(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(csrcolor, csrcolor_double) { hipsparseStatus_t status = testing_csrcolor(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(csrcolor, csrcolor_hipComplex) { hipsparseStatus_t status = testing_csrcolor(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(csrcolor, csrcolor_hipDoubleComplex) { hipsparseStatus_t status = testing_csrcolor(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_csrgeam.cpp000066400000000000000000000157451447644345400222020ustar00rootroot00000000000000/* ************************************************************************ * 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_csrgeam.hpp" #include "utility.hpp" #include #include typedef hipsparseIndexBase_t base; typedef std::tuple csrgeam_tuple; typedef std::tuple csrgeam_bin_tuple; double csrgeam_alpha_range[] = {0.0, 1.0}; double csrgeam_beta_range[] = {0.0, 2.0}; int csrgeam_M_range[] = {-1, 0, 50, 647, 1799}; int csrgeam_N_range[] = {-1, 0, 13, 523, 3712}; base csrgeam_idxbaseA_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; base csrgeam_idxbaseB_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; base csrgeam_idxbaseC_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; std::string csrgeam_bin[] = {/*"rma10.bin",*/ "mac_econ_fwd500.bin", /*"bibd_22_8.bin",*/ "mc2depi.bin", "scircuit.bin", /*"bmwcra_1.bin",*/ "nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin"}; class parameterized_csrgeam : public testing::TestWithParam { protected: parameterized_csrgeam() {} virtual ~parameterized_csrgeam() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_csrgeam_bin : public testing::TestWithParam { protected: parameterized_csrgeam_bin() {} virtual ~parameterized_csrgeam_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_csrgeam_arguments(csrgeam_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.idx_base = std::get<4>(tup); #ifdef __HIP_PLATFORM_NVIDIA__ // There is a bug with index base in cusparse arg.idx_base2 = std::get<4>(tup); arg.idx_base3 = std::get<4>(tup); #else arg.idx_base2 = std::get<5>(tup); arg.idx_base3 = std::get<6>(tup); #endif arg.timing = 0; return arg; } Arguments setup_csrgeam_arguments(csrgeam_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = -99; arg.alpha = std::get<0>(tup); arg.beta = std::get<1>(tup); arg.idx_base = std::get<2>(tup); #ifdef __HIP_PLATFORM_NVIDIA__ // There is a bug with index base in cusparse arg.idx_base2 = std::get<2>(tup); arg.idx_base3 = std::get<2>(tup); #else arg.idx_base2 = std::get<3>(tup); arg.idx_base3 = std::get<4>(tup); #endif 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.filename = get_filename(bin_file); return arg; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(csrgeam_bad_arg, csrgeam_float) { testing_csrgeam_bad_arg(); } TEST_P(parameterized_csrgeam, csrgeam_float) { Arguments arg = setup_csrgeam_arguments(GetParam()); hipsparseStatus_t status = testing_csrgeam(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrgeam, csrgeam_double) { Arguments arg = setup_csrgeam_arguments(GetParam()); hipsparseStatus_t status = testing_csrgeam(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrgeam, csrgeam_float_complex) { Arguments arg = setup_csrgeam_arguments(GetParam()); hipsparseStatus_t status = testing_csrgeam(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrgeam, csrgeam_double_complex) { Arguments arg = setup_csrgeam_arguments(GetParam()); hipsparseStatus_t status = testing_csrgeam(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrgeam_bin, csrgeam_bin_float) { Arguments arg = setup_csrgeam_arguments(GetParam()); hipsparseStatus_t status = testing_csrgeam(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrgeam_bin, csrgeam_bin_double) { Arguments arg = setup_csrgeam_arguments(GetParam()); hipsparseStatus_t status = testing_csrgeam(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(csrgeam, parameterized_csrgeam, testing::Combine(testing::ValuesIn(csrgeam_M_range), testing::ValuesIn(csrgeam_N_range), testing::ValuesIn(csrgeam_alpha_range), testing::ValuesIn(csrgeam_beta_range), testing::ValuesIn(csrgeam_idxbaseA_range), testing::ValuesIn(csrgeam_idxbaseB_range), testing::ValuesIn(csrgeam_idxbaseC_range))); INSTANTIATE_TEST_SUITE_P(csrgeam_bin, parameterized_csrgeam_bin, testing::Combine(testing::ValuesIn(csrgeam_alpha_range), testing::ValuesIn(csrgeam_beta_range), testing::ValuesIn(csrgeam_idxbaseA_range), testing::ValuesIn(csrgeam_idxbaseB_range), testing::ValuesIn(csrgeam_idxbaseC_range), testing::ValuesIn(csrgeam_bin))); hipSPARSE-rocm-5.7.1/clients/tests/test_csrgeam2.cpp000066400000000000000000000143261447644345400222560ustar00rootroot00000000000000/* ************************************************************************ * 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. * * ************************************************************************ */ #include "testing_csrgeam2.hpp" #include "utility.hpp" #include #include typedef hipsparseIndexBase_t base; typedef std::tuple csrgeam2_tuple; typedef std::tuple csrgeam2_bin_tuple; double csrgeam2_alpha_range[] = {0.0, 2.0}; double csrgeam2_beta_range[] = {0.0, 1.0}; int csrgeam2_M_range[] = {-1, 0, 50, 647, 1799}; int csrgeam2_N_range[] = {-1, 0, 13, 523, 3712}; base csrgeam2_idxbaseA_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; base csrgeam2_idxbaseB_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; base csrgeam2_idxbaseC_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; std::string csrgeam2_bin[] = {"nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin"}; class parameterized_csrgeam2 : public testing::TestWithParam { protected: parameterized_csrgeam2() {} virtual ~parameterized_csrgeam2() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_csrgeam2_bin : public testing::TestWithParam { protected: parameterized_csrgeam2_bin() {} virtual ~parameterized_csrgeam2_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_csrgeam2_arguments(csrgeam2_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.idx_base = std::get<4>(tup); arg.idx_base2 = std::get<5>(tup); arg.idx_base3 = std::get<6>(tup); arg.timing = 0; return arg; } Arguments setup_csrgeam2_arguments(csrgeam2_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = -99; arg.alpha = std::get<0>(tup); arg.beta = std::get<1>(tup); arg.idx_base = std::get<2>(tup); arg.idx_base2 = std::get<3>(tup); arg.idx_base3 = 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.filename = get_filename(bin_file); return arg; } #if(!defined(CUDART_VERSION)) TEST(csrgeam2_bad_arg, csrgeam2_float) { testing_csrgeam2_bad_arg(); } TEST_P(parameterized_csrgeam2, csrgeam2_float) { Arguments arg = setup_csrgeam2_arguments(GetParam()); hipsparseStatus_t status = testing_csrgeam2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrgeam2, csrgeam2_double) { Arguments arg = setup_csrgeam2_arguments(GetParam()); hipsparseStatus_t status = testing_csrgeam2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrgeam2, csrgeam2_float_complex) { Arguments arg = setup_csrgeam2_arguments(GetParam()); hipsparseStatus_t status = testing_csrgeam2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrgeam2, csrgeam2_double_complex) { Arguments arg = setup_csrgeam2_arguments(GetParam()); hipsparseStatus_t status = testing_csrgeam2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrgeam2_bin, csrgeam2_bin_float) { Arguments arg = setup_csrgeam2_arguments(GetParam()); hipsparseStatus_t status = testing_csrgeam2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrgeam2_bin, csrgeam2_bin_double) { Arguments arg = setup_csrgeam2_arguments(GetParam()); hipsparseStatus_t status = testing_csrgeam2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(csrgeam2, parameterized_csrgeam2, testing::Combine(testing::ValuesIn(csrgeam2_M_range), testing::ValuesIn(csrgeam2_N_range), testing::ValuesIn(csrgeam2_alpha_range), testing::ValuesIn(csrgeam2_beta_range), testing::ValuesIn(csrgeam2_idxbaseA_range), testing::ValuesIn(csrgeam2_idxbaseB_range), testing::ValuesIn(csrgeam2_idxbaseC_range))); INSTANTIATE_TEST_SUITE_P(csrgeam2_bin, parameterized_csrgeam2_bin, testing::Combine(testing::ValuesIn(csrgeam2_alpha_range), testing::ValuesIn(csrgeam2_beta_range), testing::ValuesIn(csrgeam2_idxbaseA_range), testing::ValuesIn(csrgeam2_idxbaseB_range), testing::ValuesIn(csrgeam2_idxbaseC_range), testing::ValuesIn(csrgeam2_bin))); #endif hipSPARSE-rocm-5.7.1/clients/tests/test_csrgemm.cpp000066400000000000000000000156061447644345400222120ustar00rootroot00000000000000/* ************************************************************************ * 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. * * ************************************************************************ */ #include "testing_csrgemm.hpp" #include "utility.hpp" #include #include typedef hipsparseIndexBase_t base; typedef hipsparseOperation_t trans; typedef std::tuple csrgemm_tuple; typedef std::tuple csrgemm_bin_tuple; int csrgemm_M_range[] = {-1, 0, 50, 647, 1799}; int csrgemm_N_range[] = {-1, 0, 13, 523, 3712}; int csrgemm_K_range[] = {-1, 0, 50, 254, 1942}; base csrgemm_idxbaseA_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; base csrgemm_idxbaseB_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; base csrgemm_idxbaseC_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; trans csrgemm_transA_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE}; trans csrgemm_transB_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE}; std::string csrgemm_bin[] = {/*"rma10.bin",*/ /*"bibd_22_8.bin",*/ "mc2depi.bin", "scircuit.bin", /*"bmwcra_1.bin",*/ "nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin"}; class parameterized_csrgemm : public testing::TestWithParam { protected: parameterized_csrgemm() {} virtual ~parameterized_csrgemm() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_csrgemm_bin : public testing::TestWithParam { protected: parameterized_csrgemm_bin() {} virtual ~parameterized_csrgemm_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_csrgemm_arguments(csrgemm_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.K = std::get<2>(tup); arg.idx_base = std::get<3>(tup); arg.idx_base2 = std::get<4>(tup); arg.idx_base3 = std::get<5>(tup); arg.transA = std::get<6>(tup); arg.transB = std::get<7>(tup); arg.timing = 0; return arg; } Arguments setup_csrgemm_arguments(csrgemm_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = -99; arg.K = -99; arg.idx_base = std::get<0>(tup); arg.idx_base2 = std::get<1>(tup); arg.idx_base3 = std::get<2>(tup); arg.transA = std::get<3>(tup); arg.transB = 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.filename = get_filename(bin_file); return arg; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(csrgemm_bad_arg, csrgemm_float) { testing_csrgemm_bad_arg(); } TEST_P(parameterized_csrgemm, csrgemm_float) { Arguments arg = setup_csrgemm_arguments(GetParam()); hipsparseStatus_t status = testing_csrgemm(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrgemm, csrgemm_double) { Arguments arg = setup_csrgemm_arguments(GetParam()); hipsparseStatus_t status = testing_csrgemm(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrgemm, csrgemm_float_complex) { Arguments arg = setup_csrgemm_arguments(GetParam()); hipsparseStatus_t status = testing_csrgemm(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrgemm, csrgemm_double_complex) { Arguments arg = setup_csrgemm_arguments(GetParam()); hipsparseStatus_t status = testing_csrgemm(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrgemm_bin, csrgemm_bin_float) { Arguments arg = setup_csrgemm_arguments(GetParam()); hipsparseStatus_t status = testing_csrgemm(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrgemm_bin, csrgemm_bin_double) { Arguments arg = setup_csrgemm_arguments(GetParam()); hipsparseStatus_t status = testing_csrgemm(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(csrgemm, parameterized_csrgemm, testing::Combine(testing::ValuesIn(csrgemm_M_range), testing::ValuesIn(csrgemm_N_range), testing::ValuesIn(csrgemm_K_range), testing::ValuesIn(csrgemm_idxbaseA_range), testing::ValuesIn(csrgemm_idxbaseB_range), testing::ValuesIn(csrgemm_idxbaseC_range), testing::ValuesIn(csrgemm_transA_range), testing::ValuesIn(csrgemm_transB_range))); INSTANTIATE_TEST_SUITE_P(csrgemm_bin, parameterized_csrgemm_bin, testing::Combine(testing::ValuesIn(csrgemm_idxbaseA_range), testing::ValuesIn(csrgemm_idxbaseB_range), testing::ValuesIn(csrgemm_idxbaseC_range), testing::ValuesIn(csrgemm_transA_range), testing::ValuesIn(csrgemm_transB_range), testing::ValuesIn(csrgemm_bin))); hipSPARSE-rocm-5.7.1/clients/tests/test_csrgemm2_a.cpp000066400000000000000000000145401447644345400225700ustar00rootroot00000000000000/* ************************************************************************ * 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. * * ************************************************************************ */ #include "testing_csrgemm2_a.hpp" #include "utility.hpp" #include #include typedef hipsparseIndexBase_t base; typedef std::tuple csrgemm2_a_tuple; typedef std::tuple csrgemm2_a_bin_tuple; double csrgemm2_a_alpha_range[] = {2.0}; int csrgemm2_a_M_range[] = {0, 50, 647, 1799}; int csrgemm2_a_N_range[] = {-1, 13, 523, 3712}; int csrgemm2_a_K_range[] = {0, 50, 254, 1942}; base csrgemm2_a_idxbaseA_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; base csrgemm2_a_idxbaseB_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; base csrgemm2_a_idxbaseC_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; std::string csrgemm2_a_bin[] = {"nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin"}; class parameterized_csrgemm2_a : public testing::TestWithParam { protected: parameterized_csrgemm2_a() {} virtual ~parameterized_csrgemm2_a() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_csrgemm2_a_bin : public testing::TestWithParam { protected: parameterized_csrgemm2_a_bin() {} virtual ~parameterized_csrgemm2_a_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_csrgemm2_a_arguments(csrgemm2_a_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); arg.idx_base = std::get<4>(tup); arg.idx_base2 = std::get<5>(tup); arg.idx_base3 = std::get<6>(tup); arg.timing = 0; return arg; } Arguments setup_csrgemm2_a_arguments(csrgemm2_a_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = -99; arg.K = -99; arg.alpha = std::get<0>(tup); arg.idx_base = std::get<1>(tup); arg.idx_base2 = std::get<2>(tup); arg.idx_base3 = std::get<3>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<4>(tup); // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } // Only run tests for CUDA 11.1 or greater (removed in cusparse 12.0.0) #if(!defined(CUDART_VERSION) || (CUDART_VERSION >= 11010 && CUDART_VERSION < 12000)) TEST(csrgemm2_a_bad_arg, csrgemm2_a_float) { testing_csrgemm2_a_bad_arg(); } TEST_P(parameterized_csrgemm2_a, csrgemm2_a_float) { Arguments arg = setup_csrgemm2_a_arguments(GetParam()); hipsparseStatus_t status = testing_csrgemm2_a(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrgemm2_a, csrgemm2_a_double) { Arguments arg = setup_csrgemm2_a_arguments(GetParam()); hipsparseStatus_t status = testing_csrgemm2_a(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrgemm2_a, csrgemm2_a_float_complex) { Arguments arg = setup_csrgemm2_a_arguments(GetParam()); hipsparseStatus_t status = testing_csrgemm2_a(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrgemm2_a, csrgemm2_a_double_complex) { Arguments arg = setup_csrgemm2_a_arguments(GetParam()); hipsparseStatus_t status = testing_csrgemm2_a(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrgemm2_a_bin, csrgemm2_a_bin_float) { Arguments arg = setup_csrgemm2_a_arguments(GetParam()); hipsparseStatus_t status = testing_csrgemm2_a(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrgemm2_a_bin, csrgemm2_a_bin_double) { Arguments arg = setup_csrgemm2_a_arguments(GetParam()); hipsparseStatus_t status = testing_csrgemm2_a(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(csrgemm2_a, parameterized_csrgemm2_a, testing::Combine(testing::ValuesIn(csrgemm2_a_M_range), testing::ValuesIn(csrgemm2_a_N_range), testing::ValuesIn(csrgemm2_a_K_range), testing::ValuesIn(csrgemm2_a_alpha_range), testing::ValuesIn(csrgemm2_a_idxbaseA_range), testing::ValuesIn(csrgemm2_a_idxbaseB_range), testing::ValuesIn(csrgemm2_a_idxbaseC_range))); INSTANTIATE_TEST_SUITE_P(csrgemm2_a_bin, parameterized_csrgemm2_a_bin, testing::Combine(testing::ValuesIn(csrgemm2_a_alpha_range), testing::ValuesIn(csrgemm2_a_idxbaseA_range), testing::ValuesIn(csrgemm2_a_idxbaseB_range), testing::ValuesIn(csrgemm2_a_idxbaseC_range), testing::ValuesIn(csrgemm2_a_bin))); hipSPARSE-rocm-5.7.1/clients/tests/test_csrgemm2_b.cpp000066400000000000000000000134701447644345400225720ustar00rootroot00000000000000/* ************************************************************************ * 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. * * ************************************************************************ */ #include "testing_csrgemm2_b.hpp" #include "utility.hpp" #include #include typedef hipsparseIndexBase_t base; typedef std::tuple csrgemm2_b_tuple; typedef std::tuple csrgemm2_b_bin_tuple; double csrgemm2_b_beta_range[] = {1.3}; int csrgemm2_b_M_range[] = {-1, 50, 647, 1799}; int csrgemm2_b_N_range[] = {0, 13, 523, 3712}; base csrgemm2_b_idxbaseC_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; base csrgemm2_b_idxbaseD_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; std::string csrgemm2_b_bin[] = {"nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin"}; class parameterized_csrgemm2_b : public testing::TestWithParam { protected: parameterized_csrgemm2_b() {} virtual ~parameterized_csrgemm2_b() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_csrgemm2_b_bin : public testing::TestWithParam { protected: parameterized_csrgemm2_b_bin() {} virtual ~parameterized_csrgemm2_b_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_csrgemm2_b_arguments(csrgemm2_b_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.beta = std::get<2>(tup); arg.idx_base3 = std::get<3>(tup); arg.idx_base4 = std::get<4>(tup); arg.timing = 0; return arg; } Arguments setup_csrgemm2_b_arguments(csrgemm2_b_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = -99; arg.beta = std::get<0>(tup); arg.idx_base3 = std::get<1>(tup); arg.idx_base4 = 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.filename = get_filename(bin_file); return arg; } // Only run tests for CUDA 11.1 or greater (removed in cusparse 12.0.0) #if(!defined(CUDART_VERSION) || (CUDART_VERSION >= 11010 && CUDART_VERSION < 12000)) TEST(csrgemm2_b_bad_arg, csrgemm2_b_float) { testing_csrgemm2_b_bad_arg(); } TEST_P(parameterized_csrgemm2_b, csrgemm2_b_float) { Arguments arg = setup_csrgemm2_b_arguments(GetParam()); hipsparseStatus_t status = testing_csrgemm2_b(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrgemm2_b, csrgemm2_b_double) { Arguments arg = setup_csrgemm2_b_arguments(GetParam()); hipsparseStatus_t status = testing_csrgemm2_b(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrgemm2_b, csrgemm2_b_float_complex) { Arguments arg = setup_csrgemm2_b_arguments(GetParam()); hipsparseStatus_t status = testing_csrgemm2_b(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrgemm2_b, csrgemm2_b_double_complex) { Arguments arg = setup_csrgemm2_b_arguments(GetParam()); hipsparseStatus_t status = testing_csrgemm2_b(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrgemm2_b_bin, csrgemm2_b_bin_float) { Arguments arg = setup_csrgemm2_b_arguments(GetParam()); hipsparseStatus_t status = testing_csrgemm2_b(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrgemm2_b_bin, csrgemm2_b_bin_double) { Arguments arg = setup_csrgemm2_b_arguments(GetParam()); hipsparseStatus_t status = testing_csrgemm2_b(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(csrgemm2_b, parameterized_csrgemm2_b, testing::Combine(testing::ValuesIn(csrgemm2_b_M_range), testing::ValuesIn(csrgemm2_b_N_range), testing::ValuesIn(csrgemm2_b_beta_range), testing::ValuesIn(csrgemm2_b_idxbaseC_range), testing::ValuesIn(csrgemm2_b_idxbaseD_range))); INSTANTIATE_TEST_SUITE_P(csrgemm2_b_bin, parameterized_csrgemm2_b_bin, testing::Combine(testing::ValuesIn(csrgemm2_b_beta_range), testing::ValuesIn(csrgemm2_b_idxbaseC_range), testing::ValuesIn(csrgemm2_b_idxbaseD_range), testing::ValuesIn(csrgemm2_b_bin))); hipSPARSE-rocm-5.7.1/clients/tests/test_csric02.cpp000066400000000000000000000114621447644345400220160ustar00rootroot00000000000000/* ************************************************************************ * 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_csric02.hpp" #include "utility.hpp" #include #include #include typedef hipsparseIndexBase_t base; typedef std::tuple csric02_tuple; typedef std::tuple csric02_bin_tuple; int csric02_M_range[] = {-1, 0, 50, 426}; base csric02_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; std::string csric02_bin[] = {"nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin"}; class parameterized_csric02 : public testing::TestWithParam { protected: parameterized_csric02() {} virtual ~parameterized_csric02() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_csric02_bin : public testing::TestWithParam { protected: parameterized_csric02_bin() {} virtual ~parameterized_csric02_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_csric02_arguments(csric02_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.idx_base = std::get<1>(tup); arg.timing = 0; return arg; } Arguments setup_csric02_arguments(csric02_bin_tuple tup) { Arguments arg; arg.M = -99; arg.idx_base = std::get<0>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<1>(tup); // Get current executables absolute path // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(csric02_bad_arg, csric02_float) { testing_csric02_bad_arg(); } TEST_P(parameterized_csric02, csric02_float) { Arguments arg = setup_csric02_arguments(GetParam()); hipsparseStatus_t status = testing_csric02(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csric02, csric02_double) { Arguments arg = setup_csric02_arguments(GetParam()); hipsparseStatus_t status = testing_csric02(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csric02, csric02_float_complex) { Arguments arg = setup_csric02_arguments(GetParam()); hipsparseStatus_t status = testing_csric02(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csric02, csric02_double_complex) { Arguments arg = setup_csric02_arguments(GetParam()); hipsparseStatus_t status = testing_csric02(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csric02_bin, csric02_bin_float) { Arguments arg = setup_csric02_arguments(GetParam()); hipsparseStatus_t status = testing_csric02(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csric02_bin, csric02_bin_double) { Arguments arg = setup_csric02_arguments(GetParam()); hipsparseStatus_t status = testing_csric02(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(csric02, parameterized_csric02, testing::Combine(testing::ValuesIn(csric02_M_range), testing::ValuesIn(csric02_idxbase_range))); INSTANTIATE_TEST_SUITE_P(csric02_bin, parameterized_csric02_bin, testing::Combine(testing::ValuesIn(csric02_idxbase_range), testing::ValuesIn(csric02_bin))); hipSPARSE-rocm-5.7.1/clients/tests/test_csrilu02.cpp000066400000000000000000000150041447644345400222100ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_csrilu02.hpp" #include "utility.hpp" #include #include #include typedef hipsparseIndexBase_t base; typedef std::tuple csrilu02_tuple; typedef std::tuple csrilu02_bin_tuple; int csrilu02_M_range[] = {-1, 0, 50, 647}; int csrilu02_boost_range[] = {0, 1}; double csrilu02_boost_tol_range[] = {0.5}; double csrilu02_boost_val_range[] = {0.3}; double csrilu02_boost_vali_range[] = {0.2}; base csrilu02_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; std::string csrilu02_bin[] = {"mac_econ_fwd500.bin", #ifdef __HIP_PLATFORM_AMD__ // exclude some matrices from cusparse check, // they use weaker division producing more rounding errors "rma10.bin", "nos1.bin", "nos2.bin", #endif "nos3.bin", "nos5.bin", "nos6.bin"}; class parameterized_csrilu02 : public testing::TestWithParam { protected: parameterized_csrilu02() {} virtual ~parameterized_csrilu02() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_csrilu02_bin : public testing::TestWithParam { protected: parameterized_csrilu02_bin() {} virtual ~parameterized_csrilu02_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_csrilu02_arguments(csrilu02_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.numericboost = std::get<1>(tup); arg.boosttol = std::get<2>(tup); arg.boostval = std::get<3>(tup); arg.boostvali = std::get<4>(tup); arg.idx_base = std::get<5>(tup); arg.timing = 0; return arg; } Arguments setup_csrilu02_arguments(csrilu02_bin_tuple tup) { Arguments arg; arg.M = -99; arg.numericboost = std::get<0>(tup); arg.boosttol = std::get<1>(tup); arg.boostval = std::get<2>(tup); arg.boostvali = std::get<3>(tup); arg.idx_base = 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.filename = get_filename(bin_file); return arg; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(csrilu02_bad_arg, csrilu02_float) { testing_csrilu02_bad_arg(); } TEST_P(parameterized_csrilu02, csrilu02_float) { Arguments arg = setup_csrilu02_arguments(GetParam()); hipsparseStatus_t status = testing_csrilu02(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrilu02, csrilu02_double) { Arguments arg = setup_csrilu02_arguments(GetParam()); hipsparseStatus_t status = testing_csrilu02(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrilu02, csrilu02_float_complex) { Arguments arg = setup_csrilu02_arguments(GetParam()); hipsparseStatus_t status = testing_csrilu02(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrilu02, csrilu02_double_complex) { Arguments arg = setup_csrilu02_arguments(GetParam()); hipsparseStatus_t status = testing_csrilu02(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrilu02_bin, csrilu02_bin_float) { Arguments arg = setup_csrilu02_arguments(GetParam()); hipsparseStatus_t status = testing_csrilu02(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrilu02_bin, csrilu02_bin_double) { Arguments arg = setup_csrilu02_arguments(GetParam()); hipsparseStatus_t status = testing_csrilu02(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(csrilu02, parameterized_csrilu02, testing::Combine(testing::ValuesIn(csrilu02_M_range), testing::ValuesIn(csrilu02_boost_range), testing::ValuesIn(csrilu02_boost_tol_range), testing::ValuesIn(csrilu02_boost_val_range), testing::ValuesIn(csrilu02_boost_vali_range), testing::ValuesIn(csrilu02_idxbase_range))); INSTANTIATE_TEST_SUITE_P(csrilu02_bin, parameterized_csrilu02_bin, testing::Combine(testing::ValuesIn(csrilu02_boost_range), testing::ValuesIn(csrilu02_boost_tol_range), testing::ValuesIn(csrilu02_boost_val_range), testing::ValuesIn(csrilu02_boost_vali_range), testing::ValuesIn(csrilu02_idxbase_range), testing::ValuesIn(csrilu02_bin))); hipSPARSE-rocm-5.7.1/clients/tests/test_csrilusv.cpp000066400000000000000000000064351447644345400224270ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_csrilusv.hpp" #include "utility.hpp" #include #include #include typedef hipsparseIndexBase_t base; typedef std::tuple csrilusv_bin_tuple; base csrilusv_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; std::string csrilusv_bin[] = {"scircuit.bin", #if defined(__HIP_PLATFORM_AMD__) // "bmwcra_1.bin", "nos1.bin", #endif "nos6.bin", "amazon0312.bin"}; class parameterized_csrilusv_bin : public testing::TestWithParam { protected: parameterized_csrilusv_bin() {} virtual ~parameterized_csrilusv_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_csrilusv_arguments(csrilusv_bin_tuple tup) { Arguments arg; arg.M = -99; arg.idx_base = std::get<0>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<1>(tup); // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST_P(parameterized_csrilusv_bin, csrilusv_bin_float) { Arguments arg = setup_csrilusv_arguments(GetParam()); hipsparseStatus_t status = testing_csrilusv(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrilusv_bin, csrilusv_bin_double) { Arguments arg = setup_csrilusv_arguments(GetParam()); hipsparseStatus_t status = testing_csrilusv(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(csrilusv_bin, parameterized_csrilusv_bin, testing::Combine(testing::ValuesIn(csrilusv_idxbase_range), testing::ValuesIn(csrilusv_bin))); hipSPARSE-rocm-5.7.1/clients/tests/test_csrmm.cpp000066400000000000000000000152271447644345400216750ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_csrmm.hpp" #include "utility.hpp" #include #include typedef hipsparseIndexBase_t base; typedef hipsparseOperation_t trans; typedef std::tuple csrmm_tuple; typedef std::tuple csrmm_bin_tuple; int csrmm_M_range[] = {-1, 0, 42, 275, 2059}; int csrmm_N_range[] = {-1, 0, 7, 19, 64, 78}; int csrmm_K_range[] = {-1, 0, 50, 173, 1375}; double csrmm_alpha_range[] = {-0.5}; double csrmm_beta_range[] = {0.5}; base csrmm_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; trans csrmm_transA_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_TRANSPOSE, HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE}; trans csrmm_transB_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_TRANSPOSE, HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE}; std::string csrmm_bin[] = {"rma10.bin", "nos1.bin", "nos3.bin", "nos5.bin", "nos7.bin"}; class parameterized_csrmm : public testing::TestWithParam { protected: parameterized_csrmm() {} virtual ~parameterized_csrmm() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_csrmm_bin : public testing::TestWithParam { protected: parameterized_csrmm_bin() {} virtual ~parameterized_csrmm_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_csrmm_arguments(csrmm_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); arg.beta = std::get<4>(tup); arg.idx_base = std::get<5>(tup); arg.transA = std::get<6>(tup); arg.transB = std::get<7>(tup); arg.timing = 0; return arg; } Arguments setup_csrmm_arguments(csrmm_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = std::get<0>(tup); arg.K = -99; arg.alpha = std::get<1>(tup); arg.beta = std::get<2>(tup); arg.idx_base = std::get<3>(tup); arg.transA = std::get<4>(tup); arg.transB = std::get<5>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<6>(tup); // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(csrmm_bad_arg, csrmm_float) { testing_csrmm_bad_arg(); } TEST_P(parameterized_csrmm, csrmm_float) { Arguments arg = setup_csrmm_arguments(GetParam()); hipsparseStatus_t status = testing_csrmm(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrmm, csrmm_double) { Arguments arg = setup_csrmm_arguments(GetParam()); hipsparseStatus_t status = testing_csrmm(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrmm, csrmm_float_complex) { Arguments arg = setup_csrmm_arguments(GetParam()); hipsparseStatus_t status = testing_csrmm(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrmm, csrmm_double_complex) { Arguments arg = setup_csrmm_arguments(GetParam()); hipsparseStatus_t status = testing_csrmm(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrmm_bin, csrmm_bin_float) { Arguments arg = setup_csrmm_arguments(GetParam()); hipsparseStatus_t status = testing_csrmm(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrmm_bin, csrmm_bin_double) { Arguments arg = setup_csrmm_arguments(GetParam()); hipsparseStatus_t status = testing_csrmm(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(csrmm, parameterized_csrmm, testing::Combine(testing::ValuesIn(csrmm_M_range), testing::ValuesIn(csrmm_N_range), testing::ValuesIn(csrmm_K_range), testing::ValuesIn(csrmm_alpha_range), testing::ValuesIn(csrmm_beta_range), testing::ValuesIn(csrmm_idxbase_range), testing::ValuesIn(csrmm_transA_range), testing::ValuesIn(csrmm_transB_range))); INSTANTIATE_TEST_SUITE_P(csrmm_bin, parameterized_csrmm_bin, testing::Combine(testing::ValuesIn(csrmm_N_range), testing::ValuesIn(csrmm_alpha_range), testing::ValuesIn(csrmm_beta_range), testing::ValuesIn(csrmm_idxbase_range), testing::ValuesIn(csrmm_transA_range), testing::ValuesIn(csrmm_transB_range), testing::ValuesIn(csrmm_bin))); hipSPARSE-rocm-5.7.1/clients/tests/test_csrmv.cpp000066400000000000000000000142301447644345400216770ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_csrmv.hpp" #include "utility.hpp" #include #include #include typedef hipsparseOperation_t trans; typedef hipsparseIndexBase_t base; typedef std::tuple csrmv_tuple; typedef std::tuple csrmv_bin_tuple; int csr_M_range[] = {-1, 0, 500, 7111}; int csr_N_range[] = {-3, 0, 842, 4441}; std::vector csr_alpha_range = {3.0}; std::vector csr_beta_range = {1.0}; trans csr_trans_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_TRANSPOSE, HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE}; base csr_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; std::string csr_bin[] = {"nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin", "Chebyshev4.bin", "shipsec1.bin"}; class parameterized_csrmv : public testing::TestWithParam { protected: parameterized_csrmv() {} virtual ~parameterized_csrmv() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_csrmv_bin : public testing::TestWithParam { protected: parameterized_csrmv_bin() {} virtual ~parameterized_csrmv_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_csrmv_arguments(csrmv_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.idx_base = std::get<5>(tup); arg.timing = 0; return arg; } Arguments setup_csrmv_arguments(csrmv_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.idx_base = std::get<3>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<4>(tup); // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(csrmv_bad_arg, csrmv_float) { testing_csrmv_bad_arg(); } TEST_P(parameterized_csrmv, csrmv_float) { Arguments arg = setup_csrmv_arguments(GetParam()); hipsparseStatus_t status = testing_csrmv(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrmv, csrmv_double) { Arguments arg = setup_csrmv_arguments(GetParam()); hipsparseStatus_t status = testing_csrmv(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrmv, csrmv_float_complex) { Arguments arg = setup_csrmv_arguments(GetParam()); hipsparseStatus_t status = testing_csrmv(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrmv, csrmv_double_complex) { Arguments arg = setup_csrmv_arguments(GetParam()); hipsparseStatus_t status = testing_csrmv(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrmv_bin, csrmv_bin_float) { Arguments arg = setup_csrmv_arguments(GetParam()); hipsparseStatus_t status = testing_csrmv(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrmv_bin, csrmv_bin_double) { Arguments arg = setup_csrmv_arguments(GetParam()); hipsparseStatus_t status = testing_csrmv(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(csrmv, parameterized_csrmv, testing::Combine(testing::ValuesIn(csr_M_range), testing::ValuesIn(csr_N_range), testing::ValuesIn(csr_alpha_range), testing::ValuesIn(csr_beta_range), testing::ValuesIn(csr_trans_range), testing::ValuesIn(csr_idxbase_range))); INSTANTIATE_TEST_SUITE_P(csrmv_bin, parameterized_csrmv_bin, testing::Combine(testing::ValuesIn(csr_alpha_range), testing::ValuesIn(csr_beta_range), testing::ValuesIn(csr_trans_range), testing::ValuesIn(csr_idxbase_range), testing::ValuesIn(csr_bin))); hipSPARSE-rocm-5.7.1/clients/tests/test_csrsm2.cpp000066400000000000000000000151171447644345400217630ustar00rootroot00000000000000/* ************************************************************************ * 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_csrsm2.hpp" #include "utility.hpp" #include #include #include typedef hipsparseIndexBase_t base; typedef hipsparseOperation_t op; typedef hipsparseDiagType_t diag; typedef hipsparseFillMode_t fill; typedef std::tuple csrsm2_tuple; typedef std::tuple csrsm2_bin_tuple; int csrsm2_M_range[] = {-1, 0, 124, 9381}; int csrsm2_nrhs_range[] = {3, 17}; double csrsm2_alpha_range[] = {1.0, -0.5}; base csrsm2_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; op csrsm2_opA_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE}; op csrsm2_opB_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_TRANSPOSE}; diag csrsm2_diag_range[] = {HIPSPARSE_DIAG_TYPE_NON_UNIT}; fill csrsm2_fill_range[] = {HIPSPARSE_FILL_MODE_LOWER, HIPSPARSE_FILL_MODE_UPPER}; std::string csrsm2_bin[] = {"nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin"}; class parameterized_csrsm2 : public testing::TestWithParam { protected: parameterized_csrsm2() {} virtual ~parameterized_csrsm2() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_csrsm2_bin : public testing::TestWithParam { protected: parameterized_csrsm2_bin() {} virtual ~parameterized_csrsm2_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_csrsm2_arguments(csrsm2_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.alpha = std::get<2>(tup); arg.idx_base = std::get<3>(tup); arg.transA = std::get<4>(tup); arg.transB = std::get<5>(tup); arg.diag_type = std::get<6>(tup); arg.fill_mode = std::get<7>(tup); arg.timing = 0; return arg; } Arguments setup_csrsm2_arguments(csrsm2_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = std::get<0>(tup); arg.alpha = std::get<1>(tup); arg.idx_base = std::get<2>(tup); arg.transA = std::get<3>(tup); arg.transB = std::get<4>(tup); arg.diag_type = std::get<5>(tup); arg.fill_mode = std::get<6>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<7>(tup); // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } #if(!defined(CUDART_VERSION)) TEST(csrsm2_bad_arg, csrsm2_float) { testing_csrsm2_bad_arg(); } TEST_P(parameterized_csrsm2, csrsm2_float) { Arguments arg = setup_csrsm2_arguments(GetParam()); hipsparseStatus_t status = testing_csrsm2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrsm2, csrsm2_double) { Arguments arg = setup_csrsm2_arguments(GetParam()); hipsparseStatus_t status = testing_csrsm2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrsm2, csrsm2_float_complex) { Arguments arg = setup_csrsm2_arguments(GetParam()); hipsparseStatus_t status = testing_csrsm2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrsm2, csrsm2_double_complex) { Arguments arg = setup_csrsm2_arguments(GetParam()); hipsparseStatus_t status = testing_csrsm2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrsm2_bin, csrsm2_bin_float) { Arguments arg = setup_csrsm2_arguments(GetParam()); hipsparseStatus_t status = testing_csrsm2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrsm2_bin, csrsm2_bin_double) { Arguments arg = setup_csrsm2_arguments(GetParam()); hipsparseStatus_t status = testing_csrsm2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(csrsm2, parameterized_csrsm2, testing::Combine(testing::ValuesIn(csrsm2_M_range), testing::ValuesIn(csrsm2_nrhs_range), testing::ValuesIn(csrsm2_alpha_range), testing::ValuesIn(csrsm2_idxbase_range), testing::ValuesIn(csrsm2_opA_range), testing::ValuesIn(csrsm2_opB_range), testing::ValuesIn(csrsm2_diag_range), testing::ValuesIn(csrsm2_fill_range))); INSTANTIATE_TEST_SUITE_P(csrsm2_bin, parameterized_csrsm2_bin, testing::Combine(testing::ValuesIn(csrsm2_nrhs_range), testing::ValuesIn(csrsm2_alpha_range), testing::ValuesIn(csrsm2_idxbase_range), testing::ValuesIn(csrsm2_opA_range), testing::ValuesIn(csrsm2_opB_range), testing::ValuesIn(csrsm2_diag_range), testing::ValuesIn(csrsm2_fill_range), testing::ValuesIn(csrsm2_bin))); #endif hipSPARSE-rocm-5.7.1/clients/tests/test_csrsort.cpp000066400000000000000000000122211447644345400222420ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_csrsort.hpp" #include "utility.hpp" #include #include #include typedef std::tuple csrsort_tuple; typedef std::tuple csrsort_bin_tuple; int csrsort_M_range[] = {-1, 0, 10, 500, 872, 1000}; int csrsort_N_range[] = {-3, 0, 33, 242, 623, 1000}; #if defined(__HIP_PLATFORM_AMD__) int csrsort_perm[] = {0, 1}; #elif defined(__HIP_PLATFORM_NVIDIA__) // cusparse does not allow without permutation int csrsort_perm[] = {1}; #endif hipsparseIndexBase_t csrsort_base[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; std::string csrsort_bin[] = {"rma10.bin", "mac_econ_fwd500.bin", "bibd_22_8.bin", "mc2depi.bin", "scircuit.bin", "ASIC_320k.bin", "bmwcra_1.bin", "nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin", "amazon0312.bin", "Chebyshev4.bin", "sme3Dc.bin", "webbase-1M.bin", "shipsec1.bin"}; class parameterized_csrsort : public testing::TestWithParam { protected: parameterized_csrsort() {} virtual ~parameterized_csrsort() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_csrsort_bin : public testing::TestWithParam { protected: parameterized_csrsort_bin() {} virtual ~parameterized_csrsort_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_csrsort_arguments(csrsort_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.temp = std::get<2>(tup); arg.idx_base = std::get<3>(tup); arg.timing = 0; return arg; } Arguments setup_csrsort_arguments(csrsort_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = -99; arg.temp = std::get<0>(tup); arg.idx_base = std::get<1>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<2>(tup); // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(csrsort_bad_arg, csrsort) { testing_csrsort_bad_arg(); } TEST_P(parameterized_csrsort, csrsort) { Arguments arg = setup_csrsort_arguments(GetParam()); hipsparseStatus_t status = testing_csrsort(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrsort_bin, csrsort_bin) { Arguments arg = setup_csrsort_arguments(GetParam()); hipsparseStatus_t status = testing_csrsort(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(csrsort, parameterized_csrsort, testing::Combine(testing::ValuesIn(csrsort_M_range), testing::ValuesIn(csrsort_N_range), testing::ValuesIn(csrsort_perm), testing::ValuesIn(csrsort_base))); INSTANTIATE_TEST_SUITE_P(csrsort_bin, parameterized_csrsort_bin, testing::Combine(testing::ValuesIn(csrsort_perm), testing::ValuesIn(csrsort_base), testing::ValuesIn(csrsort_bin))); hipSPARSE-rocm-5.7.1/clients/tests/test_csrsv2.cpp000066400000000000000000000145761447644345400220040ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_csrsv2.hpp" #include "utility.hpp" #include #include #include typedef hipsparseIndexBase_t base; typedef hipsparseOperation_t op; typedef hipsparseDiagType_t diag; typedef hipsparseFillMode_t fill; typedef std::tuple csrsv2_tuple; typedef std::tuple csrsv2_bin_tuple; int csrsv2_M_range[] = {-1, 0, 647}; double csrsv2_alpha_range[] = {2.3}; base csrsv2_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; op csrsv2_op_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_TRANSPOSE}; diag csrsv2_diag_range[] = {HIPSPARSE_DIAG_TYPE_NON_UNIT}; fill csrsv2_fill_range[] = {HIPSPARSE_FILL_MODE_LOWER, HIPSPARSE_FILL_MODE_UPPER}; std::string csrsv2_bin[] = {"rma10.bin", "mc2depi.bin", "nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "sme3Dc.bin"}; class parameterized_csrsv2 : public testing::TestWithParam { protected: parameterized_csrsv2() {} virtual ~parameterized_csrsv2() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_csrsv2_bin : public testing::TestWithParam { protected: parameterized_csrsv2_bin() {} virtual ~parameterized_csrsv2_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_csrsv2_arguments(csrsv2_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.alpha = std::get<1>(tup); arg.idx_base = std::get<2>(tup); arg.transA = std::get<3>(tup); arg.diag_type = std::get<4>(tup); arg.fill_mode = std::get<5>(tup); arg.timing = 0; return arg; } Arguments setup_csrsv2_arguments(csrsv2_bin_tuple tup) { Arguments arg; arg.M = -99; arg.alpha = std::get<0>(tup); arg.idx_base = std::get<1>(tup); arg.transA = std::get<2>(tup); arg.diag_type = std::get<3>(tup); arg.fill_mode = 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.filename = get_filename(bin_file); return arg; } // Only run tests for CUDA 11.1 or greater (removed in cusparse 12.0.0) #if(!defined(CUDART_VERSION) || (CUDART_VERSION >= 11010 && CUDART_VERSION < 12000)) TEST(csrsv2_bad_arg, csrsv2_float) { testing_csrsv2_bad_arg(); } TEST_P(parameterized_csrsv2, csrsv2_float) { Arguments arg = setup_csrsv2_arguments(GetParam()); hipsparseStatus_t status = testing_csrsv2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrsv2, csrsv2_double) { Arguments arg = setup_csrsv2_arguments(GetParam()); hipsparseStatus_t status = testing_csrsv2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrsv2, csrsv2_float_complex) { Arguments arg = setup_csrsv2_arguments(GetParam()); hipsparseStatus_t status = testing_csrsv2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrsv2, csrsv2_double_complex) { Arguments arg = setup_csrsv2_arguments(GetParam()); hipsparseStatus_t status = testing_csrsv2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrsv2_bin, csrsv2_bin_float) { Arguments arg = setup_csrsv2_arguments(GetParam()); hipsparseStatus_t status = testing_csrsv2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csrsv2_bin, csrsv2_bin_double) { Arguments arg = setup_csrsv2_arguments(GetParam()); hipsparseStatus_t status = testing_csrsv2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(csrsv2, parameterized_csrsv2, testing::Combine(testing::ValuesIn(csrsv2_M_range), testing::ValuesIn(csrsv2_alpha_range), testing::ValuesIn(csrsv2_idxbase_range), testing::ValuesIn(csrsv2_op_range), testing::ValuesIn(csrsv2_diag_range), testing::ValuesIn(csrsv2_fill_range))); INSTANTIATE_TEST_SUITE_P(csrsv2_bin, parameterized_csrsv2_bin, testing::Combine(testing::ValuesIn(csrsv2_alpha_range), testing::ValuesIn(csrsv2_idxbase_range), testing::ValuesIn(csrsv2_op_range), testing::ValuesIn(csrsv2_diag_range), testing::ValuesIn(csrsv2_fill_range), testing::ValuesIn(csrsv2_bin))); hipSPARSE-rocm-5.7.1/clients/tests/test_csru2csr.cpp000066400000000000000000000041471447644345400223210ustar00rootroot00000000000000/* ************************************************************************ * 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_csru2csr.hpp" #include // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(csru2csr_bad_arg, csru2csr_float) { testing_csru2csr_bad_arg(); } TEST(csru2csr, csru2csr_float) { hipsparseStatus_t status = testing_csru2csr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(csru2csr, csru2csr_double) { hipsparseStatus_t status = testing_csru2csr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(csru2csr, csru2csr_hipComplex) { hipsparseStatus_t status = testing_csru2csr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(csru2csr, csru2csr_hipDoubleComplex) { hipsparseStatus_t status = testing_csru2csr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_dense2csc.cpp000066400000000000000000000074701447644345400224260ustar00rootroot00000000000000/* ************************************************************************ * 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_dense2csc.hpp" #include "utility.hpp" #include #include #include typedef hipsparseIndexBase_t base; typedef std::tuple dense2csc_tuple; int dense2csc_M_range[] = {-1, 0, 10, 500, 872, 1000}; int dense2csc_N_range[] = {-3, 0, 33, 242, 623, 1000}; int dense2csc_LD_range[] = {5, 500, 1000}; base dense2csc_idx_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; class parameterized_dense2csc : public testing::TestWithParam { protected: parameterized_dense2csc() {} virtual ~parameterized_dense2csc() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_dense2csc_arguments(dense2csc_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.lda = std::get<2>(tup); return arg; } // Only run tests for CUDA 11.1 or greater (removed in cusparse 12.0.0) #if(!defined(CUDART_VERSION) || (CUDART_VERSION >= 11010 & CUDART_VERSION < 12000)) TEST(dense2csc_bad_arg, dense2csc) { testing_dense2csc_bad_arg(); } TEST_P(parameterized_dense2csc, dense2csc_float) { Arguments arg = setup_dense2csc_arguments(GetParam()); hipsparseStatus_t status = testing_dense2csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_dense2csc, dense2csc_double) { Arguments arg = setup_dense2csc_arguments(GetParam()); hipsparseStatus_t status = testing_dense2csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_dense2csc, dense2csc_float_complex) { Arguments arg = setup_dense2csc_arguments(GetParam()); hipsparseStatus_t status = testing_dense2csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_dense2csc, dense2csc_double_complex) { Arguments arg = setup_dense2csc_arguments(GetParam()); hipsparseStatus_t status = testing_dense2csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(dense2csc, parameterized_dense2csc, testing::Combine(testing::ValuesIn(dense2csc_M_range), testing::ValuesIn(dense2csc_N_range), testing::ValuesIn(dense2csc_LD_range), testing::ValuesIn(dense2csc_idx_base_range))); hipSPARSE-rocm-5.7.1/clients/tests/test_dense2csr.cpp000066400000000000000000000075541447644345400224500ustar00rootroot00000000000000/* ************************************************************************ * 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_dense2csr.hpp" #include "utility.hpp" #include #include #include typedef hipsparseIndexBase_t base; typedef std::tuple dense2csr_tuple; int dense2csr_M_range[] = {-1, 0, 10, 500, 872, 1000}; int dense2csr_N_range[] = {-3, 0, 33, 242, 623, 1000}; int dense2csr_LD_range[] = {5, 500, 1000}; base dense2csr_idx_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; class parameterized_dense2csr : public testing::TestWithParam { protected: parameterized_dense2csr() {} virtual ~parameterized_dense2csr() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_dense2csr_arguments(dense2csr_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.lda = std::get<2>(tup); arg.idx_base = std::get<3>(tup); return arg; } // Only run tests for CUDA 11.1 or greater (removed in cusparse 12.0.0) #if(!defined(CUDART_VERSION) || (CUDART_VERSION >= 11010 & CUDART_VERSION < 12000)) TEST(dense2csr_bad_arg, dense2csr) { testing_dense2csr_bad_arg(); } TEST_P(parameterized_dense2csr, dense2csr_float) { Arguments arg = setup_dense2csr_arguments(GetParam()); hipsparseStatus_t status = testing_dense2csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_dense2csr, dense2csr_double) { Arguments arg = setup_dense2csr_arguments(GetParam()); hipsparseStatus_t status = testing_dense2csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_dense2csr, dense2csr_float_complex) { Arguments arg = setup_dense2csr_arguments(GetParam()); hipsparseStatus_t status = testing_dense2csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_dense2csr, dense2csr_double_complex) { Arguments arg = setup_dense2csr_arguments(GetParam()); hipsparseStatus_t status = testing_dense2csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(dense2csr, parameterized_dense2csr, testing::Combine(testing::ValuesIn(dense2csr_M_range), testing::ValuesIn(dense2csr_N_range), testing::ValuesIn(dense2csr_LD_range), testing::ValuesIn(dense2csr_idx_base_range))); hipSPARSE-rocm-5.7.1/clients/tests/test_dense_to_sparse_coo.cpp000066400000000000000000000042041447644345400245620ustar00rootroot00000000000000/* ************************************************************************ * 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_dense_to_sparse_coo.hpp" #include // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(dense_to_sparse_coo_bad_arg, dense_to_sparse_coo_float) { testing_dense_to_sparse_coo_bad_arg(); } TEST(dense_to_sparse_coo, dense_to_sparse_coo_i32_i32_float) { hipsparseStatus_t status = testing_dense_to_sparse_coo(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(dense_to_sparse_coo, dense_to_sparse_coo_i64_i32_double) { hipsparseStatus_t status = testing_dense_to_sparse_coo(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(dense_to_sparse_coo, dense_to_sparse_coo_i64_i64_hipComplex) { hipsparseStatus_t status = testing_dense_to_sparse_coo(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_dense_to_sparse_csc.cpp000066400000000000000000000042371447644345400245600ustar00rootroot00000000000000/* ************************************************************************ * 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_dense_to_sparse_csc.hpp" #include // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(dense_to_sparse_csc_bad_arg, dense_to_sparse_csc_float) { testing_dense_to_sparse_csc_bad_arg(); } TEST(dense_to_sparse_csc, dense_to_sparse_csc_i32_i32_float) { hipsparseStatus_t status = testing_dense_to_sparse_csc(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(dense_to_sparse_csc, dense_to_sparse_csc_i64_i32_double) { hipsparseStatus_t status = testing_dense_to_sparse_csc(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(dense_to_sparse_csc, dense_to_sparse_csc_i64_i64_hipComplex) { hipsparseStatus_t status = testing_dense_to_sparse_csc(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_dense_to_sparse_csr.cpp000066400000000000000000000037611447644345400246000ustar00rootroot00000000000000/* ************************************************************************ * 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_dense_to_sparse_csr.hpp" #include // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(dense_to_sparse_csr_bad_arg, dense_to_sparse_csr_float) { testing_dense_to_sparse_csr_bad_arg(); } TEST(dense_to_sparse_csr, dense_to_sparse_csr_i32_i32_float) { hipsparseStatus_t status = testing_dense_to_sparse_csr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #if(!defined(CUDART_VERSION)) TEST(dense_to_sparse_csr, dense_to_sparse_csr_i64_i32_double) { hipsparseStatus_t status = testing_dense_to_sparse_csr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif #endif hipSPARSE-rocm-5.7.1/clients/tests/test_dnvec_descr.cpp000066400000000000000000000027751447644345400230370ustar00rootroot00000000000000/* ************************************************************************ * 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_dnvec_descr.hpp" // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(dnvec_descr_bad_arg, dnvec_descr_float) { testing_dnvec_descr_bad_arg(); } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_dotci.cpp000066400000000000000000000060071447644345400216520ustar00rootroot00000000000000/* ************************************************************************ * 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. * * ************************************************************************ */ #include "testing_dotci.hpp" #include "utility.hpp" #include #include typedef hipsparseIndexBase_t base; typedef std::tuple dotci_tuple; int dotci_N_range[] = {12000, 15332, 22031}; int dotci_nnz_range[] = {-1, 0, 5, 10, 500, 1000, 7111, 10000}; base dotci_idx_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; class parameterized_dotci : public testing::TestWithParam { protected: parameterized_dotci() {} virtual ~parameterized_dotci() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_dotci_arguments(dotci_tuple tup) { Arguments arg; arg.N = std::get<0>(tup); arg.nnz = std::get<1>(tup); arg.idx_base = std::get<2>(tup); arg.timing = 0; return arg; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(dotci_bad_arg, dotci_float) { testing_dotci_bad_arg(); } TEST_P(parameterized_dotci, dotci_float_complex) { Arguments arg = setup_dotci_arguments(GetParam()); hipsparseStatus_t status = testing_dotci(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_dotci, dotci_double_complex) { Arguments arg = setup_dotci_arguments(GetParam()); hipsparseStatus_t status = testing_dotci(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(dotci, parameterized_dotci, testing::Combine(testing::ValuesIn(dotci_N_range), testing::ValuesIn(dotci_nnz_range), testing::ValuesIn(dotci_idx_base_range))); hipSPARSE-rocm-5.7.1/clients/tests/test_doti.cpp000066400000000000000000000066101447644345400215070ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_doti.hpp" #include "utility.hpp" #include #include typedef hipsparseIndexBase_t base; typedef std::tuple doti_tuple; int doti_N_range[] = {12000, 15332, 22031}; int doti_nnz_range[] = {-1, 0, 5, 10, 500, 1000, 7111, 10000}; base doti_idx_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; class parameterized_doti : public testing::TestWithParam { protected: parameterized_doti() {} virtual ~parameterized_doti() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_doti_arguments(doti_tuple tup) { Arguments arg; arg.N = std::get<0>(tup); arg.nnz = std::get<1>(tup); arg.idx_base = std::get<2>(tup); arg.timing = 0; return arg; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(doti_bad_arg, doti_float) { testing_doti_bad_arg(); } TEST_P(parameterized_doti, doti_float) { Arguments arg = setup_doti_arguments(GetParam()); hipsparseStatus_t status = testing_doti(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_doti, doti_double) { Arguments arg = setup_doti_arguments(GetParam()); hipsparseStatus_t status = testing_doti(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_doti, doti_float_complex) { Arguments arg = setup_doti_arguments(GetParam()); hipsparseStatus_t status = testing_doti(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_doti, doti_double_complex) { Arguments arg = setup_doti_arguments(GetParam()); hipsparseStatus_t status = testing_doti(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(doti, parameterized_doti, testing::Combine(testing::ValuesIn(doti_N_range), testing::ValuesIn(doti_nnz_range), testing::ValuesIn(doti_idx_base_range))); hipSPARSE-rocm-5.7.1/clients/tests/test_gather.cpp000066400000000000000000000034571447644345400220300ustar00rootroot00000000000000/* ************************************************************************ * 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_gather.hpp" #include // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(gather_bad_arg, gather_float) { testing_gather_bad_arg(); } TEST(gather, gather_i32_float) { hipsparseStatus_t status = testing_gather(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(gather, gather_i64_double) { hipsparseStatus_t status = testing_gather(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_gebsr2csr.cpp000066400000000000000000000157651447644345400224570ustar00rootroot00000000000000/* ************************************************************************ * 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_gebsr2csr.hpp" #include "utility.hpp" #include #include #include typedef std:: tuple gebsr2csr_tuple; typedef std:: tuple gebsr2csr_bin_tuple; // Random matrices int gebsr2csr_M_range[] = {-1, 872, 21453}; int gebsr2csr_N_range[] = {-3, 623, 29285}; int gebsr2csr_row_block_dim_range[] = {0, 2, 4, 8}; int gebsr2csr_col_block_dim_range[] = {-1, 2, 4, 8}; hipsparseIndexBase_t gebsr2csr_csr_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO}; hipsparseIndexBase_t gebsr2csr_bsr_base_range[] = {HIPSPARSE_INDEX_BASE_ONE}; hipsparseDirection_t gebsr2csr_dir_range[] = {HIPSPARSE_DIRECTION_ROW, HIPSPARSE_DIRECTION_COLUMN}; // Matrices from files (float and double) int gebsr2csr_row_block_dim_range_bin[] = {2, 3}; int gebsr2csr_col_block_dim_range_bin[] = {3, 4}; hipsparseIndexBase_t gebsr2csr_csr_base_range_bin[] = {HIPSPARSE_INDEX_BASE_ONE}; hipsparseIndexBase_t gebsr2csr_bsr_base_range_bin[] = {HIPSPARSE_INDEX_BASE_ONE}; hipsparseDirection_t gebsr2csr_dir_range_bin[] = {HIPSPARSE_DIRECTION_ROW, HIPSPARSE_DIRECTION_COLUMN}; std::string gebsr2csr_bin[] = {"nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin"}; class parameterized_gebsr2csr : public testing::TestWithParam { protected: parameterized_gebsr2csr() {} virtual ~parameterized_gebsr2csr() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_gebsr2csr_bin : public testing::TestWithParam { protected: parameterized_gebsr2csr_bin() {} virtual ~parameterized_gebsr2csr_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_gebsr2csr_arguments(gebsr2csr_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.row_block_dimA = std::get<2>(tup); arg.col_block_dimA = std::get<3>(tup); arg.idx_base = std::get<4>(tup); arg.idx_base2 = std::get<5>(tup); arg.dirA = std::get<6>(tup); arg.timing = 0; return arg; } Arguments setup_gebsr2csr_arguments(gebsr2csr_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = -99; arg.row_block_dimA = std::get<0>(tup); arg.col_block_dimA = std::get<1>(tup); arg.idx_base = std::get<2>(tup); arg.idx_base2 = std::get<3>(tup); arg.dirA = 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.filename = get_filename(bin_file); return arg; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(gebsr2csr_bad_arg, gebsr2csr) { testing_gebsr2csr_bad_arg(); } TEST_P(parameterized_gebsr2csr, gebsr2csr_float) { Arguments arg = setup_gebsr2csr_arguments(GetParam()); hipsparseStatus_t status = testing_gebsr2csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gebsr2csr, gebsr2csr_double) { Arguments arg = setup_gebsr2csr_arguments(GetParam()); hipsparseStatus_t status = testing_gebsr2csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gebsr2csr, gebsr2csr_float_complex) { Arguments arg = setup_gebsr2csr_arguments(GetParam()); hipsparseStatus_t status = testing_gebsr2csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gebsr2csr, gebsr2csr_double_complex) { Arguments arg = setup_gebsr2csr_arguments(GetParam()); hipsparseStatus_t status = testing_gebsr2csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gebsr2csr_bin, gebsr2csr_bin_float) { Arguments arg = setup_gebsr2csr_arguments(GetParam()); hipsparseStatus_t status = testing_gebsr2csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gebsr2csr_bin, gebsr2csr_bin_double) { Arguments arg = setup_gebsr2csr_arguments(GetParam()); hipsparseStatus_t status = testing_gebsr2csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(gebsr2csr, parameterized_gebsr2csr, testing::Combine(testing::ValuesIn(gebsr2csr_M_range), testing::ValuesIn(gebsr2csr_N_range), testing::ValuesIn(gebsr2csr_row_block_dim_range), testing::ValuesIn(gebsr2csr_col_block_dim_range), testing::ValuesIn(gebsr2csr_bsr_base_range), testing::ValuesIn(gebsr2csr_csr_base_range), testing::ValuesIn(gebsr2csr_dir_range))); INSTANTIATE_TEST_SUITE_P(gebsr2csr_bin, parameterized_gebsr2csr_bin, testing::Combine(testing::ValuesIn(gebsr2csr_row_block_dim_range_bin), testing::ValuesIn(gebsr2csr_col_block_dim_range_bin), testing::ValuesIn(gebsr2csr_bsr_base_range_bin), testing::ValuesIn(gebsr2csr_csr_base_range_bin), testing::ValuesIn(gebsr2csr_dir_range_bin), testing::ValuesIn(gebsr2csr_bin))); hipSPARSE-rocm-5.7.1/clients/tests/test_gebsr2gebsc.cpp000066400000000000000000000150431447644345400227400ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_gebsr2gebsc.hpp" #include "utility.hpp" #include #include #include typedef std::tuple gebsr2gebsc_tuple; typedef std::tuple gebsr2gebsc_bin_tuple; int gebsr2gebsc_M_range[] = {-1, 0, 10, 872}; int gebsr2gebsc_N_range[] = {-3, 0, 33, 623}; int gebsr2gebsc_row_block_dim_range[] = {-1, 0, 1, 7, 16}; int gebsr2gebsc_col_block_dim_range[] = {-1, 0, 1, 4, 16}; hipsparseAction_t gebsr2gebsc_action_range[] = {HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_ACTION_SYMBOLIC}; hipsparseIndexBase_t gebsr2gebsc_csr_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; std::string gebsr2gebsc_bin[] = {"scircuit.bin", "nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin"}; class parameterized_gebsr2gebsc : public testing::TestWithParam { protected: parameterized_gebsr2gebsc() {} virtual ~parameterized_gebsr2gebsc() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_gebsr2gebsc_bin : public testing::TestWithParam { protected: parameterized_gebsr2gebsc_bin() {} virtual ~parameterized_gebsr2gebsc_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_gebsr2gebsc_arguments(gebsr2gebsc_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.row_block_dimA = std::get<2>(tup); arg.col_block_dimA = std::get<3>(tup); arg.action = std::get<4>(tup); arg.idx_base = std::get<5>(tup); arg.timing = 0; return arg; } Arguments setup_gebsr2gebsc_arguments(gebsr2gebsc_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = -99; arg.row_block_dimA = std::get<0>(tup); arg.col_block_dimA = std::get<1>(tup); arg.action = std::get<2>(tup); arg.idx_base = std::get<3>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<4>(tup); // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(gebsr2gebsc_bad_arg, gebsr2gebsc) { testing_gebsr2gebsc_bad_arg(); } TEST_P(parameterized_gebsr2gebsc, gebsr2gebsc_float) { Arguments arg = setup_gebsr2gebsc_arguments(GetParam()); hipsparseStatus_t status = testing_gebsr2gebsc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gebsr2gebsc, gebsr2gebsc_double) { Arguments arg = setup_gebsr2gebsc_arguments(GetParam()); hipsparseStatus_t status = testing_gebsr2gebsc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gebsr2gebsc, gebsr2gebsc_float_complex) { Arguments arg = setup_gebsr2gebsc_arguments(GetParam()); hipsparseStatus_t status = testing_gebsr2gebsc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gebsr2gebsc, gebsr2gebsc_double_complex) { Arguments arg = setup_gebsr2gebsc_arguments(GetParam()); hipsparseStatus_t status = testing_gebsr2gebsc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gebsr2gebsc_bin, gebsr2gebsc_bin_float) { Arguments arg = setup_gebsr2gebsc_arguments(GetParam()); hipsparseStatus_t status = testing_gebsr2gebsc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gebsr2gebsc_bin, gebsr2gebsc_bin_double) { Arguments arg = setup_gebsr2gebsc_arguments(GetParam()); hipsparseStatus_t status = testing_gebsr2gebsc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(gebsr2gebsc, parameterized_gebsr2gebsc, testing::Combine(testing::ValuesIn(gebsr2gebsc_M_range), testing::ValuesIn(gebsr2gebsc_N_range), testing::ValuesIn(gebsr2gebsc_row_block_dim_range), testing::ValuesIn(gebsr2gebsc_col_block_dim_range), testing::ValuesIn(gebsr2gebsc_action_range), testing::ValuesIn(gebsr2gebsc_csr_base_range))); INSTANTIATE_TEST_SUITE_P(gebsr2gebsc_bin, parameterized_gebsr2gebsc_bin, testing::Combine(testing::ValuesIn(gebsr2gebsc_row_block_dim_range), testing::ValuesIn(gebsr2gebsc_col_block_dim_range), testing::ValuesIn(gebsr2gebsc_action_range), testing::ValuesIn(gebsr2gebsc_csr_base_range), testing::ValuesIn(gebsr2gebsc_bin))); hipSPARSE-rocm-5.7.1/clients/tests/test_gebsr2gebsr.cpp000066400000000000000000000202701447644345400227550ustar00rootroot00000000000000/* ************************************************************************ * 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_gebsr2gebsr.hpp" #include "utility.hpp" #include #include #include typedef std::tuple gebsr2gebsr_tuple; typedef std::tuple gebsr2gebsr_bin_tuple; // Random matrices int gebsr2gebsr_M_range[] = {-1, 0, 872, 13095, 21453}; int gebsr2gebsr_N_range[] = {-3, 0, 623, 12766, 29285}; int gebsr2gebsr_row_block_dim_A_range[] = {-1, 0, 2}; int gebsr2gebsr_col_block_dim_A_range[] = {-1, 0, 5}; int gebsr2gebsr_row_block_dim_C_range[] = {-1, 0, 3}; int gebsr2gebsr_col_block_dim_C_range[] = {-1, 0, 4}; hipsparseIndexBase_t gebsr2gebsr_A_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO}; hipsparseIndexBase_t gebsr2gebsr_C_base_range[] = {HIPSPARSE_INDEX_BASE_ONE}; hipsparseDirection_t gebsr2gebsr_dir_range[] = {HIPSPARSE_DIRECTION_ROW, HIPSPARSE_DIRECTION_COLUMN}; // Matrices from files (float and double) int gebsr2gebsr_row_block_dim_A_range_bin[] = {5}; int gebsr2gebsr_col_block_dim_A_range_bin[] = {4}; int gebsr2gebsr_row_block_dim_C_range_bin[] = {2}; int gebsr2gebsr_col_block_dim_C_range_bin[] = {7}; hipsparseIndexBase_t gebsr2gebsr_A_base_range_bin[] = {HIPSPARSE_INDEX_BASE_ONE}; hipsparseIndexBase_t gebsr2gebsr_C_base_range_bin[] = {HIPSPARSE_INDEX_BASE_ONE}; hipsparseDirection_t gebsr2gebsr_dir_range_bin[] = {HIPSPARSE_DIRECTION_ROW, HIPSPARSE_DIRECTION_COLUMN}; std::string gebsr2gebsr_bin[] = {"nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin"}; class parameterized_gebsr2gebsr : public testing::TestWithParam { protected: parameterized_gebsr2gebsr() {} virtual ~parameterized_gebsr2gebsr() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_gebsr2gebsr_bin : public testing::TestWithParam { protected: parameterized_gebsr2gebsr_bin() {} virtual ~parameterized_gebsr2gebsr_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_gebsr2gebsr_arguments(gebsr2gebsr_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.row_block_dimA = std::get<2>(tup); arg.col_block_dimA = std::get<3>(tup); arg.row_block_dimB = std::get<4>(tup); arg.col_block_dimB = std::get<5>(tup); arg.idx_base = std::get<6>(tup); arg.idx_base2 = std::get<7>(tup); arg.dirA = std::get<8>(tup); arg.timing = 0; return arg; } Arguments setup_gebsr2gebsr_arguments(gebsr2gebsr_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = -99; arg.row_block_dimA = std::get<0>(tup); arg.col_block_dimA = std::get<1>(tup); arg.row_block_dimB = std::get<2>(tup); arg.col_block_dimB = std::get<3>(tup); arg.idx_base = std::get<4>(tup); arg.idx_base2 = std::get<5>(tup); arg.dirA = std::get<6>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<7>(tup); // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(gebsr2gebsr_bad_arg, gebsr2gebsr) { testing_gebsr2gebsr_bad_arg(); } TEST_P(parameterized_gebsr2gebsr, gebsr2gebsr_float) { Arguments arg = setup_gebsr2gebsr_arguments(GetParam()); hipsparseStatus_t status = testing_gebsr2gebsr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gebsr2gebsr, gebsr2gebsr_double) { Arguments arg = setup_gebsr2gebsr_arguments(GetParam()); hipsparseStatus_t status = testing_gebsr2gebsr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gebsr2gebsr, gebsr2gebsr_float_complex) { Arguments arg = setup_gebsr2gebsr_arguments(GetParam()); hipsparseStatus_t status = testing_gebsr2gebsr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gebsr2gebsr, gebsr2gebsr_double_complex) { Arguments arg = setup_gebsr2gebsr_arguments(GetParam()); hipsparseStatus_t status = testing_gebsr2gebsr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gebsr2gebsr_bin, gebsr2gebsr_bin_float) { Arguments arg = setup_gebsr2gebsr_arguments(GetParam()); hipsparseStatus_t status = testing_gebsr2gebsr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gebsr2gebsr_bin, gebsr2gebsr_bin_double) { Arguments arg = setup_gebsr2gebsr_arguments(GetParam()); hipsparseStatus_t status = testing_gebsr2gebsr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(gebsr2gebsr, parameterized_gebsr2gebsr, testing::Combine(testing::ValuesIn(gebsr2gebsr_M_range), testing::ValuesIn(gebsr2gebsr_N_range), testing::ValuesIn(gebsr2gebsr_row_block_dim_A_range), testing::ValuesIn(gebsr2gebsr_col_block_dim_A_range), testing::ValuesIn(gebsr2gebsr_row_block_dim_C_range), testing::ValuesIn(gebsr2gebsr_col_block_dim_C_range), testing::ValuesIn(gebsr2gebsr_A_base_range), testing::ValuesIn(gebsr2gebsr_C_base_range), testing::ValuesIn(gebsr2gebsr_dir_range))); INSTANTIATE_TEST_SUITE_P(gebsr2gebsr_bin, parameterized_gebsr2gebsr_bin, testing::Combine(testing::ValuesIn(gebsr2gebsr_row_block_dim_A_range_bin), testing::ValuesIn(gebsr2gebsr_col_block_dim_A_range_bin), testing::ValuesIn(gebsr2gebsr_row_block_dim_C_range_bin), testing::ValuesIn(gebsr2gebsr_col_block_dim_C_range_bin), testing::ValuesIn(gebsr2gebsr_A_base_range_bin), testing::ValuesIn(gebsr2gebsr_C_base_range_bin), testing::ValuesIn(gebsr2gebsr_dir_range_bin), testing::ValuesIn(gebsr2gebsr_bin))); hipSPARSE-rocm-5.7.1/clients/tests/test_gemmi.cpp000066400000000000000000000125101447644345400216420ustar00rootroot00000000000000/* ************************************************************************ * 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_gemmi.hpp" #include "utility.hpp" #include #include typedef std::tuple gemmi_tuple; typedef std::tuple gemmi_bin_tuple; int gemmi_M_range[] = {-1, 0, 7, 19, 64, 78, 157, 482}; int gemmi_N_range[] = {-1, 0, 42, 275, 759}; int gemmi_K_range[] = {-1, 0, 50, 173, 1375}; double gemmi_alpha_range[] = {-0.5, 2.0}; double gemmi_beta_range[] = {0.5, 0.0}; std::string gemmi_bin[] = {"nos1.bin", "nos3.bin", "nos5.bin", "nos7.bin"}; class parameterized_gemmi : public testing::TestWithParam { protected: parameterized_gemmi() {} virtual ~parameterized_gemmi() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_gemmi_bin : public testing::TestWithParam { protected: parameterized_gemmi_bin() {} virtual ~parameterized_gemmi_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_gemmi_arguments(gemmi_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); arg.beta = std::get<4>(tup); arg.timing = 0; return arg; } Arguments setup_gemmi_arguments(gemmi_bin_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = -99; arg.K = -99; arg.alpha = std::get<1>(tup); arg.beta = 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.filename = get_filename(bin_file); return arg; } // Only run tests for CUDA 11.1 or greater (removed in cusparse 12.0.0) #if(!defined(CUDART_VERSION) || (CUDART_VERSION >= 11010 && CUDART_VERSION < 12000)) TEST(gemmi_bad_arg, gemmi_float) { testing_gemmi_bad_arg(); } TEST_P(parameterized_gemmi, gemmi_float) { Arguments arg = setup_gemmi_arguments(GetParam()); hipsparseStatus_t status = testing_gemmi(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gemmi, gemmi_double) { Arguments arg = setup_gemmi_arguments(GetParam()); hipsparseStatus_t status = testing_gemmi(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gemmi, gemmi_float_complex) { Arguments arg = setup_gemmi_arguments(GetParam()); hipsparseStatus_t status = testing_gemmi(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gemmi, gemmi_double_complex) { Arguments arg = setup_gemmi_arguments(GetParam()); hipsparseStatus_t status = testing_gemmi(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gemmi_bin, gemmi_bin_float) { Arguments arg = setup_gemmi_arguments(GetParam()); hipsparseStatus_t status = testing_gemmi(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gemmi_bin, gemmi_bin_double) { Arguments arg = setup_gemmi_arguments(GetParam()); hipsparseStatus_t status = testing_gemmi(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(gemmi, parameterized_gemmi, testing::Combine(testing::ValuesIn(gemmi_M_range), testing::ValuesIn(gemmi_N_range), testing::ValuesIn(gemmi_K_range), testing::ValuesIn(gemmi_alpha_range), testing::ValuesIn(gemmi_beta_range))); INSTANTIATE_TEST_SUITE_P(gemmi_bin, parameterized_gemmi_bin, testing::Combine(testing::ValuesIn(gemmi_N_range), testing::ValuesIn(gemmi_alpha_range), testing::ValuesIn(gemmi_beta_range), testing::ValuesIn(gemmi_bin))); hipSPARSE-rocm-5.7.1/clients/tests/test_gemvi.cpp000066400000000000000000000037211447644345400216570ustar00rootroot00000000000000/* ************************************************************************ * 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_gemvi.hpp" #include TEST(gemvi_bad_arg, gemvi_float) { testing_gemvi_bad_arg(); } TEST(gemvi, gemvi_float) { hipsparseStatus_t status = testing_gemvi(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(gemvi, gemvi_double) { hipsparseStatus_t status = testing_gemvi(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(gemvi, gemvi_hipFloatComplex) { hipsparseStatus_t status = testing_gemvi(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(gemvi, gemvi_hipDoubleComplex) { hipsparseStatus_t status = testing_gemvi(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } hipSPARSE-rocm-5.7.1/clients/tests/test_gpsv_interleaved_batch.cpp000066400000000000000000000041771447644345400252600ustar00rootroot00000000000000/* ************************************************************************ * 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_gpsv_interleaved_batch.hpp" #include // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(gpsv_interleaved_batch_bad_arg, gpsv_interleaved_batch_float) { testing_gpsv_interleaved_batch_bad_arg(); } TEST(gpsv_interleaved_batch, gpsv_interleaved_batch_float) { hipsparseStatus_t status = testing_gpsv_interleaved_batch(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(gpsv_interleaved_batch, gpsv_interleaved_batch_double) { hipsparseStatus_t status = testing_gpsv_interleaved_batch(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(gpsv_interleaved_batch, gpsv_interleaved_batch_hipComplex) { hipsparseStatus_t status = testing_gpsv_interleaved_batch(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_gthr.cpp000066400000000000000000000067011447644345400215150ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_gthr.hpp" #include "utility.hpp" #include #include typedef hipsparseIndexBase_t base; typedef std::tuple gthr_tuple; int gthr_N_range[] = {12000, 15332, 22031}; int gthr_nnz_range[] = {-1, 0, 5, 10, 500, 1000, 7111, 10000}; base gthr_idx_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; class parameterized_gthr : public testing::TestWithParam { protected: parameterized_gthr() {} virtual ~parameterized_gthr() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_gthr_arguments(gthr_tuple tup) { Arguments arg; arg.N = std::get<0>(tup); arg.nnz = std::get<1>(tup); arg.idx_base = std::get<2>(tup); arg.timing = 0; return arg; } // Only run tests for CUDA 11.1 or greater (removed in cusparse 12.0.0) #if(!defined(CUDART_VERSION) || (CUDART_VERSION >= 11010 && CUDART_VERSION < 12000)) TEST(gthr_bad_arg, gthr_float) { testing_gthr_bad_arg(); } TEST_P(parameterized_gthr, gthr_float) { Arguments arg = setup_gthr_arguments(GetParam()); hipsparseStatus_t status = testing_gthr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gthr, gthr_double) { Arguments arg = setup_gthr_arguments(GetParam()); hipsparseStatus_t status = testing_gthr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gthr, gthr_float_complex) { Arguments arg = setup_gthr_arguments(GetParam()); hipsparseStatus_t status = testing_gthr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gthr, gthr_double_complex) { Arguments arg = setup_gthr_arguments(GetParam()); hipsparseStatus_t status = testing_gthr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(gthr, parameterized_gthr, testing::Combine(testing::ValuesIn(gthr_N_range), testing::ValuesIn(gthr_nnz_range), testing::ValuesIn(gthr_idx_base_range))); hipSPARSE-rocm-5.7.1/clients/tests/test_gthrz.cpp000066400000000000000000000067441447644345400217160ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_gthrz.hpp" #include "utility.hpp" #include #include typedef hipsparseIndexBase_t base; typedef std::tuple gthrz_tuple; int gthrz_N_range[] = {12000, 15332, 22031}; int gthrz_nnz_range[] = {-1, 0, 5, 10, 500, 1000, 7111, 10000}; base gthrz_idx_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; class parameterized_gthrz : public testing::TestWithParam { protected: parameterized_gthrz() {} virtual ~parameterized_gthrz() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_gthrz_arguments(gthrz_tuple tup) { Arguments arg; arg.N = std::get<0>(tup); arg.nnz = std::get<1>(tup); arg.idx_base = std::get<2>(tup); arg.timing = 0; return arg; } // Only run tests for CUDA 11.1 or greater (removed in cusparse 12.0.0) #if(!defined(CUDART_VERSION) || (CUDART_VERSION >= 11010 && CUDART_VERSION < 12000)) TEST(gthrz_bad_arg, gthrz_float) { testing_gthrz_bad_arg(); } TEST_P(parameterized_gthrz, gthrz_float) { Arguments arg = setup_gthrz_arguments(GetParam()); hipsparseStatus_t status = testing_gthrz(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gthrz, gthrz_double) { Arguments arg = setup_gthrz_arguments(GetParam()); hipsparseStatus_t status = testing_gthrz(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gthrz, gthrz_float_complex) { Arguments arg = setup_gthrz_arguments(GetParam()); hipsparseStatus_t status = testing_gthrz(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gthrz, gthrz_double_complex) { Arguments arg = setup_gthrz_arguments(GetParam()); hipsparseStatus_t status = testing_gthrz(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(gthrz, parameterized_gthrz, testing::Combine(testing::ValuesIn(gthrz_N_range), testing::ValuesIn(gthrz_nnz_range), testing::ValuesIn(gthrz_idx_base_range))); hipSPARSE-rocm-5.7.1/clients/tests/test_gtsv.cpp000066400000000000000000000036411447644345400215340ustar00rootroot00000000000000/* ************************************************************************ * 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 // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(gtsv2_bad_arg, gtsv2_float) { testing_gtsv2_bad_arg(); } TEST(gtsv2, gtsv2_float) { hipsparseStatus_t status = testing_gtsv2(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(gtsv2, gtsv2_double) { hipsparseStatus_t status = testing_gtsv2(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(gtsv2, gtsv2_hipComplex) { hipsparseStatus_t status = testing_gtsv2(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_gtsv2_nopivot.cpp000066400000000000000000000040121447644345400233650ustar00rootroot00000000000000/* ************************************************************************ * 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_gtsv2_nopivot.hpp" #include // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(gtsv2_nopivot_bad_arg, gtsv2_nopivot_float) { testing_gtsv2_nopivot_bad_arg(); } TEST(gtsv2_nopivot, gtsv2_nopivot_float) { hipsparseStatus_t status = testing_gtsv2_nopivot(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(gtsv2_nopivot, gtsv2_nopivot_double) { hipsparseStatus_t status = testing_gtsv2_nopivot(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(gtsv2_nopivot, gtsv2_nopivot_hipComplex) { hipsparseStatus_t status = testing_gtsv2_nopivot(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_gtsv2_strided_batch.cpp000066400000000000000000000041301447644345400244670ustar00rootroot00000000000000/* ************************************************************************ * 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_gtsv2_strided_batch.hpp" #include // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(gtsv2_strided_batch_bad_arg, gtsv2_strided_batch_float) { testing_gtsv2_strided_batch_bad_arg(); } TEST(gtsv2_strided_batch, gtsv2_strided_batch_float) { hipsparseStatus_t status = testing_gtsv2_strided_batch(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(gtsv2_strided_batch, gtsv2_strided_batch_double) { hipsparseStatus_t status = testing_gtsv2_strided_batch(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(gtsv2_strided_batch, gtsv2_strided_batch_hipComplex) { hipsparseStatus_t status = testing_gtsv2_strided_batch(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_gtsv_interleaved_batch.cpp000066400000000000000000000041771447644345400252640ustar00rootroot00000000000000/* ************************************************************************ * 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_interleaved_batch.hpp" #include // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(gtsv_interleaved_batch_bad_arg, gtsv_interleaved_batch_float) { testing_gtsv_interleaved_batch_bad_arg(); } TEST(gtsv_interleaved_batch, gtsv_interleaved_batch_float) { hipsparseStatus_t status = testing_gtsv_interleaved_batch(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(gtsv_interleaved_batch, gtsv_interleaved_batch_double) { hipsparseStatus_t status = testing_gtsv_interleaved_batch(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(gtsv_interleaved_batch, gtsv_interleaved_batch_hipComplex) { hipsparseStatus_t status = testing_gtsv_interleaved_batch(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_hyb2csr.cpp000066400000000000000000000124431447644345400221250ustar00rootroot00000000000000/* ************************************************************************ * 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_hyb2csr.hpp" #include "utility.hpp" #include #include #include typedef std::tuple hyb2csr_tuple; typedef std::tuple hyb2csr_bin_tuple; int hyb2csr_M_range[] = {-1, 0, 10, 500, 872, 1000}; int hyb2csr_N_range[] = {-3, 0, 33, 242, 623, 1000}; hipsparseIndexBase_t hyb2csr_idx_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; std::string hyb2csr_bin[] = {"rma10.bin", "mac_econ_fwd500.bin", "nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin", "sme3Dc.bin"}; class parameterized_hyb2csr : public testing::TestWithParam { protected: parameterized_hyb2csr() {} virtual ~parameterized_hyb2csr() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_hyb2csr_bin : public testing::TestWithParam { protected: parameterized_hyb2csr_bin() {} virtual ~parameterized_hyb2csr_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_hyb2csr_arguments(hyb2csr_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.idx_base = std::get<2>(tup); arg.timing = 0; return arg; } Arguments setup_hyb2csr_arguments(hyb2csr_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = -99; arg.idx_base = std::get<0>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<1>(tup); // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(hyb2csr_bad_arg, hyb2csr) { testing_hyb2csr_bad_arg(); } TEST_P(parameterized_hyb2csr, hyb2csr_float) { Arguments arg = setup_hyb2csr_arguments(GetParam()); hipsparseStatus_t status = testing_hyb2csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_hyb2csr, hyb2csr_double) { Arguments arg = setup_hyb2csr_arguments(GetParam()); hipsparseStatus_t status = testing_hyb2csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_hyb2csr, hyb2csr_float_complex) { Arguments arg = setup_hyb2csr_arguments(GetParam()); hipsparseStatus_t status = testing_hyb2csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_hyb2csr, hyb2csr_double_complex) { Arguments arg = setup_hyb2csr_arguments(GetParam()); hipsparseStatus_t status = testing_hyb2csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_hyb2csr_bin, hyb2csr_bin_float) { Arguments arg = setup_hyb2csr_arguments(GetParam()); hipsparseStatus_t status = testing_hyb2csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_hyb2csr_bin, hyb2csr_bin_double) { Arguments arg = setup_hyb2csr_arguments(GetParam()); hipsparseStatus_t status = testing_hyb2csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(hyb2csr, parameterized_hyb2csr, testing::Combine(testing::ValuesIn(hyb2csr_M_range), testing::ValuesIn(hyb2csr_N_range), testing::ValuesIn(hyb2csr_idx_base_range))); INSTANTIATE_TEST_SUITE_P(hyb2csr_bin, parameterized_hyb2csr_bin, testing::Combine(testing::ValuesIn(hyb2csr_idx_base_range), testing::ValuesIn(hyb2csr_bin))); hipSPARSE-rocm-5.7.1/clients/tests/test_hybmv.cpp000066400000000000000000000141741447644345400217010ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_hybmv.hpp" #include "utility.hpp" #include #include #include typedef std::tuple hybmv_tuple; typedef std::tuple hybmv_bin_tuple; int hyb_M_range[] = {-1, 0, 10, 500, 7111, 10000}; int hyb_N_range[] = {-3, 0, 33, 842, 4441, 10000}; std::vector hyb_alpha_range = {3.0}; std::vector hyb_beta_range = {0.67}; hipsparseIndexBase_t hyb_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; hipsparseHybPartition_t hyb_partition[] = {HIPSPARSE_HYB_PARTITION_AUTO, HIPSPARSE_HYB_PARTITION_MAX, HIPSPARSE_HYB_PARTITION_USER}; int hyb_ELL_range[] = {0, 2}; std::string hyb_bin[] = {"nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin"}; class parameterized_hybmv : public testing::TestWithParam { protected: parameterized_hybmv() {} virtual ~parameterized_hybmv() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_hybmv_bin : public testing::TestWithParam { protected: parameterized_hybmv_bin() {} virtual ~parameterized_hybmv_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_hybmv_arguments(hybmv_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.idx_base = std::get<4>(tup); arg.part = std::get<5>(tup); arg.ell_width = std::get<6>(tup); arg.timing = 0; return arg; } Arguments setup_hybmv_arguments(hybmv_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = -99; arg.alpha = std::get<0>(tup); arg.beta = std::get<1>(tup); arg.idx_base = std::get<2>(tup); arg.part = std::get<3>(tup); arg.ell_width = 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.filename = get_filename(bin_file); return arg; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(hybmv_bad_arg, hybmv_float) { testing_hybmv_bad_arg(); } TEST_P(parameterized_hybmv, hybmv_float) { Arguments arg = setup_hybmv_arguments(GetParam()); hipsparseStatus_t status = testing_hybmv(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_hybmv, hybmv_double) { Arguments arg = setup_hybmv_arguments(GetParam()); hipsparseStatus_t status = testing_hybmv(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_hybmv, hybmv_float_complex) { Arguments arg = setup_hybmv_arguments(GetParam()); hipsparseStatus_t status = testing_hybmv(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_hybmv, hybmv_double_complex) { Arguments arg = setup_hybmv_arguments(GetParam()); hipsparseStatus_t status = testing_hybmv(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_hybmv_bin, hybmv_bin_float) { Arguments arg = setup_hybmv_arguments(GetParam()); hipsparseStatus_t status = testing_hybmv(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_hybmv_bin, hybmv_bin_double) { Arguments arg = setup_hybmv_arguments(GetParam()); hipsparseStatus_t status = testing_hybmv(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(hybmv, parameterized_hybmv, testing::Combine(testing::ValuesIn(hyb_M_range), testing::ValuesIn(hyb_N_range), testing::ValuesIn(hyb_alpha_range), testing::ValuesIn(hyb_beta_range), testing::ValuesIn(hyb_idxbase_range), testing::ValuesIn(hyb_partition), testing::ValuesIn(hyb_ELL_range))); INSTANTIATE_TEST_SUITE_P(hybmv_bin, parameterized_hybmv_bin, testing::Combine(testing::ValuesIn(hyb_alpha_range), testing::ValuesIn(hyb_beta_range), testing::ValuesIn(hyb_idxbase_range), testing::ValuesIn(hyb_partition), testing::ValuesIn(hyb_ELL_range), testing::ValuesIn(hyb_bin))); hipSPARSE-rocm-5.7.1/clients/tests/test_identity.cpp000066400000000000000000000043531447644345400224030ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_identity.hpp" #include "utility.hpp" #include #include int identity_N_range[] = {-3, 0, 33, 242, 623, 1000}; class parameterized_identity : public testing::TestWithParam { protected: parameterized_identity() {} virtual ~parameterized_identity() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_identity_arguments(int n) { Arguments arg; arg.N = n; arg.timing = 0; return arg; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(identity_bad_arg, identity) { testing_identity_bad_arg(); } TEST_P(parameterized_identity, identity) { Arguments arg = setup_identity_arguments(GetParam()); hipsparseStatus_t status = testing_identity(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(identity, parameterized_identity, testing::ValuesIn(identity_N_range)); hipSPARSE-rocm-5.7.1/clients/tests/test_nnz.cpp000066400000000000000000000063371447644345400213630ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {-1, 0, 10, 500, 872, 1000}; int nnz_N_range[] = {-3, 0, 33, 242, 623, 1000}; int nnz_LD_range[] = {5, 500, 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; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) 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); } #endif INSTANTIATE_TEST_SUITE_P(nnz, parameterized_nnz, testing::Combine(testing::ValuesIn(nnz_M_range), testing::ValuesIn(nnz_N_range), testing::ValuesIn(nnz_LD_range))); hipSPARSE-rocm-5.7.1/clients/tests/test_prune_csr2csr.cpp000066400000000000000000000131401447644345400233360ustar00rootroot00000000000000/* ************************************************************************ * 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_prune_csr2csr.hpp" #include "utility.hpp" #include #include #include typedef std::tuple prune_csr2csr_tuple; typedef std::tuple prune_csr2csr_bin_tuple; int prune_csr2csr_M_range[] = {-1, 10, 500, 872, 27463, 35327}; int prune_csr2csr_N_range[] = {-3, 33, 242, 623, 29837, 22645}; double prune_csr2csr_threshold_range[] = {0.0, 0.0012, 0.08736, 0.33333, 0.5, 1.7}; hipsparseIndexBase_t prune_csr2csr_base_A_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; hipsparseIndexBase_t prune_csr2csr_base_C_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; std::string prune_csr2csr_bin[] = {"nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin"}; class parameterized_prune_csr2csr : public testing::TestWithParam { protected: parameterized_prune_csr2csr() {} virtual ~parameterized_prune_csr2csr() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_prune_csr2csr_bin : public testing::TestWithParam { protected: parameterized_prune_csr2csr_bin() {} virtual ~parameterized_prune_csr2csr_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_prune_csr2csr_arguments(prune_csr2csr_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.threshold = std::get<2>(tup); arg.idx_base = std::get<3>(tup); arg.idx_base2 = std::get<4>(tup); arg.timing = 0; return arg; } Arguments setup_prune_csr2csr_arguments(prune_csr2csr_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = -99; arg.threshold = std::get<0>(tup); arg.idx_base = std::get<1>(tup); arg.idx_base2 = 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.filename = get_filename(bin_file); return arg; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(prune_csr2csr_bad_arg, prune_csr2csr) { testing_prune_csr2csr_bad_arg(); } TEST_P(parameterized_prune_csr2csr, prune_csr2csr_float) { Arguments arg = setup_prune_csr2csr_arguments(GetParam()); hipsparseStatus_t status = testing_prune_csr2csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_prune_csr2csr, prune_csr2csr_double) { Arguments arg = setup_prune_csr2csr_arguments(GetParam()); hipsparseStatus_t status = testing_prune_csr2csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_prune_csr2csr_bin, prune_csr2csr_bin_float) { Arguments arg = setup_prune_csr2csr_arguments(GetParam()); hipsparseStatus_t status = testing_prune_csr2csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_prune_csr2csr_bin, prune_csr2csr_bin_double) { Arguments arg = setup_prune_csr2csr_arguments(GetParam()); hipsparseStatus_t status = testing_prune_csr2csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(prune_csr2csr, parameterized_prune_csr2csr, testing::Combine(testing::ValuesIn(prune_csr2csr_M_range), testing::ValuesIn(prune_csr2csr_N_range), testing::ValuesIn(prune_csr2csr_threshold_range), testing::ValuesIn(prune_csr2csr_base_A_range), testing::ValuesIn(prune_csr2csr_base_C_range))); INSTANTIATE_TEST_SUITE_P(prune_csr2csr_bin, parameterized_prune_csr2csr_bin, testing::Combine(testing::ValuesIn(prune_csr2csr_threshold_range), testing::ValuesIn(prune_csr2csr_base_A_range), testing::ValuesIn(prune_csr2csr_base_C_range), testing::ValuesIn(prune_csr2csr_bin))); hipSPARSE-rocm-5.7.1/clients/tests/test_prune_csr2csr_by_percentage.cpp000066400000000000000000000152261447644345400262340ustar00rootroot00000000000000/* ************************************************************************ * 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_prune_csr2csr_by_percentage.hpp" #include "utility.hpp" #include #include #include typedef std::tuple prune_csr2csr_by_percentage_tuple; typedef std::tuple prune_csr2csr_by_percentage_bin_tuple; int prune_csr2csr_by_percentage_M_range[] = {-1, 10, 500, 872, 465327}; int prune_csr2csr_by_percentage_N_range[] = {-3, 33, 242, 623, 592645}; double prune_csr2csr_by_percentage_range[] = {5.7, 75.0, 101.0}; hipsparseIndexBase_t prune_csr2csr_by_percentage_base_A_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; hipsparseIndexBase_t prune_csr2csr_by_percentage_base_C_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; std::string prune_csr2csr_by_percentage_bin[] = {"rma10.bin", "mac_econ_fwd500.bin", "nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin", "Chebyshev4.bin", "sme3Dc.bin", "shipsec1.bin"}; class parameterized_prune_csr2csr_by_percentage : public testing::TestWithParam { protected: parameterized_prune_csr2csr_by_percentage() {} virtual ~parameterized_prune_csr2csr_by_percentage() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_prune_csr2csr_by_percentage_bin : public testing::TestWithParam { protected: parameterized_prune_csr2csr_by_percentage_bin() {} virtual ~parameterized_prune_csr2csr_by_percentage_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_prune_csr2csr_by_percentage_arguments(prune_csr2csr_by_percentage_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.percentage = std::get<2>(tup); arg.idx_base = std::get<3>(tup); arg.idx_base2 = std::get<4>(tup); arg.timing = 0; return arg; } Arguments setup_prune_csr2csr_by_percentage_arguments(prune_csr2csr_by_percentage_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = -99; arg.percentage = std::get<0>(tup); arg.idx_base = std::get<1>(tup); arg.idx_base2 = 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.filename = get_filename(bin_file); return arg; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(prune_csr2csr_by_percentage_bad_arg, prune_csr2csr_by_percentage) { testing_prune_csr2csr_by_percentage_bad_arg(); } TEST_P(parameterized_prune_csr2csr_by_percentage, prune_csr2csr_by_percentage_float) { Arguments arg = setup_prune_csr2csr_by_percentage_arguments(GetParam()); hipsparseStatus_t status = testing_prune_csr2csr_by_percentage(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_prune_csr2csr_by_percentage, prune_csr2csr_by_percentage_double) { Arguments arg = setup_prune_csr2csr_by_percentage_arguments(GetParam()); hipsparseStatus_t status = testing_prune_csr2csr_by_percentage(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_prune_csr2csr_by_percentage_bin, prune_csr2csr_by_percentage_bin_float) { Arguments arg = setup_prune_csr2csr_by_percentage_arguments(GetParam()); hipsparseStatus_t status = testing_prune_csr2csr_by_percentage(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_prune_csr2csr_by_percentage_bin, prune_csr2csr_percentage_bin_double) { Arguments arg = setup_prune_csr2csr_by_percentage_arguments(GetParam()); hipsparseStatus_t status = testing_prune_csr2csr_by_percentage(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P( prune_csr2csr_by_percentage, parameterized_prune_csr2csr_by_percentage, testing::Combine(testing::ValuesIn(prune_csr2csr_by_percentage_M_range), testing::ValuesIn(prune_csr2csr_by_percentage_N_range), testing::ValuesIn(prune_csr2csr_by_percentage_range), testing::ValuesIn(prune_csr2csr_by_percentage_base_A_range), testing::ValuesIn(prune_csr2csr_by_percentage_base_C_range))); INSTANTIATE_TEST_SUITE_P( prune_csr2csr_by_percentage_bin, parameterized_prune_csr2csr_by_percentage_bin, testing::Combine(testing::ValuesIn(prune_csr2csr_by_percentage_range), testing::ValuesIn(prune_csr2csr_by_percentage_base_A_range), testing::ValuesIn(prune_csr2csr_by_percentage_base_C_range), testing::ValuesIn(prune_csr2csr_by_percentage_bin))); hipSPARSE-rocm-5.7.1/clients/tests/test_prune_dense2csr.cpp000066400000000000000000000071601447644345400236520ustar00rootroot00000000000000/* ************************************************************************ * 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_prune_dense2csr.hpp" #include "utility.hpp" #include #include #include typedef hipsparseIndexBase_t base; typedef std::tuple prune_dense2csr_tuple; int prune_dense2csr_M_range[] = {-1, 0, 10, 500, 872, 1000}; int prune_dense2csr_N_range[] = {-3, 0, 33, 242, 623, 1000}; int prune_dense2csr_LD_range[] = {50, 500, 1000}; double prune_dense2csr_threshold_range[] = {0.1, 0.55}; base prune_dense2csr_idx_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; class parameterized_prune_dense2csr : public testing::TestWithParam { protected: parameterized_prune_dense2csr() {} virtual ~parameterized_prune_dense2csr() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_prune_dense2csr_arguments(prune_dense2csr_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.lda = std::get<2>(tup); arg.threshold = std::get<3>(tup); arg.idx_base = std::get<4>(tup); return arg; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(prune_dense2csr_bad_arg, prune_dense2csr) { testing_prune_dense2csr_bad_arg(); } TEST_P(parameterized_prune_dense2csr, prune_dense2csr_float) { Arguments arg = setup_prune_dense2csr_arguments(GetParam()); hipsparseStatus_t status = testing_prune_dense2csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_prune_dense2csr, prune_dense2csr_double) { Arguments arg = setup_prune_dense2csr_arguments(GetParam()); hipsparseStatus_t status = testing_prune_dense2csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(prune_dense2csr, parameterized_prune_dense2csr, testing::Combine(testing::ValuesIn(prune_dense2csr_M_range), testing::ValuesIn(prune_dense2csr_N_range), testing::ValuesIn(prune_dense2csr_LD_range), testing::ValuesIn(prune_dense2csr_threshold_range), testing::ValuesIn(prune_dense2csr_idx_base_range))); hipSPARSE-rocm-5.7.1/clients/tests/test_prune_dense2csr_by_percentage.cpp000066400000000000000000000076351447644345400265500ustar00rootroot00000000000000/* ************************************************************************ * 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_prune_dense2csr_by_percentage.hpp" #include "utility.hpp" #include #include #include typedef hipsparseIndexBase_t base; typedef std::tuple prune_dense2csr_by_percentage_tuple; int prune_dense2csr_by_percentage_M_range[] = {-1, 0, 10, 500, 872, 1000}; int prune_dense2csr_by_percentage_N_range[] = {-3, 0, 33, 242, 623, 1000}; int prune_dense2csr_by_percentage_LD_range[] = {50, 500, 1000}; double prune_dense2csr_by_percentage_range[] = {-0.001, 0.1, 55.0, 67.0}; base prune_dense2csr_by_percentage_idx_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; class parameterized_prune_dense2csr_by_percentage : public testing::TestWithParam { protected: parameterized_prune_dense2csr_by_percentage() {} virtual ~parameterized_prune_dense2csr_by_percentage() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_prune_dense2csr_by_percentage_arguments(prune_dense2csr_by_percentage_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.lda = std::get<2>(tup); arg.percentage = std::get<3>(tup); arg.idx_base = std::get<4>(tup); return arg; } // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(prune_dense2csr_by_percentage_bad_arg, prune_dense2csr_by_percentage) { testing_prune_dense2csr_by_percentage_bad_arg(); } TEST_P(parameterized_prune_dense2csr_by_percentage, prune_dense2csr_by_percentage_float) { Arguments arg = setup_prune_dense2csr_by_percentage_arguments(GetParam()); hipsparseStatus_t status = testing_prune_dense2csr_by_percentage(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_prune_dense2csr_by_percentage, prune_dense2csr_by_percentage_double) { Arguments arg = setup_prune_dense2csr_by_percentage_arguments(GetParam()); hipsparseStatus_t status = testing_prune_dense2csr_by_percentage(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P( prune_dense2csr_by_percentage, parameterized_prune_dense2csr_by_percentage, testing::Combine(testing::ValuesIn(prune_dense2csr_by_percentage_M_range), testing::ValuesIn(prune_dense2csr_by_percentage_N_range), testing::ValuesIn(prune_dense2csr_by_percentage_LD_range), testing::ValuesIn(prune_dense2csr_by_percentage_range), testing::ValuesIn(prune_dense2csr_by_percentage_idx_base_range))); hipSPARSE-rocm-5.7.1/clients/tests/test_rot.cpp000066400000000000000000000041201447644345400213460ustar00rootroot00000000000000/* ************************************************************************ * 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_rot.hpp" #include // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(rot_bad_arg, rot_float) { testing_rot_bad_arg(); } TEST(rot, rot_i32_float) { hipsparseStatus_t status = testing_rot(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(rot, rot_i64_double) { hipsparseStatus_t status = testing_rot(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(rot, rot_i32_hipFloatComplex) { hipsparseStatus_t status = testing_rot(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(rot, rot_i64_hipDoubleComplex) { hipsparseStatus_t status = testing_rot(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_roti.cpp000066400000000000000000000065331447644345400215310ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_roti.hpp" #include "utility.hpp" #include #include typedef hipsparseIndexBase_t base; typedef std::tuple roti_tuple; int roti_N_range[] = {12000, 15332, 22031}; int roti_nnz_range[] = {-1, 0, 5, 10, 500, 1000, 7111, 10000}; double roti_c_range[] = {-2.0, 0.0, 1.0}; double roti_s_range[] = {-3.0, 0.0, 4.0}; base roti_idx_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; class parameterized_roti : public testing::TestWithParam { protected: parameterized_roti() {} virtual ~parameterized_roti() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_roti_arguments(roti_tuple tup) { Arguments arg; arg.N = std::get<0>(tup); arg.nnz = std::get<1>(tup); arg.alpha = std::get<2>(tup); arg.beta = std::get<3>(tup); arg.idx_base = std::get<4>(tup); arg.timing = 0; return arg; } // Only run tests for CUDA 11.1 or greater (removed in cusparse 12.0.0) #if(!defined(CUDART_VERSION) || (CUDART_VERSION >= 11010 && CUDART_VERSION < 12000)) TEST(roti_bad_arg, roti_float) { testing_roti_bad_arg(); } TEST_P(parameterized_roti, roti_float) { Arguments arg = setup_roti_arguments(GetParam()); hipsparseStatus_t status = testing_roti(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_roti, roti_double) { Arguments arg = setup_roti_arguments(GetParam()); hipsparseStatus_t status = testing_roti(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(roti, parameterized_roti, testing::Combine(testing::ValuesIn(roti_N_range), testing::ValuesIn(roti_nnz_range), testing::ValuesIn(roti_c_range), testing::ValuesIn(roti_s_range), testing::ValuesIn(roti_idx_base_range))); hipSPARSE-rocm-5.7.1/clients/tests/test_scatter.cpp000066400000000000000000000034711447644345400222170ustar00rootroot00000000000000/* ************************************************************************ * 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_scatter.hpp" #include // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(scatter_bad_arg, scatter_float) { testing_scatter_bad_arg(); } TEST(scatter, scatter_i32_float) { hipsparseStatus_t status = testing_scatter(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(scatter, scatter_i64_double) { hipsparseStatus_t status = testing_scatter(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_sctr.cpp000066400000000000000000000067011447644345400215240ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_sctr.hpp" #include "utility.hpp" #include #include typedef hipsparseIndexBase_t base; typedef std::tuple sctr_tuple; int sctr_N_range[] = {12000, 15332, 22031}; int sctr_nnz_range[] = {-1, 0, 5, 10, 500, 1000, 7111, 10000}; base sctr_idx_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; class parameterized_sctr : public testing::TestWithParam { protected: parameterized_sctr() {} virtual ~parameterized_sctr() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_sctr_arguments(sctr_tuple tup) { Arguments arg; arg.N = std::get<0>(tup); arg.nnz = std::get<1>(tup); arg.idx_base = std::get<2>(tup); arg.timing = 0; return arg; } // Only run tests for CUDA 11.1 or greater (removed in cusparse 12.0.0) #if(!defined(CUDART_VERSION) || (CUDART_VERSION >= 11010 && CUDART_VERSION < 12000)) TEST(sctr_bad_arg, sctr_float) { testing_sctr_bad_arg(); } TEST_P(parameterized_sctr, sctr_float) { Arguments arg = setup_sctr_arguments(GetParam()); hipsparseStatus_t status = testing_sctr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sctr, sctr_double) { Arguments arg = setup_sctr_arguments(GetParam()); hipsparseStatus_t status = testing_sctr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sctr, sctr_float_complex) { Arguments arg = setup_sctr_arguments(GetParam()); hipsparseStatus_t status = testing_sctr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sctr, sctr_double_complex) { Arguments arg = setup_sctr_arguments(GetParam()); hipsparseStatus_t status = testing_sctr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(sctr, parameterized_sctr, testing::Combine(testing::ValuesIn(sctr_N_range), testing::ValuesIn(sctr_nnz_range), testing::ValuesIn(sctr_idx_base_range))); hipSPARSE-rocm-5.7.1/clients/tests/test_sddmm_coo.cpp000066400000000000000000000037301447644345400225140ustar00rootroot00000000000000/* ************************************************************************ * 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_coo.hpp" #include // COO format not supported in cusparse #if(!defined(CUDART_VERSION)) TEST(sddmm_coo_bad_arg, sddmm_coo_float) { testing_sddmm_coo_bad_arg(); } TEST(sddmm_coo, sddmm_coo_i32_float) { hipsparseStatus_t status = testing_sddmm_coo(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(sddmm_coo, sddmm_coo_i32_double) { hipsparseStatus_t status = testing_sddmm_coo(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(sddmm_coo, sddmm_coo_i32_hipComplex) { hipsparseStatus_t status = testing_sddmm_coo(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_sddmm_coo_aos.cpp000066400000000000000000000040201447644345400233470ustar00rootroot00000000000000/* ************************************************************************ * 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_coo_aos.hpp" #include // COO_AOS format not supported in cusparse #if(!defined(CUDART_VERSION)) TEST(sddmm_coo_aos_bad_arg, sddmm_coo_aos_float) { testing_sddmm_coo_aos_bad_arg(); } TEST(sddmm_coo_aos, sddmm_coo_aos_i32_float) { hipsparseStatus_t status = testing_sddmm_coo_aos(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(sddmm_coo_aos, sddmm_coo_aos_i32_double) { hipsparseStatus_t status = testing_sddmm_coo_aos(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(sddmm_coo_aos, sddmm_coo_aos_i32_hipComplex) { hipsparseStatus_t status = testing_sddmm_coo_aos(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_sddmm_csc.cpp000066400000000000000000000037771447644345400225170ustar00rootroot00000000000000/* ************************************************************************ * 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 // CSC format not supported in cusparse #if(!defined(CUDART_VERSION)) TEST(sddmm_csc_bad_arg, sddmm_csc_float) { testing_sddmm_csc_bad_arg(); } TEST(sddmm_csc, sddmm_csc_i32_i32_float) { hipsparseStatus_t status = testing_sddmm_csc(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(sddmm_csc, sddmm_csc_i32_i32_double) { hipsparseStatus_t status = testing_sddmm_csc(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(sddmm_csc, sddmm_csc_i32_i32_hipComplex) { hipsparseStatus_t status = testing_sddmm_csc(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_sddmm_csr.cpp000066400000000000000000000040371447644345400225240ustar00rootroot00000000000000/* ************************************************************************ * 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_csr.hpp" #include // Only run tests for CUDA 11.2.2 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11022) TEST(sddmm_csr_bad_arg, sddmm_csr_float) { testing_sddmm_csr_bad_arg(); } TEST(sddmm_csr, sddmm_csr_i32_i32_float) { hipsparseStatus_t status = testing_sddmm_csr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(sddmm_csr, sddmm_csr_i32_i32_double) { hipsparseStatus_t status = testing_sddmm_csr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(sddmm_csr, sddmm_csr_i32_i32_hipComplex) { hipsparseStatus_t status = testing_sddmm_csr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_sparse_to_dense_coo.cpp000066400000000000000000000037011447644345400245630ustar00rootroot00000000000000/* ************************************************************************ * 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_coo.hpp" #include // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(sparse_to_dense_coo_bad_arg, sparse_to_dense_coo_float) { testing_sparse_to_dense_coo_bad_arg(); } TEST(sparse_to_dense_coo, sparse_to_dense_coo_i32_i32_float) { hipsparseStatus_t status = testing_sparse_to_dense_coo(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(sparse_to_dense_coo, sparse_to_dense_coo_i64_i64_hipComplex) { hipsparseStatus_t status = testing_sparse_to_dense_coo(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_sparse_to_dense_csc.cpp000066400000000000000000000046251447644345400245610ustar00rootroot00000000000000/* ************************************************************************ * 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 // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(sparse_to_dense_csc_bad_arg, sparse_to_dense_csc_float) { testing_sparse_to_dense_csc_bad_arg(); } TEST(sparse_to_dense_csc, sparse_to_dense_csc_i32_i32_float) { hipsparseStatus_t status = testing_sparse_to_dense_csc(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #if(!defined(CUDART_VERSION)) TEST(sparse_to_dense_csc, sparse_to_dense_csc_i64_i32_double) { hipsparseStatus_t status = testing_sparse_to_dense_csc(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #else TEST(sparse_to_dense_csc, sparse_to_dense_csc_i64_i64_double) { hipsparseStatus_t status = testing_sparse_to_dense_csc(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif TEST(sparse_to_dense_csc, sparse_to_dense_csc_i64_i64_hipComplex) { hipsparseStatus_t status = testing_sparse_to_dense_csc(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_sparse_to_dense_csr.cpp000066400000000000000000000046251447644345400246000ustar00rootroot00000000000000/* ************************************************************************ * 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_csr.hpp" #include // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(sparse_to_dense_csr_bad_arg, sparse_to_dense_csr_float) { testing_sparse_to_dense_csr_bad_arg(); } TEST(sparse_to_dense_csr, sparse_to_dense_csr_i32_i32_float) { hipsparseStatus_t status = testing_sparse_to_dense_csr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #if(!defined(CUDART_VERSION)) TEST(sparse_to_dense_csr, sparse_to_dense_csr_i64_i32_double) { hipsparseStatus_t status = testing_sparse_to_dense_csr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #else TEST(sparse_to_dense_csr, sparse_to_dense_csr_i64_i64_double) { hipsparseStatus_t status = testing_sparse_to_dense_csr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif TEST(sparse_to_dense_csr, sparse_to_dense_csr_i64_i64_hipComplex) { hipsparseStatus_t status = testing_sparse_to_dense_csr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_spgemm_csr.cpp000066400000000000000000000042511447644345400227060ustar00rootroot00000000000000/* ************************************************************************ * 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_spgemm_csr.hpp" #include #if(!defined(CUDART_VERSION)) TEST(spgemm_csr_bad_arg, spgemm_csr_float) { testing_spgemm_csr_bad_arg(); } TEST(spgemm_csr, spgemm_csr_i32_i32_float) { hipsparseStatus_t status = testing_spgemm_csr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(spgemm_csr, spgemm_csr_i64_i32_double) { hipsparseStatus_t status = testing_spgemm_csr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(spgemm_csr, spgemm_csr_i64_i64_hipComplex) { hipsparseStatus_t status = testing_spgemm_csr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(spgemm_csr, spgemm_csr_i64_i64_hipDoubleComplex) { hipsparseStatus_t status = testing_spgemm_csr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_spgemmreuse_csr.cpp000066400000000000000000000050451447644345400237540ustar00rootroot00000000000000/* ************************************************************************ * 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_spgemmreuse_csr.hpp" #include #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11031) TEST(spgemmreuse_csr_bad_arg, spgemmreuse_csr_float) { testing_spgemmreuse_csr_bad_arg(); } TEST(spgemmreuse_csr, spgemmreuse_csr_i32_i32_float) { hipsparseStatus_t status = testing_spgemmreuse_csr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(spgemmreuse_csr, spgemmreuse_csr_i32_i32_double) { hipsparseStatus_t status = testing_spgemmreuse_csr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } // 64 bit indices not supported in cusparse #if(!defined(CUDART_VERSION)) TEST(spgemmreuse_csr, spgemmreuse_csr_i64_i32_double) { hipsparseStatus_t status = testing_spgemmreuse_csr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(spgemmreuse_csr, spgemmreuse_csr_i64_i64_hipComplex) { hipsparseStatus_t status = testing_spgemmreuse_csr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(spgemmreuse_csr, spgemmreuse_csr_i64_i64_hipDoubleComplex) { hipsparseStatus_t status = testing_spgemmreuse_csr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif #endif hipSPARSE-rocm-5.7.1/clients/tests/test_spmat_descr.cpp000066400000000000000000000027751447644345400230640ustar00rootroot00000000000000/* ************************************************************************ * 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(); } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_spmm_batched_coo.cpp000066400000000000000000000041211447644345400240310ustar00rootroot00000000000000/* ************************************************************************ * 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. * * ************************************************************************ */ #include "testing_spmm_batched_coo.hpp" #include // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(spmm_batched_coo_bad_arg, spmm_batched_coo_float) { testing_spmm_batched_coo_bad_arg(); } TEST(spmm_batched_coo, spmm_batched_coo_i32_float) { hipsparseStatus_t status = testing_spmm_batched_coo(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(spmm_batched_coo, spmm_batched_coo_i32_double) { hipsparseStatus_t status = testing_spmm_batched_coo(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(spmm_batched_coo, spmm_batched_coo_i32_hipComplex) { hipsparseStatus_t status = testing_spmm_batched_coo(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_spmm_batched_csc.cpp000066400000000000000000000042071447644345400240260ustar00rootroot00000000000000/* ************************************************************************ * 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. * * ************************************************************************ */ #include "testing_spmm_batched_csc.hpp" #include // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(spmm_batched_csc_bad_arg, spmm_batched_csc_float) { testing_spmm_batched_csc_bad_arg(); } TEST(spmm_batched_csc, spmm_batched_csc_i32_i32_float) { hipsparseStatus_t status = testing_spmm_batched_csc(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(spmm_batched_csc, spmm_batched_csc_i32_i32_double) { hipsparseStatus_t status = testing_spmm_batched_csc(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } // TEST(spmm_batched_csc, spmm_batched_csc_i32_i32_hipComplex) // { // hipsparseStatus_t status = testing_spmm_batched_csc(); // EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); // } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_spmm_batched_csr.cpp000066400000000000000000000042071447644345400240450ustar00rootroot00000000000000/* ************************************************************************ * 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_spmm_batched_csr.hpp" #include // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(spmm_batched_csr_bad_arg, spmm_batched_csr_float) { testing_spmm_batched_csr_bad_arg(); } TEST(spmm_batched_csr, spmm_batched_csr_i32_i32_float) { hipsparseStatus_t status = testing_spmm_batched_csr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(spmm_batched_csr, spmm_batched_csr_i32_i32_double) { hipsparseStatus_t status = testing_spmm_batched_csr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } // TEST(spmm_batched_csr, spmm_batched_csr_i32_i32_hipComplex) // { // hipsparseStatus_t status = testing_spmm_batched_csr(); // EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); // } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_spmm_bell.cpp000066400000000000000000000036601447644345400225240ustar00rootroot00000000000000/* ************************************************************************ * 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_spmm_bell.hpp" #include #if(!defined(CUDART_VERSION)) TEST(spmm_bell_bad_arg, spmm_bell_float) { testing_spmm_bell_bad_arg(); } TEST(spmm_bell, spmm_bell_i32_float) { hipsparseStatus_t status = testing_spmm_bell(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(spmm_bell, spmm_bell_i64_double) { hipsparseStatus_t status = testing_spmm_bell(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(spmm_bell, spmm_bell_i64_hipComplex) { hipsparseStatus_t status = testing_spmm_bell(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_spmm_coo.cpp000066400000000000000000000037501447644345400223660ustar00rootroot00000000000000/* ************************************************************************ * 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_spmm_coo.hpp" #include // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(spmm_coo_bad_arg, spmm_coo_float) { testing_spmm_coo_bad_arg(); } TEST(spmm_coo, spmm_coo_i32_float) { hipsparseStatus_t status = testing_spmm_coo(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(spmm_coo, spmm_coo_i64_double) { hipsparseStatus_t status = testing_spmm_coo(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(spmm_coo, spmm_coo_i64_hipComplex) { hipsparseStatus_t status = testing_spmm_coo(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endifhipSPARSE-rocm-5.7.1/clients/tests/test_spmm_csc.cpp000066400000000000000000000040201447644345400223450ustar00rootroot00000000000000/* ************************************************************************ * 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_spmm_csc.hpp" #include // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(spmm_csc_bad_arg, spmm_csc_float) { testing_spmm_csc_bad_arg(); } TEST(spmm_csc, spmm_csc_i32_i32_float) { hipsparseStatus_t status = testing_spmm_csc(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(spmm_csc, spmm_csc_i32_i32_double) { hipsparseStatus_t status = testing_spmm_csc(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(spmm_csc, spmm_csc_i32_i32_hipComplex) { hipsparseStatus_t status = testing_spmm_csc(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_spmm_csr.cpp000066400000000000000000000040201447644345400223640ustar00rootroot00000000000000/* ************************************************************************ * 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_spmm_csr.hpp" #include // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(spmm_csr_bad_arg, spmm_csr_float) { testing_spmm_csr_bad_arg(); } TEST(spmm_csr, spmm_csr_i32_i32_float) { hipsparseStatus_t status = testing_spmm_csr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(spmm_csr, spmm_csr_i32_i32_double) { hipsparseStatus_t status = testing_spmm_csr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(spmm_csr, spmm_csr_i32_i32_hipComplex) { hipsparseStatus_t status = testing_spmm_csr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_spmv_coo.cpp000066400000000000000000000035031447644345400223730ustar00rootroot00000000000000/* ************************************************************************ * 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_spmv_coo.hpp" #include // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(spmv_coo_bad_arg, spmv_coo_float) { testing_spmv_coo_bad_arg(); } TEST(spmv_coo, spmv_coo_i32_float) { hipsparseStatus_t status = testing_spmv_coo(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(spmv_coo, spmv_coo_i64_double) { hipsparseStatus_t status = testing_spmv_coo(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_spmv_coo_aos.cpp000066400000000000000000000035531447644345400232420ustar00rootroot00000000000000/* ************************************************************************ * 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_spmv_coo_aos.hpp" #include // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(spmv_coo_aos_bad_arg, spmv_coo_aos_float) { testing_spmv_coo_aos_bad_arg(); } TEST(spmv_coo_aos, spmv_coo_aos_i32_float) { hipsparseStatus_t status = testing_spmv_coo_aos(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(spmv_coo_aos, spmv_coo_aos_i64_double) { hipsparseStatus_t status = testing_spmv_coo_aos(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_spmv_csr.cpp000066400000000000000000000040651447644345400224060ustar00rootroot00000000000000/* ************************************************************************ * 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_spmv_csr.hpp" #include // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(spmv_csr_bad_arg, spmv_csr_float) { testing_spmv_csr_bad_arg(); } TEST(spmv_csr, spmv_csr_i32_i32_float) { hipsparseStatus_t status = testing_spmv_csr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #if(!defined(CUDART_VERSION)) TEST(spmv_csr, spmv_csr_i64_i32_double) { hipsparseStatus_t status = testing_spmv_csr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif TEST(spmv_csr, spmv_csr_i64_i64_hipComplex) { hipsparseStatus_t status = testing_spmv_csr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_spsm_coo.cpp000066400000000000000000000040321447644345400223660ustar00rootroot00000000000000/* ************************************************************************ * 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_coo.hpp" #include // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(spsm_coo_bad_arg, spsm_coo_float) { testing_spsm_coo_bad_arg(); } TEST(spsm_coo, spsm_coo_i32_i32_float) { hipsparseStatus_t status = testing_spsm_coo(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #if(!defined(CUDART_VERSION)) TEST(spsm_coo, spsm_coo_i64_i32_double) { hipsparseStatus_t status = testing_spsm_coo(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif TEST(spsm_coo, spsm_coo_i64_i64_hipComplex) { hipsparseStatus_t status = testing_spsm_coo(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_spsm_csr.cpp000066400000000000000000000040651447644345400224030ustar00rootroot00000000000000/* ************************************************************************ * 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 // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(spsm_csr_bad_arg, spsm_csr_float) { testing_spsm_csr_bad_arg(); } TEST(spsm_csr, spsm_csr_i32_i32_float) { hipsparseStatus_t status = testing_spsm_csr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #if(!defined(CUDART_VERSION)) TEST(spsm_csr, spsm_csr_i64_i32_double) { hipsparseStatus_t status = testing_spsm_csr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif TEST(spsm_csr, spsm_csr_i64_i64_hipComplex) { hipsparseStatus_t status = testing_spsm_csr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_spsv_coo.cpp000066400000000000000000000040321447644345400223770ustar00rootroot00000000000000/* ************************************************************************ * 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_spsv_coo.hpp" #include // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(spsv_coo_bad_arg, spsv_coo_float) { testing_spsv_coo_bad_arg(); } TEST(spsv_coo, spsv_coo_i32_i32_float) { hipsparseStatus_t status = testing_spsv_coo(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #if(!defined(CUDART_VERSION)) TEST(spsv_coo, spsv_coo_i64_i32_double) { hipsparseStatus_t status = testing_spsv_coo(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif TEST(spsv_coo, spsv_coo_i64_i64_hipComplex) { hipsparseStatus_t status = testing_spsv_coo(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_spsv_csr.cpp000066400000000000000000000040651447644345400224140ustar00rootroot00000000000000/* ************************************************************************ * 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_spsv_csr.hpp" #include // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(spsv_csr_bad_arg, spsv_csr_float) { testing_spsv_csr_bad_arg(); } TEST(spsv_csr, spsv_csr_i32_i32_float) { hipsparseStatus_t status = testing_spsv_csr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #if(!defined(CUDART_VERSION)) TEST(spsv_csr, spsv_csr_i64_i32_double) { hipsparseStatus_t status = testing_spsv_csr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif TEST(spsv_csr, spsv_csr_i64_i64_hipComplex) { hipsparseStatus_t status = testing_spsv_csr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_spvec_descr.cpp000066400000000000000000000027751447644345400230600ustar00rootroot00000000000000/* ************************************************************************ * 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_spvec_descr.hpp" // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(spvec_descr_bad_arg, spvec_descr_float) { testing_spvec_descr_bad_arg(); } #endif hipSPARSE-rocm-5.7.1/clients/tests/test_spvv.cpp000066400000000000000000000041401447644345400215420ustar00rootroot00000000000000/* ************************************************************************ * 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 // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(spvv_bad_arg, spvv_float) { testing_spvv_bad_arg(); } TEST(spvv, spvv_i32_float) { hipsparseStatus_t status = testing_spvv(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(spvv, spvv_i64_double) { hipsparseStatus_t status = testing_spvv(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(spvv, spvv_i32_hipFloatComplex) { hipsparseStatus_t status = testing_spvv(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(spvv, spvv_i64_hipDoubleComplex) { hipsparseStatus_t status = testing_spvv(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif hipSPARSE-rocm-5.7.1/cmake/000077500000000000000000000000001447644345400152575ustar00rootroot00000000000000hipSPARSE-rocm-5.7.1/cmake/ClientMatrices.cmake000066400000000000000000000142571447644345400212000ustar00rootroot00000000000000# ######################################################################## # 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 ROCSPARSE_MTX_DIR) # First try user specified mirror, if available if(DEFINED ENV{ROCSPARSE_TEST_MIRROR} AND NOT $ENV{ROCSPARSE_TEST_MIRROR} STREQUAL "") message("-- Downloading and extracting test matrix ${m}.tar.gz from user specified test mirror: $ENV{ROCSPARSE_TEST_MIRROR}") file(DOWNLOAD $ENV{ROCSPARSE_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 ${ROCSPARSE_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() hipSPARSE-rocm-5.7.1/cmake/Dependencies.cmake000066400000000000000000000071651447644345400206600ustar00rootroot00000000000000# ######################################################################## # 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. # # ######################################################################## # Dependencies 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}) find_package( rocsparse REQUIRED CONFIG PATHS ${ROCSPARSE_PATH} ) else() find_package(hip REQUIRED CONFIG PATHS ${HIP_PATH} ${ROCM_PATH} /opt/rocm) find_package( rocsparse 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(ROCM 0.7.3 QUIET CONFIG PATHS ${CMAKE_PREFIX_PATH}) if(NOT ROCM_FOUND) set(PROJECT_EXTERN_DIR ${CMAKE_CURRENT_BINARY_DIR}/extern) set(rocm_cmake_tag "master" CACHE STRING "rocm-cmake tag to download") file(DOWNLOAD https://github.com/RadeonOpenCompute/rocm-cmake/archive/${rocm_cmake_tag}.zip ${PROJECT_EXTERN_DIR}/rocm-cmake-${rocm_cmake_tag}.zip STATUS status LOG log) list(GET status 0 status_code) list(GET status 1 status_string) if(NOT status_code EQUAL 0) message(FATAL_ERROR "error: downloading 'https://github.com/RadeonOpenCompute/rocm-cmake/archive/${rocm_cmake_tag}.zip' failed status_code: ${status_code} status_string: ${status_string} log: ${log} ") endif() execute_process(COMMAND ${CMAKE_COMMAND} -E tar xzf ${PROJECT_EXTERN_DIR}/rocm-cmake-${rocm_cmake_tag}.zip WORKING_DIRECTORY ${PROJECT_EXTERN_DIR}) execute_process( COMMAND ${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=${PROJECT_EXTERN_DIR}/rocm-cmake . WORKING_DIRECTORY ${PROJECT_EXTERN_DIR}/rocm-cmake-${rocm_cmake_tag} ) execute_process( COMMAND ${CMAKE_COMMAND} --build rocm-cmake-${rocm_cmake_tag} --target install WORKING_DIRECTORY ${PROJECT_EXTERN_DIR}) find_package( ROCM 0.7.3 REQUIRED CONFIG PATHS ${PROJECT_EXTERN_DIR}/rocm-cmake ) endif() include(ROCMSetupVersion) include(ROCMCreatePackage) include(ROCMInstallTargets) include(ROCMPackageConfigHelpers) include(ROCMInstallSymlinks) include(ROCMClients) include(ROCMHeaderWrapper) hipSPARSE-rocm-5.7.1/cmake/Verbose.cmake000066400000000000000000000062521447644345400176730ustar00rootroot00000000000000# ######################################################################## # 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}") hipSPARSE-rocm-5.7.1/cmake/get-cli-arguments.cmake000066400000000000000000000017771447644345400216240ustar00rootroot00000000000000# 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( )hipSPARSE-rocm-5.7.1/deps/000077500000000000000000000000001447644345400151325ustar00rootroot00000000000000hipSPARSE-rocm-5.7.1/deps/CMakeLists.txt000066400000000000000000000065261447644345400177030ustar00rootroot00000000000000# ######################################################################## # 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. # # ######################################################################## # Helper cmake script to automate building dependencies for hipsparse # This script can be invoked manually by the user with 'cmake -P' # The ROCm platform requires Ubuntu 16.04 or Fedora 24, which has cmake 3.5 cmake_minimum_required(VERSION 3.5 FATAL_ERROR) list( APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../cmake ) # Consider removing this in the future # It can be annoying for visual studio developers to build a project that tries to install into 'program files' if( WIN32 AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT ) set( CMAKE_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/package" CACHE PATH "Install path prefix, prepended onto install directories" FORCE ) 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() # The superbuild does not build anything itself; all compiling is done in external projects project( hipsparse-dependencies NONE ) option( BUILD_GTEST "Download and build googletest library" ON ) # This module scrapes the CMakeCache.txt file and attempts to get all the cli options the user specified to cmake invocation include( get-cli-arguments ) # The following is a series of super-build projects; this cmake project will download and build if( BUILD_GTEST ) include( external-gtest ) list( APPEND hipsparse_dependencies googletest ) set( gtest_custom_target COMMAND cd ${GTEST_BINARY_ROOT}$ ${CMAKE_COMMAND} --build . --target install ) endif( ) # POLICY CMP0037 - "Target names should not be reserved and should match a validity pattern" # Familiar target names like 'install' should be OK at the super-build level if( POLICY CMP0037 ) cmake_policy( SET CMP0037 OLD ) endif( ) add_custom_target( install ${gtest_custom_target} DEPENDS ${hipsparse_dependencies} ) hipSPARSE-rocm-5.7.1/deps/convert.cpp000066400000000000000000000152401447644345400173200ustar00rootroot00000000000000/* ************************************************************************ * 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 #include #include #include #include #include #include int read_mtx_matrix(const char* filename, int& nrow, int& ncol, int& nnz, std::vector& row, std::vector& col, std::vector& val) { FILE* f = fopen(filename, "r"); if(!f) { 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, "%s %s %s %s %s", 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 int snnz; sscanf(line, "%d %d %d", &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 int idx = 0; while(fgets(line, 1024, f)) { if(idx >= nnz) { return -1; } int irow; int icol; double ival; if(!strcmp(data, "pattern")) { sscanf(line, "%d %d", &irow, &icol); ival = 1.0; } else { sscanf(line, "%d %d %lg", &irow, &icol, &ival); } --irow; --icol; // Take absolute matrix value to avoid rounding issues when testing ival = std::abs(ival); 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(int i = 0; i < nnz; ++i) { perm[i] = i; } std::sort(perm.begin(), perm.end(), [&](const int& a, const int& 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; } }); for(int i = 0; i < nnz; ++i) { row[i] = unsorted_row[perm[i]]; col[i] = unsorted_col[perm[i]]; val[i] = unsorted_val[perm[i]]; } return 0; } int write_bin_matrix( const char* filename, int m, int n, int nnz, const int* ptr, const int* col, const double* val) { FILE* f = fopen(filename, "wb"); if(!f) { return -1; } int err; err = fwrite(&m, sizeof(int), 1, f); err |= fwrite(&n, sizeof(int), 1, f); err |= fwrite(&nnz, sizeof(int), 1, f); err |= fwrite(ptr, sizeof(int), m + 1, f); err |= fwrite(col, sizeof(int), nnz, f); err |= fwrite(val, sizeof(double), nnz, f); fclose(f); return 0; } int coo_to_csr(int m, int nnz, const int* src_row, std::vector& dst_ptr) { dst_ptr.resize(m + 1, 0); // Compute nnz entries per row for(int i = 0; i < nnz; ++i) { ++dst_ptr[src_row[i] + 1]; } // Exclusive scan for(int i = 0; i < m; ++i) { dst_ptr[i + 1] += dst_ptr[i]; } return 0; } int main(int argc, char* argv[]) { int m; int n; int nnz; std::vector ptr; std::vector row; std::vector col; std::vector val; if(read_mtx_matrix(argv[1], m, n, nnz, row, col, val) != 0) { fprintf(stderr, "Cannot open [read] %s.\n", argv[1]); return -1; } if(coo_to_csr(m, nnz, row.data(), ptr) != 0) { fprintf(stderr, "Cannot convert %s from COO to CSR.\n", argv[1]); return -1; } if(write_bin_matrix(argv[2], m, n, nnz, ptr.data(), col.data(), val.data()) != 0) { fprintf(stderr, "Cannot open [write] %s.\n", argv[2]); return -1; } return 0; } hipSPARSE-rocm-5.7.1/deps/external-gtest.cmake000066400000000000000000000114741447644345400211110ustar00rootroot00000000000000# ######################################################################## # 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. # # ######################################################################## message( STATUS "Configuring gtest external dependency" ) include( ExternalProject ) # set( gtest_cmake_args -DCMAKE_INSTALL_PREFIX=/package ) set( PREFIX_GTEST ${CMAKE_INSTALL_PREFIX} CACHE PATH "Location where gtest should install, defaults to /usr/local" ) set( gtest_cmake_args -DCMAKE_INSTALL_PREFIX=${PREFIX_GTEST} ) append_cmake_cli_arguments( gtest_cmake_args gtest_cmake_args ) set( gtest_git_repository "https://github.com/google/googletest.git" CACHE STRING "URL to download gtest from" ) set( gtest_git_tag "release-1.11.0" CACHE STRING "URL to download gtest from" ) if( MSVC ) list( APPEND gtest_cmake_args -Dgtest_force_shared_crt=ON -DCMAKE_DEBUG_POSTFIX=d ) # else( ) # GTEST_USE_OWN_TR1_TUPLE necessary to compile with hipcc # list( APPEND gtest_cmake_args -DGTEST_USE_OWN_TR1_TUPLE=1 ) endif( ) if( CMAKE_CONFIGURATION_TYPES ) set( gtest_make COMMAND ${CMAKE_COMMAND} --build --config Release COMMAND ${CMAKE_COMMAND} --build --config Debug ) else( ) # Add build thread in addition to the number of cores that we have include( ProcessorCount ) ProcessorCount( Cores ) # If we are not using an IDE, assume nmake with visual studio if( MSVC ) set( gtest_make "nmake" ) else( ) set( gtest_make "make" ) # The -j paramter does not work with nmake if( NOT Cores EQUAL 0 ) math( EXPR Cores "${Cores} + 1 " ) list( APPEND gtest_make -j ${Cores} ) else( ) # If we could not detect # of cores, assume 1 core and add an additional build thread list( APPEND gtest_make -j 2 ) endif( ) endif( ) message( STATUS "ExternalGmock using ( " ${Cores} " ) cores to build with" ) endif( ) # message( STATUS "gtest_make ( " ${gtest_make} " ) " ) # message( STATUS "gtest_cmake_args ( " ${gtest_cmake_args} " ) " ) # Master branch has a new structure that combines googletest with googlemock ExternalProject_Add( googletest PREFIX ${CMAKE_BINARY_DIR}/gtest GIT_REPOSITORY ${gtest_git_repository} GIT_TAG ${gtest_git_tag} CMAKE_ARGS ${gtest_cmake_args} BUILD_COMMAND ${gtest_make} LOG_BUILD 1 INSTALL_COMMAND "" LOG_INSTALL 1 ) ExternalProject_Get_Property( googletest source_dir ) # For visual studio, the path 'debug' is hardcoded because that is the default VS configuration for a build. # Doesn't matter if its the gtest or gtestd project above set( package_dir "${PREFIX_GTEST}" ) if( CMAKE_CONFIGURATION_TYPES ) # Create a package by bundling libraries and header files if( BUILD_64 ) set( LIB_DIR lib64 ) else( ) set( LIB_DIR lib ) endif( ) set( gtest_lib_dir "/${LIB_DIR}" ) ExternalProject_Add_Step( googletest createPackage COMMAND ${CMAKE_COMMAND} -E copy_directory ${gtest_lib_dir}/Debug ${package_dir}/${LIB_DIR} COMMAND ${CMAKE_COMMAND} -E copy_directory ${gtest_lib_dir}/Release ${package_dir}/${LIB_DIR} COMMAND ${CMAKE_COMMAND} -E copy_directory ${gtest_lib_dir}/Debug ${package_dir}/${LIB_DIR} COMMAND ${CMAKE_COMMAND} -E copy_directory ${gtest_lib_dir}/Release ${package_dir}/${LIB_DIR} COMMAND ${CMAKE_COMMAND} -E copy_directory /include ${package_dir}/include COMMAND ${CMAKE_COMMAND} -E copy_directory /gtest/include/gtest ${package_dir}/include/gtest DEPENDEES install ) endif( ) set_property( TARGET googletest PROPERTY FOLDER "extern") ExternalProject_Get_Property( googletest install_dir ) ExternalProject_Get_Property( googletest binary_dir ) # For use by the user of ExternalGtest.cmake set( GTEST_INSTALL_ROOT ${install_dir} ) set( GTEST_BINARY_ROOT ${binary_dir} ) hipSPARSE-rocm-5.7.1/deps/to_hipSPARSE.sh000077500000000000000000000230241447644345400176720ustar00rootroot00000000000000# ######################################################################## # 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. # # ######################################################################## #!/bin/bash echo Replacing rocSPARSE function calls in \"$1\" ... # Int sed -i 's/rocsparse_int/int/g' $1 # Status verification sed -i 's/verify_rocsparse_status_invalid_pointer/verify_hipsparse_status_invalid_pointer/g' $1 sed -i 's/verify_rocsparse_status_invalid_size/verify_hipsparse_status_invalid_size/g' $1 sed -i 's/verify_rocsparse_status_invalid_value/verify_hipsparse_status_invalid_value/g' $1 sed -i 's/verify_rocsparse_status_invalid_handle/verify_hipsparse_status_invalid_handle/g' $1 sed -i 's/verify_rocsparse_status_zero_pivot/verify_hipsparse_status_zero_pivot/g' $1 sed -i 's/verify_rocsparse_status_success/verify_hipsparse_status_success/g' $1 # Handle sed -i 's/rocsparse_handle/hipsparseHandle_t/g' $1 sed -i 's/rocsparse_create_handle/hipsparseCreate/g' $1 sed -i 's/rocsparse_destroy_handle/hipsparseDestroy/g' $1 sed -i 's/rocsparse_get_version/hipsparseGetVersion/g' $1 # Stream sed -i 's/rocsparse_set_stream/hipsparseSetStream/g' $1 sed -i 's/rocsparse_get_stream/hipsparseGetStream/g' $1 # Mat descr sed -i 's/rocsparse_mat_descr/hipsparseMatDescr_t/g' $1 sed -i 's/rocsparse_create_mat_descr/hipsparseCreateMatDescr/g' $1 sed -i 's/rocsparse_destroy_mat_descr/hipsparseDestroyMatDescr/g' $1 sed -i 's/rocsparse_set_mat_index_base/hipsparseSetMatIndexBase/g' $1 sed -i 's/rocsparse_get_mat_index_base/hipsparseGetMatIndexBase/g' $1 sed -i 's/rocsparse_set_mat_fill_mode/hipsparseSetMatFillMode/g' $1 sed -i 's/rocsparse_get_mat_fill_mode/hipsparseGetMatFillMode/g' $1 sed -i 's/rocsparse_set_mat_diag_type/hipsparseSetMatDiagType/g' $1 sed -i 's/rocsparse_get_mat_diag_type/hipsparseGetMatDiagType/g' $1 # Operation sed -i 's/rocsparse_operation_none/HIPSPARSE_OPERATION_NON_TRANSPOSE/g' $1 sed -i 's/rocsparse_operation_transpose/HIPSPARSE_OPERATION_TRANSPOSE/g' $1 sed -i 's/rocsparse_operation_conjugate_transpose/HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE/g' $1 sed -i 's/rocsparse_operation/hipsparseOperation_t/g' $1 # Index base sed -i 's/rocsparse_index_base_zero/HIPSPARSE_INDEX_BASE_ZERO/g' $1 sed -i 's/rocsparse_index_base_one/HIPSPARSE_INDEX_BASE_ONE/g' $1 sed -i 's/rocsparse_index_base/hipsparseIndexBase_t/g' $1 # Matrix type sed -i 's/rocsparse_matrix_type_general/HIPSPARSE_MATRIX_TYPE_GENERAL/g' $1 sed -i 's/rocsparse_matrix_type_symmetric/HIPSPARSE_MATRIX_TYPE_SYMMETRIC/g' $1 sed -i 's/rocsparse_matrix_type_hermitian/HIPSPARSE_MATRIX_TYPE_HERMITIAN/g' $1 sed -i 's/rocsparse_matrix_type_triangular/HIPSPARSE_MATRIX_TYPE_TRIANGULAR/g' $1 sed -i 's/rocsparse_matrix_type/hipsparseMatrixType_t/g' $1 # Fill mode sed -i 's/rocsparse_fill_mode_lower/HIPSPARSE_FILL_MODE_LOWER/g' $1 sed -i 's/rocsparse_fill_mode_upper/HIPSPARSE_FILL_MODE_UPPER/g' $1 sed -i 's/rocsparse_fill_mode/hipsparseFillMode_t/g' $1 # Diag type sed -i 's/rocsparse_diag_type_unit/HIPSPARSE_DIAG_TYPE_UNIT/g' $1 sed -i 's/rocsparse_diag_type_non_unit/HIPSPARSE_DIAG_TYPE_NON_UNIT/g' $1 sed -i 's/rocsparse_diag_type/hipsparseDiagType_t/g' $1 # Action sed -i 's/rocsparse_action_symbolic/HIPSPARSE_ACTION_SYMBOLIC/g' $1 sed -i 's/rocsparse_action_numeric/HIPSPARSE_ACTION_NUMERIC/g' $1 sed -i 's/rocsparse_action/hipsparseAction_t/g' $1 # Hyb sed -i 's/rocsparse_hyb_partition_auto/HIPSPARSE_HYB_PARTITION_AUTO/g' $1 sed -i 's/rocsparse_hyb_partition_user/HIPSPARSE_HYB_PARTITION_USER/g' $1 sed -i 's/rocsparse_hyb_partition_max/HIPSPARSE_HYB_PARTITION_MAX/g' $1 sed -i 's/rocsparse_hyb_partition/hipsparseHybPartition_t/g' $1 sed -i 's/rocsparse_hyb_mat/hipsparseHybMat_t/g' $1 sed -i 's/rocsparse_create_hyb_mat/hipsparseCreateHybMat/g' $1 sed -i 's/rocsparse_destroy_hyb_mat/hipsparseDestroyHybMat/g' $1 # Status sed -i 's/rocsparse_status_success/HIPSPARSE_STATUS_SUCCESS/g' $1 sed -i 's/rocsparse_status_invalid_handle/HIPSPARSE_STATUS_NOT_INITIALIZED/g' $1 sed -i 's/rocsparse_status_not_implemented/HIPSPARSE_STATUS_NOT_SUPPORTED/g' $1 sed -i 's/rocsparse_status_invalid_pointer/HIPSPARSE_STATUS_INVALID_VALUE/g' $1 sed -i 's/rocsparse_status_invalid_size/HIPSPARSE_STATUS_INVALID_VALUE/g' $1 sed -i 's/rocsparse_status_memory_error/HIPSPARSE_STATUS_ALLOC_FAILED/g' $1 sed -i 's/rocsparse_status_internal_error/HIPSPARSE_STATUS_INTERNAL_ERROR/g' $1 sed -i 's/rocsparse_status_invalid_value/HIPSPARSE_STATUS_INVALID_VALUE/g' $1 sed -i 's/rocsparse_status_arch_mismatch/HIPSPARSE_STATUS_ARCH_MISMATCH/g' $1 sed -i 's/rocsparse_status_zero_pivot/HIPSPARSE_STATUS_ZERO_PIVOT/g' $1 sed -i 's/rocsparse_status/hipsparseStatus_t/g' $1 # Pointer mode sed -i 's/rocsparse_pointer_mode_host/HIPSPARSE_POINTER_MODE_HOST/g' $1 sed -i 's/rocsparse_pointer_mode_device/HIPSPARSE_POINTER_MODE_DEVICE/g' $1 sed -i 's/rocsparse_pointer_mode/hipsparsePointerMode_t/g' $1 sed -i 's/rocsparse_set_pointer_mode/hipsparseSetPointerMode/g' $1 sed -i 's/rocsparse_get_pointer_mode/hipsparseGetPointerMode/g' $1 # Level 1 sed -i 's/rocsparse_saxpyi/hipsparseSaxpyi/g' $1 sed -i 's/rocsparse_daxpyi/hipsparseDaxpyi/g' $1 sed -i 's/rocsparse_axpyi/hipsparseXaxpyi/g' $1 sed -i 's/rocsparse_sdoti/hipsparseSdoti/g' $1 sed -i 's/rocsparse_ddoti/hipsparseDdoti/g' $1 sed -i 's/rocsparse_doti/hipsparseXdoti/g' $1 sed -i 's/rocsparse_sgthr/hipsparseSgthr/g' $1 sed -i 's/rocsparse_dgthr/hipsparseDgthr/g' $1 sed -i 's/rocsparse_gthr/hipsparseXgthr/g' $1 sed -i 's/rocsparse_sgthrz/hipsparseSgthrz/g' $1 sed -i 's/rocsparse_dgthrz/hipsparseDgthrz/g' $1 sed -i 's/rocsparse_gthrz/hipsparseXgthrz/g' $1 sed -i 's/rocsparse_sroti/hipsparseSroti/g' $1 sed -i 's/rocsparse_droti/hipsparseDroti/g' $1 sed -i 's/rocsparse_roti/hipsparseXroti/g' $1 sed -i 's/rocsparse_ssctr/hipsparseSsctr/g' $1 sed -i 's/rocsparse_dsctr/hipsparseDsctr/g' $1 sed -i 's/rocsparse_sctr/hipsparseXsctr/g' $1 # Level 2 sed -i 's/rocsparse_scoomv/hipsparseScoomv/g' $1 sed -i 's/rocsparse_dcoomv/hipsparseDcoomv/g' $1 sed -i 's/rocsparse_coomv/hipsparseXcoomv/g' $1 sed -i 's/rocsparse_scsrmv/hipsparseScsrmv/g' $1 sed -i 's/rocsparse_dcsrmv/hipsparseDcsrmv/g' $1 sed -i 's/rocsparse_csrmv/hipsparseXcsrmv/g' $1 sed -i 's/rocsparse_sellmv/hipsparseSellmv/g' $1 sed -i 's/rocsparse_dellmv/hipsparseDellmv/g' $1 sed -i 's/rocsparse_ellmv/hipsparseXellmv/g' $1 sed -i 's/rocsparse_shybmv/hipsparseShybmv/g' $1 sed -i 's/rocsparse_dhybmv/hipsparseDhybmv/g' $1 sed -i 's/rocsparse_hybmv/hipsparseXhybmv/g' $1 # Level 3 sed -i 's/rocsparse_sbsrmm/hipsparseSbsrmm/g' $1 sed -i 's/rocsparse_dbsrmm/hipsparseDbsrmm/g' $1 sed -i 's/rocsparse_bsrmm/hipsparseXbsrmm/g' $1 sed -i 's/rocsparse_scsrmm/hipsparseScsrmm2/g' $1 sed -i 's/rocsparse_dcsrmm/hipsparseDcsrmm2/g' $1 sed -i 's/rocsparse_csrmm/hipsparseXcsrmm2/g' $1 # Conversion sed -i 's/rocsparse_csr2coo/hipsparseXcsr2coo/g' $1 sed -i 's/rocsparse_scsr2csc/hipsparseScsr2csc/g' $1 sed -i 's/rocsparse_dcsr2csc/hipsparseDcsr2csc/g' $1 sed -i 's/rocsparse_csr2csc/hipsparseXcsr2csc/g' $1 sed -i 's/rocsparse_csr2ell_width/hipsparseXcsr2ellWidth/g' $1 sed -i 's/rocsparse_scsr2ell/hipsparseScsr2ell/g' $1 sed -i 's/rocsparse_dcsr2ell/hipsparseDcsr2ell/g' $1 sed -i 's/rocsparse_csr2ell/hipsparseXcsr2ell/g' $1 sed -i 's/rocsparse_scsr2hyb/hipsparseScsr2hyb/g' $1 sed -i 's/rocsparse_dcsr2hyb/hipsparseDcsr2hyb/g' $1 sed -i 's/rocsparse_csr2hyb/hipsparseXcsr2hyb/g' $1 sed -i 's/rocsparse_coo2csr/hipsparseXcoo2csr/g' $1 sed -i 's/rocsparse_create_identity_permutation/hipsparseCreateIdentityPermutation/g' $1 sed -i 's/rocsparse_csrsort_buffer_size/hipsparseXcsrsort_bufferSizeExt/g' $1 sed -i 's/rocsparse_csrsort/hipsparseXcsrsort/g' $1 sed -i 's/rocsparse_coosort_buffer_size/hipsparseXcoosort_bufferSizeExt/g' $1 sed -i 's/rocsparse_coosort_by_row/hipsparseXcoosortByRow/g' $1 sed -i 's/rocsparse_coosort_by_column/hipsparseXcoosortByColumn/g' $1 sed -i 's/rocsparse_ell2csr_nnz/hipsparseXell2csrNnz/g' $1 sed -i 's/rocsparse_sell2csr/hipsparseSell2csr/g' $1 sed -i 's/rocsparse_dell2csr/hipsparseDell2csr/g' $1 sed -i 's/rocsparse_ell2csr/hipsparseXell2csr/g' $1 # Header sed -i 's/rocsparse.h/hipsparse.h/g' $1 sed -i 's/rocsparse_test_unique_ptr.hpp/hipsparse_test_unique_ptr.hpp/g' $1 # Namespace sed -i 's/namespace rocsparse/namespace hipsparse/g' $1 sed -i 's/namespace rocsparse_test/namespace hipsparse_test/g' $1 # Unique ptr sed -i 's/rocsparse_unique_ptr/hipsparse_unique_ptr/g' $1 # Error macro sed -i 's/CHECK_ROCSPARSE_ERROR/CHECK_HIPSPARSE_ERROR/g' $1 # Utilities sed -i 's/rocsparse_init_index/hipsparseInitIndex/g' $1 sed -i 's/rocsparse_init_csr/hipsparseInitCSR/g' $1 sed -i 's/rocsparse_init/hipsparseInit/g' $1 hipSPARSE-rocm-5.7.1/docs/000077500000000000000000000000001447644345400151275ustar00rootroot00000000000000hipSPARSE-rocm-5.7.1/docs/.doxygen/000077500000000000000000000000001447644345400166625ustar00rootroot00000000000000hipSPARSE-rocm-5.7.1/docs/.doxygen/Doxyfile000066400000000000000000003337321447644345400204030ustar00rootroot00000000000000# Doxyfile 1.8.17 # This file describes the settings to be used by the documentation system # doxygen (www.doxygen.org) for a project. # # All text after a double hash (##) is considered a comment and is placed in # front of the TAG it is preceding. # # All text after a single hash (#) is considered a comment and will be ignored. # The format is: # TAG = value [value, ...] # For lists, items can also be appended using: # TAG += value [value, ...] # Values that contain spaces should be placed between quotes (\" \"). #--------------------------------------------------------------------------- # Project related configuration options #--------------------------------------------------------------------------- # This tag specifies the encoding used for all characters in the configuration # file that follow. The default is UTF-8 which is also the encoding used for all # text before the first occurrence of this tag. Doxygen uses libiconv (or the # iconv built into libc) for the transcoding. See # https://www.gnu.org/software/libiconv/ for the list of possible encodings. # The default value is: UTF-8. DOXYFILE_ENCODING = UTF-8 # The PROJECT_NAME tag is a single word (or a sequence of words surrounded by # double-quotes, unless you are using Doxywizard) that should identify the # project for which the documentation is generated. This name is used in the # title of most generated pages and in a few other places. # The default value is: My Project. PROJECT_NAME = "hipSPARSE" # The PROJECT_NUMBER tag can be used to enter a project or revision number. This # could be handy for archiving the generated documentation or if some version # control system is used. PROJECT_NUMBER = v # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a # quick idea about the purpose of the project. Keep the description short. PROJECT_BRIEF = "prototype interfaces compatible with ROCm platform and HiP" # With the PROJECT_LOGO tag one can specify a logo or an icon that is included # in the documentation. The maximum height of the logo should not exceed 55 # pixels and the maximum width should not exceed 200 pixels. Doxygen will copy # the logo to the output directory. PROJECT_LOGO = # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path # into which the generated documentation will be written. If a relative path is # entered, it will be relative to the location where doxygen was started. If # left blank the current directory will be used. OUTPUT_DIRECTORY = docBin # If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub- # directories (in 2 levels) under the output directory of each output format and # will distribute the generated files over these directories. Enabling this # option can be useful when feeding doxygen a huge amount of source files, where # putting all generated files in the same directory would otherwise causes # performance problems for the file system. # The default value is: NO. CREATE_SUBDIRS = NO # If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII # characters to appear in the names of generated files. If set to NO, non-ASCII # characters will be escaped, for example _xE3_x81_x84 will be used for Unicode # U+3044. # The default value is: NO. ALLOW_UNICODE_NAMES = NO # The OUTPUT_LANGUAGE tag is used to specify the language in which all # documentation generated by doxygen is written. Doxygen will use this # information to generate all constant output in the proper language. # Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Catalan, Chinese, # Chinese-Traditional, Croatian, Czech, Danish, Dutch, English (United States), # Esperanto, Farsi (Persian), Finnish, French, German, Greek, Hungarian, # Indonesian, Italian, Japanese, Japanese-en (Japanese with English messages), # Korean, Korean-en (Korean with English messages), Latvian, Lithuanian, # Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, Romanian, Russian, # Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, Swedish, Turkish, # Ukrainian and Vietnamese. # The default value is: English. OUTPUT_LANGUAGE = English # The OUTPUT_TEXT_DIRECTION tag is used to specify the direction in which all # documentation generated by doxygen is written. Doxygen will use this # information to generate all generated output in the proper direction. # Possible values are: None, LTR, RTL and Context. # The default value is: None. OUTPUT_TEXT_DIRECTION = None # If the BRIEF_MEMBER_DESC tag is set to YES, doxygen will include brief member # descriptions after the members that are listed in the file and class # documentation (similar to Javadoc). Set to NO to disable this. # The default value is: YES. BRIEF_MEMBER_DESC = YES # If the REPEAT_BRIEF tag is set to YES, doxygen will prepend the brief # description of a member or function before the detailed description # # Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the # brief descriptions will be completely suppressed. # The default value is: YES. REPEAT_BRIEF = YES # This tag implements a quasi-intelligent brief description abbreviator that is # used to form the text in various listings. Each string in this list, if found # as the leading text of the brief description, will be stripped from the text # and the result, after processing the whole list, is used as the annotated # text. Otherwise, the brief description is used as-is. If left blank, the # following values are used ($name is automatically replaced with the name of # the entity):The $name class, The $name widget, The $name file, is, provides, # specifies, contains, represents, a, an and the. ABBREVIATE_BRIEF = "The $name class" \ "The $name widget" \ "The $name file" \ is \ provides \ specifies \ contains \ represents \ a \ an \ the # If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then # doxygen will generate a detailed section even if there is only a brief # description. # The default value is: NO. ALWAYS_DETAILED_SEC = NO # If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all # inherited members of a class in the documentation of that class as if those # members were ordinary class members. Constructors, destructors and assignment # operators of the base classes will not be shown. # The default value is: NO. INLINE_INHERITED_MEMB = NO # If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path # before files name in the file list and in the header files. If set to NO the # shortest path that makes the file name unique will be used # The default value is: YES. FULL_PATH_NAMES = NO # The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path. # Stripping is only done if one of the specified strings matches the left-hand # part of the path. The tag can be used to show relative paths in the file list. # If left blank the directory from which doxygen is run is used as the path to # strip. # # Note that you can specify absolute paths here, but also relative paths, which # will be relative from the directory where doxygen is started. # This tag requires that the tag FULL_PATH_NAMES is set to YES. STRIP_FROM_PATH = # The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the # path mentioned in the documentation of a class, which tells the reader which # header file to include in order to use a class. If left blank only the name of # the header file containing the class definition is used. Otherwise one should # specify the list of include paths that are normally passed to the compiler # using the -I flag. STRIP_FROM_INC_PATH = # If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but # less readable) file names. This can be useful is your file systems doesn't # support long names like on DOS, Mac, or CD-ROM. # The default value is: NO. SHORT_NAMES = NO # If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the # first line (until the first dot) of a Javadoc-style comment as the brief # description. If set to NO, the Javadoc-style will behave just like regular Qt- # style comments (thus requiring an explicit @brief command for a brief # description.) # The default value is: NO. JAVADOC_AUTOBRIEF = NO # If the JAVADOC_BANNER tag is set to YES then doxygen will interpret a line # such as # /*************** # as being the beginning of a Javadoc-style comment "banner". If set to NO, the # Javadoc-style will behave just like regular comments and it will not be # interpreted by doxygen. # The default value is: NO. JAVADOC_BANNER = NO # If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first # line (until the first dot) of a Qt-style comment as the brief description. If # set to NO, the Qt-style will behave just like regular Qt-style comments (thus # requiring an explicit \brief command for a brief description.) # The default value is: NO. QT_AUTOBRIEF = NO # The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a # multi-line C++ special comment block (i.e. a block of //! or /// comments) as # a brief description. This used to be the default behavior. The new default is # to treat a multi-line C++ comment block as a detailed description. Set this # tag to YES if you prefer the old behavior instead. # # Note that setting this tag to YES also means that rational rose comments are # not recognized any more. # The default value is: NO. MULTILINE_CPP_IS_BRIEF = NO # If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the # documentation from any documented member that it re-implements. # The default value is: YES. INHERIT_DOCS = YES # If the SEPARATE_MEMBER_PAGES tag is set to YES then doxygen will produce a new # page for each member. If set to NO, the documentation of a member will be part # of the file/class/namespace that contains it. # The default value is: NO. SEPARATE_MEMBER_PAGES = NO # The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen # uses this value to replace tabs by spaces in code fragments. # Minimum value: 1, maximum value: 16, default value: 4. TAB_SIZE = 4 # This tag can be used to specify a number of aliases that act as commands in # the documentation. An alias has the form: # name=value # For example adding # "sideeffect=@par Side Effects:\n" # will allow you to put the command \sideeffect (or @sideeffect) in the # documentation, which will result in a user-defined paragraph with heading # "Side Effects:". You can put \n's in the value part of an alias to insert # newlines (in the resulting output). You can put ^^ in the value part of an # alias to insert a newline as if a physical newline was in the original file. # When you need a literal { or } or , in the value part of an alias you have to # escape them by means of a backslash (\), this can lead to conflicts with the # commands \{ and \} for these it is advised to use the version @{ and @} or use # a double escape (\\{ and \\}) ALIASES = # This tag can be used to specify a number of word-keyword mappings (TCL only). # A mapping has the form "name=value". For example adding "class=itcl::class" # will allow you to use the command class in the itcl::class meaning. TCL_SUBST = # Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources # only. Doxygen will then generate output that is more tailored for C. For # instance, some of the names that are used will be different. The list of all # members will be omitted, etc. # The default value is: NO. OPTIMIZE_OUTPUT_FOR_C = YES # Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or # Python sources only. Doxygen will then generate output that is more tailored # for that language. For instance, namespaces will be presented as packages, # qualified scopes will look different, etc. # The default value is: NO. OPTIMIZE_OUTPUT_JAVA = NO # Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran # sources. Doxygen will then generate output that is tailored for Fortran. # The default value is: NO. OPTIMIZE_FOR_FORTRAN = NO # Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL # sources. Doxygen will then generate output that is tailored for VHDL. # The default value is: NO. OPTIMIZE_OUTPUT_VHDL = NO # Set the OPTIMIZE_OUTPUT_SLICE tag to YES if your project consists of Slice # sources only. Doxygen will then generate output that is more tailored for that # language. For instance, namespaces will be presented as modules, types will be # separated into more groups, etc. # The default value is: NO. OPTIMIZE_OUTPUT_SLICE = NO # Doxygen selects the parser to use depending on the extension of the files it # parses. With this tag you can assign which parser to use for a given # extension. Doxygen has a built-in mapping, but you can override or extend it # using this tag. The format is ext=language, where ext is a file extension, and # language is one of the parsers supported by doxygen: IDL, Java, JavaScript, # Csharp (C#), C, C++, D, PHP, md (Markdown), Objective-C, Python, Slice, # Fortran (fixed format Fortran: FortranFixed, free formatted Fortran: # FortranFree, unknown formatted Fortran: Fortran. In the later case the parser # tries to guess whether the code is fixed or free formatted code, this is the # default for Fortran type files), VHDL, tcl. For instance to make doxygen treat # .inc files as Fortran files (default is PHP), and .f files as C (default is # Fortran), use: inc=Fortran f=C. # # Note: For files without extension you can use no_extension as a placeholder. # # Note that for custom extensions you also need to set FILE_PATTERNS otherwise # the files are not read by doxygen. EXTENSION_MAPPING = # If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments # according to the Markdown format, which allows for more readable # documentation. See https://daringfireball.net/projects/markdown/ for details. # The output of markdown processing is further processed by doxygen, so you can # mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in # case of backward compatibilities issues. # The default value is: YES. MARKDOWN_SUPPORT = YES # When the TOC_INCLUDE_HEADINGS tag is set to a non-zero value, all headings up # to that level are automatically included in the table of contents, even if # they do not have an id attribute. # Note: This feature currently applies only to Markdown headings. # Minimum value: 0, maximum value: 99, default value: 5. # This tag requires that the tag MARKDOWN_SUPPORT is set to YES. TOC_INCLUDE_HEADINGS = 5 # When enabled doxygen tries to link words that correspond to documented # classes, or namespaces to their corresponding documentation. Such a link can # be prevented in individual cases by putting a % sign in front of the word or # globally by setting AUTOLINK_SUPPORT to NO. # The default value is: YES. AUTOLINK_SUPPORT = YES # If you use STL classes (i.e. std::string, std::vector, etc.) but do not want # to include (a tag file for) the STL sources as input, then you should set this # tag to YES in order to let doxygen match functions declarations and # definitions whose arguments contain STL classes (e.g. func(std::string); # versus func(std::string) {}). This also make the inheritance and collaboration # diagrams that involve STL classes more complete and accurate. # The default value is: NO. BUILTIN_STL_SUPPORT = NO # If you use Microsoft's C++/CLI language, you should set this option to YES to # enable parsing support. # The default value is: NO. CPP_CLI_SUPPORT = NO # Set the SIP_SUPPORT tag to YES if your project consists of sip (see: # https://www.riverbankcomputing.com/software/sip/intro) sources only. Doxygen # will parse them like normal C++ but will assume all classes use public instead # of private inheritance when no explicit protection keyword is present. # The default value is: NO. SIP_SUPPORT = NO # For Microsoft's IDL there are propget and propput attributes to indicate # getter and setter methods for a property. Setting this option to YES will make # doxygen to replace the get and set methods by a property in the documentation. # This will only work if the methods are indeed getting or setting a simple # type. If this is not the case, or you want to show the methods anyway, you # should set this option to NO. # The default value is: YES. IDL_PROPERTY_SUPPORT = YES # If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC # tag is set to YES then doxygen will reuse the documentation of the first # member in the group (if any) for the other members of the group. By default # all members of a group must be documented explicitly. # The default value is: NO. DISTRIBUTE_GROUP_DOC = YES # If one adds a struct or class to a group and this option is enabled, then also # any nested class or struct is added to the same group. By default this option # is disabled and one has to add nested compounds explicitly via \ingroup. # The default value is: NO. GROUP_NESTED_COMPOUNDS = NO # Set the SUBGROUPING tag to YES to allow class member groups of the same type # (for instance a group of public functions) to be put as a subgroup of that # type (e.g. under the Public Functions section). Set it to NO to prevent # subgrouping. Alternatively, this can be done per class using the # \nosubgrouping command. # The default value is: YES. SUBGROUPING = YES # When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions # are shown inside the group in which they are included (e.g. using \ingroup) # instead of on a separate page (for HTML and Man pages) or section (for LaTeX # and RTF). # # Note that this feature does not work in combination with # SEPARATE_MEMBER_PAGES. # The default value is: NO. INLINE_GROUPED_CLASSES = NO # When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions # with only public data fields or simple typedef fields will be shown inline in # the documentation of the scope in which they are defined (i.e. file, # namespace, or group documentation), provided this scope is documented. If set # to NO, structs, classes, and unions are shown on a separate page (for HTML and # Man pages) or section (for LaTeX and RTF). # The default value is: NO. INLINE_SIMPLE_STRUCTS = NO # When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or # enum is documented as struct, union, or enum with the name of the typedef. So # typedef struct TypeS {} TypeT, will appear in the documentation as a struct # with name TypeT. When disabled the typedef will appear as a member of a file, # namespace, or class. And the struct will be named TypeS. This can typically be # useful for C code in case the coding convention dictates that all compound # types are typedef'ed and only the typedef is referenced, never the tag name. # The default value is: NO. TYPEDEF_HIDES_STRUCT = YES # The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This # cache is used to resolve symbols given their name and scope. Since this can be # an expensive process and often the same symbol appears multiple times in the # code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small # doxygen will become slower. If the cache is too large, memory is wasted. The # cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range # is 0..9, the default is 0, corresponding to a cache size of 2^16=65536 # symbols. At the end of a run doxygen will report the cache usage and suggest # the optimal cache size from a speed point of view. # Minimum value: 0, maximum value: 9, default value: 0. LOOKUP_CACHE_SIZE = 0 #--------------------------------------------------------------------------- # Build related configuration options #--------------------------------------------------------------------------- # If the EXTRACT_ALL tag is set to YES, doxygen will assume all entities in # documentation are documented, even if no documentation was available. Private # class members and static file members will be hidden unless the # EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES. # Note: This will also disable the warnings about undocumented members that are # normally produced when WARNINGS is set to YES. # The default value is: NO. EXTRACT_ALL = NO # If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will # be included in the documentation. # The default value is: NO. EXTRACT_PRIVATE = NO # If the EXTRACT_PRIV_VIRTUAL tag is set to YES, documented private virtual # methods of a class will be included in the documentation. # The default value is: NO. EXTRACT_PRIV_VIRTUAL = NO # If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal # scope will be included in the documentation. # The default value is: NO. EXTRACT_PACKAGE = NO # If the EXTRACT_STATIC tag is set to YES, all static members of a file will be # included in the documentation. # The default value is: NO. EXTRACT_STATIC = NO # If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined # locally in source files will be included in the documentation. If set to NO, # only classes defined in header files are included. Does not have any effect # for Java sources. # The default value is: YES. EXTRACT_LOCAL_CLASSES = NO # This flag is only useful for Objective-C code. If set to YES, local methods, # which are defined in the implementation section but not in the interface are # included in the documentation. If set to NO, only methods in the interface are # included. # The default value is: NO. EXTRACT_LOCAL_METHODS = NO # If this flag is set to YES, the members of anonymous namespaces will be # extracted and appear in the documentation as a namespace called # 'anonymous_namespace{file}', where file will be replaced with the base name of # the file that contains the anonymous namespace. By default anonymous namespace # are hidden. # The default value is: NO. EXTRACT_ANON_NSPACES = NO # If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all # undocumented members inside documented classes or files. If set to NO these # members will be included in the various overviews, but no documentation # section is generated. This option has no effect if EXTRACT_ALL is enabled. # The default value is: NO. HIDE_UNDOC_MEMBERS = NO # If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all # undocumented classes that are normally visible in the class hierarchy. If set # to NO, these classes will be included in the various overviews. This option # has no effect if EXTRACT_ALL is enabled. # The default value is: NO. HIDE_UNDOC_CLASSES = YES # If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend # declarations. If set to NO, these declarations will be included in the # documentation. # The default value is: NO. HIDE_FRIEND_COMPOUNDS = NO # If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any # documentation blocks found inside the body of a function. If set to NO, these # blocks will be appended to the function's detailed documentation block. # The default value is: NO. HIDE_IN_BODY_DOCS = NO # The INTERNAL_DOCS tag determines if documentation that is typed after a # \internal command is included. If the tag is set to NO then the documentation # will be excluded. Set it to YES to include the internal documentation. # The default value is: NO. INTERNAL_DOCS = NO # If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file # names in lower-case letters. If set to YES, upper-case letters are also # allowed. This is useful if you have classes or files whose names only differ # in case and if your file system supports case sensitive file names. Windows # (including Cygwin) ands Mac users are advised to set this option to NO. # The default value is: system dependent. CASE_SENSE_NAMES = NO # If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with # their full class and namespace scopes in the documentation. If set to YES, the # scope will be hidden. # The default value is: NO. HIDE_SCOPE_NAMES = NO # If the HIDE_COMPOUND_REFERENCE tag is set to NO (default) then doxygen will # append additional text to a page's title, such as Class Reference. If set to # YES the compound reference will be hidden. # The default value is: NO. HIDE_COMPOUND_REFERENCE= NO # If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of # the files that are included by a file in the documentation of that file. # The default value is: YES. SHOW_INCLUDE_FILES = NO # If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each # grouped member an include statement to the documentation, telling the reader # which file to include in order to use the member. # The default value is: NO. SHOW_GROUPED_MEMB_INC = NO # If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include # files with double quotes in the documentation rather than with sharp brackets. # The default value is: NO. FORCE_LOCAL_INCLUDES = NO # If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the # documentation for inline members. # The default value is: YES. INLINE_INFO = YES # If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the # (detailed) documentation of file and class members alphabetically by member # name. If set to NO, the members will appear in declaration order. # The default value is: YES. SORT_MEMBER_DOCS = NO # If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief # descriptions of file, namespace and class members alphabetically by member # name. If set to NO, the members will appear in declaration order. Note that # this will also influence the order of the classes in the class list. # The default value is: NO. SORT_BRIEF_DOCS = NO # If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the # (brief and detailed) documentation of class members so that constructors and # destructors are listed first. If set to NO the constructors will appear in the # respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS. # Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief # member documentation. # Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting # detailed member documentation. # The default value is: NO. SORT_MEMBERS_CTORS_1ST = NO # If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy # of group names into alphabetical order. If set to NO the group names will # appear in their defined order. # The default value is: NO. SORT_GROUP_NAMES = NO # If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by # fully-qualified names, including namespaces. If set to NO, the class list will # be sorted only by class name, not including the namespace part. # Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. # Note: This option applies only to the class list, not to the alphabetical # list. # The default value is: NO. SORT_BY_SCOPE_NAME = NO # If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper # type resolution of all parameters of a function it will reject a match between # the prototype and the implementation of a member function even if there is # only one candidate or it is obvious which candidate to choose by doing a # simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still # accept a match between prototype and implementation in such cases. # The default value is: NO. STRICT_PROTO_MATCHING = NO # The GENERATE_TODOLIST tag can be used to enable (YES) or disable (NO) the todo # list. This list is created by putting \todo commands in the documentation. # The default value is: YES. GENERATE_TODOLIST = YES # The GENERATE_TESTLIST tag can be used to enable (YES) or disable (NO) the test # list. This list is created by putting \test commands in the documentation. # The default value is: YES. GENERATE_TESTLIST = YES # The GENERATE_BUGLIST tag can be used to enable (YES) or disable (NO) the bug # list. This list is created by putting \bug commands in the documentation. # The default value is: YES. GENERATE_BUGLIST = YES # The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or disable (NO) # the deprecated list. This list is created by putting \deprecated commands in # the documentation. # The default value is: YES. GENERATE_DEPRECATEDLIST= YES # The ENABLED_SECTIONS tag can be used to enable conditional documentation # sections, marked by \if ... \endif and \cond # ... \endcond blocks. ENABLED_SECTIONS = # The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the # initial value of a variable or macro / define can have for it to appear in the # documentation. If the initializer consists of more lines than specified here # it will be hidden. Use a value of 0 to hide initializers completely. The # appearance of the value of individual variables and macros / defines can be # controlled using \showinitializer or \hideinitializer command in the # documentation regardless of this setting. # Minimum value: 0, maximum value: 10000, default value: 30. MAX_INITIALIZER_LINES = 30 # Set the SHOW_USED_FILES tag to NO to disable the list of files generated at # the bottom of the documentation of classes and structs. If set to YES, the # list will mention the files that were used to generate the documentation. # The default value is: YES. SHOW_USED_FILES = YES # Set the SHOW_FILES tag to NO to disable the generation of the Files page. This # will remove the Files entry from the Quick Index and from the Folder Tree View # (if specified). # The default value is: YES. SHOW_FILES = YES # Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces # page. This will remove the Namespaces entry from the Quick Index and from the # Folder Tree View (if specified). # The default value is: YES. SHOW_NAMESPACES = YES # The FILE_VERSION_FILTER tag can be used to specify a program or script that # doxygen should invoke to get the current version for each file (typically from # the version control system). Doxygen will invoke the program by executing (via # popen()) the command command input-file, where command is the value of the # FILE_VERSION_FILTER tag, and input-file is the name of an input file provided # by doxygen. Whatever the program writes to standard output is used as the file # version. For an example see the documentation. FILE_VERSION_FILTER = # The LAYOUT_FILE tag can be used to specify a layout file which will be parsed # by doxygen. The layout file controls the global structure of the generated # output files in an output format independent way. To create the layout file # that represents doxygen's defaults, run doxygen with the -l option. You can # optionally specify a file name after the option, if omitted DoxygenLayout.xml # will be used as the name of the layout file. # # Note that if you run doxygen from a directory containing a file called # DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE # tag is left empty. LAYOUT_FILE = # The CITE_BIB_FILES tag can be used to specify one or more bib files containing # the reference definitions. This must be a list of .bib files. The .bib # extension is automatically appended if omitted. This requires the bibtex tool # to be installed. See also https://en.wikipedia.org/wiki/BibTeX for more info. # For LaTeX the style of the bibliography can be controlled using # LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the # search path. See also \cite for info how to create references. CITE_BIB_FILES = #--------------------------------------------------------------------------- # Configuration options related to warning and progress messages #--------------------------------------------------------------------------- # The QUIET tag can be used to turn on/off the messages that are generated to # standard output by doxygen. If QUIET is set to YES this implies that the # messages are off. # The default value is: NO. QUIET = NO # The WARNINGS tag can be used to turn on/off the warning messages that are # generated to standard error (stderr) by doxygen. If WARNINGS is set to YES # this implies that the warnings are on. # # Tip: Turn warnings on while writing the documentation. # The default value is: YES. WARNINGS = YES # If the WARN_IF_UNDOCUMENTED tag is set to YES then doxygen will generate # warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag # will automatically be disabled. # The default value is: YES. WARN_IF_UNDOCUMENTED = YES # If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for # potential errors in the documentation, such as not documenting some parameters # in a documented function, or documenting parameters that don't exist or using # markup commands wrongly. # The default value is: YES. WARN_IF_DOC_ERROR = YES # This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that # are documented, but have no documentation for their parameters or return # value. If set to NO, doxygen will only warn about wrong or incomplete # parameter documentation, but not about the absence of documentation. If # EXTRACT_ALL is set to YES then this flag will automatically be disabled. # The default value is: NO. WARN_NO_PARAMDOC = NO # If the WARN_AS_ERROR tag is set to YES then doxygen will immediately stop when # a warning is encountered. # The default value is: NO. WARN_AS_ERROR = NO # The WARN_FORMAT tag determines the format of the warning messages that doxygen # can produce. The string should contain the $file, $line, and $text tags, which # will be replaced by the file and line number from which the warning originated # and the warning text. Optionally the format may contain $version, which will # be replaced by the version of the file (if it could be obtained via # FILE_VERSION_FILTER) # The default value is: $file:$line: $text. WARN_FORMAT = "$file:$line: $text" # The WARN_LOGFILE tag can be used to specify a file to which warning and error # messages should be written. If left blank the output is written to standard # error (stderr). WARN_LOGFILE = #--------------------------------------------------------------------------- # Configuration options related to the input files #--------------------------------------------------------------------------- # The INPUT tag is used to specify the files and/or directories that contain # documented source files. You may enter file names like myfile.cpp or # directories like /usr/src/myproject. Separate the files or directories with # spaces. See also FILE_PATTERNS and EXTENSION_MAPPING # Note: If this tag is empty the current directory is searched. INPUT = ../../library/include # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses # libiconv (or the iconv built into libc) for the transcoding. See the libiconv # documentation (see: https://www.gnu.org/software/libiconv/) for the list of # possible encodings. # The default value is: UTF-8. INPUT_ENCODING = UTF-8 # If the value of the INPUT tag contains directories, you can use the # FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and # *.h) to filter out the source-files in the directories. # # Note that for custom extensions or not directly supported extensions you also # need to set EXTENSION_MAPPING for the extension otherwise the files are not # read by doxygen. # # If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cpp, # *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, # *.hh, *.hxx, *.hpp, *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc, # *.m, *.markdown, *.md, *.mm, *.dox (to be provided as doxygen C comment), # *.doc (to be provided as doxygen C comment), *.txt (to be provided as doxygen # C comment), *.py, *.pyw, *.f90, *.f95, *.f03, *.f08, *.f, *.for, *.tcl, *.vhd, # *.vhdl, *.ucf, *.qsf and *.ice. FILE_PATTERNS = *.c \ *.cc \ *.cxx \ *.cpp \ *.c++ \ *.java \ *.ii \ *.ixx \ *.ipp \ *.i++ \ *.inl \ *.idl \ *.ddl \ *.odl \ *.h \ *.hh \ *.hxx \ *.hpp \ *.h++ \ *.cs \ *.d \ *.php \ *.php4 \ *.php5 \ *.phtml \ *.inc \ *.m \ *.markdown \ *.md \ *.mm \ *.dox \ *.py \ *.f90 \ *.f \ *.for \ *.tcl \ *.vhd \ *.vhdl \ *.ucf \ *.qsf \ *.as \ *.js # The RECURSIVE tag can be used to specify whether or not subdirectories should # be searched for input files as well. # The default value is: NO. RECURSIVE = YES # The EXCLUDE tag can be used to specify files and/or directories that should be # excluded from the INPUT source files. This way you can easily exclude a # subdirectory from a directory tree whose root is specified with the INPUT tag. # # Note that relative paths are relative to the directory from which doxygen is # run. EXCLUDE = # The EXCLUDE_SYMLINKS tag can be used to select whether or not files or # directories that are symbolic links (a Unix file system feature) are excluded # from the input. # The default value is: NO. EXCLUDE_SYMLINKS = NO # If the value of the INPUT tag contains directories, you can use the # EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude # certain files from those directories. # # Note that the wildcards are matched against the file with absolute path, so to # exclude all test directories for example use the pattern */test/* EXCLUDE_PATTERNS = # The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names # (namespaces, classes, functions, etc.) that should be excluded from the # output. The symbol name can be a fully qualified name, a word, or if the # wildcard * is used, a substring. Examples: ANamespace, AClass, # AClass::ANamespace, ANamespace::*Test # # Note that the wildcards are matched against the file with absolute path, so to # exclude all test directories use the pattern */test/* EXCLUDE_SYMBOLS = # The EXAMPLE_PATH tag can be used to specify one or more files or directories # that contain example code fragments that are included (see the \include # command). EXAMPLE_PATH = # If the value of the EXAMPLE_PATH tag contains directories, you can use the # EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and # *.h) to filter out the source-files in the directories. If left blank all # files are included. EXAMPLE_PATTERNS = * # If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be # searched for input files to be used with the \include or \dontinclude commands # irrespective of the value of the RECURSIVE tag. # The default value is: NO. EXAMPLE_RECURSIVE = NO # The IMAGE_PATH tag can be used to specify one or more files or directories # that contain images that are to be included in the documentation (see the # \image command). IMAGE_PATH = # The INPUT_FILTER tag can be used to specify a program that doxygen should # invoke to filter for each input file. Doxygen will invoke the filter program # by executing (via popen()) the command: # # # # where is the value of the INPUT_FILTER tag, and is the # name of an input file. Doxygen will then use the output that the filter # program writes to standard output. If FILTER_PATTERNS is specified, this tag # will be ignored. # # Note that the filter must not add or remove lines; it is applied before the # code is scanned, but not when the output code is generated. If lines are added # or removed, the anchors will not be placed correctly. # # Note that for custom extensions or not directly supported extensions you also # need to set EXTENSION_MAPPING for the extension otherwise the files are not # properly processed by doxygen. INPUT_FILTER = # The FILTER_PATTERNS tag can be used to specify filters on a per file pattern # basis. Doxygen will compare the file name with each pattern and apply the # filter if there is a match. The filters are a list of the form: pattern=filter # (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how # filters are used. If the FILTER_PATTERNS tag is empty or if none of the # patterns match the file name, INPUT_FILTER is applied. # # Note that for custom extensions or not directly supported extensions you also # need to set EXTENSION_MAPPING for the extension otherwise the files are not # properly processed by doxygen. FILTER_PATTERNS = # If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using # INPUT_FILTER) will also be used to filter the input files that are used for # producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES). # The default value is: NO. FILTER_SOURCE_FILES = NO # The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file # pattern. A pattern will override the setting for FILTER_PATTERN (if any) and # it is also possible to disable source filtering for a specific pattern using # *.ext= (so without naming a filter). # This tag requires that the tag FILTER_SOURCE_FILES is set to YES. FILTER_SOURCE_PATTERNS = # If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that # is part of the input, its contents will be placed on the main page # (index.html). This can be useful if you have a project on for instance GitHub # and want to reuse the introduction page also for the doxygen output. USE_MDFILE_AS_MAINPAGE = ../README.md #--------------------------------------------------------------------------- # Configuration options related to source browsing #--------------------------------------------------------------------------- # If the SOURCE_BROWSER tag is set to YES then a list of source files will be # generated. Documented entities will be cross-referenced with these sources. # # Note: To get rid of all source code in the generated output, make sure that # also VERBATIM_HEADERS is set to NO. # The default value is: NO. SOURCE_BROWSER = NO # Setting the INLINE_SOURCES tag to YES will include the body of functions, # classes and enums directly into the documentation. # The default value is: NO. INLINE_SOURCES = NO # Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any # special comment blocks from generated source code fragments. Normal C, C++ and # Fortran comments will always remain visible. # The default value is: YES. STRIP_CODE_COMMENTS = YES # If the REFERENCED_BY_RELATION tag is set to YES then for each documented # entity all documented functions referencing it will be listed. # The default value is: NO. REFERENCED_BY_RELATION = NO # If the REFERENCES_RELATION tag is set to YES then for each documented function # all documented entities called/used by that function will be listed. # The default value is: NO. REFERENCES_RELATION = NO # If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set # to YES then the hyperlinks from functions in REFERENCES_RELATION and # REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will # link to the documentation. # The default value is: YES. REFERENCES_LINK_SOURCE = YES # If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the # source code will show a tooltip with additional information such as prototype, # brief description and links to the definition and documentation. Since this # will make the HTML file larger and loading of large files a bit slower, you # can opt to disable this feature. # The default value is: YES. # This tag requires that the tag SOURCE_BROWSER is set to YES. SOURCE_TOOLTIPS = YES # If the USE_HTAGS tag is set to YES then the references to source code will # point to the HTML generated by the htags(1) tool instead of doxygen built-in # source browser. The htags tool is part of GNU's global source tagging system # (see https://www.gnu.org/software/global/global.html). You will need version # 4.8.6 or higher. # # To use it do the following: # - Install the latest version of global # - Enable SOURCE_BROWSER and USE_HTAGS in the configuration file # - Make sure the INPUT points to the root of the source tree # - Run doxygen as normal # # Doxygen will invoke htags (and that will in turn invoke gtags), so these # tools must be available from the command line (i.e. in the search path). # # The result: instead of the source browser generated by doxygen, the links to # source code will now point to the output of htags. # The default value is: NO. # This tag requires that the tag SOURCE_BROWSER is set to YES. USE_HTAGS = NO # If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a # verbatim copy of the header file for each class for which an include is # specified. Set to NO to disable this. # See also: Section \class. # The default value is: YES. VERBATIM_HEADERS = YES # If the CLANG_ASSISTED_PARSING tag is set to YES then doxygen will use the # clang parser (see: http://clang.llvm.org/) for more accurate parsing at the # cost of reduced performance. This can be particularly helpful with template # rich C++ code for which doxygen's built-in parser lacks the necessary type # information. # Note: The availability of this option depends on whether or not doxygen was # generated with the -Duse_libclang=ON option for CMake. # The default value is: NO. CLANG_ASSISTED_PARSING = NO # If clang assisted parsing is enabled you can provide the compiler with command # line options that you would normally use when invoking the compiler. Note that # the include paths will already be set by doxygen for the files and directories # specified with INPUT and INCLUDE_PATH. # This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES. CLANG_OPTIONS = # If clang assisted parsing is enabled you can provide the clang parser with the # path to the compilation database (see: # http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html) used when the files # were built. This is equivalent to specifying the "-p" option to a clang tool, # such as clang-check. These options will then be passed to the parser. # Note: The availability of this option depends on whether or not doxygen was # generated with the -Duse_libclang=ON option for CMake. CLANG_DATABASE_PATH = #--------------------------------------------------------------------------- # Configuration options related to the alphabetical class index #--------------------------------------------------------------------------- # If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all # compounds will be generated. Enable this if the project contains a lot of # classes, structs, unions or interfaces. # The default value is: YES. ALPHABETICAL_INDEX = YES # The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in # which the alphabetical index list will be split. # Minimum value: 1, maximum value: 20, default value: 5. # This tag requires that the tag ALPHABETICAL_INDEX is set to YES. COLS_IN_ALPHA_INDEX = 5 # In case all classes in a project start with a common prefix, all classes will # be put under the same header in the alphabetical index. The IGNORE_PREFIX tag # can be used to specify a prefix (or a list of prefixes) that should be ignored # while generating the index headers. # This tag requires that the tag ALPHABETICAL_INDEX is set to YES. IGNORE_PREFIX = #--------------------------------------------------------------------------- # Configuration options related to the HTML output #--------------------------------------------------------------------------- # If the GENERATE_HTML tag is set to YES, doxygen will generate HTML output # The default value is: YES. GENERATE_HTML = YES # The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a # relative path is entered the value of OUTPUT_DIRECTORY will be put in front of # it. # The default directory is: html. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_OUTPUT = html # The HTML_FILE_EXTENSION tag can be used to specify the file extension for each # generated HTML page (for example: .htm, .php, .asp). # The default value is: .html. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_FILE_EXTENSION = .html # The HTML_HEADER tag can be used to specify a user-defined HTML header file for # each generated HTML page. If the tag is left blank doxygen will generate a # standard header. # # To get valid HTML the header file that includes any scripts and style sheets # that doxygen needs, which is dependent on the configuration options used (e.g. # the setting GENERATE_TREEVIEW). It is highly recommended to start with a # default header using # doxygen -w html new_header.html new_footer.html new_stylesheet.css # YourConfigFile # and then modify the file new_header.html. See also section "Doxygen usage" # for information on how to generate the default header that doxygen normally # uses. # Note: The header is subject to change so you typically have to regenerate the # default header when upgrading to a newer version of doxygen. For a description # of the possible markers and block names see the documentation. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_HEADER = # The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each # generated HTML page. If the tag is left blank doxygen will generate a standard # footer. See HTML_HEADER for more information on how to generate a default # footer and what special commands can be used inside the footer. See also # section "Doxygen usage" for information on how to generate the default footer # that doxygen normally uses. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_FOOTER = # The HTML_STYLESHEET tag can be used to specify a user-defined cascading style # sheet that is used by each HTML page. It can be used to fine-tune the look of # the HTML output. If left blank doxygen will generate a default style sheet. # See also section "Doxygen usage" for information on how to generate the style # sheet that doxygen normally uses. # Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as # it is more robust and this tag (HTML_STYLESHEET) will in the future become # obsolete. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_STYLESHEET = # The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined # cascading style sheets that are included after the standard style sheets # created by doxygen. Using this option one can overrule certain style aspects. # This is preferred over using HTML_STYLESHEET since it does not replace the # standard style sheet and is therefore more robust against future updates. # Doxygen will copy the style sheet files to the output directory. # Note: The order of the extra style sheet files is of importance (e.g. the last # style sheet in the list overrules the setting of the previous ones in the # list). For an example see the documentation. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_EXTRA_STYLESHEET = # The HTML_EXTRA_FILES tag can be used to specify one or more extra images or # other source files which should be copied to the HTML output directory. Note # that these files will be copied to the base HTML output directory. Use the # $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these # files. In the HTML_STYLESHEET file, use the file name only. Also note that the # files will be copied as-is; there are no commands or markers available. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_EXTRA_FILES = # The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen # will adjust the colors in the style sheet and background images according to # this color. Hue is specified as an angle on a colorwheel, see # https://en.wikipedia.org/wiki/Hue for more information. For instance the value # 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300 # purple, and 360 is red again. # Minimum value: 0, maximum value: 359, default value: 220. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_COLORSTYLE_HUE = 220 # The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors # in the HTML output. For a value of 0 the output will use grayscales only. A # value of 255 will produce the most vivid colors. # Minimum value: 0, maximum value: 255, default value: 100. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_COLORSTYLE_SAT = 100 # The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the # luminance component of the colors in the HTML output. Values below 100 # gradually make the output lighter, whereas values above 100 make the output # darker. The value divided by 100 is the actual gamma applied, so 80 represents # a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not # change the gamma. # Minimum value: 40, maximum value: 240, default value: 80. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_COLORSTYLE_GAMMA = 80 # If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML # page will contain the date and time when the page was generated. Setting this # to YES can help to show when doxygen was last run and thus if the # documentation is up to date. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_TIMESTAMP = NO # If the HTML_DYNAMIC_MENUS tag is set to YES then the generated HTML # documentation will contain a main index with vertical navigation menus that # are dynamically created via JavaScript. If disabled, the navigation index will # consists of multiple levels of tabs that are statically embedded in every HTML # page. Disable this option to support browsers that do not have JavaScript, # like the Qt help browser. # The default value is: YES. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_DYNAMIC_MENUS = YES # If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML # documentation will contain sections that can be hidden and shown after the # page has loaded. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_DYNAMIC_SECTIONS = NO # With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries # shown in the various tree structured indices initially; the user can expand # and collapse entries dynamically later on. Doxygen will expand the tree to # such a level that at most the specified number of entries are visible (unless # a fully collapsed tree already exceeds this amount). So setting the number of # entries 1 will produce a full collapsed tree by default. 0 is a special value # representing an infinite number of entries and will result in a full expanded # tree by default. # Minimum value: 0, maximum value: 9999, default value: 100. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_INDEX_NUM_ENTRIES = 100 # If the GENERATE_DOCSET tag is set to YES, additional index files will be # generated that can be used as input for Apple's Xcode 3 integrated development # environment (see: https://developer.apple.com/xcode/), introduced with OSX # 10.5 (Leopard). To create a documentation set, doxygen will generate a # Makefile in the HTML output directory. Running make will produce the docset in # that directory and running make install will install the docset in # ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at # startup. See https://developer.apple.com/library/archive/featuredarticles/Doxy # genXcode/_index.html for more information. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. GENERATE_DOCSET = NO # This tag determines the name of the docset feed. A documentation feed provides # an umbrella under which multiple documentation sets from a single provider # (such as a company or product suite) can be grouped. # The default value is: Doxygen generated docs. # This tag requires that the tag GENERATE_DOCSET is set to YES. DOCSET_FEEDNAME = "Doxygen generated docs" # This tag specifies a string that should uniquely identify the documentation # set bundle. This should be a reverse domain-name style string, e.g. # com.mycompany.MyDocSet. Doxygen will append .docset to the name. # The default value is: org.doxygen.Project. # This tag requires that the tag GENERATE_DOCSET is set to YES. DOCSET_BUNDLE_ID = org.doxygen.Project # The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify # the documentation publisher. This should be a reverse domain-name style # string, e.g. com.mycompany.MyDocSet.documentation. # The default value is: org.doxygen.Publisher. # This tag requires that the tag GENERATE_DOCSET is set to YES. DOCSET_PUBLISHER_ID = org.doxygen.Publisher # The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher. # The default value is: Publisher. # This tag requires that the tag GENERATE_DOCSET is set to YES. DOCSET_PUBLISHER_NAME = Publisher # If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three # additional HTML index files: index.hhp, index.hhc, and index.hhk. The # index.hhp is a project file that can be read by Microsoft's HTML Help Workshop # (see: https://www.microsoft.com/en-us/download/details.aspx?id=21138) on # Windows. # # The HTML Help Workshop contains a compiler that can convert all HTML output # generated by doxygen into a single compiled HTML file (.chm). Compiled HTML # files are now used as the Windows 98 help format, and will replace the old # Windows help format (.hlp) on all Windows platforms in the future. Compressed # HTML files also contain an index, a table of contents, and you can search for # words in the documentation. The HTML workshop also contains a viewer for # compressed HTML files. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. GENERATE_HTMLHELP = NO # The CHM_FILE tag can be used to specify the file name of the resulting .chm # file. You can add a path in front of the file if the result should not be # written to the html output directory. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. CHM_FILE = # The HHC_LOCATION tag can be used to specify the location (absolute path # including file name) of the HTML help compiler (hhc.exe). If non-empty, # doxygen will try to run the HTML help compiler on the generated index.hhp. # The file has to be specified with full path. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. HHC_LOCATION = # The GENERATE_CHI flag controls if a separate .chi index file is generated # (YES) or that it should be included in the master .chm file (NO). # The default value is: NO. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. GENERATE_CHI = NO # The CHM_INDEX_ENCODING is used to encode HtmlHelp index (hhk), content (hhc) # and project file content. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. CHM_INDEX_ENCODING = # The BINARY_TOC flag controls whether a binary table of contents is generated # (YES) or a normal table of contents (NO) in the .chm file. Furthermore it # enables the Previous and Next buttons. # The default value is: NO. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. BINARY_TOC = NO # The TOC_EXPAND flag can be set to YES to add extra items for group members to # the table of contents of the HTML help documentation and to the tree view. # The default value is: NO. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. TOC_EXPAND = NO # If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and # QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that # can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help # (.qch) of the generated HTML documentation. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. GENERATE_QHP = NO # If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify # the file name of the resulting .qch file. The path specified is relative to # the HTML output folder. # This tag requires that the tag GENERATE_QHP is set to YES. QCH_FILE = # The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help # Project output. For more information please see Qt Help Project / Namespace # (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#namespace). # The default value is: org.doxygen.Project. # This tag requires that the tag GENERATE_QHP is set to YES. QHP_NAMESPACE = org.doxygen.Project # The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt # Help Project output. For more information please see Qt Help Project / Virtual # Folders (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#virtual- # folders). # The default value is: doc. # This tag requires that the tag GENERATE_QHP is set to YES. QHP_VIRTUAL_FOLDER = doc # If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom # filter to add. For more information please see Qt Help Project / Custom # Filters (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom- # filters). # This tag requires that the tag GENERATE_QHP is set to YES. QHP_CUST_FILTER_NAME = # The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the # custom filter to add. For more information please see Qt Help Project / Custom # Filters (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom- # filters). # This tag requires that the tag GENERATE_QHP is set to YES. QHP_CUST_FILTER_ATTRS = # The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this # project's filter section matches. Qt Help Project / Filter Attributes (see: # https://doc.qt.io/archives/qt-4.8/qthelpproject.html#filter-attributes). # This tag requires that the tag GENERATE_QHP is set to YES. QHP_SECT_FILTER_ATTRS = # The QHG_LOCATION tag can be used to specify the location of Qt's # qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the # generated .qhp file. # This tag requires that the tag GENERATE_QHP is set to YES. QHG_LOCATION = # If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be # generated, together with the HTML files, they form an Eclipse help plugin. To # install this plugin and make it available under the help contents menu in # Eclipse, the contents of the directory containing the HTML and XML files needs # to be copied into the plugins directory of eclipse. The name of the directory # within the plugins directory should be the same as the ECLIPSE_DOC_ID value. # After copying Eclipse needs to be restarted before the help appears. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. GENERATE_ECLIPSEHELP = NO # A unique identifier for the Eclipse help plugin. When installing the plugin # the directory name containing the HTML and XML files should also have this # name. Each documentation set should have its own identifier. # The default value is: org.doxygen.Project. # This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES. ECLIPSE_DOC_ID = org.doxygen.Project # If you want full control over the layout of the generated HTML pages it might # be necessary to disable the index and replace it with your own. The # DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top # of each HTML page. A value of NO enables the index and the value YES disables # it. Since the tabs in the index contain the same information as the navigation # tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. DISABLE_INDEX = NO # The GENERATE_TREEVIEW tag is used to specify whether a tree-like index # structure should be generated to display hierarchical information. If the tag # value is set to YES, a side panel will be generated containing a tree-like # index structure (just like the one that is generated for HTML Help). For this # to work a browser that supports JavaScript, DHTML, CSS and frames is required # (i.e. any modern browser). Windows users are probably better off using the # HTML help feature. Via custom style sheets (see HTML_EXTRA_STYLESHEET) one can # further fine-tune the look of the index. As an example, the default style # sheet generated by doxygen has an example that shows how to put an image at # the root of the tree instead of the PROJECT_NAME. Since the tree basically has # the same information as the tab index, you could consider setting # DISABLE_INDEX to YES when enabling this option. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. GENERATE_TREEVIEW = NO # The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that # doxygen will group on one line in the generated HTML documentation. # # Note that a value of 0 will completely suppress the enum values from appearing # in the overview section. # Minimum value: 0, maximum value: 20, default value: 4. # This tag requires that the tag GENERATE_HTML is set to YES. ENUM_VALUES_PER_LINE = 1 # If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used # to set the initial width (in pixels) of the frame in which the tree is shown. # Minimum value: 0, maximum value: 1500, default value: 250. # This tag requires that the tag GENERATE_HTML is set to YES. TREEVIEW_WIDTH = 250 # If the EXT_LINKS_IN_WINDOW option is set to YES, doxygen will open links to # external symbols imported via tag files in a separate window. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. EXT_LINKS_IN_WINDOW = NO # Use this tag to change the font size of LaTeX formulas included as images in # the HTML documentation. When you change the font size after a successful # doxygen run you need to manually remove any form_*.png images from the HTML # output directory to force them to be regenerated. # Minimum value: 8, maximum value: 50, default value: 10. # This tag requires that the tag GENERATE_HTML is set to YES. FORMULA_FONTSIZE = 10 # Use the FORMULA_TRANSPARENT tag to determine whether or not the images # generated for formulas are transparent PNGs. Transparent PNGs are not # supported properly for IE 6.0, but are supported on all modern browsers. # # Note that when changing this option you need to delete any form_*.png files in # the HTML output directory before the changes have effect. # The default value is: YES. # This tag requires that the tag GENERATE_HTML is set to YES. FORMULA_TRANSPARENT = YES # The FORMULA_MACROFILE can contain LaTeX \newcommand and \renewcommand commands # to create new LaTeX commands to be used in formulas as building blocks. See # the section "Including formulas" for details. FORMULA_MACROFILE = # Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see # https://www.mathjax.org) which uses client side JavaScript for the rendering # instead of using pre-rendered bitmaps. Use this if you do not have LaTeX # installed or if you want to formulas look prettier in the HTML output. When # enabled you may also need to install MathJax separately and configure the path # to it using the MATHJAX_RELPATH option. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. USE_MATHJAX = YES # When MathJax is enabled you can set the default output format to be used for # the MathJax output. See the MathJax site (see: # http://docs.mathjax.org/en/latest/output.html) for more details. # Possible values are: HTML-CSS (which is slower, but has the best # compatibility), NativeMML (i.e. MathML) and SVG. # The default value is: HTML-CSS. # This tag requires that the tag USE_MATHJAX is set to YES. MATHJAX_FORMAT = HTML-CSS # When MathJax is enabled you need to specify the location relative to the HTML # output directory using the MATHJAX_RELPATH option. The destination directory # should contain the MathJax.js script. For instance, if the mathjax directory # is located at the same level as the HTML output directory, then # MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax # Content Delivery Network so you can quickly see the result without installing # MathJax. However, it is strongly recommended to install a local copy of # MathJax from https://www.mathjax.org before deployment. # The default value is: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/. # This tag requires that the tag USE_MATHJAX is set to YES. MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest # The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax # extension names that should be enabled during MathJax rendering. For example # MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols # This tag requires that the tag USE_MATHJAX is set to YES. MATHJAX_EXTENSIONS = # The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces # of code that will be used on startup of the MathJax code. See the MathJax site # (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an # example see the documentation. # This tag requires that the tag USE_MATHJAX is set to YES. MATHJAX_CODEFILE = # When the SEARCHENGINE tag is enabled doxygen will generate a search box for # the HTML output. The underlying search engine uses javascript and DHTML and # should work on any modern browser. Note that when using HTML help # (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET) # there is already a search function so this one should typically be disabled. # For large projects the javascript based search engine can be slow, then # enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to # search using the keyboard; to jump to the search box use + S # (what the is depends on the OS and browser, but it is typically # , /