pax_global_header00006660000000000000000000000064150176400340014512gustar00rootroot0000000000000052 comment=d2c8ddc3c5180e75eab2bbba07d8023769971053 hipSPARSE-rocm-6.4.3/000077500000000000000000000000001501764003400141605ustar00rootroot00000000000000hipSPARSE-rocm-6.4.3/.azuredevops/000077500000000000000000000000001501764003400166055ustar00rootroot00000000000000hipSPARSE-rocm-6.4.3/.azuredevops/rocm-ci.yml000066400000000000000000000012431501764003400206610ustar00rootroot00000000000000resources: repositories: - repository: pipelines_repo type: github endpoint: ROCm name: ROCm/ROCm variables: - group: common - template: /.azuredevops/variables-global.yml@pipelines_repo trigger: batch: true branches: include: - develop - mainline paths: exclude: - .githooks - .github - .jenkins - docs - '.*.y*ml' - '*.md' pr: autoCancel: true branches: include: - develop - mainline paths: exclude: - .githooks - .github - .jenkins - docs - '.*.y*ml' - '*.md' drafts: false jobs: - template: ${{ variables.CI_COMPONENT_PATH }}/hipSPARSE.yml@pipelines_repo hipSPARSE-rocm-6.4.3/.clang-format000066400000000000000000000065421501764003400165420ustar00rootroot00000000000000# 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-6.4.3/.githooks/000077500000000000000000000000001501764003400160655ustar00rootroot00000000000000hipSPARSE-rocm-6.4.3/.githooks/install000077500000000000000000000002231501764003400174560ustar00rootroot00000000000000#!/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-6.4.3/.githooks/pre-commit000077500000000000000000000017671501764003400201020ustar00rootroot00000000000000#!/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-6.4.3/.github/000077500000000000000000000000001501764003400155205ustar00rootroot00000000000000hipSPARSE-rocm-6.4.3/.github/CODEOWNERS000077500000000000000000000004331501764003400171160ustar00rootroot00000000000000* @ntrost57 @YvanMokwinski @jsandham # Documentation files docs/* @ROCm/rocm-documentation *.md @ROCm/rocm-documentation *.rst @ROCm/rocm-documentation .readthedocs.yaml @ROCm/rocm-documentation # Header directory for Doxygen documentation library/include/* @ROCm/rocm-documentation hipSPARSE-rocm-6.4.3/.github/CONTRIBUTING.md000066400000000000000000000206401501764003400177530ustar00rootroot00000000000000 # Contributing to hipSPARSE # AMD welcomes contributions to hipSPARSE from the community. Whether those contributions are bug reports, bug fixes, documentation additions, performance notes, or other improvements, we value collaboration with our users. We can build better solutions together. Please follow these details to help ensure your contributions will be successfully accepted. Our code contriubtion guidelines closely follow the model of [GitHub pull-requests](https://help.github.com/articles/using-pull-requests/). This repository follows the [git flow](http://nvie.com/posts/a-successful-git-branching-model/) workflow, which dictates a /master branch where releases are cut, and a /develop branch which serves as an integration branch for new code. ## Issue Discussion ## Please use the GitHub Issues tab to notify us of issues. * Use your best judgement for issue creation. If your issue is already listed, upvote the issue and comment or post to provide additional details, such as how you reproduced this issue. * If you're not sure if your issue is the same, err on the side of caution and file your issue. You can add a comment to include the issue number (and link) for the similar issue. If we evaluate your issue as being the same as the existing issue, we'll close the duplicate. * If your issue doesn't exist, use the issue template to file a new issue. * When filing an issue, be sure to provide as much information as possible, including script output so we can collect information about your configuration. This helps reduce the time required to reproduce your issue. * Check your issue regularly, as we may require additional information to successfully reproduce the issue. * You may also open an issue to ask questions to the maintainers about whether a proposed change meets the acceptance criteria, or to discuss an idea pertaining to the library. ## Acceptance Criteria ## hipSPARSE exposes a common interface that provides basic linear algebra subroutines for sparse computation implemented on top of the AMD ROCm runtime and toolchains. hipSPARSE is a SPARSE marshalling library supporting both rocSPARSE and cuSPARSE as backends. It sits between the application and a worker SPARSE library, marshalling inputs into the backend library and marshalling results back to the application. Because hipSPARSE is simply a wrapper library around rocSPARSE (on AMD GPU systems), any routine added to hipSPARSE must have a corresponding routine in rocSPARSE. Additionally, all routines found in cuSPARSE should have an equivalent on in hipSPARSE. With this in mind, contributions that accompilish the following are greatly appreciated: * Fixing compilation issues when using different cuSPARSE or rocSPARSE versions. * Adding missing hipSPARSE routines that match routines found in cuSPARSE. ## Code Structure ## The following is the structure of the hipSPARSE library in the GitHub repository. The `library/include/` directory contains the hipsparse.h header which declares the public API of hipSPARSE The `library/src/` directory contains the implementations of all the hipSPARSE routines. For hipSPARSE code wrapping rocSPARSE routines (i.e. when running hipSPARSE on an AMD GPU system), the code can be found in `library/src/amd_detail`. Similarily, for hipSPARSE code wrapping cuSPARSE routines (i.e. when running hipSPARSE on a NVIDIA GPU system), the code can be found in `library/src/nvidia_detail`. The `clients/` directory contains the testing and benchmarking code as well as all the samples demonstrating hipSPARSE usage. The `docs/` directory contains all of the documentation files. ## Coding Style ## In general, follow the style of the surrounding code. C and C++ code is formatted using `clang-format`. Use the clang-format version installed with ROCm (found in the `/opt/rocm/llvm/bin` directory). Please do not use your system's built-in `clang-format`, as this is a different version that may result in incorrect results. To format a file, use: ``` /opt/rocm/llvm/bin/clang-format -style=file -i ``` To format all files, run the following script in rocSPARSE directory: ``` #!/bin/bash git ls-files -z *.cc *.cpp *.h *.hpp *.cl *.h.in *.hpp.in *.cpp.in | xargs -0 /opt/rocm/llvm/bin/clang-format -style=file -i ``` Also, githooks can be installed to format the code per-commit: ``` ./.githooks/install ``` ## Pull Request Guidelines ## When you create a pull request, you should target the default branch. Our current default branch is the **develop** branch, which serves as our integration branch. ### Deliverables ### When raising a PR in hipSPARSE here are some important things to include: 1. For each new file in the repository, Please include the licensing header ``` /* ************************************************************************ * Copyright (C) 20xx Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ ``` and adjust the date to the current year. When simply modifying a file, the date should automatically be updated pre-commit as long as the githook has been installed (./.githooks/install). 2. When adding a new routine, please make sure you are also adding appropriate testing code. These new unit tests should integrate within the existing [googletest framework](https://github.com/google/googletest/blob/master/googletest/docs/primer.md). This typically involves adding the following files: * testing_.hpp file in the directory `clients/include/` * test_.cpp file in directory `clients/tests/` See existing tests for guidance when adding your own. 3. When modifiying an existing routine, add appropriate testing to test_.cpp file in directory `clients/tests/`. 4. Tests must have good code coverage. 7. Ensure code builds successfully. This includes making sure that the code can compile, that the code is properly formatted, and that all tests pass. Because hipSPARSE is just a wrapper around both rocSPARSE (on AMD GPU systems) and cuSPARSE (on NVIDIA GPU systems), please ensure that your code compiles and runs on both an AMD GPU system using the rocSPARSE backend and a NVIDIA GPU system using the cuSPARSE backend. Please be mindful that routines often become deprecated in rocSPARSE/cuSPARSE and that this must be properly accounted for in hipSPARSE to ensure successful compilation depending on which version of rocSPARSE/cuSPARSE you are using. In hipSPARSE this is currently accomplished using the pre-processor for condition compilation. See existing code for guidance. 8. Do not break existing test cases ### Process ### When a PR is raised targetting the develop branch in hipSPARSE, CI will be automatically triggered. This will: * Test that the PR passes static analysis (i.e ensure clang formatting rules have been followed). * Test that the documentation can be properly built. * Ensure that the PR compiles on different OS and GPU device architecture combinations (including systems using both rocSPARSE and cuSPARSE). * Ensure that all tests pass on different OS and GPU device architecture combinations (including systems using both rocSPARSE and cuSPARSE). Feel free to ask questions on your PR regarding any CI failures you encounter. * Reviewers are listed in the CODEOWNERS filehipSPARSE-rocm-6.4.3/.github/dependabot.yml000066400000000000000000000012601501764003400203470ustar00rootroot00000000000000# 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-6.4.3/.gitignore000066400000000000000000000005731501764003400161550ustar00rootroot00000000000000# 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/ # matrices *.csr *.mtx hipSPARSE-rocm-6.4.3/.jenkins/000077500000000000000000000000001501764003400156775ustar00rootroot00000000000000hipSPARSE-rocm-6.4.3/.jenkins/common.groovy000066400000000000000000000035341501764003400204430ustar00rootroot00000000000000// 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 packageHelper = platform.makePackage(platform.jenkinsLabel,"${project.paths.project_build_prefix}/build/release") platform.runCommand(this, packageHelper[0]) platform.archiveArtifacts(this, packageHelper[1]) } return this hipSPARSE-rocm-6.4.3/.jenkins/extended.groovy000066400000000000000000000060011501764003400207430ustar00rootroot00000000000000#!/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 = ['hipBLAS-common', 'hipBLASLt', 'rocBLAS', '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-6.4.3/.jenkins/precheckin-cuda.groovy000066400000000000000000000045711501764003400222020ustar00rootroot00000000000000#!/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 propertyList = [:] propertyList = auxiliary.appendPropertyList(propertyList) def jobNameList = [:] jobNameList = auxiliary.appendJobNameList(jobNameList, 'hipSPARSE') propertyList.each { jobName, property-> if (urlJobName == jobName) { properties(auxiliary.addCommonProperties(property)) } } jobNameList.each { jobName, nodeDetails-> if (urlJobName == jobName) stage(jobName) { runCI(nodeDetails, jobName) } } // 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')])])) stage(urlJobName) { runCI(['ubuntu22-cuda12':['anycuda']], urlJobName) } } } hipSPARSE-rocm-6.4.3/.jenkins/precheckin.groovy000066400000000000000000000060011501764003400212560ustar00rootroot00000000000000#!/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 = ['hipBLAS-common', 'hipBLASLt', 'rocBLAS', '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-6.4.3/.jenkins/static.groovy000066400000000000000000000060511501764003400204370ustar00rootroot00000000000000#!/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') prj.paths.build_command = './install.sh -c --static' prj.compiler.compiler_name = 'amdclang++' prj.compiler.compiler_path = '/opt/rocm/bin/amdclang++' prj.libraryDependencies = ['hipBLAS-common', 'hipBLASLt', 'rocBLAS', '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-6.4.3/.jenkins/staticanalysis.groovy000066400000000000000000000027411501764003400222050ustar00rootroot00000000000000#!/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) def propertyList = ["compute-rocm-dkms-no-npi-hipclang":[pipelineTriggers([cron('0 1 * * 0')])], "rocm-docker":[]] propertyList = auxiliary.appendPropertyList(propertyList) def jobNameList = ["compute-rocm-dkms-no-npi-hipclang":[]] jobNameList = auxiliary.appendJobNameList(jobNameList) propertyList.each { jobName, property-> if (urlJobName == jobName) properties(auxiliary.addCommonProperties(property)) } jobNameList.each { jobName, nodeDetails-> if (urlJobName == jobName) stage(jobName) { runCI(nodeDetails, jobName) } } } hipSPARSE-rocm-6.4.3/.readthedocs.yaml000066400000000000000000000004671501764003400174160ustar00rootroot00000000000000# 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: install: - requirements: docs/sphinx/requirements.txt build: os: ubuntu-22.04 tools: python: "3.10" hipSPARSE-rocm-6.4.3/CHANGELOG.md000066400000000000000000000163511501764003400157770ustar00rootroot00000000000000# Changelog for hipSPARSE Documentation for hipSPARSE is available at [https://rocm.docs.amd.com/projects/hipSPARSE/en/latest/](https://rocm.docs.amd.com/projects/hipSPARSE/en/latest/). ## hipSPARSE 3.2.0 for ROCm 6.4.0 ### Added * Added build dependencies for CentOS/RHEL 9 in install script ### Changed * Moved the `hipsparse_clientmatrices.cmake` and `hipsparse_mtx2csr` files from the `hipsparse-tests` package to the `hipsparse-clients-common` package ### Optimized * Removed unused `GTest` dependency from `hipsparse-bench` ### Known issues * In `hipsparseSpSM_solve()`, the external buffer is passed as a parameter. This does not match the NVIDIA CUDA cuSPARSE API. This extra external buffer parameter will be removed in a future release. For now this extra parameter can be ignored and nullptr passed as it is unused internally by `hipsparseSpSM_solve()`. ## hipSPARSE 3.1.2 for ROCm 6.3.0 ### Added * Added an alpha version of the hipsparse-bench executable to facilitate comparing NVIDIA CUDA cuSPARSE and rocSPARSE backends ### Changed * Changed the default compiler from hipcc to amdclang in the install script and cmake files. ### Optimized * Improved the user documentation ### Resolved issues * Fixed the gfortran dependency for the `azurelinux` operating system. ### Known issues * In `hipsparseSpSM_solve()`, the external buffer is passed as a parameter. This does not match the NVIDIA CUDA cuSPARSE API. This extra external buffer parameter will be removed in a future release. For now this extra parameter can be ignored and nullptr passed as it is unused internally by `hipsparseSpSM_solve()`. ## hipSPARSE 3.1.1 for ROCm 6.2.0 ### Additions * Added missing `hipsparseCscGet()` routine ### Changes * All internal hipSPARSE functions now exist inside a namespace * Match deprecations found in NVIDIA CUDA cuSPARSE 12.x.x when using NVIDIA CUDA cuSPARSE backend. ### Fixes * Fixed SpGEMM and SpGEMM_reuse routines which were not matching NVIDIA CUDA cuSPARSE behaviour ### Optimizations * Improved user manual * Improved contribution guidelines ### Known issues * In `hipsparseSpSM_solve()`, we currently pass the external buffer as a parameter. This does not match the NVIDIA CUDA cuSPARSE API and this extra external buffer parameter will be removed in a future release. For now this extra parameter can be ignored and nullptr passed as it is unused internally by `hipsparseSpSM_solve()`. ## hipSPARSE 3.0.1 for ROCm 6.1.0 ### Fixes * Fixes to the build chain ## hipSPARSE 3.0.0 for ROCm 6.0.0 ### Additions * Added `hipsparseGetErrorName` and `hipsparseGetErrorString` ### Changes * Changed the `hipsparseSpSV_solve()` API function to match the NVIDIA CUDA cuSPARSE API * Changed generic API functions to use const descriptors * Improved documentation ## hipSPARSE 2.3.8 for ROCm 5.7.0 ### Fixes * Compilation failures when using the NVIDIA CUDA cuSPARSE 12.1.0 and 12.0.0 backends * Compilation failures when using the NVIDIA CUDA cuSPARSE 10.1 (non-update version) backend ## hipSPARSE 2.3.7 for ROCm 5.6.1 ### Fixes * Reverted an undocumented API change in hipSPARSE 2.3.6 that affected the `hipsparseSpSV_solve` function ## hipSPARSE 2.3.6 for ROCm 5.6.0 ### Additions * Added SpGEMM algorithms ### Changes * blockDim == 0 now returns `HIPSPARSE_STATUS_INVALID_SIZE` for `hipsparseXbsr2csr` and `hipsparseXcsr2bsr` ## hipSPARSE 2.3.5 for ROCm 5.5.0 ### Fixes * Fixed an issue where the `rocm` folder was not removed after upgrading meta packages * Fixed a compilation issue with the NVIDIA CUDA cuSPARSE backend * Added more detailed messages for unit test failures due related to missing input data * Improved documentation * Fixed a bug with deprecation messages when using gcc9 ## hipSPARSE 2.3.3 for ROCm 5.4.0 ### Additions * Added `hipsparseCsr2cscEx2_bufferSize` and `hipsparseCsr2cscEx2` routines ### Changes * `HIPSPARSE_ORDER_COLUMN` has been renamed to `HIPSPARSE_ORDER_COL` in order to match NVIDIA CUDA cuSPARSE ## hipSPARSE 2.3.1 for ROCm 5.3.0 ### Additions * Added SpMM and SpMM batched for CSC format ## hipSPARSE 2.2.0 for ROCm 5.2.0 ### Additions * New packages for test and benchmark executables on all supported operating systems using CPack ## hipSPARSE 2.1.0 for ROCm 5.1.0 ### Additions * Added `gtsv_interleaved_batch` and `gpsv_interleaved_batch` routines * Added `SpGEMM_reuse` ### Changes * Changed `BUILD_CUDA` with `USE_CUDA` in the install script and CMake files * Updated GoogleTest to 11.1 ### Fixes * Fixed a bug in SpMM Alg versioning ## hipSPARSE 2.0.0 for ROCm 5.0.0 ### Additions * Added (conjugate) transpose support for `csrmv`, `hybmv`, and `spmv` routines ## hipSPARSE 1.11.2 for ROCm 4.5.0 ### Additions * Triangular solve for multiple right-hand sides using BSR format * SpMV for BSRX format * Enhanced SpMM in CSR format to work with transposed A * Matrix coloring for CSR matrices * Batched tridiagonal solve (`gtsv_strided_batch`) * SpMM for BLOCKED ELL format * Generic routines for SpSV and SpSM * Beta support for Windows 10 * Additional atomic-based algorithms for SpMM in COO format * Additional algorithm for SpMM in CSR format ### Changes * Packaging has been split into a runtime package (`hipsparse`) and a development package (`hipsparse-devel`): The development package depends on the runtime package. When installing the runtime package, the package manager will suggest the installation of the development package to aid users transitioning from the previous version's combined package. This suggestion by package manager is for all supported operating systems (except CentOS 7) to aid in the transition. The `suggestion` feature in the runtime package is introduced as a deprecated feature and will be removed in a future ROCm release. * GTest dependency has been updated to v1.10.0 ### Fixes * Fixed a bug with `gemvi` on Navi21 ### Optimizations * Optimization for pivot-based GTSV ## hipSPARSE 1.10.7 for ROCm 4.3.0 ### Additions * Tridiagonal solve with and without pivoting (batched) * Dense matrix sparse vector multiplication (`gemvi`) * Sampled dense-dense matrix multiplication (`sddmm`) ## hipSPARSE 1.10.6 for ROCm 4.2.0 ### Additions * Generic API support, including SpMM ## hipSPARSE 1.10.4 for ROCm 4.1.0 ### Additions * Generic API support, including Axpby, Gather, Scatter, Rot, SpVV, SpMV, SparseToDense, DenseToSparse, and SpGEMM ## hipSPARSE 1.9.6 for ROCm 4.0.0 ### Additions * Changelog file * `csr2gebsr` * `gebsr2csr` * `gebsr2gebsc` * `gebsr2gebsr` ### Changes * Updates to Debian package name. ## hipSPARSE 1.9.4 for ROCm 3.9 ### Additions * `prune_csr2csr, prune_dense2csr_percentage` and `prune_csr2csr_percentage` * `bsrilu0` ## hipSPARSE 1.8.1 for ROCm 3.8 ### Additions * `bsric0` ## hipSPARSE 1.7.1 for ROCm 3.7 ### Additions * Fortran bindings * Triangular solve for BSR format (bsrsv) * CentOS 6 support ## hipSPARSE 1.7.1 for ROCm 3.6 ### Additions * Fortran bindings * Triangular solve for BSR format (bsrsv) * CentOS 6 support ## hipSPARSE 1.6.5 for ROCm 3.5 ### Additions * Switched to HIP-Clang as default compiler * `csr2dense`, `csc2dense`, `csr2csr_compress`, `nnz_compress`, `bsr2csr`, `csr2bsr`, `bsrmv`, and `csrgeam` * static build * New examples ### Optimizations * `dense2csr`, `dense2csc` ### Fixes * Installation process hipSPARSE-rocm-6.4.3/CMakeLists.txt000066400000000000000000000246161501764003400167310ustar00rootroot00000000000000# ######################################################################## # 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. # # ######################################################################## 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 ${ROCM_PATH}/lib/cmake/hip /opt/rocm /opt/rocm/llvm /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_language}) # 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_BENCHMARKS "Build benchmarks" ON) 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) option(BUILD_DOCS "Build documentation" 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" OFF) 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 3.2.0) set(hipsparse_SOVERSION 1.1.0) # hipSPARSE library add_subdirectory(library) if(BUILD_CLIENTS_SAMPLES OR BUILD_CLIENTS_TESTS OR BUILD_CLIENTS_BENCHMARKS) 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_RPM "libgfortran4") set(GFORTRAN_DEB "libgfortran4") find_package(OpenMP QUIET) if(OPENMP_FOUND) set(OPENMP_RPM "libgomp") set(OPENMP_DEB "libomp-dev") endif() if(CLIENTS_OS STREQUAL "centos" OR CLIENTS_OS STREQUAL "rhel") if(CLIENTS_OS_VERSION VERSION_GREATER_EQUAL "8") set(GFORTRAN_RPM "libgfortran") endif() elseif(CLIENTS_OS STREQUAL "ubuntu" AND CLIENTS_OS_VERSION VERSION_GREATER_EQUAL "20.04") set(GFORTRAN_DEB "libgfortran5") elseif(CLIENTS_OS STREQUAL "sles" AND OPENMP_FOUND) set(OPENMP_RPM "libgomp1") elseif(CLIENTS_OS STREQUAL "mariner" OR CLIENTS_OS STREQUAL "azurelinux") set(GFORTRAN_RPM "gfortran") endif() rocm_package_setup_component(clients) rocm_package_setup_client_component(clients-common) if(BUILD_CLIENTS_TESTS) rocm_package_setup_client_component( tests DEPENDS COMPONENT clients-common DEB "${GFORTRAN_DEB}" RPM "${GFORTRAN_RPM}") rocm_package_setup_client_component( tests DEPENDS COMPONENT clients-common DEB "${OPENMP_DEB}" RPM "${OPENMP_RPM}" ) endif() if(BUILD_CLIENTS_SAMPLES) rocm_package_setup_client_component( samples DEPENDS COMPONENT clients-common DEB "${GFORTRAN_DEB}" RPM "${GFORTRAN_RPM}") endif() if( BUILD_CLIENTS_BENCHMARKS ) rocm_package_setup_client_component( benchmarks DEPENDS COMPONENT clients-common DEB "${OPENMP_DEB}" RPM "${OPENMP_RPM}" ) endif() add_subdirectory( clients ) if(NOT WIN32) rocm_package_add_rpm_dependencies(COMPONENT tests DEPENDS "${GFORTRAN_RPM}") rocm_package_add_deb_dependencies(COMPONENT tests DEPENDS "${GFORTRAN_DEB}") rocm_package_add_rpm_dependencies(COMPONENT samples DEPENDS "${GFORTRAN_RPM}") rocm_package_add_deb_dependencies(COMPONENT samples DEPENDS "${GFORTRAN_DEB}") rocm_package_add_rpm_dependencies(COMPONENT benchmarks DEPENDS "${GFORTRAN_RPM}") rocm_package_add_deb_dependencies(COMPONENT benchmarks DEPENDS "${GFORTRAN_DEB}") endif() if(TARGET OpenMP::OpenMP_CXX) rocm_package_add_rpm_dependencies(COMPONENT tests DEPENDS "${OPENMP_RPM}") rocm_package_add_deb_dependencies(COMPONENT tests DEPENDS "${OPENMP_DEB}") endif() endif() # Package specific CPACK vars if(NOT USE_CUDA) set(ROCSPARSE_MINIMUM "1.12.10") rocm_package_add_dependencies(SHARED_DEPENDS "rocsparse >= ${ROCSPARSE_MINIMUM}") rocm_package_add_deb_dependencies(STATIC_DEPENDS "rocsparse-static-dev >= ${ROCSPARSE_MINIMUM}") rocm_package_add_rpm_dependencies(STATIC_DEPENDS "rocsparse-static-devel >= ${ROCSPARSE_MINIMUM}") 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 "ROCm SPARSE library" MAINTAINER "hipSPARSE Maintainer " LDCONFIG LDCONFIG_DIR ${HIPSPARSE_CONFIG_DIR}) # Build docs if(BUILD_DOCS) add_subdirectory(docs) endif() # # 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-6.4.3/LICENSE.md000066400000000000000000000021011501764003400155560ustar00rootroot00000000000000MIT License Copyright © 2018-2024 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-6.4.3/README.md000066400000000000000000000071201501764003400154370ustar00rootroot00000000000000# hipSPARSE hipSPARSE is a SPARSE marshalling library with multiple supported backends. It sits between your application and a 'worker' SPARSE library, where it marshals inputs to the backend library and marshals results to your application. hipSPARSE exports an interface that doesn't require the client to change, regardless of the chosen backend. Currently, hipSPARSE supports [rocSPARSE](https://github.com/ROCmSoftwarePlatform/rocSPARSE) and [NVIDIA CUDA cuSPARSE](https://developer.nvidia.com/cusparse) backends. ## Documentation > [!NOTE] > The published hipSPARSE documentation is available at [https://rocm.docs.amd.com/projects/hipSPARSE/en/latest/](https://rocm.docs.amd.com/projects/hipSPARSE/en/latest/index.html) in an organized, easy-to-read format, with search and a table of contents. The documentation source files reside in the hipSPARSE/docs folder of this repository. As with all ROCm projects, the documentation is open source. For more information, see [Contribute to ROCm documentation](https://rocm.docs.amd.com/en/latest/contribute/contributing.html). To build our documentation locally, run the following code: ```bash cd docs pip3 install -r sphinx/requirements.txt python3 -m sphinx -T -E -b html -d _build/doctrees -D language=en . _build/html ``` Alternatively, build with CMake: ```bash cmake -DBUILD_DOCS=ON ... ``` ## Installing pre-built packages Download pre-built packages from [ROCm's package servers](https://rocm.docs.amd.com/en/latest/deploy/linux/index.html) using the following code: ```bash `sudo apt update && sudo apt install hipsparse` ``` ## Build hipSPARSE To build hipSPARSE, you can use our bash helper script (for Ubuntu only) or you can perform a manual build (for all supported platforms). * Bash helper script (`install.sh`): This script, which is located in the root of this repository, builds and installs hipSPARSE on Ubuntu with a single command. Note that this option doesn't allow much customization and hard-codes configurations that can be specified through invoking CMake directly. Some commands in the script require sudo access, so it may prompt you for a password. ```bash `./install -h` # shows help `./install -id` # builds library, dependencies, then installs (the `-d` flag only needs to be passed once on a system) ``` * Manual build: If you use a distribution other than Ubuntu, or would like more control over the build process, the [hipSPARSE build wiki](https://github.com/ROCmSoftwarePlatform/hipSPARSE/wiki/Build) provides information on how to configure CMake and build hipSPARSE manually. ### Supported functions You can find a list of [exported functions](https://github.com/ROCmSoftwarePlatform/hipSPARSE/wiki/Exported-functions) on our wiki. ## Interface examples The hipSPARSE interface is compatible with rocSPARSE and CUDA cuSPARSE-v2 APIs. Porting a CUDA application that calls the CUDA cuSPARSE API to an application that calls the hipSPARSE API is 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 to and from the host and device memory. hipSPARSE-rocm-6.4.3/clients/000077500000000000000000000000001501764003400156215ustar00rootroot00000000000000hipSPARSE-rocm-6.4.3/clients/CMakeLists.txt000066400000000000000000000114261501764003400203650ustar00rootroot00000000000000# ######################################################################## # 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) option(BUILD_CLIENTS_BENCHMARKS "Build benchmarks" ON) endif() # Build flags set(CMAKE_CXX_STANDARD 14) 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_BENCHMARKS) add_subdirectory(benchmarks) endif() if(BUILD_CLIENTS_TESTS) enable_testing() add_subdirectory(tests) if(NOT CONVERT_SOURCE) set(CONVERT_SOURCE ${CMAKE_SOURCE_DIR}/deps/convert.cpp) endif() execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CONVERT_SOURCE} -Wl,--build-id=sha1 -O3 -o ${PROJECT_BINARY_DIR}/mtx2csr.exe RESULT_VARIABLE STATUS) if(STATUS AND NOT STATUS EQUAL 0) message(FATAL_ERROR "mtx2csr.exe failed to build, aborting.") endif() set(HIPSPARSE_CLIENTMATRICES "${CMAKE_SOURCE_DIR}/cmake/hipsparse_clientmatrices.cmake") set(HIPSPARSE_CONVERT "${PROJECT_BINARY_DIR}/hipsparse_mtx2csr") add_custom_command(OUTPUT "${HIPSPARSE_CONVERT}" COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_BINARY_DIR}/mtx2csr.exe" "${HIPSPARSE_CONVERT}" DEPENDS "${PROJECT_BINARY_DIR}/mtx2csr.exe" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") add_custom_target(hipsparse-common DEPENDS "${HIPSPARSE_CLIENTMATRICES}" "${HIPSPARSE_CONVERT}") rocm_install( PROGRAMS "${HIPSPARSE_CONVERT}" COMPONENT clients-common DESTINATION ${CMAKE_INSTALL_BINDIR} ) rocm_install( FILES "${HIPSPARSE_CLIENTMATRICES}" COMPONENT clients-common DESTINATION "${CMAKE_INSTALL_DATADIR}/hipsparse/test" ) endif() hipSPARSE-rocm-6.4.3/clients/benchmarks/000077500000000000000000000000001501764003400177365ustar00rootroot00000000000000hipSPARSE-rocm-6.4.3/clients/benchmarks/CMakeLists.txt000066400000000000000000000052541501764003400225040ustar00rootroot00000000000000# ######################################################################## # Copyright (C) 2024 Advanced Micro Devices, Inc. All rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # # ######################################################################## set(HIPSPARSE_BENCHMARK_SOURCES client.cpp hipsparse_arguments_config.cpp hipsparse_bench.cpp hipsparse_bench_app.cpp hipsparse_bench_cmdlines.cpp hipsparse_routine.cpp ) set(HIPSPARSE_CLIENTS_COMMON ../common/arg_check.cpp ../common/unit.cpp ../common/utility.cpp ../common/hipsparse_template_specialization.cpp ) add_executable(hipsparse-bench ${HIPSPARSE_BENCHMARK_SOURCES} ${HIPSPARSE_CLIENTS_COMMON}) # Target compile options target_compile_options(hipsparse-bench PRIVATE -Wno-deprecated -Wno-unused-command-line-argument -Wall) # Internal common header target_include_directories(hipsparse-bench PRIVATE $) # Target link libraries target_link_libraries(hipsparse-bench PRIVATE roc::hipsparse) # Add OpenMP if available if(OPENMP_FOUND AND THREADS_FOUND) target_link_libraries(hipsparse-bench PRIVATE OpenMP::OpenMP_CXX ${OpenMP_CXX_FLAGS}) endif() if(NOT USE_CUDA) target_link_libraries(hipsparse-bench PRIVATE hip::host) else() target_compile_definitions(hipsparse-bench PRIVATE __HIP_PLATFORM_NVIDIA__) target_include_directories(hipsparse-bench PRIVATE ${HIP_INCLUDE_DIRS}) target_link_libraries(hipsparse-bench PRIVATE ${CUDA_LIBRARIES}) endif() # Set benchmark output directory set_target_properties(hipsparse-bench PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/staging") rocm_install(TARGETS hipsparse-bench COMPONENT benchmarks) hipSPARSE-rocm-6.4.3/clients/benchmarks/client.cpp000066400000000000000000000076161501764003400217320ustar00rootroot00000000000000/*! \file */ /* ************************************************************************ * Copyright (C) 2020-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 "hipsparse_bench.hpp" #include "hipsparse_bench_app.hpp" #include "hipsparse_routine.hpp" #include "utility.hpp" #include #include hipsparseStatus_t hipsparse_record_output_legend(const std::string& s) { auto* s_bench_app = hipsparse_bench_app::instance(); if(s_bench_app) { auto status = s_bench_app->record_output_legend(s); return status; } else { return HIPSPARSE_STATUS_SUCCESS; } } hipsparseStatus_t hipsparse_record_output(const std::string& s) { auto* s_bench_app = hipsparse_bench_app::instance(); if(s_bench_app) { auto status = s_bench_app->record_output(s); return status; } else { return HIPSPARSE_STATUS_SUCCESS; } } hipsparseStatus_t hipsparse_record_timing(double msec, double gflops, double gbs) { auto* s_bench_app = hipsparse_bench_app::instance(); if(s_bench_app) { return s_bench_app->record_timing(msec, gflops, gbs); } else { return HIPSPARSE_STATUS_SUCCESS; } } bool display_timing_info_is_stdout_disabled() { auto* s_bench_app = hipsparse_bench_app::instance(); if(s_bench_app) { return s_bench_app->is_stdout_disabled(); } else { return false; } } int main(int argc, char* argv[]) { if(hipsparse_bench_app::applies(argc, argv)) { try { auto* s_bench_app = hipsparse_bench_app::instance(argc, argv); // // RUN CASES. // hipsparseStatus_t status = s_bench_app->run_cases(); if(status != HIPSPARSE_STATUS_SUCCESS) { return status; } // // EXPORT FILE. // status = s_bench_app->export_file(); if(status != HIPSPARSE_STATUS_SUCCESS) { return status; } return status; } catch(const hipsparseStatus_t& status) { return status; } } else { // // old style. // try { hipsparse_bench bench(argc, argv); // // Print info devices. // bench.info_devices(std::cout); // // Run benchmark. // hipsparseStatus_t status = bench.run(); if(status != HIPSPARSE_STATUS_SUCCESS) { return status; } return status; } catch(const hipsparseStatus_t& status) { return status; } } } hipSPARSE-rocm-6.4.3/clients/benchmarks/hipsparse_arguments_config.cpp000066400000000000000000000420651501764003400260610ustar00rootroot00000000000000/*! \file */ /* ************************************************************************ * Copyright (C) 2024 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse_arguments_config.hpp" hipsparse_arguments_config::hipsparse_arguments_config() { { this->M = 0; this->N = 0; this->K = 0; this->nnz = 0; this->block_dim = 0; this->row_block_dimA = 0; this->col_block_dimA = 0; this->row_block_dimB = 0; this->col_block_dimB = 0; this->lda = 0; this->ldb = 0; this->ldc = 0; this->batch_count = 1; this->filename = ""; this->function_name = ""; this->index_type_I = HIPSPARSE_INDEX_32I; this->index_type_J = HIPSPARSE_INDEX_32I; this->compute_type = HIP_R_32F; this->alpha = 0.0; this->alphai = 0.0; this->beta = 0.0; this->betai = 0.0; this->threshold = 0.0; this->percentage = 0.0; this->transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; this->transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; this->baseA = HIPSPARSE_INDEX_BASE_ZERO; this->baseB = HIPSPARSE_INDEX_BASE_ZERO; this->baseC = HIPSPARSE_INDEX_BASE_ZERO; this->baseD = HIPSPARSE_INDEX_BASE_ZERO; this->action = HIPSPARSE_ACTION_NUMERIC; this->part = HIPSPARSE_HYB_PARTITION_AUTO; this->diag_type = HIPSPARSE_DIAG_TYPE_NON_UNIT; this->fill_mode = HIPSPARSE_FILL_MODE_LOWER; this->solve_policy = HIPSPARSE_SOLVE_POLICY_NO_LEVEL; this->dirA = HIPSPARSE_DIRECTION_ROW; this->orderA = HIPSPARSE_ORDER_COL; this->orderB = HIPSPARSE_ORDER_COL; this->orderC = HIPSPARSE_ORDER_COL; this->formatA = HIPSPARSE_FORMAT_COO; this->formatB = HIPSPARSE_FORMAT_COO; this->csr2csc_alg = csr2csc_alg_support::get_default_algorithm(); this->dense2sparse_alg = dense2sparse_alg_support::get_default_algorithm(); this->sparse2dense_alg = sparse2dense_alg_support::get_default_algorithm(); this->sddmm_alg = sddmm_alg_support::get_default_algorithm(); this->spgemm_alg = spgemm_alg_support::get_default_algorithm(); this->spmm_alg = spmm_alg_support::get_default_algorithm(); this->spmv_alg = spmv_alg_support::get_default_algorithm(); this->spsm_alg = spsm_alg_support::get_default_algorithm(); this->spsv_alg = spsv_alg_support::get_default_algorithm(); this->numericboost = 0; this->boosttol = 0.0; this->boostval = 0.0; this->boostvali = 0.0; this->ell_width = 0; this->permute = 0; this->gpsv_alg = 0; this->gtsv_alg = 0; this->precision = 's'; this->indextype = 's'; } } void hipsparse_arguments_config::set_description(options_description& desc) { desc.add_options()("help,h", "produces this help message") // clang-format off ("sizem,m", value(&this->M)->default_value(128), "Specific matrix size testing: sizem is only applicable to SPARSE-2 " "& SPARSE-3: the number of rows.") ("sizen,n", value(&this->N)->default_value(128), "Specific matrix/vector size testing: SPARSE-1: the length of the " "dense vector. SPARSE-2 & SPARSE-3: the number of columns") ("sizek,k", value(&this->K)->default_value(128), "Specific matrix/vector size testing: SPARSE-3: the number of columns") ("sizennz,z", value(&this->nnz)->default_value(32), "Specific vector size testing, LEVEL-1: the number of non-zero elements " "of the sparse vector.") ("blockdim", value(&this->block_dim)->default_value(2), "BSR block dimension (default: 2)") ("row-blockdimA", value(&this->row_block_dimA)->default_value(2), "General BSR row block dimension (default: 2)") ("col-blockdimA", value(&this->col_block_dimA)->default_value(2), "General BSR col block dimension (default: 2)") ("row-blockdimB", value(&this->row_block_dimB)->default_value(2), "General BSR row block dimension (default: 2)") ("col-blockdimB", value(&this->col_block_dimB)->default_value(2), "General BSR col block dimension (default: 2)") ("lda", value(&this->lda)->default_value(2), "Leading dimension (default: 2)") ("ldb", value(&this->ldb)->default_value(2), "Leading dimension (default: 2)") ("ldc", value(&this->ldc)->default_value(2), "Leading dimension (default: 2)") ("batch_count", value(&this->batch_count)->default_value(1), "Batch count (default: 1)") ("file", value(&this->filename)->default_value(""), "read from file with file extension detection.") ("alpha", value(&this->alpha)->default_value(1.0), "specifies the scalar alpha") ("beta", value(&this->beta)->default_value(0.0), "specifies the scalar beta") ("threshold", value(&this->threshold)->default_value(1.0), "specifies the scalar threshold") ("percentage", value(&this->percentage)->default_value(0.0), "specifies the scalar percentage") ("transposeA", value(&this->b_transA)->default_value('N'), "N = no transpose, T = transpose, C = conjugate transpose") ("transposeB", value(&this->b_transB)->default_value('N'), "N = no transpose, T = transpose, C = conjugate transpose, (default = N)") ("indexbaseA", value(&this->b_baseA)->default_value(0), "0 = zero-based indexing, 1 = one-based indexing, (default: 0)") ("indexbaseB", value(&this->b_baseB)->default_value(0), "0 = zero-based indexing, 1 = one-based indexing, (default: 0)") ("indexbaseC", value(&this->b_baseC)->default_value(0), "0 = zero-based indexing, 1 = one-based indexing, (default: 0)") ("indexbaseD", value(&this->b_baseD)->default_value(0), "0 = zero-based indexing, 1 = one-based indexing, (default: 0)") ("action", value(&this->b_action)->default_value(0), "0 = HIPSPARSE_ACTION_NUMERIC, 1 = HIPSPARSE_ACTION_SYMBOLIC, (default: 0)") ("hybpart", value(&this->b_part)->default_value(0), "0 = HIPSPARSE_HYB_PARTITION_AUTO, 1 = HIPSPARSE_HYB_PARTITION_USER,\n" "2 = HIPSPARSE_HYB_PARTITION_MAX, (default: 0)") ("diag", value(&this->b_diag)->default_value('N'), "N = non-unit diagonal, U = unit diagonal, (default = N)") ("uplo", value(&this->b_uplo)->default_value('L'), "L = lower fill, U = upper fill, (default = L)") ("solve_policy", value(&this->b_spol)->default_value('N'), "N = no level data, L = level data, (default = N)") ("function,f", value(&this->function_name)->default_value("axpyi"), "SPARSE function to test. Options:\n" " Level1: axpyi, doti, dotci, gthr, gthrz, roti, sctr\n" " Level2: bsrsv2, coomv, csrmv, csrsv, gemvi, hybmv\n" " Level3: bsrmm, bsrsm2, coomm, cscmm, csrmm, coosm, csrsm, gemmi\n" " Extra: csrgeam, csrgemm\n" " Preconditioner: bsric02, bsrilu02, csric02, csrilu02, gtsv2, gtsv2_nopivot, gtsv2_strided_batch, gtsv_interleaved_batch, gpsv_interleaved_batch\n" " Conversion: bsr2csr, csr2coo, csr2csc, csr2hyb, csr2bsr, csr2gebsr, csr2csr_compress, coo2csr, hyb2csr, csr2dense, csc2dense, coo2dense\n" " dense2csr, dense2csc, dense2coo, gebsr2csr, gebsr2gebsc, gebsr2gebsr\n") ("verify,v", value(&this->unit_check)->default_value(0), "Validate GPU results with CPU? 0 = No, 1 = Yes (default: No)") ("indextype", value(&this->indextype)->default_value('s'), "Specify index types to be int32_t (s), int64_t (d) or mixed (m). Options: s,d,m") ("precision,r", value(&this->precision)->default_value('s'), "Options: s,d,c,z") ("iters,i", value(&this->iters)->default_value(10), "Iterations to run inside timing loop") ("device,d", value(&this->device_id)->default_value(0), "Set default device to be used for subsequent program runs") ("dirA", value(&this->b_dir)->default_value(HIPSPARSE_DIRECTION_ROW), "Indicates whether BSR blocks should be laid out in row-major storage or by column-major storage: row-major storage = 0, column-major storage = 1 (default: 0)") ("orderA", value(&this->b_orderA)->default_value(HIPSPARSE_ORDER_COL), "Indicates whether a dense matrix is laid out in column-major storage: 1, or row-major storage 0 (default: 1)") ("orderB", value(&this->b_orderB)->default_value(HIPSPARSE_ORDER_COL), "Indicates whether a dense matrix is laid out in column-major storage: 1, or row-major storage 0 (default: 1)") ("orderC", value(&this->b_orderC)->default_value(HIPSPARSE_ORDER_COL), "Indicates whether a dense matrix is laid out in column-major storage: 1, or row-major storage 0 (default: 1)") ("format", value(&this->b_formatA)->default_value(HIPSPARSE_FORMAT_COO), "Indicates whether a sparse matrix is laid out in coo format: 0, coo_aos format: 1, csr format: 2, csc format: 3, bell format: 4 (default:0)") ("formatA", value(&this->b_formatA)->default_value(HIPSPARSE_FORMAT_COO), "Indicates whether a sparse matrix is laid out in coo format: 0, coo_aos format: 1, csr format: 2, csc format: 3, bell format: 4 (default:0)") ("formatB", value(&this->b_formatB)->default_value(HIPSPARSE_FORMAT_COO), "Indicates whether a sparse matrix is laid out in coo format: 0, coo_aos format: 1, csr format: 2, csc format: 3, bell format: 4 (default:0)") ("csr2csc_alg", value(&this->csr2csc_alg)->default_value(csr2csc_alg_support::get_default_algorithm()), csr2csc_alg_support::get_description()) ("dense2sparse_alg", value(&this->dense2sparse_alg)->default_value(dense2sparse_alg_support::get_default_algorithm()), dense2sparse_alg_support::get_description()) ("sparse2dense_alg", value(&this->sparse2dense_alg)->default_value(sparse2dense_alg_support::get_default_algorithm()), sparse2dense_alg_support::get_description()) ("sddmm_alg", value(&this->sddmm_alg)->default_value(sddmm_alg_support::get_default_algorithm()), sddmm_alg_support::get_description()) ("spgemm_alg", value(&this->spgemm_alg)->default_value(spgemm_alg_support::get_default_algorithm()), spgemm_alg_support::get_description()) ("spmm_alg", value(&this->spmm_alg)->default_value(spmm_alg_support::get_default_algorithm()), spmm_alg_support::get_description()) ("spmv_alg", value(&this->spmv_alg)->default_value(spmv_alg_support::get_default_algorithm()), spmv_alg_support::get_description()) ("spsm_alg", value(&this->spsm_alg)->default_value(spsm_alg_support::get_default_algorithm()), spsm_alg_support::get_description()) ("spsv_alg", value(&this->spsv_alg)->default_value(spsv_alg_support::get_default_algorithm()), spsv_alg_support::get_description()) ("ell_width", value(&this->ell_width)->default_value(0), "ELL width (default 0)") ("permute", value(&this->permute)->default_value(0), "Using permutation vector in coosort, csrsort, cscsort. Do not use vector: 0, Use vector: 1 (default 0)") ("gpsv_alg", value(&this->gpsv_alg)->default_value(0), "Algorithm for gpsv routine. Currently only qr supported: 0, (default 0)") ("gtsv_alg", value(&this->gtsv_alg)->default_value(0), "Algorithm for gtsv routine. Possibly choices are thomas: 1, lu: 2, qr: 3, (default 0)"); } int hipsparse_arguments_config::parse(int&argc,char**&argv, options_description&desc) { variables_map vm; store(parse_command_line(argc, argv, desc, sizeof(hipsparse_arguments_config)), vm); notify(vm); if(vm.count("help")) { std::cout << desc << std::endl; return -2; } if(this->b_transA == 'N') { this->transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; } else if(this->b_transA == 'T') { this->transA = HIPSPARSE_OPERATION_TRANSPOSE; } else if(this->b_transA == 'C') { this->transA = HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE; } if(this->b_transB == 'N') { this->transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; } else if(this->b_transB == 'T') { this->transB = HIPSPARSE_OPERATION_TRANSPOSE; } else if(this->b_transB == 'C') { this->transB = HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE; } this->baseA = (this->b_baseA == 0) ? HIPSPARSE_INDEX_BASE_ZERO : HIPSPARSE_INDEX_BASE_ONE; this->baseB = (this->b_baseB == 0) ? HIPSPARSE_INDEX_BASE_ZERO : HIPSPARSE_INDEX_BASE_ONE; this->baseC = (this->b_baseC == 0) ? HIPSPARSE_INDEX_BASE_ZERO : HIPSPARSE_INDEX_BASE_ONE; this->baseD = (this->b_baseD == 0) ? HIPSPARSE_INDEX_BASE_ZERO : HIPSPARSE_INDEX_BASE_ONE; this->action = (this->b_action == 0) ? HIPSPARSE_ACTION_NUMERIC : HIPSPARSE_ACTION_SYMBOLIC; this->part = (this->b_part == 0) ? HIPSPARSE_HYB_PARTITION_AUTO : (this->b_part == 1) ? HIPSPARSE_HYB_PARTITION_USER : HIPSPARSE_HYB_PARTITION_MAX; this->diag_type = (this->b_diag == 'N') ? HIPSPARSE_DIAG_TYPE_NON_UNIT : HIPSPARSE_DIAG_TYPE_UNIT; this->fill_mode = (this->b_uplo == 'L') ? HIPSPARSE_FILL_MODE_LOWER : HIPSPARSE_FILL_MODE_UPPER; this->solve_policy = (this->b_spol == 'N') ? HIPSPARSE_SOLVE_POLICY_NO_LEVEL : HIPSPARSE_SOLVE_POLICY_USE_LEVEL; this->dirA = (this->b_dir == 0) ? HIPSPARSE_DIRECTION_ROW : HIPSPARSE_DIRECTION_COLUMN; this->orderA = (this->b_orderA == 0) ? HIPSPARSE_ORDER_ROW : HIPSPARSE_ORDER_COL; this->orderB = (this->b_orderB == 0) ? HIPSPARSE_ORDER_ROW : HIPSPARSE_ORDER_COL; this->orderC = (this->b_orderC == 0) ? HIPSPARSE_ORDER_ROW : HIPSPARSE_ORDER_COL; this->formatA = (hipsparseFormat_t)this->b_formatA; this->formatB = (hipsparseFormat_t)this->b_formatB; if(this->M < 0 || this->N < 0) { std::cerr << "Invalid dimension" << std::endl; return -1; } if(this->block_dim < 1) { std::cerr << "Invalid value for --blockdim" << std::endl; return -1; } if(this->row_block_dimA < 1) { std::cerr << "Invalid value for --row-blockdimA" << std::endl; return -1; } if(this->col_block_dimA < 1) { std::cerr << "Invalid value for --col-blockdimA" << std::endl; return -1; } if(this->row_block_dimB < 1) { std::cerr << "Invalid value for --row-blockdimB" << std::endl; return -1; } if(this->col_block_dimB < 1) { std::cerr << "Invalid value for --col-blockdimB" << std::endl; return -1; } switch(this->indextype) { case 's': { this->index_type_I = HIPSPARSE_INDEX_32I; this->index_type_J = HIPSPARSE_INDEX_32I; break; } case 'd': { this->index_type_I = HIPSPARSE_INDEX_64I; this->index_type_J = HIPSPARSE_INDEX_64I; break; } case 'm': { this->index_type_I = HIPSPARSE_INDEX_64I; this->index_type_J = HIPSPARSE_INDEX_32I; break; } default: { std::cerr << "Invalid value for --indextype" << std::endl; return -1; } } switch(this->precision) { case 's': { this->compute_type = HIP_R_32F; break; } case 'd': { this->compute_type = HIP_R_64F; break; } case 'c': { this->compute_type = HIP_C_32F; break; } case 'z': { this->compute_type = HIP_C_64F; break; } default: { std::cerr << "Invalid value for --precision" << std::endl; return -1; } } return 0; } hipSPARSE-rocm-6.4.3/clients/benchmarks/hipsparse_arguments_config.hpp000066400000000000000000000040651501764003400260640ustar00rootroot00000000000000/*! \file */ /* ************************************************************************ * Copyright (C) 2024 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #include "hipsparse_arguments.hpp" #include "program_options.hpp" struct hipsparse_arguments_config : Arguments { public: char precision{}; char indextype{}; int device_id{}; private: char b_transA{}; char b_transB{}; int b_baseA{}; int b_baseB{}; int b_baseC{}; int b_baseD{}; int b_action{}; int b_part{}; int b_dir{}; int b_orderA{}; int b_orderB{}; int b_orderC{}; int b_formatA{}; int b_formatB{}; char b_diag{}; char b_uplo{}; char b_spol{}; public: hipsparse_arguments_config(); void set_description(options_description& desc); int parse(int& argc, char**& argv, options_description& desc); int parse_no_default(int& argc, char**& argv, options_description& desc); }; hipSPARSE-rocm-6.4.3/clients/benchmarks/hipsparse_bench.cpp000066400000000000000000000111221501764003400235740ustar00rootroot00000000000000/*! \file */ /* ************************************************************************ * Copyright (C) 2024 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse_bench.hpp" #include "hipsparse_bench_cmdlines.hpp" // Return version. std::string hipsparse_get_version() { int hipsparse_ver; char hipsparse_rev[64]; { hipsparseHandle_t handle; hipsparseCreate(&handle); hipsparseGetVersion(handle, &hipsparse_ver); hipsparseGetGitRevision(handle, hipsparse_rev); hipsparseDestroy(handle); } std::ostringstream os; os << hipsparse_ver / 100000 << "." << hipsparse_ver / 100 % 1000 << "." << hipsparse_ver % 100 << "-" << hipsparse_rev; return os.str(); } void hipsparse_bench::parse(int& argc, char**& argv, hipsparse_arguments_config& config) { config.set_description(this->desc); config.unit_check = 0; config.timing = 1; int i = config.parse(argc, argv, this->desc); if(i == -1) { throw HIPSPARSE_STATUS_INTERNAL_ERROR; } else if(i == -2) { // Help. hipsparse_bench_cmdlines::help(std::cout); exit(0); } } hipsparse_bench::hipsparse_bench() : desc("hipsparse client command line options") { } hipsparse_bench::hipsparse_bench(int& argc, char**& argv) : desc("hipsparse client command line options") { this->parse(argc, argv, this->config); routine(this->config.function_name.c_str()); // Device query int devs; if(hipGetDeviceCount(&devs) != hipSuccess) { std::cerr << "Error: cannot get device count" << std::endl; exit(-1); } auto device_id = this->config.device_id; // Set device if(hipSetDevice(device_id) != hipSuccess || device_id >= devs) { std::cerr << "Error: cannot set device ID " << device_id << std::endl; exit(-1); } } hipsparse_bench& hipsparse_bench::operator()(int& argc, char**& argv) { this->parse(argc, argv, this->config); routine(this->config.function_name.c_str()); return *this; } hipsparseStatus_t hipsparse_bench::run() { return this->routine.dispatch(this->config.precision, this->config.indextype, this->config); } int hipsparse_bench::get_device_id() const { return this->config.device_id; } // This is used for backward compatibility. void hipsparse_bench::info_devices(std::ostream& out_) const { int devs; if(hipGetDeviceCount(&devs) != hipSuccess) { std::cerr << "Error: cannot get device count" << std::endl; exit(1); } std::cout << "Query device success: there are " << devs << " devices" << std::endl; for(int i = 0; i < devs; ++i) { hipDeviceProp_t prop; if(hipGetDeviceProperties(&prop, i) != hipSuccess) { std::cerr << "Error: cannot get device properties" << std::endl; exit(1); } out_ << "Device ID " << i << ": " << prop.name << std::endl; gpu_config g(prop); g.print(out_); } // Print header. { int device_id = this->get_device_id(); hipDeviceProp_t prop; hipGetDeviceProperties(&prop, device_id); out_ << "Using device ID " << device_id << " (" << prop.name << ") for hipSPARSE" << std::endl << "-------------------------------------------------------------------------" << std::endl << "hipSPARSE version: " << hipsparse_get_version() << std::endl << std::endl; } } hipSPARSE-rocm-6.4.3/clients/benchmarks/hipsparse_bench.hpp000066400000000000000000000102641501764003400236070ustar00rootroot00000000000000/*! \file */ /* ************************************************************************ * Copyright (C) 2024 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #include "hipsparse_arguments_config.hpp" #include "hipsparse_routine.hpp" struct gpu_config { char name[32]; long memory_MB; long clockRate_MHz; long major; long minor; long maxGridSizeX; long sharedMemPerBlock_KB; long maxThreadsPerBlock; long warpSize; explicit gpu_config(const hipDeviceProp_t& prop) { strcpy(this->name, prop.name); this->memory_MB = (prop.totalGlobalMem >> 20); this->clockRate_MHz = prop.clockRate / 1000; this->major = prop.major; this->minor = prop.minor; this->maxGridSizeX = prop.maxGridSize[0]; this->sharedMemPerBlock_KB = (prop.sharedMemPerBlock >> 10); this->maxThreadsPerBlock = prop.maxThreadsPerBlock; this->warpSize = prop.warpSize; } void print(std::ostream& out_) { out_ << "-------------------------------------------------------------------------" << std::endl << "with " << this->memory_MB << "MB memory, clock rate " << this->clockRate_MHz << "MHz @ computing capability " << this->major << "." << this->minor << std::endl << "maxGridDimX " << this->maxGridSizeX << ", sharedMemPerBlock " << this->sharedMemPerBlock_KB << "KB, maxThreadsPerBlock " << this->maxThreadsPerBlock << std::endl << "wavefrontSize " << this->warpSize << std::endl << "-------------------------------------------------------------------------" << std::endl; } void print_json(std::ostream& out) { out << std::endl << "\"config gpu\": {" << std::endl << " \"memory\" : \"" << this->memory_MB << "\"," << std::endl << " \"clockrate\" : \"" << this->clockRate_MHz << "\"," << std::endl << " \"capability\" : \"" << this->major << "." << this->minor << "\"," << std::endl << " \"dimension\" : \"" << this->maxGridSizeX << "\"," << std::endl << " \"shared memory\" : \"" << this->sharedMemPerBlock_KB << "\"," << std::endl << " \"max thread per block\": \"" << this->maxThreadsPerBlock << "\"," << std::endl << " \"wavefront size\" : \"" << this->warpSize << "\"}," << std::endl; } }; class hipsparse_bench { private: void parse(int& argc, char**& argv, hipsparse_arguments_config& config); options_description desc; hipsparse_arguments_config config{}; hipsparse_routine routine{}; public: hipsparse_bench(); hipsparse_bench(int& argc, char**& argv); hipsparse_bench& operator()(int& argc, char**& argv); hipsparseStatus_t run(); int get_device_id() const; void info_devices(std::ostream& out_) const; }; std::string hipsparse_get_version(); hipSPARSE-rocm-6.4.3/clients/benchmarks/hipsparse_bench_app.cpp000066400000000000000000000354531501764003400244510ustar00rootroot00000000000000/*! \file */ /* ************************************************************************ * Copyright (C) 2024 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse_bench_app.hpp" #include "hipsparse_bench.hpp" #include #include hipsparse_bench_app* hipsparse_bench_app::s_instance = nullptr; hipsparse_bench_app_base::hipsparse_bench_app_base(int argc, char** argv) : m_initial_argc(hipsparse_bench_app_base::save_initial_cmdline(argc, argv, &m_initial_argv)) , m_bench_cmdlines(argc, argv) , m_bench_timing(m_bench_cmdlines.get_nsamples(), m_bench_cmdlines.get_nruns()) {}; hipsparseStatus_t hipsparse_bench_app_base::run_case(int isample, int irun, int argc, char** argv) { hipsparse_bench bench(argc, argv); return bench.run(); } hipsparseStatus_t hipsparse_bench_app_base::run_cases() { int sample_argc; char** sample_argv = nullptr; // // Loop over cases. // int nruns = this->m_bench_cmdlines.get_nruns(); int nsamples = this->m_bench_cmdlines.get_nsamples(); if(is_stdout_disabled()) { printf("// start benchmarking ... (nsamples = %d, nruns = %d)\n", nsamples, nruns); } for(int isample = 0; isample < nsamples; ++isample) { this->m_isample = isample; // // Add an item to collect data through hipsparse_record_timing // for(int irun = 0; irun < nruns; ++irun) { this->m_irun = irun; // // Get command line arguments, copy each time since it is mutable afterwards. // if(sample_argv == nullptr) { this->m_bench_cmdlines.get_argc(this->m_isample, sample_argc); sample_argv = new char*[sample_argc]; } this->m_bench_cmdlines.get(this->m_isample, sample_argc, sample_argv); // // Run the case. // hipsparseStatus_t status = this->run_case(this->m_isample, this->m_irun, sample_argc, sample_argv); if(status != HIPSPARSE_STATUS_SUCCESS) { std::cerr << "run_cases::run_case failed at line " << __LINE__ << std::endl; return status; } if(is_stdout_disabled()) { if((isample * nruns + irun) % 10 == 0) { fprintf(stdout, "\r// %2.0f%%", (double(isample * nruns + irun + 1) / double(nsamples * nruns)) * 100); fflush(stdout); } } } } if(is_stdout_disabled()) { printf("\r// benchmarking done.\n"); } if(sample_argv != nullptr) { delete[] sample_argv; } return HIPSPARSE_STATUS_SUCCESS; }; hipsparse_bench_app::hipsparse_bench_app(int argc, char** argv) : hipsparse_bench_app_base(argc, argv) { } hipsparse_bench_app::~hipsparse_bench_app() {} void hipsparse_bench_app::confidence_interval(const double alpha, const int resize, const int nboots, const std::vector& v, double interval[2]) { const size_t size = v.size(); static std::random_device dev; static std::mt19937 rng(dev()); static std::uniform_int_distribution dist(0, size - 1); std::vector medians(nboots); std::vector resample(resize); #define median_value(n__, s__) \ ((n__ % 2 == 0) ? (s__[n__ / 2 - 1] + s__[n__ / 2]) * 0.5 : s__[n__ / 2]) for(int iboot = 0; iboot < nboots; ++iboot) { for(int i = 0; i < resize; ++i) { const int j = dist(rng); resample[i] = v[j]; } std::sort(resample.begin(), resample.end()); medians[iboot] = median_value(resize, resample); } std::sort(medians.begin(), medians.end()); interval[0] = medians[int(floor(nboots * 0.5 * (1.0 - alpha)))]; interval[1] = medians[int(ceil(nboots * (1.0 - 0.5 * (1.0 - alpha))))]; #undef median_value } void hipsparse_bench_app::export_item(std::ostream& out, hipsparse_bench_timing_t::item_t& item) { // // // auto N = item.m_nruns; if(N > 1) { const double alpha = 0.95; std::sort(item.msec.begin(), item.msec.end()); std::sort(item.gflops.begin(), item.gflops.end()); std::sort(item.gbs.begin(), item.gbs.end()); double msec = (N % 2 == 0) ? (item.msec[N / 2 - 1] + item.msec[N / 2]) * 0.5 : item.msec[N / 2]; double gflops = (N % 2 == 0) ? (item.gflops[N / 2 - 1] + item.gflops[N / 2]) * 0.5 : item.gflops[N / 2]; double gbs = (N % 2 == 0) ? (item.gbs[N / 2 - 1] + item.gbs[N / 2]) * 0.5 : item.gbs[N / 2]; double interval_msec[2], interval_gflops[2], interval_gbs[2]; int nboots = 200; confidence_interval(alpha, 10, nboots, item.msec, interval_msec); confidence_interval(alpha, 10, nboots, item.gflops, interval_gflops); confidence_interval(alpha, 10, nboots, item.gbs, interval_gbs); out << std::endl << " \"time\": [\"" << msec << "\", \"" << interval_msec[0] << "\", \"" << interval_msec[1] << "\"]," << std::endl; out << " \"flops\": [\"" << gflops << "\", \"" << interval_gflops[0] << "\", \"" << interval_gflops[1] << "\"]," << std::endl; out << " \"bandwidth\": [\"" << gbs << "\", \"" << interval_gbs[0] << "\", \"" << interval_gbs[1] << "\"]"; if(!no_rawdata()) { out << ","; out << std::endl << " \"raw_legend\": \"" << item.outputs_legend << "\""; out << ","; out << std::endl << " \"raw_data\": \"" << item.outputs[0] << "\""; } } else { out << std::endl << "\"time\": [\"" << item.msec[0] << "\", \"" << item.msec[0] << "\", \"" << item.msec[0] << "\"]," << std::endl; out << "\"flops\": [\"" << item.gflops[0] << "\", \"" << item.gflops[0] << "\", \"" << item.gflops[0] << "\"]," << std::endl; out << "\"bandwidth\": [\"" << item.gbs[0] << "\", \"" << item.gbs[0] << "\", \"" << item.gbs[0] << "\"]"; if(!no_rawdata()) { out << ","; out << std::endl << " \"raw_legend\": \"" << item.outputs_legend << "\""; out << ","; out << std::endl << " \"raw_data\": "; out << "\"" << item.outputs[0] << "\""; out << "" << std::endl; } } } hipsparseStatus_t hipsparse_bench_app::export_file() { const char* ofilename = this->m_bench_cmdlines.get_ofilename(); if(ofilename == nullptr) { std::cerr << "//" << std::endl; std::cerr << "// hipsparse_bench_app warning: no output filename has been specified," << std::endl; std::cerr << "// default output filename is 'a.json'." << std::endl; std::cerr << "//" << std::endl; ofilename = "a.json"; } std::ofstream out(ofilename); int sample_argc; char* sample_argv[64]; hipsparseStatus_t status; // // Write header. // status = define_results_json(out); if(status != HIPSPARSE_STATUS_SUCCESS) { std::cerr << "run_cases failed at line " << __LINE__ << std::endl; return status; } // // Loop over cases. // const size_t nsamples = m_bench_cmdlines.get_nsamples(); if(nsamples != m_bench_timing.size()) { std::cerr << "incompatible sizes at line " << __LINE__ << " " << m_bench_cmdlines.get_nsamples() << " " << m_bench_timing.size() << std::endl; if(m_bench_timing.size() == 0) { std::cerr << "No data has been harvested from running case" << std::endl; } exit(1); } for(int isample = 0; isample < nsamples; ++isample) { this->m_bench_cmdlines.get(isample, sample_argc, sample_argv); this->define_case_json(out, isample, sample_argc, sample_argv); out << "{ "; { this->export_item(out, this->m_bench_timing[isample]); } out << " }"; this->close_case_json(out, isample, sample_argc, sample_argv); } // // Write footer. // status = this->close_results_json(out); if(status != HIPSPARSE_STATUS_SUCCESS) { std::cerr << "run_cases failed at line " << __LINE__ << std::endl; return status; } out.close(); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparse_bench_app::define_case_json(std::ostream& out, int isample, int argc, char** argv) { if(isample > 0) out << "," << std::endl; out << std::endl; out << "{ \"cmdline\": \""; out << argv[0]; for(int i = 1; i < argc; ++i) out << " " << argv[i]; out << " \"," << std::endl; out << " \"timing\": "; return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparse_bench_app::close_case_json(std::ostream& out, int isample, int argc, char** argv) { out << " }"; return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparse_bench_app::define_results_json(std::ostream& out) { out << "{" << std::endl; auto end = std::chrono::system_clock::now(); std::time_t end_time = std::chrono::system_clock::to_time_t(end); char* str = std::ctime(&end_time); for(int i = 0; i >= 0; ++i) if(str[i] == '\n') { str[i] = '\0'; break; } out << "\"date\": \"" << str << "\"," << std::endl; out << "\"hipSPARSE version\": \"" << hipsparse_get_version() << "\"," << std::endl; // // !!! To fix, not necessarily the gpu used from hipsparse_bench. // hipDeviceProp_t prop; hipGetDeviceProperties(&prop, 0); gpu_config g(prop); g.print_json(out); out << std::endl << "\"cmdline\": \"" << this->m_initial_argv[0]; for(int i = 1; i < this->m_initial_argc; ++i) { out << " " << this->m_initial_argv[i]; } out << "\"," << std::endl; size_t option_index_x = this->m_bench_cmdlines.get_option_index_x(); out << std::endl << "\"xargs\": \["; for(int j = 0; j < this->m_bench_cmdlines.get_option_nargs(option_index_x); ++j) { auto arg = this->m_bench_cmdlines.get_option_arg(option_index_x, j); if(j > 0) out << ", "; out << "\"" << arg << "\""; } out << "]," << std::endl; out << std::endl << "\"yargs\":"; // // Harvest expanded options. // std::vector y_options_size; std::vector y_options_index; for(int k = 0; k < this->m_bench_cmdlines.get_noptions(); ++k) { if(k != option_index_x) { if(this->m_bench_cmdlines.get_option_nargs(k) > 1) { y_options_index.push_back(k); y_options_size.push_back(this->m_bench_cmdlines.get_option_nargs(k)); } } } const int num_y_options = y_options_index.size(); if(num_y_options > 0) { std::vector> indices(num_y_options); for(int k = 0; k < num_y_options; ++k) { indices[k].resize(y_options_size[k], 0); } } int nplots = this->m_bench_cmdlines.get_nsamples() / this->m_bench_cmdlines.get_option_nargs(option_index_x); std::vector plot_titles(nplots); if(plot_titles.size() == 1) { plot_titles.push_back(""); } else { int n = y_options_size[0]; auto argname0 = this->m_bench_cmdlines.get_option_name(y_options_index[0]); for(int iplot = 0; iplot < nplots; ++iplot) { std::string title(""); int p = n; { int jref = iplot % p; auto arg0 = this->m_bench_cmdlines.get_option_arg(y_options_index[0], jref); if(argname0[1] == '-') { title += std::string(argname0 + 2) + std::string("=") + arg0; } else { title += std::string(argname0 + 1) + std::string("=") + arg0; } } for(int k = 1; k < num_y_options; ++k) { int kref = iplot / p; p *= this->m_bench_cmdlines.get_option_nargs(y_options_index[k]); auto arg = this->m_bench_cmdlines.get_option_arg(y_options_index[k], kref); auto argname = this->m_bench_cmdlines.get_option_name(y_options_index[k]); if(argname[1] == '-') { title += std::string(",") + std::string(argname + 2) + std::string("=") + arg; } else { title += std::string(",") + std::string(argname + 1) + std::string("=") + arg; } } plot_titles[iplot] = title; } } out << "["; { out << "\"" << plot_titles[0] << "\""; for(int iplot = 1; iplot < nplots; ++iplot) out << ", \"" << plot_titles[iplot] << "\""; } out << "]," << std::endl << std::endl; ; out << "\"" << "results" << "\": ["; return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparse_bench_app::close_results_json(std::ostream& out) { out << "]" << std::endl; out << "}" << std::endl; return HIPSPARSE_STATUS_SUCCESS; } hipSPARSE-rocm-6.4.3/clients/benchmarks/hipsparse_bench_app.hpp000066400000000000000000000157661501764003400244630ustar00rootroot00000000000000/*! \file */ /* ************************************************************************ * Copyright (C) 2024 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #include "hipsparse.h" #include "hipsparse_bench_cmdlines.hpp" #include #include // // Struct collecting benchmark timing results. // struct hipsparse_bench_timing_t { // // Local item // struct item_t { int m_nruns{}; std::vector msec{}; std::vector gflops{}; std::vector gbs{}; std::vector outputs{}; std::string outputs_legend{}; item_t(){}; explicit item_t(int nruns_) : m_nruns(nruns_) , msec(nruns_) , gflops(nruns_) , gbs(nruns_) , outputs(nruns_){}; item_t& operator()(int nruns_) { this->m_nruns = nruns_; this->msec.resize(nruns_); this->gflops.resize(nruns_); this->gbs.resize(nruns_); this->outputs.resize(nruns_); return *this; }; hipsparseStatus_t record(int irun, double msec_, double gflops_, double gbs_) { if(irun >= 0 && irun < m_nruns) { this->msec[irun] = msec_; this->gflops[irun] = gflops_; this->gbs[irun] = gbs_; return HIPSPARSE_STATUS_SUCCESS; } else { return HIPSPARSE_STATUS_INTERNAL_ERROR; } } hipsparseStatus_t record(int irun, const std::string& s) { if(irun >= 0 && irun < m_nruns) { this->outputs[irun] = s; return HIPSPARSE_STATUS_SUCCESS; } else { return HIPSPARSE_STATUS_INTERNAL_ERROR; } } hipsparseStatus_t record_output_legend(const std::string& s) { this->outputs_legend = s; return HIPSPARSE_STATUS_SUCCESS; } }; size_t size() const { return this->m_items.size(); }; item_t& operator[](size_t i) { return this->m_items[i]; } const item_t& operator[](size_t i) const { return this->m_items[i]; } hipsparse_bench_timing_t(int nsamples, int nruns_per_sample) : m_items(nsamples) { for(int i = 0; i < nsamples; ++i) { m_items[i](nruns_per_sample); } } private: std::vector m_items; }; class hipsparse_bench_app_base { protected: // // Record initial command line. // int m_initial_argc{}; char** m_initial_argv; // // Set of command lines. // hipsparse_bench_cmdlines m_bench_cmdlines; // // // hipsparse_bench_timing_t m_bench_timing; bool m_stdout_disabled{true}; static int save_initial_cmdline(int argc, char** argv, char*** argv_) { argv_[0] = new char*[argc]; for(int i = 0; i < argc; ++i) { argv_[0][i] = argv[i]; } return argc; } // // @brief Constructor. // hipsparse_bench_app_base(int argc, char** argv); // // @brief Run case. // hipsparseStatus_t run_case(int isample, int irun, int argc, char** argv); // // For internal use, to get the current isample and irun. // int m_isample{}; int m_irun{}; int get_isample() const { return this->m_isample; }; int get_irun() const { return this->m_irun; }; public: bool is_stdout_disabled() const { return m_bench_cmdlines.is_stdout_disabled(); } bool no_rawdata() const { return m_bench_cmdlines.no_rawdata(); } // // @brief Run cases. // hipsparseStatus_t run_cases(); }; class hipsparse_bench_app : public hipsparse_bench_app_base { private: static hipsparse_bench_app* s_instance; public: static hipsparse_bench_app* instance(int argc, char** argv) { s_instance = new hipsparse_bench_app(argc, argv); return s_instance; } static hipsparse_bench_app* instance() { return s_instance; } hipsparse_bench_app(const hipsparse_bench_app&) = delete; hipsparse_bench_app& operator=(const hipsparse_bench_app&) = delete; static bool applies(int argc, char** argv) { return hipsparse_bench_cmdlines::applies(argc, argv); } hipsparse_bench_app(int argc, char** argv); ~hipsparse_bench_app(); hipsparseStatus_t export_file(); hipsparseStatus_t record_timing(double msec, double gflops, double bandwidth) { return this->m_bench_timing[this->m_isample].record(this->m_irun, msec, gflops, bandwidth); } hipsparseStatus_t record_output(const std::string& s) { return this->m_bench_timing[this->m_isample].record(this->m_irun, s); } hipsparseStatus_t record_output_legend(const std::string& s) { return this->m_bench_timing[this->m_isample].record_output_legend(s); } protected: void export_item(std::ostream& out, hipsparse_bench_timing_t::item_t& item); hipsparseStatus_t define_case_json(std::ostream& out, int isample, int argc, char** argv); hipsparseStatus_t close_case_json(std::ostream& out, int isample, int argc, char** argv); hipsparseStatus_t define_results_json(std::ostream& out); hipsparseStatus_t close_results_json(std::ostream& out); void confidence_interval(const double alpha, const int resize, const int nboots, const std::vector& v, double interval[2]); }; hipSPARSE-rocm-6.4.3/clients/benchmarks/hipsparse_bench_cmdlines.cpp000066400000000000000000000056441501764003400254660ustar00rootroot00000000000000#include "hipsparse_bench_cmdlines.hpp" // // @brief Get the output filename. // const char* hipsparse_bench_cmdlines::get_ofilename() const { return this->m_cmd.get_ofilename(); } // // @brief Get the number of samples.. // int hipsparse_bench_cmdlines::get_nsamples() const { return this->m_cmd.get_nsamples(); }; size_t hipsparse_bench_cmdlines::get_option_index_x() const { return this->m_cmd.get_option_index_x(); }; int hipsparse_bench_cmdlines::get_option_nargs(int i) { return this->m_cmd.get_option_nargs(i); } const char* hipsparse_bench_cmdlines::get_option_arg(int i, int j) { return this->m_cmd.get_option_arg(i, j); } const char* hipsparse_bench_cmdlines::get_option_name(int i) { return this->m_cmd.get_option_name(i); } int hipsparse_bench_cmdlines::get_noptions_x() const { return this->m_cmd.get_noptions_x(); }; int hipsparse_bench_cmdlines::get_noptions() const { return this->m_cmd.get_noptions(); }; bool hipsparse_bench_cmdlines::is_stdout_disabled() const { return this->m_cmd.is_stdout_disabled(); }; bool hipsparse_bench_cmdlines::no_rawdata() const { return this->m_cmd.no_rawdata(); }; // // @brief Get the number of runs per sample. // int hipsparse_bench_cmdlines::get_nruns() const { return this->m_cmd.get_nruns(); }; // // @brief Copy the command line arguments corresponding to a given sample. // void hipsparse_bench_cmdlines::get(int isample, int& argc, char** argv) const { const auto& cmdsample = this->m_cmdset[isample]; for(int j = 0; j < cmdsample.argc; ++j) { argv[j] = cmdsample.argv[j]; } argc = cmdsample.argc; } void hipsparse_bench_cmdlines::get_argc(int isample, int& argc_) const { argc_ = this->m_cmdset[isample].argc; } hipsparse_bench_cmdlines::~hipsparse_bench_cmdlines() { if(this->m_cmdset != nullptr) { delete[] this->m_cmdset; this->m_cmdset = nullptr; } } // // @brief Constructor. // hipsparse_bench_cmdlines::hipsparse_bench_cmdlines(int argc, char** argv) : m_cmd(argc, argv) { // // Expand the command line . // this->m_cmdset = new val[this->m_cmd.get_nsamples()]; this->m_cmd.expand(this->m_cmdset); } bool hipsparse_bench_cmdlines::applies(int argc, char** argv) { for(int i = 1; i < argc; ++i) { if(!strcmp(argv[i], "--bench-x")) { return true; } } return false; } void hipsparse_bench_cmdlines::info() const { int nsamples = this->m_cmd.get_nsamples(); for(int isample = 0; isample < nsamples; ++isample) { const auto& cmdsample = this->m_cmdset[isample]; const auto argc = cmdsample.argc; const auto argv = cmdsample.argv; std::cout << "sample[" << isample << "/" << nsamples << "], argc = " << argc << std::endl; for(int jarg = 0; jarg < argc; ++jarg) { std::cout << " " << argv[jarg]; } std::cout << std::endl; } } hipSPARSE-rocm-6.4.3/clients/benchmarks/hipsparse_bench_cmdlines.hpp000066400000000000000000000456331501764003400254750ustar00rootroot00000000000000/*! \file */ /* ************************************************************************ * Copyright (C) 2024 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #include #include #include #include // // @brief The role of this class is to expand a command line into multiple command lines. // @details // // What is expanding a command line into multiple command lines? // Let's consider the following command line './foo -m 10' where option '-m' of ./foo // takes only one argument, here 10. // // An expansion mechanism is implemented in this class to provide the set of command lines // './foo -m 10', // './foo -m 2', // './foo -m 7', // './foo -m -4' // // from: ./foo -m 10 2 7 -4 // // It allows to generate a set of command lines to be useful in a benchmarking context. // // Rules: // - any keyword starting with '-' is considered as an option. // - each option having exactly one argument is subject to a possible expansion, there is no limit on the number of options to expand. // // // Number of command lines generated : product of all the options' number (>=1) of arguments // examples: // cmd: './foo -m 10 2 7 -k 32 -l f -v' gives // './foo -m 10 -k 32 -l f' // './foo -m 2 -k 32 -l f' // './foo -m 7 -k 32 -l f' // num cmds: max(1,3) * max(1,1) * max(1,0) = 3 // cmd: './foo -m 10 2 7 -k 32 64 -l f g' gives // './foo -m 10 -k 32 -l f' // './foo -m 2 -k 32 -l f' // './foo -m 7 -k 32 -l f' // './foo -m 10 -k 64 -l f' // './foo -m 2 -k 64 -l f' // './foo -m 7 -k 64 -l f' // './foo -m 10 -k 32 -l g' // './foo -m 2 -k 32 -l g' // './foo -m 7 -k 32 -l g' // './foo -m 10 -k 64 -l g' // './foo -m 2 -k 64 -l g' // './foo -m 7 -k 64 -l g' // num cmds: max(1,3) * max(1,2) * max(1,2) = 12 // // Specific options: // // option: --bench-x, to precede the option the user want to be the first one. // example // cmd: './foo -m 10 2 7 --bench-x -k 32 64 -l f g' gives // './foo -m 32 -k 10 -l f' // './foo -m 64 -k 10 -l f' // './foo -m 32 -k 2 -l f' // './foo -m 64 -k 2 -l f' // './foo -m 32 -k 7 -l f' // './foo -m 64 -k 7 -l f' // './foo -m 32 -k 10 -l g' // './foo -m 64 -k 10 -l g' // './foo -m 32 -k 2 -l g' // './foo -m 64 -k 2 -l g' // './foo -m 32 -k 7 -l g' // './foo -m 64 -k 7 -l g' // // option: --bench-o, output filename. // option: --bench-n, number of runs. // option: --bench-std, prevent from standard output to be disabled. // class hipsparse_bench_cmdlines { private: struct val { // // Everything is public. // public: int argc{}; char** argv{}; val& operator=(const val&) = delete; ~val() { if(this->argv != nullptr) { delete[] this->argv; this->argv = nullptr; } } val(){}; val(const val& v) = delete; explicit val(int n) : argc(n) { this->argv = new char*[this->argc]; } val& operator()(int n) { this->argc = n; if(this->argv) { delete[] this->argv; } this->argv = new char*[this->argc]; return *this; } }; struct cmdline { public: // // @brief Return the output filename. // const char* get_ofilename() const { return this->m_ofilename; }; // // @brief Return the number of plots. // int get_nplots() const { return this->get_nsamples() / this->m_options[this->m_option_index_x].args.size(); }; int get_noptions_x() const { return this->m_options[this->m_option_index_x].args.size(); }; int get_noptions() const { return this->m_options.size(); }; int get_option_nargs(int i) { return this->m_options[i].args.size(); } const char* get_option_arg(int i, int j) { return this->m_options[i].args[j].name; } const char* get_option_name(int i) { return this->m_options[i].name; } int get_nsamples() const { return this->m_nsamples; } size_t get_option_index_x() const { return this->m_option_index_x; } int get_nruns() const { return this->m_bench_nruns; } bool is_stdout_disabled() const { return this->m_is_stdout_disabled; } bool no_rawdata() const { return this->m_no_rawdata; } // // Constructor. // cmdline(int argc, char** argv) { // // Any option --bench-? // // // Try to get the option --bench-n. // int detected_option_bench_n = detect_option(argc, argv, "--bench-n", this->m_bench_nruns); if(detected_option_bench_n == -1) { std::cerr << "missing parameter ?" << std::endl; exit(1); } // // Try to get the option --bench-o. // int detected_option_bench_o = detect_option_string(argc, argv, "--bench-o", this->m_ofilename); if(detected_option_bench_o == -1) { std::cerr << "missing parameter ?" << std::endl; exit(1); } // // Try to get the option --bench-x. // const char* option_x = nullptr; int detected_option_bench_x = detect_option_string(argc, argv, "--bench-x", option_x); if(detected_option_bench_x == -1 || false == is_option(option_x)) { std::cerr << "wrong position of option --bench-x ?" << std::endl; exit(1); } this->m_name = argv[0]; this->m_has_bench_option = (detected_option_bench_x || detected_option_bench_o || detected_option_bench_n); this->m_no_rawdata = detect_flag(argc, argv, "--bench-no-rawdata"); this->m_is_stdout_disabled = (false == detect_flag(argc, argv, "--bench-std")); int jarg = -1; for(int iarg = 1; iarg < argc; ++iarg) { if(argv[iarg] == option_x) { jarg = iarg; break; } } int iarg = 1; while(iarg < argc) { // // Any argument starting with the character '-' is considered as an option. // if(is_option(argv[iarg])) { if(!strcmp(argv[iarg], "--bench-std")) { ++iarg; } else if(!strcmp(argv[iarg], "--bench-o")) { iarg += 2; } else if(!strcmp(argv[iarg], "--bench-x")) { ++iarg; } else if(!strcmp(argv[iarg], "--bench-n")) { iarg += 2; } else { // // Create the option. // cmdline_option option(argv[iarg]); // // Calculate the number of arguments based on the position of the next option, if any. // const int option_nargs = count_option_nargs(iarg, argc, argv); const int next_option_index = iarg + 1 + option_nargs; for(int k = iarg + 1; k < next_option_index; ++k) { option.args.push_back(cmdline_arg(argv[k])); } // // If this option has been flagged being the 'X' field. // otherwise, other ('Y') options will be classified from the order of their appearances as Y1, Y2, Y3. // if(jarg == iarg) // { this->m_option_index_x = this->m_options.size(); } // // Insert the option created. // this->m_options.push_back(option); iarg = next_option_index; } } else { // // Regular argument. // this->m_args.push_back(cmdline_arg(argv[iarg])); ++iarg; } } this->m_nsamples = 1; for(size_t ioption = 0; ioption < this->m_options.size(); ++ioption) { size_t n = this->m_options[ioption].args.size(); this->m_nsamples *= std::max(n, static_cast(1)); } } void expand(val* p) { const auto num_options = this->m_options.size(); const auto num_samples = this->m_nsamples; for(int i = 0; i < num_samples; ++i) { p[i](1 + this->m_args.size() + num_options * 2); p[i].argc = 0; } // // Program name. // for(int i = 0; i < num_samples; ++i) { p[i].argv[p[i].argc++] = this->m_name; } // // Arguments without options // for(auto& arg : this->m_args) { for(int i = 0; i < num_samples; ++i) p[i].argv[p[i].argc++] = arg.name; } const int option_x_nargs = this->m_options[this->m_option_index_x].args.size(); int N = option_x_nargs; for(size_t iopt = 0; iopt < num_options; ++iopt) { cmdline_option& option = this->m_options[iopt]; // // // for(int isample = 0; isample < num_samples; ++isample) { p[isample].argv[p[isample].argc++] = option.name; } if(iopt == this->m_option_index_x) { // // // { const int ngroups = num_samples / option_x_nargs; for(int jgroup = 0; jgroup < ngroups; ++jgroup) { for(int ix = 0; ix < option_x_nargs; ++ix) { const int flat_index = jgroup * option_x_nargs + ix; p[flat_index].argv[p[flat_index].argc++] = option.args[ix].name; } } } // // // for(int isample = 0; isample < num_samples; ++isample) { if(p[isample].argc != p[0].argc) { std::cerr << "invalid struct line " << __LINE__ << std::endl; } } } else { const int option_narg = option.args.size(); if(option_narg > 1) { const int ngroups = num_samples / (N * option_narg); for(int jgroup = 0; jgroup < ngroups; ++jgroup) { for(int option_iarg = 0; option_iarg < option_narg; ++option_iarg) { for(int i = 0; i < N; ++i) { const int flat_index = N * (jgroup * option_narg + option_iarg) + i; p[flat_index].argv[p[flat_index].argc++] = option.args[option_iarg].name; } } } N *= std::max(option_narg, 1); } else { if(option_narg == 1) { for(int isample = 0; isample < num_samples; ++isample) { p[isample].argv[p[isample].argc++] = option.args[0].name; } } } } } } private: static inline int count_option_nargs(int iarg, int argc, char** argv) { int c = 0; for(int j = iarg + 1; j < argc; ++j) { if(is_option(argv[j])) { return c; } ++c; } return c; } static bool detect_flag(int argc, char** argv, const char* option_name) { for(int iarg = 1; iarg < argc; ++iarg) { if(!strcmp(argv[iarg], option_name)) { return true; } } return false; } template static int detect_option(int argc, char** argv, const char* option_name, T& value) { for(int iarg = 1; iarg < argc; ++iarg) { if(!strcmp(argv[iarg], option_name)) { ++iarg; if(iarg < argc) { std::istringstream iss(argv[iarg]); iss >> value; return 1; } else { std::cerr << "missing value for option --bench-n " << std::endl; return -1; } } } return 0; } static int detect_option_string(int argc, char** argv, const char* option_name, const char*& value) { for(int iarg = 1; iarg < argc; ++iarg) { if(!strcmp(argv[iarg], option_name)) { ++iarg; if(iarg < argc) { value = argv[iarg]; return 1; } else { std::cerr << "missing value for option " << option_name << std::endl; return -1; } } } return 0; } // // argument name. // struct cmdline_arg { char* name{}; explicit cmdline_arg(char* name_) : name(name_){}; }; // // argument option. // struct cmdline_option { char* name{}; std::vector args{}; explicit cmdline_option(char* name_) : name(name_){}; }; static inline bool is_option(const char* arg) { return arg[0] == '-'; } // // Name. // char* m_name; // // set of options. // std::vector m_options; // // set of arguments. // std::vector m_args; bool m_has_bench_option{}; int m_bench_nruns{1}; size_t m_option_index_x; int m_nsamples; bool m_is_stdout_disabled{true}; bool m_no_rawdata{}; const char* m_ofilename{}; }; private: cmdline m_cmd; val* m_cmdset{}; public: static void help(std::ostream& out) { out << "Example:" << std::endl; out << "hipsparse-bench -f csrmv --bench-x -M 10 20 30 40" << std::endl; } // // @brief Get the output filename. // const char* get_ofilename() const; // // @brief Get the number of samples.. // int get_nsamples() const; size_t get_option_index_x() const; int get_option_nargs(int i); const char* get_option_arg(int i, int j); const char* get_option_name(int i); int get_noptions_x() const; int get_noptions() const; bool is_stdout_disabled() const; bool no_rawdata() const; // // @brief Get the number of runs per sample. // int get_nruns() const; void get(int isample, int& argc, char** argv) const; void get_argc(int isample, int& argc_) const; hipsparse_bench_cmdlines& operator=(const hipsparse_bench_cmdlines&) = delete; // // @brief Constructor. // hipsparse_bench_cmdlines(int argc, char** argv); hipsparse_bench_cmdlines(const hipsparse_bench_cmdlines&) = delete; virtual ~hipsparse_bench_cmdlines(); static bool applies(int argc, char** argv); // // @brief Some info. // void info() const; }; hipSPARSE-rocm-6.4.3/clients/benchmarks/hipsparse_routine.cpp000066400000000000000000000614031501764003400242110ustar00rootroot00000000000000/*! \file */ /* ************************************************************************ * Copyright (C) 2024 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse_routine.hpp" constexpr const char* hipsparse_routine::s_routine_names[hipsparse_routine::num_routines]; hipsparse_routine::hipsparse_routine(const char* function) { for(auto routine : all_routines) { const char* str = s_routine_names[routine]; if(!strcmp(function, str)) { this->value = routine; return; } } std::cerr << "// function " << function << " is invalid, list of valid function is" << std::endl; for(auto routine : all_routines) { const char* str = s_routine_names[routine]; std::cerr << "// - " << str << std::endl; } throw HIPSPARSE_STATUS_INVALID_VALUE; } hipsparse_routine::hipsparse_routine() : value((value_type)-1){}; hipsparse_routine& hipsparse_routine::operator()(const char* function) { for(auto routine : all_routines) { const char* str = s_routine_names[routine]; if(!strcmp(function, str)) { this->value = routine; return *this; } } std::cerr << "// function " << function << " is invalid, list of valid function is" << std::endl; for(auto routine : all_routines) { const char* str = s_routine_names[routine]; std::cerr << "// - " << str << std::endl; } throw HIPSPARSE_STATUS_INVALID_VALUE; } constexpr hipsparse_routine::value_type hipsparse_routine::all_routines[]; template hipsparseStatus_t hipsparse_routine::dispatch_indextype(const char cindextype, const Arguments& arg) { const hipsparseIndexType_t indextype = (cindextype == 'm') ? HIPSPARSE_INDEX_64I : (cindextype == 's') ? HIPSPARSE_INDEX_32I : (cindextype == 'd') ? HIPSPARSE_INDEX_64I : ((hipsparseIndexType_t)-1); const bool mixed = (cindextype == 'm'); switch(indextype) { case HIPSPARSE_INDEX_16U: { break; } case HIPSPARSE_INDEX_32I: { return dispatch_call(arg); } case HIPSPARSE_INDEX_64I: { if(mixed) { return dispatch_call(arg); } else { return dispatch_call(arg); } } } return HIPSPARSE_STATUS_INVALID_VALUE; } template hipsparseStatus_t hipsparse_routine::dispatch_precision(const char precision, const char indextype, const Arguments& arg) { const hipDataType datatype = (precision == 's') ? HIP_R_32F : (precision == 'd') ? HIP_R_64F : (precision == 'c') ? HIP_C_32F : (precision == 'z') ? HIP_C_64F : ((hipDataType)-1); switch(datatype) { case HIP_R_32F: return dispatch_indextype(indextype, arg); case HIP_R_64F: return dispatch_indextype(indextype, arg); case HIP_C_32F: return dispatch_indextype(indextype, arg); case HIP_C_64F: return dispatch_indextype(indextype, arg); default: return HIPSPARSE_STATUS_INVALID_VALUE; } } hipsparseStatus_t hipsparse_routine::dispatch(const char precision, const char indextype, const Arguments& arg) const { switch(this->value) { #define HIPSPARSE_DO_ROUTINE(FNAME) \ case FNAME: \ return dispatch_precision(precision, indextype, arg); HIPSPARSE_FOREACH_ROUTINE; #undef HIPSPARSE_DO_ROUTINE } return HIPSPARSE_STATUS_INVALID_VALUE; } constexpr const char* hipsparse_routine::to_string() const { // switch for checking inconsistency. switch(this->value) { #define HIPSPARSE_DO_ROUTINE(x_) \ case x_: \ { \ if(strcmp(#x_, s_routine_names[this->value])) \ return nullptr; \ break; \ } HIPSPARSE_FOREACH_ROUTINE; } #undef HIPSPARSE_DO_ROUTINE return s_routine_names[this->value]; } // Level1 #include "testing_axpyi.hpp" #include "testing_dotci.hpp" #include "testing_doti.hpp" #include "testing_gthr.hpp" #include "testing_gthrz.hpp" #include "testing_roti.hpp" #include "testing_sctr.hpp" // Level2 #include "testing_bsrmv.hpp" #include "testing_bsrsv2.hpp" #include "testing_csrsv2.hpp" #include "testing_gemvi.hpp" #include "testing_hybmv.hpp" // Level3 #include "testing_bsrmm.hpp" #include "testing_bsrsm2.hpp" #include "testing_gemmi.hpp" // Extra #include "testing_csrgeam.hpp" #include "testing_csrgemm.hpp" // Precond #include "testing_bsric02.hpp" #include "testing_bsrilu02.hpp" #include "testing_csric02.hpp" #include "testing_csrilu02.hpp" #include "testing_gpsv_interleaved_batch.hpp" #include "testing_gtsv.hpp" // File should be renamed to testing_gtsv2.hpp #include "testing_gtsv2_nopivot.hpp" #include "testing_gtsv2_strided_batch.hpp" #include "testing_gtsv_interleaved_batch.hpp" // Conversion #include "testing_bsr2csr.hpp" #include "testing_coo2csr.hpp" #include "testing_csr2bsr.hpp" #include "testing_csr2coo.hpp" #include "testing_csr2csc.hpp" #include "testing_csr2csr_compress.hpp" #include "testing_csr2gebsr.hpp" #include "testing_csr2hyb.hpp" #include "testing_gebsr2csr.hpp" #include "testing_gebsr2gebsc.hpp" #include "testing_gebsr2gebsr.hpp" #include "testing_hyb2csr.hpp" // Generic #include "testing_dense_to_sparse_coo.hpp" #include "testing_dense_to_sparse_csc.hpp" #include "testing_dense_to_sparse_csr.hpp" #include "testing_sparse_to_dense_coo.hpp" #include "testing_sparse_to_dense_csc.hpp" #include "testing_sparse_to_dense_csr.hpp" #include "testing_spmm_coo.hpp" #include "testing_spmm_csc.hpp" #include "testing_spmm_csr.hpp" #include "testing_spmv_coo.hpp" #include "testing_spmv_csr.hpp" #include "testing_spsm_coo.hpp" #include "testing_spsm_csr.hpp" #include "testing_spsv_csr.hpp" bool hipsparse_routine::is_routine_supported(hipsparse_routine::value_type FNAME) { switch(FNAME) { // Level 1 case axpyi: return routine_support::is_axpyi_supported(); case doti: return routine_support::is_doti_supported(); case dotci: return routine_support::is_dotci_supported(); case gthr: return routine_support::is_gthr_supported(); case gthrz: return routine_support::is_gthrz_supported(); case roti: return routine_support::is_roti_supported(); case sctr: return routine_support::is_sctr_supported(); // Level 2 case bsrsv2: return routine_support::is_bsrsv2_supported(); case coomv: return routine_support::is_coomv_supported(); case csrmv: return routine_support::is_csrmv_supported(); case csrsv: return routine_support::is_csrsv_supported(); case gemvi: return routine_support::is_gemvi_supported(); case hybmv: return routine_support::is_hybmv_supported(); // Level 3 case bsrmm: return routine_support::is_bsrmm_supported(); case bsrsm2: return routine_support::is_bsrsm2_supported(); case coomm: return routine_support::is_coomm_supported(); case cscmm: return routine_support::is_cscmm_supported(); case csrmm: return routine_support::is_csrmm_supported(); case coosm: return routine_support::is_coosm_supported(); case csrsm: return routine_support::is_csrsm_supported(); case gemmi: return routine_support::is_gemmi_supported(); // Extra case csrgeam: return routine_support::is_csrgeam_supported(); case csrgemm: return routine_support::is_csrgemm_supported(); // Precond case bsric02: return routine_support::is_bsric02_supported(); case bsrilu02: return routine_support::is_bsrilu02_supported(); case csric02: return routine_support::is_csric02_supported(); case csrilu02: return routine_support::is_csrilu02_supported(); case gtsv2: return routine_support::is_gtsv2_supported(); case gtsv2_nopivot: return routine_support::is_gtsv2_nopivot_supported(); case gtsv2_strided_batch: return routine_support::is_gtsv2_strided_batch_supported(); case gtsv_interleaved_batch: return routine_support::is_gtsv_interleaved_batch_supported(); case gpsv_interleaved_batch: return routine_support::is_gpsv_interleaved_batch_supported(); // Conversion case bsr2csr: return routine_support::is_bsr2csr_supported(); case csr2coo: return routine_support::is_csr2coo_supported(); case csr2csc: return routine_support::is_csr2csc_supported(); case csr2hyb: return routine_support::is_csr2hyb_supported(); case csr2bsr: return routine_support::is_csr2bsr_supported(); case csr2gebsr: return routine_support::is_csr2gebsr_supported(); case csr2csr_compress: return routine_support::is_csr2csr_compress_supported(); case coo2csr: return routine_support::is_coo2csr_supported(); case hyb2csr: return routine_support::is_hyb2csr_supported(); case csr2dense: return routine_support::is_csr2dense_supported(); case csc2dense: return routine_support::is_csc2dense_supported(); case coo2dense: return routine_support::is_coo2dense_supported(); case dense2csr: return routine_support::is_dense2csr_supported(); case dense2csc: return routine_support::is_dense2csc_supported(); case dense2coo: return routine_support::is_dense2coo_supported(); case gebsr2csr: return routine_support::is_gebsr2csr_supported(); case gebsr2gebsc: return routine_support::is_gebsr2gebsc_supported(); case gebsr2gebsr: return routine_support::is_gebsr2gebsr_supported(); } return false; } void hipsparse_routine::print_routine_support_info(hipsparse_routine::value_type FNAME) { switch(FNAME) { // Level 1 case axpyi: routine_support::print_axpyi_support_warning(); break; case doti: routine_support::print_doti_support_warning(); break; case dotci: routine_support::print_dotci_support_warning(); break; case gthr: routine_support::print_gthr_support_warning(); break; case gthrz: routine_support::print_gthrz_support_warning(); break; case roti: routine_support::print_roti_support_warning(); break; case sctr: routine_support::print_sctr_support_warning(); break; // Level 2 case bsrsv2: routine_support::print_bsrsv2_support_warning(); break; case coomv: routine_support::print_coomv_support_warning(); break; case csrmv: routine_support::print_csrmv_support_warning(); break; case csrsv: routine_support::print_csrsv_support_warning(); break; case gemvi: routine_support::print_gemvi_support_warning(); break; case hybmv: routine_support::print_hybmv_support_warning(); break; // Level 3 case bsrmm: routine_support::print_bsrmm_support_warning(); break; case bsrsm2: routine_support::print_bsrsm2_support_warning(); break; case coomm: routine_support::print_coomm_support_warning(); break; case cscmm: routine_support::print_cscmm_support_warning(); break; case csrmm: routine_support::print_csrmm_support_warning(); break; case coosm: routine_support::print_coosm_support_warning(); break; case csrsm: routine_support::print_csrsm_support_warning(); break; case gemmi: routine_support::print_gemmi_support_warning(); break; // Extra case csrgeam: routine_support::print_csrgeam_support_warning(); break; case csrgemm: routine_support::print_csrgemm_support_warning(); break; // Precond case bsric02: routine_support::print_bsric02_support_warning(); break; case bsrilu02: routine_support::print_bsrilu02_support_warning(); break; case csric02: routine_support::print_csric02_support_warning(); break; case csrilu02: routine_support::print_csrilu02_support_warning(); break; case gtsv2: routine_support::print_gtsv2_support_warning(); break; case gtsv2_nopivot: routine_support::print_gtsv2_nopivot_support_warning(); break; case gtsv2_strided_batch: routine_support::print_gtsv2_strided_batch_support_warning(); break; case gtsv_interleaved_batch: routine_support::print_gtsv_interleaved_batch_support_warning(); break; case gpsv_interleaved_batch: routine_support::print_gpsv_interleaved_batch_support_warning(); break; // Conversion case bsr2csr: routine_support::print_bsr2csr_support_warning(); break; case csr2coo: routine_support::print_csr2coo_support_warning(); break; case csr2csc: routine_support::print_csr2csc_support_warning(); break; case csr2hyb: routine_support::print_csr2hyb_support_warning(); break; case csr2bsr: routine_support::print_csr2bsr_support_warning(); break; case csr2gebsr: routine_support::print_csr2gebsr_support_warning(); break; case csr2csr_compress: routine_support::print_csr2csr_compress_support_warning(); break; case coo2csr: routine_support::print_coo2csr_support_warning(); break; case hyb2csr: routine_support::print_hyb2csr_support_warning(); break; case csr2dense: routine_support::print_csr2dense_support_warning(); break; case csc2dense: routine_support::print_csc2dense_support_warning(); break; case coo2dense: routine_support::print_coo2dense_support_warning(); break; case dense2csr: routine_support::print_dense2csr_support_warning(); break; case dense2csc: routine_support::print_dense2csc_support_warning(); break; case dense2coo: routine_support::print_dense2coo_support_warning(); break; case gebsr2csr: routine_support::print_gebsr2csr_support_warning(); break; case gebsr2gebsc: routine_support::print_gebsr2gebsc_support_warning(); break; case gebsr2gebsr: routine_support::print_gebsr2gebsr_support_warning(); break; } } template hipsparseStatus_t hipsparse_routine::dispatch_call(const Arguments& arg) { if(!is_routine_supported(FNAME)) { print_routine_support_info(FNAME); return HIPSPARSE_STATUS_INVALID_VALUE; } #define DEFINE_CASE_T_X(value, testingf) \ case value: \ { \ try \ { \ testingf(arg); \ return HIPSPARSE_STATUS_SUCCESS; \ } \ catch(const hipsparseStatus_t& status) \ { \ return status; \ } \ } #define DEFINE_CASE_IT_X(value, testingf) \ case value: \ { \ try \ { \ testingf(arg); \ return HIPSPARSE_STATUS_SUCCESS; \ } \ catch(const hipsparseStatus_t& status) \ { \ return status; \ } \ } #define DEFINE_CASE_IJT_X(value, testingf) \ case value: \ { \ try \ { \ testingf(arg); \ return HIPSPARSE_STATUS_SUCCESS; \ } \ catch(const hipsparseStatus_t& status) \ { \ return status; \ } \ } #define DEFINE_CASE_T(value) DEFINE_CASE_T_X(value, testing_##value) #define IS_T_FLOAT (std::is_same()) #define IS_T_DOUBLE (std::is_same()) #define IS_T_COMPLEX_FLOAT (std::is_same()) #define IS_T_COMPLEX_DOUBLE (std::is_same()) #define DEFINE_CASE_T_REAL_ONLY(value) \ case value: \ { \ if(IS_T_FLOAT) \ { \ try \ { \ testing_##value(arg); \ return HIPSPARSE_STATUS_SUCCESS; \ } \ catch(const hipsparseStatus_t& status) \ { \ return status; \ } \ } \ else if(IS_T_DOUBLE) \ { \ try \ { \ testing_##value(arg); \ return HIPSPARSE_STATUS_SUCCESS; \ } \ catch(const hipsparseStatus_t& status) \ { \ return status; \ } \ } \ else \ { \ return HIPSPARSE_STATUS_INTERNAL_ERROR; \ } \ } #define DEFINE_CASE_T_REAL_VS_COMPLEX(value, rtestingf, ctestingf) \ case value: \ { \ try \ { \ if(IS_T_FLOAT) \ { \ rtestingf(arg); \ } \ else if(IS_T_DOUBLE) \ { \ rtestingf(arg); \ } \ else if(IS_T_COMPLEX_FLOAT) \ { \ ctestingf(arg); \ } \ else if(IS_T_COMPLEX_DOUBLE) \ { \ ctestingf(arg); \ } \ else \ { \ return HIPSPARSE_STATUS_INTERNAL_ERROR; \ } \ } \ catch(const hipsparseStatus_t& status) \ { \ return status; \ } \ } switch(FNAME) { // Level 1 DEFINE_CASE_T(axpyi); DEFINE_CASE_T(doti); DEFINE_CASE_T_REAL_VS_COMPLEX(dotci, testing_doti, testing_dotci); DEFINE_CASE_T(gthr); DEFINE_CASE_T(gthrz); DEFINE_CASE_T_REAL_ONLY(roti); DEFINE_CASE_T(sctr); // Level2 DEFINE_CASE_T(bsrsv2); DEFINE_CASE_IT_X(coomv, testing_spmv_coo); DEFINE_CASE_IJT_X(csrmv, testing_spmv_csr); DEFINE_CASE_IJT_X(csrsv, testing_spsv_csr); DEFINE_CASE_T(gemvi); DEFINE_CASE_T(hybmv); // Level3 DEFINE_CASE_T(bsrmm); DEFINE_CASE_T(bsrsm2); DEFINE_CASE_IT_X(coomm, testing_spmm_coo); DEFINE_CASE_IJT_X(cscmm, testing_spmm_csc); DEFINE_CASE_IJT_X(csrmm, testing_spmm_csr); DEFINE_CASE_IT_X(coosm, testing_spsm_coo); DEFINE_CASE_IJT_X(csrsm, testing_spsm_csr); DEFINE_CASE_T(gemmi); // Extra DEFINE_CASE_T(csrgeam); DEFINE_CASE_T(csrgemm); // Precond DEFINE_CASE_T(bsric02); DEFINE_CASE_T(bsrilu02); DEFINE_CASE_T(csric02); DEFINE_CASE_T(csrilu02); DEFINE_CASE_T(gtsv2); DEFINE_CASE_T(gtsv2_nopivot); DEFINE_CASE_T(gtsv2_strided_batch); DEFINE_CASE_T(gtsv_interleaved_batch); DEFINE_CASE_T(gpsv_interleaved_batch); // Conversion DEFINE_CASE_T(bsr2csr); DEFINE_CASE_T(csr2coo); DEFINE_CASE_T(csr2csc); DEFINE_CASE_T(csr2hyb); DEFINE_CASE_T(csr2bsr); DEFINE_CASE_T(csr2gebsr); DEFINE_CASE_T(csr2csr_compress); DEFINE_CASE_T(coo2csr); DEFINE_CASE_T(hyb2csr); DEFINE_CASE_IJT_X(csr2dense, testing_sparse_to_dense_csr); DEFINE_CASE_IJT_X(csc2dense, testing_sparse_to_dense_csc); DEFINE_CASE_IT_X(coo2dense, testing_sparse_to_dense_coo); DEFINE_CASE_IJT_X(dense2csr, testing_dense_to_sparse_csr); DEFINE_CASE_IJT_X(dense2csc, testing_dense_to_sparse_csc); DEFINE_CASE_IT_X(dense2coo, testing_dense_to_sparse_coo); DEFINE_CASE_T(gebsr2csr); DEFINE_CASE_T(gebsr2gebsc); DEFINE_CASE_T(gebsr2gebsr); } #undef DEFINE_CASE_T_X #undef DEFINE_CASE_IT_X #undef DEFINE_CASE_IJT_X #undef DEFINE_CASE_T #undef IS_T_FLOAT #undef IS_T_DOUBLE #undef IS_T_COMPLEX_FLOAT #undef IS_T_COMPLEX_DOUBLE #undef DEFINE_CASE_T_REAL_ONLY #undef DEFINE_CASE_T_REAL_VS_COMPLEX return HIPSPARSE_STATUS_INVALID_VALUE; } hipSPARSE-rocm-6.4.3/clients/benchmarks/hipsparse_routine.hpp000066400000000000000000000114541501764003400242170ustar00rootroot00000000000000/*! \file */ /* ************************************************************************ * Copyright (C) 2024 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #include "hipsparse_arguments.hpp" // clang-format off #define HIPSPARSE_FOREACH_ROUTINE \ HIPSPARSE_DO_ROUTINE(axpyi) \ HIPSPARSE_DO_ROUTINE(doti) \ HIPSPARSE_DO_ROUTINE(dotci) \ HIPSPARSE_DO_ROUTINE(gthr) \ HIPSPARSE_DO_ROUTINE(gthrz) \ HIPSPARSE_DO_ROUTINE(roti) \ HIPSPARSE_DO_ROUTINE(sctr) \ HIPSPARSE_DO_ROUTINE(bsrsv2) \ HIPSPARSE_DO_ROUTINE(coomv) \ HIPSPARSE_DO_ROUTINE(csrmv) \ HIPSPARSE_DO_ROUTINE(csrsv) \ HIPSPARSE_DO_ROUTINE(gemvi) \ HIPSPARSE_DO_ROUTINE(hybmv) \ HIPSPARSE_DO_ROUTINE(bsrmm) \ HIPSPARSE_DO_ROUTINE(bsrsm2) \ HIPSPARSE_DO_ROUTINE(coomm) \ HIPSPARSE_DO_ROUTINE(cscmm) \ HIPSPARSE_DO_ROUTINE(csrmm) \ HIPSPARSE_DO_ROUTINE(coosm) \ HIPSPARSE_DO_ROUTINE(csrsm) \ HIPSPARSE_DO_ROUTINE(gemmi) \ HIPSPARSE_DO_ROUTINE(csrgeam) \ HIPSPARSE_DO_ROUTINE(csrgemm) \ HIPSPARSE_DO_ROUTINE(bsric02) \ HIPSPARSE_DO_ROUTINE(bsrilu02) \ HIPSPARSE_DO_ROUTINE(csric02) \ HIPSPARSE_DO_ROUTINE(csrilu02) \ HIPSPARSE_DO_ROUTINE(gtsv2) \ HIPSPARSE_DO_ROUTINE(gtsv2_nopivot) \ HIPSPARSE_DO_ROUTINE(gtsv2_strided_batch) \ HIPSPARSE_DO_ROUTINE(gtsv_interleaved_batch) \ HIPSPARSE_DO_ROUTINE(gpsv_interleaved_batch) \ HIPSPARSE_DO_ROUTINE(bsr2csr) \ HIPSPARSE_DO_ROUTINE(csr2coo) \ HIPSPARSE_DO_ROUTINE(csr2csc) \ HIPSPARSE_DO_ROUTINE(csr2hyb) \ HIPSPARSE_DO_ROUTINE(csr2bsr) \ HIPSPARSE_DO_ROUTINE(csr2gebsr) \ HIPSPARSE_DO_ROUTINE(csr2csr_compress) \ HIPSPARSE_DO_ROUTINE(coo2csr) \ HIPSPARSE_DO_ROUTINE(hyb2csr) \ HIPSPARSE_DO_ROUTINE(csr2dense) \ HIPSPARSE_DO_ROUTINE(csc2dense) \ HIPSPARSE_DO_ROUTINE(coo2dense) \ HIPSPARSE_DO_ROUTINE(dense2csr) \ HIPSPARSE_DO_ROUTINE(dense2csc) \ HIPSPARSE_DO_ROUTINE(dense2coo) \ HIPSPARSE_DO_ROUTINE(gebsr2csr) \ HIPSPARSE_DO_ROUTINE(gebsr2gebsc) \ HIPSPARSE_DO_ROUTINE(gebsr2gebsr) // clang-format on template static constexpr std::size_t countof(T (&)[N]) { return N; } struct hipsparse_routine { private: public: #define HIPSPARSE_DO_ROUTINE(x_) x_, typedef enum _ : int { HIPSPARSE_FOREACH_ROUTINE } value_type; value_type value{}; static constexpr value_type all_routines[] = {HIPSPARSE_FOREACH_ROUTINE}; #undef HIPSPARSE_DO_ROUTINE static constexpr std::size_t num_routines = countof(all_routines); private: #define HIPSPARSE_DO_ROUTINE(x_) #x_, static constexpr const char* s_routine_names[num_routines]{HIPSPARSE_FOREACH_ROUTINE}; #undef HIPSPARSE_DO_ROUTINE public: hipsparse_routine(); hipsparse_routine& operator()(const char* function); explicit hipsparse_routine(const char* function); hipsparseStatus_t dispatch(const char precision, const char indextype, const Arguments& arg) const; constexpr const char* to_string() const; private: template static hipsparseStatus_t dispatch_call(const Arguments& arg); template static hipsparseStatus_t dispatch_indextype(const char cindextype, const Arguments& arg); template static hipsparseStatus_t dispatch_precision(const char precision, const char indextype, const Arguments& arg); static bool is_routine_supported(hipsparse_routine::value_type FNAME); static void print_routine_support_info(hipsparse_routine::value_type FNAME); }; hipSPARSE-rocm-6.4.3/clients/benchmarks/program_options.hpp000066400000000000000000000303611501764003400236740ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020-2021 Advanced Micro Devices, Inc. All rights Reserved. * ************************************************************************ */ // This emulates the required functionality of boost::program_options #pragma once #include #include #include #include #include #include #include #include #include #include #include // Regular expression for token delimiters (whitespace and commas) static const std::regex program_options_regex{"[, \\f\\n\\r\\t\\v]+", std::regex_constants::optimize}; // variables_map is a set of seen options using variables_map = std::set; // Polymorphic base class to use with dynamic_cast class value_base { protected: bool m_has_default = false; public: bool has_default() const { return m_has_default; } virtual ~value_base() = default; }; // Value parameters template class value : public value_base { T* m_var; // Pointer to variable to be modified public: // Constructor explicit value(T* var) : m_var(var) { } // Pointer to variable T* get_ptr() const { return m_var; } // Allows default_value() value* operator->() { return this; } // Set default value value& default_value(T val) { *m_var = std::move(val); m_has_default = true; return *this; } }; // bool_switch is a value, which is handled specially using bool_switch = value; class options_description { // desc_option describes a particular option class desc_option { std::string m_opts; value_base* m_val; std::string m_desc; public: desc_option& operator=(const desc_option&) = delete; // Constructor with options, value and description template desc_option(std::string opts, value val, std::string desc) : m_opts(std::move(opts)) , m_val(new auto(std::move(val))) , m_desc(std::move(desc)) { } // Constructor with options and description desc_option(std::string opts, std::string desc) : m_opts(std::move(opts)) , m_val(nullptr) , m_desc(std::move(desc)) { } // Copy constructor is deleted desc_option(const desc_option&) = delete; // Move constructor desc_option(desc_option&& other) : m_opts(std::move(other.m_opts)) , m_val(other.m_val) , m_desc(std::move(other.m_desc)) { other.m_val = nullptr; } // Destructor ~desc_option() { delete m_val; } // Accessors const std::string& get_opts() const { return m_opts; } const value_base* get_val() const { return m_val; } const std::string& get_desc() const { return m_desc; } // Set a value void set_val(int& argc, char**& argv) const { // We test all supported types with dynamic_cast and parse accordingly bool match = false; if(dynamic_cast*>(m_val)) { auto* val = dynamic_cast*>(m_val)->get_ptr(); match = argc && sscanf(*argv, "%" SCNd32, val) == 1; } else if(dynamic_cast*>(m_val)) { auto* val = dynamic_cast*>(m_val)->get_ptr(); match = argc && sscanf(*argv, "%" SCNu32, val) == 1; } else if(dynamic_cast*>(m_val)) { auto* val = dynamic_cast*>(m_val)->get_ptr(); match = argc && sscanf(*argv, "%" SCNd64, val) == 1; } else if(dynamic_cast*>(m_val)) { auto* val = dynamic_cast*>(m_val)->get_ptr(); match = argc && sscanf(*argv, "%" SCNu64, val) == 1; } else if(dynamic_cast*>(m_val)) { auto* val = dynamic_cast*>(m_val)->get_ptr(); match = argc && sscanf(*argv, "%f", val) == 1; } else if(dynamic_cast*>(m_val)) { auto* val = dynamic_cast*>(m_val)->get_ptr(); match = argc && sscanf(*argv, "%lf", val) == 1; } else if(dynamic_cast*>(m_val)) { auto* val = dynamic_cast*>(m_val)->get_ptr(); match = argc && sscanf(*argv, " %c", val) == 1; } else if(dynamic_cast*>(m_val)) { // We handle bool specially, setting the value to true without argument auto* val = dynamic_cast*>(m_val)->get_ptr(); *val = true; return; } else if(dynamic_cast*>(m_val)) { if(argc) { *dynamic_cast*>(m_val)->get_ptr() = *argv; match = true; } } else { throw std::logic_error("Internal error: Unsupported data type"); } if(!match) throw std::invalid_argument(argc ? *argv : "Missing required argument"); // Skip past the argument's value ++argv; --argc; } }; // Description and option list std::string m_desc; std::vector m_optlist; // desc_optionlist allows chains of options to be parenthesized class desc_optionlist { std::vector& m_list; public: explicit desc_optionlist(std::vector& list) : m_list(list) { } template desc_optionlist operator()(Ts&&... arg) { m_list.push_back(desc_option(std::forward(arg)...)); return *this; } }; public: // Constructor explicit options_description(std::string desc) : m_desc(std::move(desc)) { } // Start a desc_optionlist chain desc_optionlist add_options() & { return desc_optionlist(m_optlist); } // Parse an option at the current (argc, argv) position void parse_option(int& argc, char**& argv, variables_map& vm, bool ignoreUnknown = false) const { // Iterate across all options for(const auto& opt : m_optlist) { // Canonical name used for map std::string canonical_name; // Iterate across tokens in the opts for(std::sregex_token_iterator tok{ opt.get_opts().begin(), opt.get_opts().end(), program_options_regex, -1}; tok != std::sregex_token_iterator(); ++tok) { // The first option in a list of options is the canonical name if(!canonical_name.length()) canonical_name = tok->str(); // If the length of the option is 1, it is single-dash; otherwise double-dash const char* prefix = tok->length() == 1 ? "-" : "--"; // If option matches if(*argv == prefix + tok->str()) { ++argv; --argc; // If option has a value, set it; otherwise indicate option in set if(opt.get_val()) opt.set_val(argc, argv); else vm.insert(canonical_name); return; // Return successfully } } } // No options were matched if(ignoreUnknown) { ++argv; --argc; } else { throw std::invalid_argument(*argv); } } // Formatted output of command-line arguments description friend std::ostream& operator<<(std::ostream& os, const options_description& d) { // Iterate across all options for(const auto& opt : d.m_optlist) { bool first = true; const char* delim = ""; std::ostringstream left; // Iterate across tokens in the opts for(std::sregex_token_iterator tok{opt.get_opts().begin(), opt.get_opts().end(), program_options_regex, -1}; tok != std::sregex_token_iterator(); ++tok, first = false, delim = " ") { // If the length of the option is 1, it is single-dash; otherwise double-dash const char* prefix = tok->length() == 1 ? "-" : "--"; left << delim << (first ? "" : "[ ") << prefix << tok->str() << (first ? "" : " ]"); } // Print the default value of the variable type if it exists // We do not print the default value for bool const value_base* val = opt.get_val(); if(val && !dynamic_cast*>(val)) { left << " arg"; if(val->has_default()) { // We test all supported types with dynamic_cast and print accordingly left << " (="; if(dynamic_cast*>(val)) left << *dynamic_cast*>(val)->get_ptr(); else if(dynamic_cast*>(val)) left << *dynamic_cast*>(val)->get_ptr(); else if(dynamic_cast*>(val)) left << *dynamic_cast*>(val)->get_ptr(); else if(dynamic_cast*>(val)) left << *dynamic_cast*>(val)->get_ptr(); else if(dynamic_cast*>(val)) left << *dynamic_cast*>(val)->get_ptr(); else if(dynamic_cast*>(val)) left << *dynamic_cast*>(val)->get_ptr(); else if(dynamic_cast*>(val)) left << *dynamic_cast*>(val)->get_ptr(); else if(dynamic_cast*>(val)) left << *dynamic_cast*>(val)->get_ptr(); else throw std::logic_error("Internal error: Unsupported data type"); left << ")"; } } os << std::setw(36) << std::left << left.str() << " " << opt.get_desc() << "\n\n"; } return os << std::flush; } }; // Class representing command line parser class parse_command_line { variables_map m_vm; public: parse_command_line(int argc, char** argv, const options_description& desc, bool ignoreUnknown = false) { ++argv; // Skip argv[0] --argc; while(argc) desc.parse_option(argc, argv, m_vm, ignoreUnknown); } // Copy the variables_map friend void store(const parse_command_line& p, variables_map& vm) { vm = p.m_vm; } // Move the variables_map friend void store(parse_command_line&& p, variables_map& vm) { vm = std::move(p.m_vm); } }; // We can define the notify() function as a no-op for our purposes inline void notify(const variables_map&) {} hipSPARSE-rocm-6.4.3/clients/common/000077500000000000000000000000001501764003400171115ustar00rootroot00000000000000hipSPARSE-rocm-6.4.3/clients/common/arg_check.cpp000066400000000000000000000127621501764003400215330ustar00rootroot00000000000000/* ************************************************************************ * 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-6.4.3/clients/common/hipsparse_template_specialization.cpp000066400000000000000000020352651501764003400266210ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2018-2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.hpp" #include namespace hipsparse { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXaxpyi(hipsparseHandle_t handle, int nnz, const float* alpha, const float* xVal, const int* xInd, float* y, hipsparseIndexBase_t idxBase) { return hipsparseSaxpyi(handle, nnz, alpha, xVal, xInd, y, idxBase); } template <> hipsparseStatus_t hipsparseXaxpyi(hipsparseHandle_t handle, int nnz, const double* alpha, const double* xVal, const int* xInd, double* y, hipsparseIndexBase_t idxBase) { return hipsparseDaxpyi(handle, nnz, alpha, xVal, xInd, y, idxBase); } template <> hipsparseStatus_t hipsparseXaxpyi(hipsparseHandle_t handle, int nnz, const hipComplex* alpha, const hipComplex* xVal, const int* xInd, hipComplex* y, hipsparseIndexBase_t idxBase) { return hipsparseCaxpyi(handle, nnz, alpha, xVal, xInd, y, idxBase); } template <> hipsparseStatus_t hipsparseXaxpyi(hipsparseHandle_t handle, int nnz, const hipDoubleComplex* alpha, const hipDoubleComplex* xVal, const int* xInd, hipDoubleComplex* y, hipsparseIndexBase_t idxBase) { return hipsparseZaxpyi(handle, nnz, alpha, xVal, xInd, y, idxBase); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template <> hipsparseStatus_t hipsparseXdoti(hipsparseHandle_t handle, int nnz, const float* xVal, const int* xInd, const float* y, float* result, hipsparseIndexBase_t idxBase) { return hipsparseSdoti(handle, nnz, xVal, xInd, y, result, idxBase); } template <> hipsparseStatus_t hipsparseXdoti(hipsparseHandle_t handle, int nnz, const double* xVal, const int* xInd, const double* y, double* result, hipsparseIndexBase_t idxBase) { return hipsparseDdoti(handle, nnz, xVal, xInd, y, result, idxBase); } template <> hipsparseStatus_t hipsparseXdoti(hipsparseHandle_t handle, int nnz, const hipComplex* xVal, const int* xInd, const hipComplex* y, hipComplex* result, hipsparseIndexBase_t idxBase) { return hipsparseCdoti(handle, nnz, xVal, xInd, y, result, idxBase); } template <> hipsparseStatus_t hipsparseXdoti(hipsparseHandle_t handle, int nnz, const hipDoubleComplex* xVal, const int* xInd, const hipDoubleComplex* y, hipDoubleComplex* result, hipsparseIndexBase_t idxBase) { return hipsparseZdoti(handle, nnz, xVal, xInd, y, result, idxBase); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template <> hipsparseStatus_t hipsparseXdotci(hipsparseHandle_t handle, int nnz, const hipComplex* xVal, const int* xInd, const hipComplex* y, hipComplex* result, hipsparseIndexBase_t idxBase) { return hipsparseCdotci(handle, nnz, xVal, xInd, y, result, idxBase); } template <> hipsparseStatus_t hipsparseXdotci(hipsparseHandle_t handle, int nnz, const hipDoubleComplex* xVal, const int* xInd, const hipDoubleComplex* y, hipDoubleComplex* result, hipsparseIndexBase_t idxBase) { return hipsparseZdotci(handle, nnz, xVal, xInd, y, result, idxBase); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXgthr(hipsparseHandle_t handle, int nnz, const float* y, float* xVal, const int* xInd, hipsparseIndexBase_t idxBase) { return hipsparseSgthr(handle, nnz, y, xVal, xInd, idxBase); } template <> hipsparseStatus_t hipsparseXgthr(hipsparseHandle_t handle, int nnz, const double* y, double* xVal, const int* xInd, hipsparseIndexBase_t idxBase) { return hipsparseDgthr(handle, nnz, y, xVal, xInd, idxBase); } template <> hipsparseStatus_t hipsparseXgthr(hipsparseHandle_t handle, int nnz, const hipComplex* y, hipComplex* xVal, const int* xInd, hipsparseIndexBase_t idxBase) { return hipsparseCgthr(handle, nnz, y, xVal, xInd, idxBase); } template <> hipsparseStatus_t hipsparseXgthr(hipsparseHandle_t handle, int nnz, const hipDoubleComplex* y, hipDoubleComplex* xVal, const int* xInd, hipsparseIndexBase_t idxBase) { return hipsparseZgthr(handle, nnz, y, xVal, xInd, idxBase); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXgthrz(hipsparseHandle_t handle, int nnz, float* y, float* xVal, const int* xInd, hipsparseIndexBase_t idxBase) { return hipsparseSgthrz(handle, nnz, y, xVal, xInd, idxBase); } template <> hipsparseStatus_t hipsparseXgthrz(hipsparseHandle_t handle, int nnz, double* y, double* xVal, const int* xInd, hipsparseIndexBase_t idxBase) { return hipsparseDgthrz(handle, nnz, y, xVal, xInd, idxBase); } template <> hipsparseStatus_t hipsparseXgthrz(hipsparseHandle_t handle, int nnz, hipComplex* y, hipComplex* xVal, const int* xInd, hipsparseIndexBase_t idxBase) { return hipsparseCgthrz(handle, nnz, y, xVal, xInd, idxBase); } template <> hipsparseStatus_t hipsparseXgthrz(hipsparseHandle_t handle, int nnz, hipDoubleComplex* y, hipDoubleComplex* xVal, const int* xInd, hipsparseIndexBase_t idxBase) { return hipsparseZgthrz(handle, nnz, y, xVal, xInd, idxBase); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXroti(hipsparseHandle_t handle, int nnz, float* xVal, const int* xInd, float* y, const float* c, const float* s, hipsparseIndexBase_t idxBase) { return hipsparseSroti(handle, nnz, xVal, xInd, y, c, s, idxBase); } template <> hipsparseStatus_t hipsparseXroti(hipsparseHandle_t handle, int nnz, double* xVal, const int* xInd, double* y, const double* c, const double* s, hipsparseIndexBase_t idxBase) { return hipsparseDroti(handle, nnz, xVal, xInd, y, c, s, idxBase); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXsctr(hipsparseHandle_t handle, int nnz, const float* xVal, const int* xInd, float* y, hipsparseIndexBase_t idxBase) { return hipsparseSsctr(handle, nnz, xVal, xInd, y, idxBase); } template <> hipsparseStatus_t hipsparseXsctr(hipsparseHandle_t handle, int nnz, const double* xVal, const int* xInd, double* y, hipsparseIndexBase_t idxBase) { return hipsparseDsctr(handle, nnz, xVal, xInd, y, idxBase); } template <> hipsparseStatus_t hipsparseXsctr(hipsparseHandle_t handle, int nnz, const hipComplex* xVal, const int* xInd, hipComplex* y, hipsparseIndexBase_t idxBase) { return hipsparseCsctr(handle, nnz, xVal, xInd, y, idxBase); } template <> hipsparseStatus_t hipsparseXsctr(hipsparseHandle_t handle, int nnz, const hipDoubleComplex* xVal, const int* xInd, hipDoubleComplex* y, hipsparseIndexBase_t idxBase) { return hipsparseZsctr(handle, nnz, xVal, xInd, y, idxBase); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template <> hipsparseStatus_t hipsparseXcsrmv(hipsparseHandle_t handle, hipsparseOperation_t trans, int m, int n, int nnz, const float* alpha, const hipsparseMatDescr_t descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, const float* x, const float* beta, float* y) { return hipsparseScsrmv( handle, trans, m, n, nnz, alpha, descr, csrVal, csrRowPtr, csrColInd, x, beta, y); } template <> hipsparseStatus_t hipsparseXcsrmv(hipsparseHandle_t handle, hipsparseOperation_t trans, int m, int n, int nnz, const double* alpha, const hipsparseMatDescr_t descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, const double* x, const double* beta, double* y) { return hipsparseDcsrmv( handle, trans, m, n, nnz, alpha, descr, csrVal, csrRowPtr, csrColInd, x, beta, y); } template <> hipsparseStatus_t hipsparseXcsrmv(hipsparseHandle_t handle, hipsparseOperation_t trans, int m, int n, int nnz, const hipComplex* alpha, const hipsparseMatDescr_t descr, const hipComplex* csrVal, const int* csrRowPtr, const int* csrColInd, const hipComplex* x, const hipComplex* beta, hipComplex* y) { return hipsparseCcsrmv( handle, trans, m, n, nnz, alpha, descr, csrVal, csrRowPtr, csrColInd, x, beta, y); } template <> hipsparseStatus_t hipsparseXcsrmv(hipsparseHandle_t handle, hipsparseOperation_t trans, int m, int n, int nnz, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descr, const hipDoubleComplex* csrVal, const int* csrRowPtr, const int* csrColInd, const hipDoubleComplex* x, const hipDoubleComplex* beta, hipDoubleComplex* y) { return hipsparseZcsrmv( handle, trans, m, n, nnz, alpha, descr, csrVal, csrRowPtr, csrColInd, x, beta, y); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXcsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, int* pBufferSizeInBytes) { return hipsparseScsrsv2_bufferSize(handle, transA, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, int* pBufferSizeInBytes) { return hipsparseDcsrsv2_bufferSize(handle, transA, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, int* pBufferSizeInBytes) { return hipsparseCcsrsv2_bufferSize(handle, transA, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, int* pBufferSizeInBytes) { return hipsparseZcsrsv2_bufferSize(handle, transA, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } #endif template <> hipsparseStatus_t hipsparseXcsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, size_t* pBufferSizeInBytes) { return hipsparseScsrsv2_bufferSizeExt(handle, transA, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, size_t* pBufferSizeInBytes) { return hipsparseDcsrsv2_bufferSizeExt(handle, transA, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, size_t* pBufferSizeInBytes) { return hipsparseCcsrsv2_bufferSizeExt(handle, transA, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, size_t* pBufferSizeInBytes) { return hipsparseZcsrsv2_bufferSizeExt(handle, transA, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXcsrsv2_analysis(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseScsrsv2_analysis(handle, transA, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrsv2_analysis(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseDcsrsv2_analysis(handle, transA, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrsv2_analysis(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseCcsrsv2_analysis(handle, transA, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrsv2_analysis(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseZcsrsv2_analysis(handle, transA, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXcsrsv2_solve(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const float* alpha, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, const float* f, float* x, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseScsrsv2_solve(handle, transA, m, nnz, alpha, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, f, x, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrsv2_solve(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const double* alpha, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, const double* f, double* x, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseDcsrsv2_solve(handle, transA, m, nnz, alpha, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, f, x, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrsv2_solve(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, const hipComplex* f, hipComplex* x, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseCcsrsv2_solve(handle, transA, m, nnz, alpha, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, f, x, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrsv2_solve(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, const hipDoubleComplex* f, hipDoubleComplex* x, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseZcsrsv2_solve(handle, transA, m, nnz, alpha, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, f, x, policy, pBuffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template <> hipsparseStatus_t hipsparseXhybmv(hipsparseHandle_t handle, hipsparseOperation_t trans, const float* alpha, const hipsparseMatDescr_t descr, const hipsparseHybMat_t hyb, const float* x, const float* beta, float* y) { return hipsparseShybmv(handle, trans, alpha, descr, hyb, x, beta, y); } template <> hipsparseStatus_t hipsparseXhybmv(hipsparseHandle_t handle, hipsparseOperation_t trans, const double* alpha, const hipsparseMatDescr_t descr, const hipsparseHybMat_t hyb, const double* x, const double* beta, double* y) { return hipsparseDhybmv(handle, trans, alpha, descr, hyb, x, beta, y); } template <> hipsparseStatus_t hipsparseXhybmv(hipsparseHandle_t handle, hipsparseOperation_t trans, const hipComplex* alpha, const hipsparseMatDescr_t descr, const hipsparseHybMat_t hyb, const hipComplex* x, const hipComplex* beta, hipComplex* y) { return hipsparseChybmv(handle, trans, alpha, descr, hyb, x, beta, y); } template <> hipsparseStatus_t hipsparseXhybmv(hipsparseHandle_t handle, hipsparseOperation_t trans, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descr, const hipsparseHybMat_t hyb, const hipDoubleComplex* x, const hipDoubleComplex* beta, hipDoubleComplex* y) { return hipsparseZhybmv(handle, trans, alpha, descr, hyb, x, beta, y); } #endif template <> hipsparseStatus_t hipsparseXbsrmv(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nb, int nnzb, const float* alpha, const hipsparseMatDescr_t descrA, const float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, const float* x, const float* beta, float* y) { return hipsparseSbsrmv(handle, dirA, transA, mb, nb, nnzb, alpha, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, x, beta, y); } template <> hipsparseStatus_t hipsparseXbsrmv(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nb, int nnzb, const double* alpha, const hipsparseMatDescr_t descrA, const double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, const double* x, const double* beta, double* y) { return hipsparseDbsrmv(handle, dirA, transA, mb, nb, nnzb, alpha, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, x, beta, y); } template <> hipsparseStatus_t hipsparseXbsrmv(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nb, int nnzb, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, const hipComplex* x, const hipComplex* beta, hipComplex* y) { return hipsparseCbsrmv(handle, dirA, transA, mb, nb, nnzb, alpha, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, x, beta, y); } template <> hipsparseStatus_t hipsparseXbsrmv(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nb, int nnzb, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, const hipDoubleComplex* x, const hipDoubleComplex* beta, hipDoubleComplex* y) { return hipsparseZbsrmv(handle, dirA, transA, mb, nb, nnzb, alpha, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, x, beta, y); } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXbsrxmv(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t trans, int sizeOfMask, int mb, int nb, int nnzb, const float* alpha, const hipsparseMatDescr_t descr, const float* bsrVal, const int* bsrMaskPtr, const int* bsrRowPtr, const int* bsrEndPtr, const int* bsrColInd, int blockDim, const float* x, const float* beta, float* y) { return hipsparseSbsrxmv(handle, dir, trans, sizeOfMask, mb, nb, nnzb, alpha, descr, bsrVal, bsrMaskPtr, bsrRowPtr, bsrEndPtr, bsrColInd, blockDim, x, beta, y); } template <> hipsparseStatus_t hipsparseXbsrxmv(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t trans, int sizeOfMask, int mb, int nb, int nnzb, const double* alpha, const hipsparseMatDescr_t descr, const double* bsrVal, const int* bsrMaskPtr, const int* bsrRowPtr, const int* bsrEndPtr, const int* bsrColInd, int blockDim, const double* x, const double* beta, double* y) { return hipsparseDbsrxmv(handle, dir, trans, sizeOfMask, mb, nb, nnzb, alpha, descr, bsrVal, bsrMaskPtr, bsrRowPtr, bsrEndPtr, bsrColInd, blockDim, x, beta, y); } template <> hipsparseStatus_t hipsparseXbsrxmv(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t trans, int sizeOfMask, int mb, int nb, int nnzb, const hipComplex* alpha, const hipsparseMatDescr_t descr, const hipComplex* bsrVal, const int* bsrMaskPtr, const int* bsrRowPtr, const int* bsrEndPtr, const int* bsrColInd, int blockDim, const hipComplex* x, const hipComplex* beta, hipComplex* y) { return hipsparseCbsrxmv(handle, dir, trans, sizeOfMask, mb, nb, nnzb, alpha, descr, bsrVal, bsrMaskPtr, bsrRowPtr, bsrEndPtr, bsrColInd, blockDim, x, beta, y); } template <> hipsparseStatus_t hipsparseXbsrxmv(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t trans, int sizeOfMask, int mb, int nb, int nnzb, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descr, const hipDoubleComplex* bsrVal, const int* bsrMaskPtr, const int* bsrRowPtr, const int* bsrEndPtr, const int* bsrColInd, int blockDim, const hipDoubleComplex* x, const hipDoubleComplex* beta, hipDoubleComplex* y) { return hipsparseZbsrxmv(handle, dir, trans, sizeOfMask, mb, nb, nnzb, alpha, descr, bsrVal, bsrMaskPtr, bsrRowPtr, bsrEndPtr, bsrColInd, blockDim, x, beta, y); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXbsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, int* pBufferSizeInBytes) { return hipsparseSbsrsv2_bufferSize(handle, dir, transA, mb, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXbsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, int* pBufferSizeInBytes) { return hipsparseDbsrsv2_bufferSize(handle, dir, transA, mb, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXbsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, int* pBufferSizeInBytes) { return hipsparseCbsrsv2_bufferSize(handle, dir, transA, mb, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXbsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, int* pBufferSizeInBytes) { return hipsparseZbsrsv2_bufferSize(handle, dir, transA, mb, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, pBufferSizeInBytes); } #endif template <> hipsparseStatus_t hipsparseXbsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, size_t* pBufferSizeInBytes) { return hipsparseSbsrsv2_bufferSizeExt(handle, dir, transA, mb, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXbsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, size_t* pBufferSizeInBytes) { return hipsparseDbsrsv2_bufferSizeExt(handle, dir, transA, mb, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXbsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, size_t* pBufferSizeInBytes) { return hipsparseCbsrsv2_bufferSizeExt(handle, dir, transA, mb, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXbsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, size_t* pBufferSizeInBytes) { return hipsparseZbsrsv2_bufferSizeExt(handle, dir, transA, mb, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, pBufferSizeInBytes); } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXbsrsv2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseSbsrsv2_analysis(handle, dir, transA, mb, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsrsv2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseDbsrsv2_analysis(handle, dir, transA, mb, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsrsv2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseCbsrsv2_analysis(handle, dir, transA, mb, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsrsv2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseZbsrsv2_analysis(handle, dir, transA, mb, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, policy, pBuffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXbsrsv2_solve(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const float* alpha, const hipsparseMatDescr_t descrA, const float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, const float* f, float* x, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseSbsrsv2_solve(handle, dir, transA, mb, nnzb, alpha, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, f, x, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsrsv2_solve(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const double* alpha, const hipsparseMatDescr_t descrA, const double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, const double* f, double* x, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseDbsrsv2_solve(handle, dir, transA, mb, nnzb, alpha, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, f, x, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsrsv2_solve(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, const hipComplex* f, hipComplex* x, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseCbsrsv2_solve(handle, dir, transA, mb, nnzb, alpha, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, f, x, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsrsv2_solve(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, const hipDoubleComplex* f, hipDoubleComplex* x, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseZbsrsv2_solve(handle, dir, transA, mb, nnzb, alpha, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, f, x, policy, pBuffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXgemvi_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, int* pBufferSizeInBytes) { return hipsparseSgemvi_bufferSize(handle, transA, m, n, nnz, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgemvi_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, int* pBufferSizeInBytes) { return hipsparseDgemvi_bufferSize(handle, transA, m, n, nnz, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgemvi_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, int* pBufferSizeInBytes) { return hipsparseCgemvi_bufferSize(handle, transA, m, n, nnz, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgemvi_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, int* pBufferSizeInBytes) { return hipsparseZgemvi_bufferSize(handle, transA, m, n, nnz, pBufferSizeInBytes); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXgemvi(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, const float* alpha, const float* A, int lda, int nnz, const float* x, const int* xInd, const float* beta, float* y, hipsparseIndexBase_t idxBase, void* pBuffer) { return hipsparseSgemvi( handle, transA, m, n, alpha, A, lda, nnz, x, xInd, beta, y, idxBase, pBuffer); } template <> hipsparseStatus_t hipsparseXgemvi(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, const double* alpha, const double* A, int lda, int nnz, const double* x, const int* xInd, const double* beta, double* y, hipsparseIndexBase_t idxBase, void* pBuffer) { return hipsparseDgemvi( handle, transA, m, n, alpha, A, lda, nnz, x, xInd, beta, y, idxBase, pBuffer); } template <> hipsparseStatus_t hipsparseXgemvi(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, const hipComplex* alpha, const hipComplex* A, int lda, int nnz, const hipComplex* x, const int* xInd, const hipComplex* beta, hipComplex* y, hipsparseIndexBase_t idxBase, void* pBuffer) { return hipsparseCgemvi( handle, transA, m, n, alpha, A, lda, nnz, x, xInd, beta, y, idxBase, pBuffer); } template <> hipsparseStatus_t hipsparseXgemvi(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, const hipDoubleComplex* alpha, const hipDoubleComplex* A, int lda, int nnz, const hipDoubleComplex* x, const int* xInd, const hipDoubleComplex* beta, hipDoubleComplex* y, hipsparseIndexBase_t idxBase, void* pBuffer) { return hipsparseZgemvi( handle, transA, m, n, alpha, A, lda, nnz, x, xInd, beta, y, idxBase, pBuffer); } #endif template <> hipsparseStatus_t hipsparseXbsrmm(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transB, int mb, int n, int kb, int nnzb, const float* alpha, const hipsparseMatDescr_t descrA, const float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const float* B, int ldb, const float* beta, float* C, int ldc) { return hipsparseSbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, alpha, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, B, ldb, beta, C, ldc); } template <> hipsparseStatus_t hipsparseXbsrmm(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transB, int mb, int n, int kb, int nnzb, const double* alpha, const hipsparseMatDescr_t descrA, const double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const double* B, int ldb, const double* beta, double* C, int ldc) { return hipsparseDbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, alpha, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, B, ldb, beta, C, ldc); } template <> hipsparseStatus_t hipsparseXbsrmm(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transB, int mb, int n, int kb, int nnzb, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const hipComplex* B, int ldb, const hipComplex* beta, hipComplex* C, int ldc) { return hipsparseCbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, alpha, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, B, ldb, beta, C, ldc); } template <> hipsparseStatus_t hipsparseXbsrmm(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transB, int mb, int n, int kb, int nnzb, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const hipDoubleComplex* B, int ldb, const hipDoubleComplex* beta, hipDoubleComplex* C, int ldc) { return hipsparseZbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, alpha, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, B, ldb, beta, C, ldc); } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template <> hipsparseStatus_t hipsparseXcsrmm2(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, int nnz, const float* alpha, const hipsparseMatDescr_t descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, const float* B, int ldb, const float* beta, float* C, int ldc) { return hipsparseScsrmm2(handle, transA, transB, m, n, k, nnz, alpha, descr, csrVal, csrRowPtr, csrColInd, B, ldb, beta, C, ldc); } template <> hipsparseStatus_t hipsparseXcsrmm2(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, int nnz, const double* alpha, const hipsparseMatDescr_t descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, const double* B, int ldb, const double* beta, double* C, int ldc) { return hipsparseDcsrmm2(handle, transA, transB, m, n, k, nnz, alpha, descr, csrVal, csrRowPtr, csrColInd, B, ldb, beta, C, ldc); } template <> hipsparseStatus_t hipsparseXcsrmm2(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, int nnz, const hipComplex* alpha, const hipsparseMatDescr_t descr, const hipComplex* csrVal, const int* csrRowPtr, const int* csrColInd, const hipComplex* B, int ldb, const hipComplex* beta, hipComplex* C, int ldc) { return hipsparseCcsrmm2(handle, transA, transB, m, n, k, nnz, alpha, descr, csrVal, csrRowPtr, csrColInd, B, ldb, beta, C, ldc); } template <> hipsparseStatus_t hipsparseXcsrmm2(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, int nnz, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descr, const hipDoubleComplex* csrVal, const int* csrRowPtr, const int* csrColInd, const hipDoubleComplex* B, int ldb, const hipDoubleComplex* beta, hipDoubleComplex* C, int ldc) { return hipsparseZcsrmm2(handle, transA, transB, m, n, k, nnz, alpha, descr, csrVal, csrRowPtr, csrColInd, B, ldb, beta, C, ldc); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXbsrsm2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, int* pBufferSizeInBytes) { return hipsparseSbsrsm2_bufferSize(handle, dirA, transA, transX, mb, nrhs, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXbsrsm2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, int* pBufferSizeInBytes) { return hipsparseDbsrsm2_bufferSize(handle, dirA, transA, transX, mb, nrhs, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXbsrsm2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, int* pBufferSizeInBytes) { return hipsparseCbsrsm2_bufferSize(handle, dirA, transA, transX, mb, nrhs, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXbsrsm2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, int* pBufferSizeInBytes) { return hipsparseZbsrsm2_bufferSize(handle, dirA, transA, transX, mb, nrhs, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, pBufferSizeInBytes); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXbsrsm2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, const float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseSbsrsm2_analysis(handle, dirA, transA, transX, mb, nrhs, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsrsm2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, const double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseDbsrsm2_analysis(handle, dirA, transA, transX, mb, nrhs, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsrsm2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, const hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseCbsrsm2_analysis(handle, dirA, transA, transX, mb, nrhs, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsrsm2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseZbsrsm2_analysis(handle, dirA, transA, transX, mb, nrhs, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, policy, pBuffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXbsrsm2_solve(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const float* alpha, const hipsparseMatDescr_t descrA, const float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, const float* B, int ldb, float* X, int ldx, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseSbsrsm2_solve(handle, dirA, transA, transX, mb, nrhs, nnzb, alpha, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, B, ldb, X, ldx, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsrsm2_solve(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const double* alpha, const hipsparseMatDescr_t descrA, const double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, const double* B, int ldb, double* X, int ldx, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseDbsrsm2_solve(handle, dirA, transA, transX, mb, nrhs, nnzb, alpha, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, B, ldb, X, ldx, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsrsm2_solve(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, const hipComplex* B, int ldb, hipComplex* X, int ldx, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseCbsrsm2_solve(handle, dirA, transA, transX, mb, nrhs, nnzb, alpha, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, B, ldb, X, ldx, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsrsm2_solve(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, const hipDoubleComplex* B, int ldb, hipDoubleComplex* X, int ldx, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseZbsrsm2_solve(handle, dirA, transA, transX, mb, nrhs, nnzb, alpha, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, B, ldb, X, ldx, policy, pBuffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXcsrsm2_bufferSizeExt(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const float* alpha, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const float* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, size_t* pBufferSizeInBytes) { return hipsparseScsrsm2_bufferSizeExt(handle, algo, transA, transB, m, nrhs, nnz, alpha, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, info, policy, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrsm2_bufferSizeExt(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const double* alpha, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const double* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, size_t* pBufferSizeInBytes) { return hipsparseDcsrsm2_bufferSizeExt(handle, algo, transA, transB, m, nrhs, nnz, alpha, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, info, policy, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrsm2_bufferSizeExt(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipComplex* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, size_t* pBufferSizeInBytes) { return hipsparseCcsrsm2_bufferSizeExt(handle, algo, transA, transB, m, nrhs, nnz, alpha, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, info, policy, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrsm2_bufferSizeExt(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipDoubleComplex* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, size_t* pBufferSizeInBytes) { return hipsparseZcsrsm2_bufferSizeExt(handle, algo, transA, transB, m, nrhs, nnz, alpha, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, info, policy, pBufferSizeInBytes); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXcsrsm2_analysis(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const float* alpha, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const float* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseScsrsm2_analysis(handle, algo, transA, transB, m, nrhs, nnz, alpha, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrsm2_analysis(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const double* alpha, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const double* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseDcsrsm2_analysis(handle, algo, transA, transB, m, nrhs, nnz, alpha, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrsm2_analysis(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipComplex* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseCcsrsm2_analysis(handle, algo, transA, transB, m, nrhs, nnz, alpha, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrsm2_analysis(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipDoubleComplex* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseZcsrsm2_analysis(handle, algo, transA, transB, m, nrhs, nnz, alpha, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, info, policy, pBuffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXcsrsm2_solve(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const float* alpha, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, float* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseScsrsm2_solve(handle, algo, transA, transB, m, nrhs, nnz, alpha, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrsm2_solve(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const double* alpha, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, double* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseDcsrsm2_solve(handle, algo, transA, transB, m, nrhs, nnz, alpha, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrsm2_solve(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, hipComplex* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseCcsrsm2_solve(handle, algo, transA, transB, m, nrhs, nnz, alpha, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrsm2_solve(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, hipDoubleComplex* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseZcsrsm2_solve(handle, algo, transA, transB, m, nrhs, nnz, alpha, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, info, policy, pBuffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXgemmi(hipsparseHandle_t handle, int m, int n, int k, int nnz, const float* alpha, const float* A, int lda, const float* cscValB, const int* cscColPtrB, const int* cscRowIndB, const float* beta, float* C, int ldc) { return hipsparseSgemmi( handle, m, n, k, nnz, alpha, A, lda, cscValB, cscColPtrB, cscRowIndB, beta, C, ldc); } template <> hipsparseStatus_t hipsparseXgemmi(hipsparseHandle_t handle, int m, int n, int k, int nnz, const double* alpha, const double* A, int lda, const double* cscValB, const int* cscColPtrB, const int* cscRowIndB, const double* beta, double* C, int ldc) { return hipsparseDgemmi( handle, m, n, k, nnz, alpha, A, lda, cscValB, cscColPtrB, cscRowIndB, beta, C, ldc); } template <> hipsparseStatus_t hipsparseXgemmi(hipsparseHandle_t handle, int m, int n, int k, int nnz, const hipComplex* alpha, const hipComplex* A, int lda, const hipComplex* cscValB, const int* cscColPtrB, const int* cscRowIndB, const hipComplex* beta, hipComplex* C, int ldc) { return hipsparseCgemmi( handle, m, n, k, nnz, alpha, A, lda, cscValB, cscColPtrB, cscRowIndB, beta, C, ldc); } template <> hipsparseStatus_t hipsparseXgemmi(hipsparseHandle_t handle, int m, int n, int k, int nnz, const hipDoubleComplex* alpha, const hipDoubleComplex* A, int lda, const hipDoubleComplex* cscValB, const int* cscColPtrB, const int* cscRowIndB, const hipDoubleComplex* beta, hipDoubleComplex* C, int ldc) { return hipsparseZgemmi( handle, m, n, k, nnz, alpha, A, lda, cscValB, cscColPtrB, cscRowIndB, beta, C, ldc); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template <> hipsparseStatus_t hipsparseXcsrgeam(hipsparseHandle_t handle, int m, int n, const float* alpha, const hipsparseMatDescr_t descrA, int nnzA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const float* beta, const hipsparseMatDescr_t descrB, int nnzB, const float* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, float* csrSortedValC, int* csrSortedRowPtrC, int* csrSortedColIndC) { return hipsparseScsrgeam(handle, m, n, alpha, descrA, nnzA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, beta, descrB, nnzB, csrSortedValB, csrSortedRowPtrB, csrSortedColIndB, descrC, csrSortedValC, csrSortedRowPtrC, csrSortedColIndC); } template <> hipsparseStatus_t hipsparseXcsrgeam(hipsparseHandle_t handle, int m, int n, const double* alpha, const hipsparseMatDescr_t descrA, int nnzA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const double* beta, const hipsparseMatDescr_t descrB, int nnzB, const double* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, double* csrSortedValC, int* csrSortedRowPtrC, int* csrSortedColIndC) { return hipsparseDcsrgeam(handle, m, n, alpha, descrA, nnzA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, beta, descrB, nnzB, csrSortedValB, csrSortedRowPtrB, csrSortedColIndB, descrC, csrSortedValC, csrSortedRowPtrC, csrSortedColIndC); } template <> hipsparseStatus_t hipsparseXcsrgeam(hipsparseHandle_t handle, int m, int n, const hipComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipComplex* beta, const hipsparseMatDescr_t descrB, int nnzB, const hipComplex* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, hipComplex* csrSortedValC, int* csrSortedRowPtrC, int* csrSortedColIndC) { return hipsparseCcsrgeam(handle, m, n, alpha, descrA, nnzA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, beta, descrB, nnzB, csrSortedValB, csrSortedRowPtrB, csrSortedColIndB, descrC, csrSortedValC, csrSortedRowPtrC, csrSortedColIndC); } template <> hipsparseStatus_t hipsparseXcsrgeam(hipsparseHandle_t handle, int m, int n, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipDoubleComplex* beta, const hipsparseMatDescr_t descrB, int nnzB, const hipDoubleComplex* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, hipDoubleComplex* csrSortedValC, int* csrSortedRowPtrC, int* csrSortedColIndC) { return hipsparseZcsrgeam(handle, m, n, alpha, descrA, nnzA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, beta, descrB, nnzB, csrSortedValB, csrSortedRowPtrB, csrSortedColIndB, descrC, csrSortedValC, csrSortedRowPtrC, csrSortedColIndC); } #endif template <> hipsparseStatus_t hipsparseXcsrgeam2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const float* alpha, const hipsparseMatDescr_t descrA, int nnzA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const float* beta, const hipsparseMatDescr_t descrB, int nnzB, const float* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, const float* csrSortedValC, const int* csrSortedRowPtrC, const int* csrSortedColIndC, size_t* pBufferSizeInBytes) { return hipsparseScsrgeam2_bufferSizeExt(handle, m, n, alpha, descrA, nnzA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, beta, descrB, nnzB, csrSortedValB, csrSortedRowPtrB, csrSortedColIndB, descrC, csrSortedValC, csrSortedRowPtrC, csrSortedColIndC, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrgeam2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const double* alpha, const hipsparseMatDescr_t descrA, int nnzA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const double* beta, const hipsparseMatDescr_t descrB, int nnzB, const double* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, const double* csrSortedValC, const int* csrSortedRowPtrC, const int* csrSortedColIndC, size_t* pBufferSizeInBytes) { return hipsparseDcsrgeam2_bufferSizeExt(handle, m, n, alpha, descrA, nnzA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, beta, descrB, nnzB, csrSortedValB, csrSortedRowPtrB, csrSortedColIndB, descrC, csrSortedValC, csrSortedRowPtrC, csrSortedColIndC, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrgeam2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const hipComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipComplex* beta, const hipsparseMatDescr_t descrB, int nnzB, const hipComplex* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, const hipComplex* csrSortedValC, const int* csrSortedRowPtrC, const int* csrSortedColIndC, size_t* pBufferSizeInBytes) { return hipsparseCcsrgeam2_bufferSizeExt(handle, m, n, alpha, descrA, nnzA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, beta, descrB, nnzB, csrSortedValB, csrSortedRowPtrB, csrSortedColIndB, descrC, csrSortedValC, csrSortedRowPtrC, csrSortedColIndC, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrgeam2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipDoubleComplex* beta, const hipsparseMatDescr_t descrB, int nnzB, const hipDoubleComplex* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, const hipDoubleComplex* csrSortedValC, const int* csrSortedRowPtrC, const int* csrSortedColIndC, size_t* pBufferSizeInBytes) { return hipsparseZcsrgeam2_bufferSizeExt(handle, m, n, alpha, descrA, nnzA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, beta, descrB, nnzB, csrSortedValB, csrSortedRowPtrB, csrSortedColIndB, descrC, csrSortedValC, csrSortedRowPtrC, csrSortedColIndC, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrgeam2(hipsparseHandle_t handle, int m, int n, const float* alpha, const hipsparseMatDescr_t descrA, int nnzA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const float* beta, const hipsparseMatDescr_t descrB, int nnzB, const float* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, float* csrSortedValC, int* csrSortedRowPtrC, int* csrSortedColIndC, void* pBuffer) { return hipsparseScsrgeam2(handle, m, n, alpha, descrA, nnzA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, beta, descrB, nnzB, csrSortedValB, csrSortedRowPtrB, csrSortedColIndB, descrC, csrSortedValC, csrSortedRowPtrC, csrSortedColIndC, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrgeam2(hipsparseHandle_t handle, int m, int n, const double* alpha, const hipsparseMatDescr_t descrA, int nnzA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const double* beta, const hipsparseMatDescr_t descrB, int nnzB, const double* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, double* csrSortedValC, int* csrSortedRowPtrC, int* csrSortedColIndC, void* pBuffer) { return hipsparseDcsrgeam2(handle, m, n, alpha, descrA, nnzA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, beta, descrB, nnzB, csrSortedValB, csrSortedRowPtrB, csrSortedColIndB, descrC, csrSortedValC, csrSortedRowPtrC, csrSortedColIndC, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrgeam2(hipsparseHandle_t handle, int m, int n, const hipComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipComplex* beta, const hipsparseMatDescr_t descrB, int nnzB, const hipComplex* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, hipComplex* csrSortedValC, int* csrSortedRowPtrC, int* csrSortedColIndC, void* pBuffer) { return hipsparseCcsrgeam2(handle, m, n, alpha, descrA, nnzA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, beta, descrB, nnzB, csrSortedValB, csrSortedRowPtrB, csrSortedColIndB, descrC, csrSortedValC, csrSortedRowPtrC, csrSortedColIndC, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrgeam2(hipsparseHandle_t handle, int m, int n, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipDoubleComplex* beta, const hipsparseMatDescr_t descrB, int nnzB, const hipDoubleComplex* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, hipDoubleComplex* csrSortedValC, int* csrSortedRowPtrC, int* csrSortedColIndC, void* pBuffer) { return hipsparseZcsrgeam2(handle, m, n, alpha, descrA, nnzA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, beta, descrB, nnzB, csrSortedValB, csrSortedRowPtrB, csrSortedColIndB, descrC, csrSortedValC, csrSortedRowPtrC, csrSortedColIndC, pBuffer); } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template <> hipsparseStatus_t hipsparseXcsrgemm(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, const hipsparseMatDescr_t descrA, int nnzA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const float* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, float* csrValC, const int* csrRowPtrC, int* csrColIndC) { return hipsparseScsrgemm(handle, transA, transB, m, n, k, descrA, nnzA, csrValA, csrRowPtrA, csrColIndA, descrB, nnzB, csrValB, csrRowPtrB, csrColIndB, descrC, csrValC, csrRowPtrC, csrColIndC); } template <> hipsparseStatus_t hipsparseXcsrgemm(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, const hipsparseMatDescr_t descrA, int nnzA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const double* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, double* csrValC, const int* csrRowPtrC, int* csrColIndC) { return hipsparseDcsrgemm(handle, transA, transB, m, n, k, descrA, nnzA, csrValA, csrRowPtrA, csrColIndA, descrB, nnzB, csrValB, csrRowPtrB, csrColIndB, descrC, csrValC, csrRowPtrC, csrColIndC); } template <> hipsparseStatus_t hipsparseXcsrgemm(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, const hipsparseMatDescr_t descrA, int nnzA, const hipComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const hipComplex* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, hipComplex* csrValC, const int* csrRowPtrC, int* csrColIndC) { return hipsparseCcsrgemm(handle, transA, transB, m, n, k, descrA, nnzA, csrValA, csrRowPtrA, csrColIndA, descrB, nnzB, csrValB, csrRowPtrB, csrColIndB, descrC, csrValC, csrRowPtrC, csrColIndC); } template <> hipsparseStatus_t hipsparseXcsrgemm(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, const hipsparseMatDescr_t descrA, int nnzA, const hipDoubleComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const hipDoubleComplex* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, hipDoubleComplex* csrValC, const int* csrRowPtrC, int* csrColIndC) { return hipsparseZcsrgemm(handle, transA, transB, m, n, k, descrA, nnzA, csrValA, csrRowPtrA, csrColIndA, descrB, nnzB, csrValB, csrRowPtrB, csrColIndB, descrC, csrValC, csrRowPtrC, csrColIndC); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXcsrgemm2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int k, const float* alpha, const hipsparseMatDescr_t descrA, int nnzA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const int* csrRowPtrB, const int* csrColIndB, const float* beta, const hipsparseMatDescr_t descrD, int nnzD, const int* csrRowPtrD, const int* csrColIndD, csrgemm2Info_t info, size_t* pBufferSizeInBytes) { return hipsparseScsrgemm2_bufferSizeExt(handle, m, n, k, alpha, descrA, nnzA, csrRowPtrA, csrColIndA, descrB, nnzB, csrRowPtrB, csrColIndB, beta, descrD, nnzD, csrRowPtrD, csrColIndD, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrgemm2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int k, const double* alpha, const hipsparseMatDescr_t descrA, int nnzA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const int* csrRowPtrB, const int* csrColIndB, const double* beta, const hipsparseMatDescr_t descrD, int nnzD, const int* csrRowPtrD, const int* csrColIndD, csrgemm2Info_t info, size_t* pBufferSizeInBytes) { return hipsparseDcsrgemm2_bufferSizeExt(handle, m, n, k, alpha, descrA, nnzA, csrRowPtrA, csrColIndA, descrB, nnzB, csrRowPtrB, csrColIndB, beta, descrD, nnzD, csrRowPtrD, csrColIndD, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrgemm2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int k, const hipComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const int* csrRowPtrB, const int* csrColIndB, const hipComplex* beta, const hipsparseMatDescr_t descrD, int nnzD, const int* csrRowPtrD, const int* csrColIndD, csrgemm2Info_t info, size_t* pBufferSizeInBytes) { return hipsparseCcsrgemm2_bufferSizeExt(handle, m, n, k, alpha, descrA, nnzA, csrRowPtrA, csrColIndA, descrB, nnzB, csrRowPtrB, csrColIndB, beta, descrD, nnzD, csrRowPtrD, csrColIndD, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrgemm2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int k, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const int* csrRowPtrB, const int* csrColIndB, const hipDoubleComplex* beta, const hipsparseMatDescr_t descrD, int nnzD, const int* csrRowPtrD, const int* csrColIndD, csrgemm2Info_t info, size_t* pBufferSizeInBytes) { return hipsparseZcsrgemm2_bufferSizeExt(handle, m, n, k, alpha, descrA, nnzA, csrRowPtrA, csrColIndA, descrB, nnzB, csrRowPtrB, csrColIndB, beta, descrD, nnzD, csrRowPtrD, csrColIndD, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrgemm2(hipsparseHandle_t handle, int m, int n, int k, const float* alpha, const hipsparseMatDescr_t descrA, int nnzA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const float* csrValB, const int* csrRowPtrB, const int* csrColIndB, const float* beta, const hipsparseMatDescr_t descrD, int nnzD, const float* csrValD, const int* csrRowPtrD, const int* csrColIndD, const hipsparseMatDescr_t descrC, float* csrValC, const int* csrRowPtrC, int* csrColIndC, const csrgemm2Info_t info, void* pBuffer) { return hipsparseScsrgemm2(handle, m, n, k, alpha, descrA, nnzA, csrValA, csrRowPtrA, csrColIndA, descrB, nnzB, csrValB, csrRowPtrB, csrColIndB, beta, descrD, nnzD, csrValD, csrRowPtrD, csrColIndD, descrC, csrValC, csrRowPtrC, csrColIndC, info, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrgemm2(hipsparseHandle_t handle, int m, int n, int k, const double* alpha, const hipsparseMatDescr_t descrA, int nnzA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const double* csrValB, const int* csrRowPtrB, const int* csrColIndB, const double* beta, const hipsparseMatDescr_t descrD, int nnzD, const double* csrValD, const int* csrRowPtrD, const int* csrColIndD, const hipsparseMatDescr_t descrC, double* csrValC, const int* csrRowPtrC, int* csrColIndC, const csrgemm2Info_t info, void* pBuffer) { return hipsparseDcsrgemm2(handle, m, n, k, alpha, descrA, nnzA, csrValA, csrRowPtrA, csrColIndA, descrB, nnzB, csrValB, csrRowPtrB, csrColIndB, beta, descrD, nnzD, csrValD, csrRowPtrD, csrColIndD, descrC, csrValC, csrRowPtrC, csrColIndC, info, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrgemm2(hipsparseHandle_t handle, int m, int n, int k, const hipComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const hipComplex* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipComplex* beta, const hipsparseMatDescr_t descrD, int nnzD, const hipComplex* csrValD, const int* csrRowPtrD, const int* csrColIndD, const hipsparseMatDescr_t descrC, hipComplex* csrValC, const int* csrRowPtrC, int* csrColIndC, const csrgemm2Info_t info, void* pBuffer) { return hipsparseCcsrgemm2(handle, m, n, k, alpha, descrA, nnzA, csrValA, csrRowPtrA, csrColIndA, descrB, nnzB, csrValB, csrRowPtrB, csrColIndB, beta, descrD, nnzD, csrValD, csrRowPtrD, csrColIndD, descrC, csrValC, csrRowPtrC, csrColIndC, info, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrgemm2(hipsparseHandle_t handle, int m, int n, int k, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipDoubleComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const hipDoubleComplex* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipDoubleComplex* beta, const hipsparseMatDescr_t descrD, int nnzD, const hipDoubleComplex* csrValD, const int* csrRowPtrD, const int* csrColIndD, const hipsparseMatDescr_t descrC, hipDoubleComplex* csrValC, const int* csrRowPtrC, int* csrColIndC, const csrgemm2Info_t info, void* pBuffer) { return hipsparseZcsrgemm2(handle, m, n, k, alpha, descrA, nnzA, csrValA, csrRowPtrA, csrColIndA, descrB, nnzB, csrValB, csrRowPtrB, csrColIndB, beta, descrD, nnzD, csrValD, csrRowPtrD, csrColIndD, descrC, csrValC, csrRowPtrC, csrColIndC, info, pBuffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXbsrilu02_numericBoost(hipsparseHandle_t handle, bsrilu02Info_t info, int enable_boost, double* tol, float* boost_val) { return hipsparseSbsrilu02_numericBoost(handle, info, enable_boost, tol, boost_val); } template <> hipsparseStatus_t hipsparseXbsrilu02_numericBoost(hipsparseHandle_t handle, bsrilu02Info_t info, int enable_boost, double* tol, double* boost_val) { return hipsparseDbsrilu02_numericBoost(handle, info, enable_boost, tol, boost_val); } template <> hipsparseStatus_t hipsparseXbsrilu02_numericBoost(hipsparseHandle_t handle, bsrilu02Info_t info, int enable_boost, double* tol, hipComplex* boost_val) { return hipsparseCbsrilu02_numericBoost(handle, info, enable_boost, tol, boost_val); } template <> hipsparseStatus_t hipsparseXbsrilu02_numericBoost(hipsparseHandle_t handle, bsrilu02Info_t info, int enable_boost, double* tol, hipDoubleComplex* boost_val) { return hipsparseZbsrilu02_numericBoost(handle, info, enable_boost, tol, boost_val); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXbsrilu02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsrilu02Info_t info, int* pBufferSizeInBytes) { return hipsparseSbsrilu02_bufferSize(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXbsrilu02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsrilu02Info_t info, int* pBufferSizeInBytes) { return hipsparseDbsrilu02_bufferSize(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXbsrilu02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsrilu02Info_t info, int* pBufferSizeInBytes) { return hipsparseCbsrilu02_bufferSize(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXbsrilu02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsrilu02Info_t info, int* pBufferSizeInBytes) { return hipsparseZbsrilu02_bufferSize(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, pBufferSizeInBytes); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXbsrilu02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseSbsrilu02_analysis(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsrilu02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseDbsrilu02_analysis(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsrilu02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseCbsrilu02_analysis(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsrilu02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseZbsrilu02_analysis(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, policy, pBuffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXbsrilu02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseSbsrilu02(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsrilu02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseDbsrilu02(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsrilu02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseCbsrilu02(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsrilu02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseZbsrilu02(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, policy, pBuffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXcsrilu02_numericBoost(hipsparseHandle_t handle, csrilu02Info_t info, int enable_boost, double* tol, float* boost_val) { return hipsparseScsrilu02_numericBoost(handle, info, enable_boost, tol, boost_val); } template <> hipsparseStatus_t hipsparseXcsrilu02_numericBoost(hipsparseHandle_t handle, csrilu02Info_t info, int enable_boost, double* tol, double* boost_val) { return hipsparseDcsrilu02_numericBoost(handle, info, enable_boost, tol, boost_val); } template <> hipsparseStatus_t hipsparseXcsrilu02_numericBoost(hipsparseHandle_t handle, csrilu02Info_t info, int enable_boost, double* tol, hipComplex* boost_val) { return hipsparseCcsrilu02_numericBoost(handle, info, enable_boost, tol, boost_val); } template <> hipsparseStatus_t hipsparseXcsrilu02_numericBoost(hipsparseHandle_t handle, csrilu02Info_t info, int enable_boost, double* tol, hipDoubleComplex* boost_val) { return hipsparseZcsrilu02_numericBoost(handle, info, enable_boost, tol, boost_val); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXcsrilu02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, int* pBufferSizeInBytes) { return hipsparseScsrilu02_bufferSize(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrilu02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, int* pBufferSizeInBytes) { return hipsparseDcsrilu02_bufferSize(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrilu02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, int* pBufferSizeInBytes) { return hipsparseCcsrilu02_bufferSize(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrilu02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, int* pBufferSizeInBytes) { return hipsparseZcsrilu02_bufferSize(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } #endif template <> hipsparseStatus_t hipsparseXcsrilu02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, size_t* pBufferSizeInBytes) { return hipsparseScsrilu02_bufferSizeExt(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrilu02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, size_t* pBufferSizeInBytes) { return hipsparseDcsrilu02_bufferSizeExt(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrilu02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, size_t* pBufferSizeInBytes) { return hipsparseCcsrilu02_bufferSizeExt(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrilu02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, size_t* pBufferSizeInBytes) { return hipsparseZcsrilu02_bufferSizeExt(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXcsrilu02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseScsrilu02_analysis(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrilu02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseDcsrilu02_analysis(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrilu02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseCcsrilu02_analysis(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrilu02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseZcsrilu02_analysis(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXcsrilu02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseScsrilu02(handle, m, nnz, descrA, csrSortedValA_valM, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrilu02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseDcsrilu02(handle, m, nnz, descrA, csrSortedValA_valM, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrilu02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseCcsrilu02(handle, m, nnz, descrA, csrSortedValA_valM, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrilu02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseZcsrilu02(handle, m, nnz, descrA, csrSortedValA_valM, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXbsric02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, int* pBufferSizeInBytes) { return hipsparseSbsric02_bufferSize(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXbsric02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, int* pBufferSizeInBytes) { return hipsparseDbsric02_bufferSize(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXbsric02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, int* pBufferSizeInBytes) { return hipsparseCbsric02_bufferSize(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXbsric02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, int* pBufferSizeInBytes) { return hipsparseZbsric02_bufferSize(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, pBufferSizeInBytes); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXbsric02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseSbsric02_analysis(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsric02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseDbsric02_analysis(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsric02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseCbsric02_analysis(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsric02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseZbsric02_analysis(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, policy, pBuffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXbsric02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseSbsric02(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsric02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseDbsric02(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsric02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseCbsric02(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsric02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseZbsric02(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, policy, pBuffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXcsric02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, int* pBufferSizeInBytes) { return hipsparseScsric02_bufferSize(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsric02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, int* pBufferSizeInBytes) { return hipsparseDcsric02_bufferSize(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsric02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, int* pBufferSizeInBytes) { return hipsparseCcsric02_bufferSize(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsric02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, int* pBufferSizeInBytes) { return hipsparseZcsric02_bufferSize(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } #endif template <> hipsparseStatus_t hipsparseXcsric02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, size_t* pBufferSizeInBytes) { return hipsparseScsric02_bufferSizeExt(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsric02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, size_t* pBufferSizeInBytes) { return hipsparseDcsric02_bufferSizeExt(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsric02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, size_t* pBufferSizeInBytes) { return hipsparseCcsric02_bufferSizeExt(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsric02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, size_t* pBufferSizeInBytes) { return hipsparseZcsric02_bufferSizeExt(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXcsric02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseScsric02_analysis(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsric02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseDcsric02_analysis(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsric02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseCcsric02_analysis(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsric02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseZcsric02_analysis(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXcsric02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseScsric02(handle, m, nnz, descrA, csrSortedValA_valM, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsric02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseDcsric02(handle, m, nnz, descrA, csrSortedValA_valM, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsric02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseCcsric02(handle, m, nnz, descrA, csrSortedValA_valM, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsric02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseZcsric02(handle, m, nnz, descrA, csrSortedValA_valM, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } #endif template <> hipsparseStatus_t hipsparseXnnz(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const float* A, int lda, int* nnzPerRowColumn, int* nnzTotalDevHostPtr) { return hipsparseSnnz( handle, dirA, m, n, descrA, A, lda, nnzPerRowColumn, nnzTotalDevHostPtr); } template <> hipsparseStatus_t hipsparseXnnz(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const double* A, int lda, int* nnzPerRowColumn, int* nnzTotalDevHostPtr) { return hipsparseDnnz( handle, dirA, m, n, descrA, A, lda, nnzPerRowColumn, nnzTotalDevHostPtr); } template <> hipsparseStatus_t hipsparseXnnz(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const hipComplex* A, int lda, int* nnzPerRowColumn, int* nnzTotalDevHostPtr) { return hipsparseCnnz( handle, dirA, m, n, descrA, A, lda, nnzPerRowColumn, nnzTotalDevHostPtr); } template <> hipsparseStatus_t hipsparseXnnz(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const hipDoubleComplex* A, int lda, int* nnzPerRowColumn, int* nnzTotalDevHostPtr) { return hipsparseZnnz( handle, dirA, m, n, descrA, A, lda, nnzPerRowColumn, nnzTotalDevHostPtr); } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXnnz_compress(hipsparseHandle_t handle, int m, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, int* nnzPerRow, int* nnzC, float tol) { return hipsparseSnnz_compress(handle, m, descrA, csrValA, csrRowPtrA, nnzPerRow, nnzC, tol); } template <> hipsparseStatus_t hipsparseXnnz_compress(hipsparseHandle_t handle, int m, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, int* nnzPerRow, int* nnzC, double tol) { return hipsparseDnnz_compress(handle, m, descrA, csrValA, csrRowPtrA, nnzPerRow, nnzC, tol); } template <> hipsparseStatus_t hipsparseXnnz_compress(hipsparseHandle_t handle, int m, const hipsparseMatDescr_t descrA, const hipComplex* csrValA, const int* csrRowPtrA, int* nnzPerRow, int* nnzC, hipComplex tol) { return hipsparseCnnz_compress(handle, m, descrA, csrValA, csrRowPtrA, nnzPerRow, nnzC, tol); } template <> hipsparseStatus_t hipsparseXnnz_compress(hipsparseHandle_t handle, int m, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrValA, const int* csrRowPtrA, int* nnzPerRow, int* nnzC, hipDoubleComplex tol) { return hipsparseZnnz_compress(handle, m, descrA, csrValA, csrRowPtrA, nnzPerRow, nnzC, tol); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXdense2csr(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const float* A, int ld, const int* nnzPerRow, float* csrVal, int* csrRowPtr, int* csrColInd) { return hipsparseSdense2csr( handle, m, n, descr, A, ld, nnzPerRow, csrVal, csrRowPtr, csrColInd); } template <> hipsparseStatus_t hipsparseXdense2csr(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const double* A, int ld, const int* nnzPerRow, double* csrVal, int* csrRowPtr, int* csrColInd) { return hipsparseDdense2csr( handle, m, n, descr, A, ld, nnzPerRow, csrVal, csrRowPtr, csrColInd); } template <> hipsparseStatus_t hipsparseXdense2csr(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipComplex* A, int ld, const int* nnzPerRow, hipComplex* csrVal, int* csrRowPtr, int* csrColInd) { return hipsparseCdense2csr( handle, m, n, descr, A, ld, nnzPerRow, csrVal, csrRowPtr, csrColInd); } template <> hipsparseStatus_t hipsparseXdense2csr(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipDoubleComplex* A, int ld, const int* nnzPerRow, hipDoubleComplex* csrVal, int* csrRowPtr, int* csrColInd) { return hipsparseZdense2csr( handle, m, n, descr, A, ld, nnzPerRow, csrVal, csrRowPtr, csrColInd); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXpruneDense2csr_bufferSize(hipsparseHandle_t handle, int m, int n, const float* A, int lda, const float* threshold, const hipsparseMatDescr_t descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, size_t* pBufferSizeInBytes) { return hipsparseSpruneDense2csr_bufferSize(handle, m, n, A, lda, threshold, descr, csrVal, csrRowPtr, csrColInd, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXpruneDense2csr_bufferSize(hipsparseHandle_t handle, int m, int n, const double* A, int lda, const double* threshold, const hipsparseMatDescr_t descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, size_t* pBufferSizeInBytes) { return hipsparseDpruneDense2csr_bufferSize(handle, m, n, A, lda, threshold, descr, csrVal, csrRowPtr, csrColInd, pBufferSizeInBytes); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXpruneDense2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const float* A, int lda, const float* threshold, const hipsparseMatDescr_t descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, size_t* pBufferSizeInBytes) { return hipsparseSpruneDense2csr_bufferSizeExt(handle, m, n, A, lda, threshold, descr, csrVal, csrRowPtr, csrColInd, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXpruneDense2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const double* A, int lda, const double* threshold, const hipsparseMatDescr_t descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, size_t* pBufferSizeInBytes) { return hipsparseDpruneDense2csr_bufferSizeExt(handle, m, n, A, lda, threshold, descr, csrVal, csrRowPtr, csrColInd, pBufferSizeInBytes); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXpruneDense2csrNnz(hipsparseHandle_t handle, int m, int n, const float* A, int lda, const float* threshold, const hipsparseMatDescr_t descr, int* csrRowPtr, int* nnzTotalDevHostPtr, void* buffer) { return hipsparseSpruneDense2csrNnz( handle, m, n, A, lda, threshold, descr, csrRowPtr, nnzTotalDevHostPtr, buffer); } template <> hipsparseStatus_t hipsparseXpruneDense2csrNnz(hipsparseHandle_t handle, int m, int n, const double* A, int lda, const double* threshold, const hipsparseMatDescr_t descr, int* csrRowPtr, int* nnzTotalDevHostPtr, void* buffer) { return hipsparseDpruneDense2csrNnz( handle, m, n, A, lda, threshold, descr, csrRowPtr, nnzTotalDevHostPtr, buffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXpruneDense2csr(hipsparseHandle_t handle, int m, int n, const float* A, int lda, const float* threshold, const hipsparseMatDescr_t descr, float* csrVal, const int* csrRowPtr, int* csrColInd, void* buffer) { return hipsparseSpruneDense2csr( handle, m, n, A, lda, threshold, descr, csrVal, csrRowPtr, csrColInd, buffer); } template <> hipsparseStatus_t hipsparseXpruneDense2csr(hipsparseHandle_t handle, int m, int n, const double* A, int lda, const double* threshold, const hipsparseMatDescr_t descr, double* csrVal, const int* csrRowPtr, int* csrColInd, void* buffer) { return hipsparseDpruneDense2csr( handle, m, n, A, lda, threshold, descr, csrVal, csrRowPtr, csrColInd, buffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXpruneDense2csrByPercentage_bufferSize(hipsparseHandle_t handle, int m, int n, const float* A, int lda, float percentage, const hipsparseMatDescr_t descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, pruneInfo_t info, size_t* pBufferSizeInBytes) { return hipsparseSpruneDense2csrByPercentage_bufferSize(handle, m, n, A, lda, percentage, descr, csrVal, csrRowPtr, csrColInd, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXpruneDense2csrByPercentage_bufferSize(hipsparseHandle_t handle, int m, int n, const double* A, int lda, double percentage, const hipsparseMatDescr_t descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, pruneInfo_t info, size_t* pBufferSizeInBytes) { return hipsparseDpruneDense2csrByPercentage_bufferSize(handle, m, n, A, lda, percentage, descr, csrVal, csrRowPtr, csrColInd, info, pBufferSizeInBytes); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXpruneDense2csrByPercentage_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const float* A, int lda, float percentage, const hipsparseMatDescr_t descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, pruneInfo_t info, size_t* pBufferSizeInBytes) { return hipsparseSpruneDense2csrByPercentage_bufferSizeExt(handle, m, n, A, lda, percentage, descr, csrVal, csrRowPtr, csrColInd, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXpruneDense2csrByPercentage_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const double* A, int lda, double percentage, const hipsparseMatDescr_t descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, pruneInfo_t info, size_t* pBufferSizeInBytes) { return hipsparseDpruneDense2csrByPercentage_bufferSizeExt(handle, m, n, A, lda, percentage, descr, csrVal, csrRowPtr, csrColInd, info, pBufferSizeInBytes); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXpruneDense2csrNnzByPercentage(hipsparseHandle_t handle, int m, int n, const float* A, int lda, float percentage, const hipsparseMatDescr_t descr, int* csrRowPtr, int* nnzTotalDevHostPtr, pruneInfo_t info, void* buffer) { return hipsparseSpruneDense2csrNnzByPercentage( handle, m, n, A, lda, percentage, descr, csrRowPtr, nnzTotalDevHostPtr, info, buffer); } template <> hipsparseStatus_t hipsparseXpruneDense2csrNnzByPercentage(hipsparseHandle_t handle, int m, int n, const double* A, int lda, double percentage, const hipsparseMatDescr_t descr, int* csrRowPtr, int* nnzTotalDevHostPtr, pruneInfo_t info, void* buffer) { return hipsparseDpruneDense2csrNnzByPercentage( handle, m, n, A, lda, percentage, descr, csrRowPtr, nnzTotalDevHostPtr, info, buffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXpruneDense2csrByPercentage(hipsparseHandle_t handle, int m, int n, const float* A, int lda, float percentage, const hipsparseMatDescr_t descr, float* csrVal, const int* csrRowPtr, int* csrColInd, pruneInfo_t info, void* buffer) { return hipsparseSpruneDense2csrByPercentage( handle, m, n, A, lda, percentage, descr, csrVal, csrRowPtr, csrColInd, info, buffer); } template <> hipsparseStatus_t hipsparseXpruneDense2csrByPercentage(hipsparseHandle_t handle, int m, int n, const double* A, int lda, double percentage, const hipsparseMatDescr_t descr, double* csrVal, const int* csrRowPtr, int* csrColInd, pruneInfo_t info, void* buffer) { return hipsparseDpruneDense2csrByPercentage( handle, m, n, A, lda, percentage, descr, csrVal, csrRowPtr, csrColInd, info, buffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXdense2csc(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const float* A, int ld, const int* nnzPerColumn, float* cscVal, int* cscRowInd, int* cscColPtr) { return hipsparseSdense2csc( handle, m, n, descr, A, ld, nnzPerColumn, cscVal, cscRowInd, cscColPtr); } template <> hipsparseStatus_t hipsparseXdense2csc(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const double* A, int ld, const int* nnzPerColumn, double* cscVal, int* cscRowInd, int* cscColPtr) { return hipsparseDdense2csc( handle, m, n, descr, A, ld, nnzPerColumn, cscVal, cscRowInd, cscColPtr); } template <> hipsparseStatus_t hipsparseXdense2csc(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipComplex* A, int ld, const int* nnzPerColumn, hipComplex* cscVal, int* cscRowInd, int* cscColPtr) { return hipsparseCdense2csc( handle, m, n, descr, A, ld, nnzPerColumn, cscVal, cscRowInd, cscColPtr); } template <> hipsparseStatus_t hipsparseXdense2csc(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipDoubleComplex* A, int ld, const int* nnzPerColumn, hipDoubleComplex* cscVal, int* cscRowInd, int* cscColPtr) { return hipsparseZdense2csc( handle, m, n, descr, A, ld, nnzPerColumn, cscVal, cscRowInd, cscColPtr); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXcsr2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, float* A, int ld) { return hipsparseScsr2dense(handle, m, n, descr, csrVal, csrRowPtr, csrColInd, A, ld); } template <> hipsparseStatus_t hipsparseXcsr2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, double* A, int ld) { return hipsparseDcsr2dense(handle, m, n, descr, csrVal, csrRowPtr, csrColInd, A, ld); } template <> hipsparseStatus_t hipsparseXcsr2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipComplex* csrVal, const int* csrRowPtr, const int* csrColInd, hipComplex* A, int ld) { return hipsparseCcsr2dense(handle, m, n, descr, csrVal, csrRowPtr, csrColInd, A, ld); } template <> hipsparseStatus_t hipsparseXcsr2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipDoubleComplex* csrVal, const int* csrRowPtr, const int* csrColInd, hipDoubleComplex* A, int ld) { return hipsparseZcsr2dense(handle, m, n, descr, csrVal, csrRowPtr, csrColInd, A, ld); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXcsc2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const float* cscVal, const int* cscRowInd, const int* cscColPtr, float* A, int ld) { return hipsparseScsc2dense(handle, m, n, descr, cscVal, cscRowInd, cscColPtr, A, ld); } template <> hipsparseStatus_t hipsparseXcsc2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const double* cscVal, const int* cscRowInd, const int* cscColPtr, double* A, int ld) { return hipsparseDcsc2dense(handle, m, n, descr, cscVal, cscRowInd, cscColPtr, A, ld); } template <> hipsparseStatus_t hipsparseXcsc2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipComplex* cscVal, const int* cscRowInd, const int* cscColPtr, hipComplex* A, int ld) { return hipsparseCcsc2dense(handle, m, n, descr, cscVal, cscRowInd, cscColPtr, A, ld); } template <> hipsparseStatus_t hipsparseXcsc2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipDoubleComplex* cscVal, const int* cscRowInd, const int* cscColPtr, hipDoubleComplex* A, int ld) { return hipsparseZcsc2dense(handle, m, n, descr, cscVal, cscRowInd, cscColPtr, A, ld); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template <> hipsparseStatus_t hipsparseXcsr2csc(hipsparseHandle_t handle, int m, int n, int nnz, const float* csrVal, const int* csrRowPtr, const int* csrColInd, float* csc_val, int* cscRowInd, int* cscColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase) { return hipsparseScsr2csc(handle, m, n, nnz, csrVal, csrRowPtr, csrColInd, csc_val, cscRowInd, cscColPtr, copyValues, idxBase); } template <> hipsparseStatus_t hipsparseXcsr2csc(hipsparseHandle_t handle, int m, int n, int nnz, const double* csrVal, const int* csrRowPtr, const int* csrColInd, double* csc_val, int* cscRowInd, int* cscColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase) { return hipsparseDcsr2csc(handle, m, n, nnz, csrVal, csrRowPtr, csrColInd, csc_val, cscRowInd, cscColPtr, copyValues, idxBase); } template <> hipsparseStatus_t hipsparseXcsr2csc(hipsparseHandle_t handle, int m, int n, int nnz, const hipComplex* csrVal, const int* csrRowPtr, const int* csrColInd, hipComplex* csc_val, int* cscRowInd, int* cscColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase) { return hipsparseCcsr2csc(handle, m, n, nnz, csrVal, csrRowPtr, csrColInd, csc_val, cscRowInd, cscColPtr, copyValues, idxBase); } template <> hipsparseStatus_t hipsparseXcsr2csc(hipsparseHandle_t handle, int m, int n, int nnz, const hipDoubleComplex* csrVal, const int* csrRowPtr, const int* csrColInd, hipDoubleComplex* csc_val, int* cscRowInd, int* cscColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase) { return hipsparseZcsr2csc(handle, m, n, nnz, csrVal, csrRowPtr, csrColInd, csc_val, cscRowInd, cscColPtr, copyValues, idxBase); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template <> hipsparseStatus_t hipsparseXcsr2hyb(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, hipsparseHybMat_t hyb, int user_ell_width, hipsparseHybPartition_t partition_type) { return hipsparseScsr2hyb( handle, m, n, descr, csrVal, csrRowPtr, csrColInd, hyb, user_ell_width, partition_type); } template <> hipsparseStatus_t hipsparseXcsr2hyb(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, hipsparseHybMat_t hyb, int user_ell_width, hipsparseHybPartition_t partition_type) { return hipsparseDcsr2hyb( handle, m, n, descr, csrVal, csrRowPtr, csrColInd, hyb, user_ell_width, partition_type); } template <> hipsparseStatus_t hipsparseXcsr2hyb(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipComplex* csrVal, const int* csrRowPtr, const int* csrColInd, hipsparseHybMat_t hyb, int user_ell_width, hipsparseHybPartition_t partition_type) { return hipsparseCcsr2hyb( handle, m, n, descr, csrVal, csrRowPtr, csrColInd, hyb, user_ell_width, partition_type); } template <> hipsparseStatus_t hipsparseXcsr2hyb(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipDoubleComplex* csrVal, const int* csrRowPtr, const int* csrColInd, hipsparseHybMat_t hyb, int user_ell_width, hipsparseHybPartition_t partition_type) { return hipsparseZcsr2hyb( handle, m, n, descr, csrVal, csrRowPtr, csrColInd, hyb, user_ell_width, partition_type); } #endif template <> hipsparseStatus_t hipsparseXgebsr2gebsc_bufferSize(hipsparseHandle_t handle, int mb, int nb, int nnzb, const float* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes) { return hipsparseSgebsr2gebsc_bufferSize(handle, mb, nb, nnzb, bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgebsr2gebsc_bufferSize(hipsparseHandle_t handle, int mb, int nb, int nnzb, const double* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes) { return hipsparseDgebsr2gebsc_bufferSize(handle, mb, nb, nnzb, bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgebsr2gebsc_bufferSize(hipsparseHandle_t handle, int mb, int nb, int nnzb, const hipComplex* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes) { return hipsparseCgebsr2gebsc_bufferSize(handle, mb, nb, nnzb, bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgebsr2gebsc_bufferSize(hipsparseHandle_t handle, int mb, int nb, int nnzb, const hipDoubleComplex* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes) { return hipsparseZgebsr2gebsc_bufferSize(handle, mb, nb, nnzb, bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgebsr2gebsc(hipsparseHandle_t handle, int mb, int nb, int nnzb, const float* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, float* bscVal, int* bscRowInd, int* bscColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase, void* temp_buffer) { return hipsparseSgebsr2gebsc(handle, mb, nb, nnzb, bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, bscVal, bscRowInd, bscColPtr, copyValues, idxBase, temp_buffer); } template <> hipsparseStatus_t hipsparseXgebsr2gebsc(hipsparseHandle_t handle, int mb, int nb, int nnzb, const double* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, double* bscVal, int* bscRowInd, int* bscColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase, void* temp_buffer) { return hipsparseDgebsr2gebsc(handle, mb, nb, nnzb, bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, bscVal, bscRowInd, bscColPtr, copyValues, idxBase, temp_buffer); } template <> hipsparseStatus_t hipsparseXgebsr2gebsc(hipsparseHandle_t handle, int mb, int nb, int nnzb, const hipComplex* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, hipComplex* bscVal, int* bscRowInd, int* bscColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase, void* temp_buffer) { return hipsparseCgebsr2gebsc(handle, mb, nb, nnzb, bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, bscVal, bscRowInd, bscColPtr, copyValues, idxBase, temp_buffer); } template <> hipsparseStatus_t hipsparseXgebsr2gebsc(hipsparseHandle_t handle, int mb, int nb, int nnzb, const hipDoubleComplex* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, hipDoubleComplex* bscVal, int* bscRowInd, int* bscColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase, void* temp_buffer) { return hipsparseZgebsr2gebsc(handle, mb, nb, nnzb, bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, bscVal, bscRowInd, bscColPtr, copyValues, idxBase, temp_buffer); } template <> hipsparseStatus_t hipsparseXcsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const hipDoubleComplex* csrVal, const int* csrRowPtr, const int* csrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes) { return hipsparseZcsr2gebsr_bufferSize(handle, dir, m, n, csr_descr, csrVal, csrRowPtr, csrColInd, rowBlockDim, colBlockDim, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes) { return hipsparseScsr2gebsr_bufferSize(handle, dir, m, n, csr_descr, csrVal, csrRowPtr, csrColInd, rowBlockDim, colBlockDim, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes) { return hipsparseDcsr2gebsr_bufferSize(handle, dir, m, n, csr_descr, csrVal, csrRowPtr, csrColInd, rowBlockDim, colBlockDim, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const hipComplex* csrVal, const int* csrRowPtr, const int* csrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes) { return hipsparseCcsr2gebsr_bufferSize(handle, dir, m, n, csr_descr, csrVal, csrRowPtr, csrColInd, rowBlockDim, colBlockDim, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, const hipsparseMatDescr_t bsr_descr, float* bsrVal, int* bsrRowPtr, int* bsrColInd, int rowBlockDim, int colBlockDim, void* pbuffer) { return hipsparseScsr2gebsr(handle, dir, m, n, csr_descr, csrVal, csrRowPtr, csrColInd, bsr_descr, bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, pbuffer); } template <> hipsparseStatus_t hipsparseXcsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, const hipsparseMatDescr_t bsr_descr, double* bsrVal, int* bsrRowPtr, int* bsrColInd, int rowBlockDim, int colBlockDim, void* pbuffer) { return hipsparseDcsr2gebsr(handle, dir, m, n, csr_descr, csrVal, csrRowPtr, csrColInd, bsr_descr, bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, pbuffer); } template <> hipsparseStatus_t hipsparseXcsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const hipComplex* csrVal, const int* csrRowPtr, const int* csrColInd, const hipsparseMatDescr_t bsr_descr, hipComplex* bsrVal, int* bsrRowPtr, int* bsrColInd, int rowBlockDim, int colBlockDim, void* pbuffer) { return hipsparseCcsr2gebsr(handle, dir, m, n, csr_descr, csrVal, csrRowPtr, csrColInd, bsr_descr, bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, pbuffer); } template <> hipsparseStatus_t hipsparseXcsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const hipDoubleComplex* csrVal, const int* csrRowPtr, const int* csrColInd, const hipsparseMatDescr_t bsr_descr, hipDoubleComplex* bsrVal, int* bsrRowPtr, int* bsrColInd, int rowBlockDim, int colBlockDim, void* pbuffer) { return hipsparseZcsr2gebsr(handle, dir, m, n, csr_descr, csrVal, csrRowPtr, csrColInd, bsr_descr, bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, pbuffer); } template <> hipsparseStatus_t hipsparseXcsr2bsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, int blockDim, const hipsparseMatDescr_t descrC, float* bsrValC, int* bsrRowPtrC, int* bsrColIndC) { return hipsparseScsr2bsr(handle, dirA, m, n, descrA, csrValA, csrRowPtrA, csrColIndA, blockDim, descrC, bsrValC, bsrRowPtrC, bsrColIndC); } template <> hipsparseStatus_t hipsparseXcsr2bsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, int blockDim, const hipsparseMatDescr_t descrC, double* bsrValC, int* bsrRowPtrC, int* bsrColIndC) { return hipsparseDcsr2bsr(handle, dirA, m, n, descrA, csrValA, csrRowPtrA, csrColIndA, blockDim, descrC, bsrValC, bsrRowPtrC, bsrColIndC); } template <> hipsparseStatus_t hipsparseXcsr2bsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const hipComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, int blockDim, const hipsparseMatDescr_t descrC, hipComplex* bsrValC, int* bsrRowPtrC, int* bsrColIndC) { return hipsparseCcsr2bsr(handle, dirA, m, n, descrA, csrValA, csrRowPtrA, csrColIndA, blockDim, descrC, bsrValC, bsrRowPtrC, bsrColIndC); } template <> hipsparseStatus_t hipsparseXcsr2bsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, int blockDim, const hipsparseMatDescr_t descrC, hipDoubleComplex* bsrValC, int* bsrRowPtrC, int* bsrColIndC) { return hipsparseZcsr2bsr(handle, dirA, m, n, descrA, csrValA, csrRowPtrA, csrColIndA, blockDim, descrC, bsrValC, bsrRowPtrC, bsrColIndC); } template <> hipsparseStatus_t hipsparseXbsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const hipsparseMatDescr_t descrC, float* csrValC, int* csrRowPtrC, int* csrColIndC) { return hipsparseSbsr2csr(handle, dirA, mb, nb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, descrC, csrValC, csrRowPtrC, csrColIndC); } template <> hipsparseStatus_t hipsparseXbsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const hipsparseMatDescr_t descrC, double* csrValC, int* csrRowPtrC, int* csrColIndC) { return hipsparseDbsr2csr(handle, dirA, mb, nb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, descrC, csrValC, csrRowPtrC, csrColIndC); } template <> hipsparseStatus_t hipsparseXbsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const hipsparseMatDescr_t descrC, hipComplex* csrValC, int* csrRowPtrC, int* csrColIndC) { return hipsparseCbsr2csr(handle, dirA, mb, nb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, descrC, csrValC, csrRowPtrC, csrColIndC); } template <> hipsparseStatus_t hipsparseXbsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const hipsparseMatDescr_t descrC, hipDoubleComplex* csrValC, int* csrRowPtrC, int* csrColIndC) { return hipsparseZbsr2csr(handle, dirA, mb, nb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, descrC, csrValC, csrRowPtrC, csrColIndC); } template <> hipsparseStatus_t hipsparseXgebsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDim, int colBlockDim, const hipsparseMatDescr_t descrC, float* csrValC, int* csrRowPtrC, int* csrColIndC) { return hipsparseSgebsr2csr(handle, dirA, mb, nb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDim, colBlockDim, descrC, csrValC, csrRowPtrC, csrColIndC); } template <> hipsparseStatus_t hipsparseXgebsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDim, int colBlockDim, const hipsparseMatDescr_t descrC, double* csrValC, int* csrRowPtrC, int* csrColIndC) { return hipsparseDgebsr2csr(handle, dirA, mb, nb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDim, colBlockDim, descrC, csrValC, csrRowPtrC, csrColIndC); } template <> hipsparseStatus_t hipsparseXgebsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDim, int colBlockDim, const hipsparseMatDescr_t descrC, hipComplex* csrValC, int* csrRowPtrC, int* csrColIndC) { return hipsparseCgebsr2csr(handle, dirA, mb, nb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDim, colBlockDim, descrC, csrValC, csrRowPtrC, csrColIndC); } template <> hipsparseStatus_t hipsparseXgebsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDim, int colBlockDim, const hipsparseMatDescr_t descrC, hipDoubleComplex* csrValC, int* csrRowPtrC, int* csrColIndC) { return hipsparseZgebsr2csr(handle, dirA, mb, nb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDim, colBlockDim, descrC, csrValC, csrRowPtrC, csrColIndC); } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template <> hipsparseStatus_t hipsparseXhyb2csr(hipsparseHandle_t handle, const hipsparseMatDescr_t descrA, const hipsparseHybMat_t hybA, float* csrValA, int* csrRowPtrA, int* csrColIndA) { return hipsparseShyb2csr(handle, descrA, hybA, csrValA, csrRowPtrA, csrColIndA); } template <> hipsparseStatus_t hipsparseXhyb2csr(hipsparseHandle_t handle, const hipsparseMatDescr_t descrA, const hipsparseHybMat_t hybA, double* csrValA, int* csrRowPtrA, int* csrColIndA) { return hipsparseDhyb2csr(handle, descrA, hybA, csrValA, csrRowPtrA, csrColIndA); } template <> hipsparseStatus_t hipsparseXhyb2csr(hipsparseHandle_t handle, const hipsparseMatDescr_t descrA, const hipsparseHybMat_t hybA, hipComplex* csrValA, int* csrRowPtrA, int* csrColIndA) { return hipsparseChyb2csr(handle, descrA, hybA, csrValA, csrRowPtrA, csrColIndA); } template <> hipsparseStatus_t hipsparseXhyb2csr(hipsparseHandle_t handle, const hipsparseMatDescr_t descrA, const hipsparseHybMat_t hybA, hipDoubleComplex* csrValA, int* csrRowPtrA, int* csrColIndA) { return hipsparseZhyb2csr(handle, descrA, hybA, csrValA, csrRowPtrA, csrColIndA); } #endif template <> hipsparseStatus_t hipsparseXcsr2csr_compress(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrColIndA, const int* csrRowPtrA, int nnzA, const int* nnzPerRow, float* csrValC, int* csrColIndC, int* csrRowPtrC, float tol) { return hipsparseScsr2csr_compress(handle, m, n, descrA, csrValA, csrColIndA, csrRowPtrA, nnzA, nnzPerRow, csrValC, csrColIndC, csrRowPtrC, tol); } template <> hipsparseStatus_t hipsparseXcsr2csr_compress(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrColIndA, const int* csrRowPtrA, int nnzA, const int* nnzPerRow, double* csrValC, int* csrColIndC, int* csrRowPtrC, double tol) { return hipsparseDcsr2csr_compress(handle, m, n, descrA, csrValA, csrColIndA, csrRowPtrA, nnzA, nnzPerRow, csrValC, csrColIndC, csrRowPtrC, tol); } template <> hipsparseStatus_t hipsparseXcsr2csr_compress(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, const hipComplex* csrValA, const int* csrColIndA, const int* csrRowPtrA, int nnzA, const int* nnzPerRow, hipComplex* csrValC, int* csrColIndC, int* csrRowPtrC, hipComplex tol) { return hipsparseCcsr2csr_compress(handle, m, n, descrA, csrValA, csrColIndA, csrRowPtrA, nnzA, nnzPerRow, csrValC, csrColIndC, csrRowPtrC, tol); } template <> hipsparseStatus_t hipsparseXcsr2csr_compress(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrValA, const int* csrColIndA, const int* csrRowPtrA, int nnzA, const int* nnzPerRow, hipDoubleComplex* csrValC, int* csrColIndC, int* csrRowPtrC, hipDoubleComplex tol) { return hipsparseZcsr2csr_compress(handle, m, n, descrA, csrValA, csrColIndA, csrRowPtrA, nnzA, nnzPerRow, csrValC, csrColIndC, csrRowPtrC, tol); } template <> hipsparseStatus_t hipsparseXpruneCsr2csr_bufferSize(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const float* threshold, const hipsparseMatDescr_t descrC, const float* csrValC, const int* csrRowPtrC, const int* csrColIndC, size_t* pBufferSizeInBytes) { return hipsparseSpruneCsr2csr_bufferSize(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, threshold, descrC, csrValC, csrRowPtrC, csrColIndC, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXpruneCsr2csr_bufferSize(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const double* threshold, const hipsparseMatDescr_t descrC, const double* csrValC, const int* csrRowPtrC, const int* csrColIndC, size_t* pBufferSizeInBytes) { return hipsparseDpruneCsr2csr_bufferSize(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, threshold, descrC, csrValC, csrRowPtrC, csrColIndC, pBufferSizeInBytes); } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXpruneCsr2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const float* threshold, const hipsparseMatDescr_t descrC, const float* csrValC, const int* csrRowPtrC, const int* csrColIndC, size_t* pBufferSizeInBytes) { return hipsparseSpruneCsr2csr_bufferSizeExt(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, threshold, descrC, csrValC, csrRowPtrC, csrColIndC, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXpruneCsr2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const double* threshold, const hipsparseMatDescr_t descrC, const double* csrValC, const int* csrRowPtrC, const int* csrColIndC, size_t* pBufferSizeInBytes) { return hipsparseDpruneCsr2csr_bufferSizeExt(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, threshold, descrC, csrValC, csrRowPtrC, csrColIndC, pBufferSizeInBytes); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXpruneCsr2csrNnz(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const float* threshold, const hipsparseMatDescr_t descrC, int* csrRowPtrC, int* nnzTotalDevHostPtr, void* buffer) { return hipsparseSpruneCsr2csrNnz(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, threshold, descrC, csrRowPtrC, nnzTotalDevHostPtr, buffer); } template <> hipsparseStatus_t hipsparseXpruneCsr2csrNnz(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const double* threshold, const hipsparseMatDescr_t descrC, int* csrRowPtrC, int* nnzTotalDevHostPtr, void* buffer) { return hipsparseDpruneCsr2csrNnz(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, threshold, descrC, csrRowPtrC, nnzTotalDevHostPtr, buffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXpruneCsr2csr(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const float* threshold, const hipsparseMatDescr_t descrC, float* csrValC, const int* csrRowPtrC, int* csrColIndC, void* buffer) { return hipsparseSpruneCsr2csr(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, threshold, descrC, csrValC, csrRowPtrC, csrColIndC, buffer); } template <> hipsparseStatus_t hipsparseXpruneCsr2csr(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const double* threshold, const hipsparseMatDescr_t descrC, double* csrValC, const int* csrRowPtrC, int* csrColIndC, void* buffer) { return hipsparseDpruneCsr2csr(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, threshold, descrC, csrValC, csrRowPtrC, csrColIndC, buffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXpruneCsr2csrByPercentage_bufferSize(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, float percentage, const hipsparseMatDescr_t descrC, const float* csrValC, const int* csrRowPtrC, const int* csrColIndC, pruneInfo_t info, size_t* pBufferSizeInBytes) { return hipsparseSpruneCsr2csrByPercentage_bufferSize(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, percentage, descrC, csrValC, csrRowPtrC, csrColIndC, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXpruneCsr2csrByPercentage_bufferSize(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, double percentage, const hipsparseMatDescr_t descrC, const double* csrValC, const int* csrRowPtrC, const int* csrColIndC, pruneInfo_t info, size_t* pBufferSizeInBytes) { return hipsparseDpruneCsr2csrByPercentage_bufferSize(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, percentage, descrC, csrValC, csrRowPtrC, csrColIndC, info, pBufferSizeInBytes); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXpruneCsr2csrByPercentage_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, float percentage, const hipsparseMatDescr_t descrC, const float* csrValC, const int* csrRowPtrC, const int* csrColIndC, pruneInfo_t info, size_t* pBufferSizeInBytes) { return hipsparseSpruneCsr2csrByPercentage_bufferSizeExt(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, percentage, descrC, csrValC, csrRowPtrC, csrColIndC, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXpruneCsr2csrByPercentage_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, double percentage, const hipsparseMatDescr_t descrC, const double* csrValC, const int* csrRowPtrC, const int* csrColIndC, pruneInfo_t info, size_t* pBufferSizeInBytes) { return hipsparseDpruneCsr2csrByPercentage_bufferSizeExt(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, percentage, descrC, csrValC, csrRowPtrC, csrColIndC, info, pBufferSizeInBytes); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXpruneCsr2csrNnzByPercentage(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, float percentage, const hipsparseMatDescr_t descrC, int* csrRowPtrC, int* nnzTotalDevHostPtr, pruneInfo_t info, void* buffer) { return hipsparseSpruneCsr2csrNnzByPercentage(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, percentage, descrC, csrRowPtrC, nnzTotalDevHostPtr, info, buffer); } template <> hipsparseStatus_t hipsparseXpruneCsr2csrNnzByPercentage(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, double percentage, const hipsparseMatDescr_t descrC, int* csrRowPtrC, int* nnzTotalDevHostPtr, pruneInfo_t info, void* buffer) { return hipsparseDpruneCsr2csrNnzByPercentage(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, percentage, descrC, csrRowPtrC, nnzTotalDevHostPtr, info, buffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXpruneCsr2csrByPercentage(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, float percentage, const hipsparseMatDescr_t descrC, float* csrValC, const int* csrRowPtrC, int* csrColIndC, pruneInfo_t info, void* buffer) { return hipsparseSpruneCsr2csrByPercentage(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, percentage, descrC, csrValC, csrRowPtrC, csrColIndC, info, buffer); } template <> hipsparseStatus_t hipsparseXpruneCsr2csrByPercentage(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, double percentage, const hipsparseMatDescr_t descrC, double* csrValC, const int* csrRowPtrC, int* csrColIndC, pruneInfo_t info, void* buffer) { return hipsparseDpruneCsr2csrByPercentage(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, percentage, descrC, csrValC, csrRowPtrC, csrColIndC, info, buffer); } #endif template <> hipsparseStatus_t hipsparseXgebsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, int rowBlockDimC, int colBlockDimC, int* pBufferSizeInBytes) { return hipsparseSgebsr2gebsr_bufferSize(handle, dirA, mb, nb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, rowBlockDimC, colBlockDimC, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgebsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, int rowBlockDimC, int colBlockDimC, int* pBufferSizeInBytes) { return hipsparseDgebsr2gebsr_bufferSize(handle, dirA, mb, nb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, rowBlockDimC, colBlockDimC, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgebsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, int rowBlockDimC, int colBlockDimC, int* pBufferSizeInBytes) { return hipsparseCgebsr2gebsr_bufferSize(handle, dirA, mb, nb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, rowBlockDimC, colBlockDimC, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgebsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, int rowBlockDimC, int colBlockDimC, int* pBufferSizeInBytes) { return hipsparseZgebsr2gebsr_bufferSize(handle, dirA, mb, nb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, rowBlockDimC, colBlockDimC, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgebsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, const hipsparseMatDescr_t descrC, float* bsrValC, int* bsrRowPtrC, int* bsrColIndC, int rowBlockDimC, int colBlockDimC, void* buffer) { return hipsparseSgebsr2gebsr(handle, dirA, mb, nb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, descrC, bsrValC, bsrRowPtrC, bsrColIndC, rowBlockDimC, colBlockDimC, buffer); } template <> hipsparseStatus_t hipsparseXgebsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, const hipsparseMatDescr_t descrC, double* bsrValC, int* bsrRowPtrC, int* bsrColIndC, int rowBlockDimC, int colBlockDimC, void* buffer) { return hipsparseDgebsr2gebsr(handle, dirA, mb, nb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, descrC, bsrValC, bsrRowPtrC, bsrColIndC, rowBlockDimC, colBlockDimC, buffer); } template <> hipsparseStatus_t hipsparseXgebsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, const hipsparseMatDescr_t descrC, hipComplex* bsrValC, int* bsrRowPtrC, int* bsrColIndC, int rowBlockDimC, int colBlockDimC, void* buffer) { return hipsparseCgebsr2gebsr(handle, dirA, mb, nb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, descrC, bsrValC, bsrRowPtrC, bsrColIndC, rowBlockDimC, colBlockDimC, buffer); } template <> hipsparseStatus_t hipsparseXgebsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, const hipsparseMatDescr_t descrC, hipDoubleComplex* bsrValC, int* bsrRowPtrC, int* bsrColIndC, int rowBlockDimC, int colBlockDimC, void* buffer) { return hipsparseZgebsr2gebsr(handle, dirA, mb, nb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, descrC, bsrValC, bsrRowPtrC, bsrColIndC, rowBlockDimC, colBlockDimC, buffer); } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXcsru2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnz, float* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, size_t* pBufferSizeInBytes) { return hipsparseScsru2csr_bufferSizeExt( handle, m, n, nnz, csrVal, csrRowPtr, csrColInd, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsru2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnz, double* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, size_t* pBufferSizeInBytes) { return hipsparseDcsru2csr_bufferSizeExt( handle, m, n, nnz, csrVal, csrRowPtr, csrColInd, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsru2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnz, hipComplex* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, size_t* pBufferSizeInBytes) { return hipsparseCcsru2csr_bufferSizeExt( handle, m, n, nnz, csrVal, csrRowPtr, csrColInd, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsru2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnz, hipDoubleComplex* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, size_t* pBufferSizeInBytes) { return hipsparseZcsru2csr_bufferSizeExt( handle, m, n, nnz, csrVal, csrRowPtr, csrColInd, info, pBufferSizeInBytes); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXcsru2csr(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, float* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer) { return hipsparseScsru2csr( handle, m, n, nnz, descrA, csrVal, csrRowPtr, csrColInd, info, pBuffer); } template <> hipsparseStatus_t hipsparseXcsru2csr(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, double* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer) { return hipsparseDcsru2csr( handle, m, n, nnz, descrA, csrVal, csrRowPtr, csrColInd, info, pBuffer); } template <> hipsparseStatus_t hipsparseXcsru2csr(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer) { return hipsparseCcsru2csr( handle, m, n, nnz, descrA, csrVal, csrRowPtr, csrColInd, info, pBuffer); } template <> hipsparseStatus_t hipsparseXcsru2csr(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer) { return hipsparseZcsru2csr( handle, m, n, nnz, descrA, csrVal, csrRowPtr, csrColInd, info, pBuffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXcsr2csru(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, float* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer) { return hipsparseScsr2csru( handle, m, n, nnz, descrA, csrVal, csrRowPtr, csrColInd, info, pBuffer); } template <> hipsparseStatus_t hipsparseXcsr2csru(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, double* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer) { return hipsparseDcsr2csru( handle, m, n, nnz, descrA, csrVal, csrRowPtr, csrColInd, info, pBuffer); } template <> hipsparseStatus_t hipsparseXcsr2csru(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer) { return hipsparseCcsr2csru( handle, m, n, nnz, descrA, csrVal, csrRowPtr, csrColInd, info, pBuffer); } template <> hipsparseStatus_t hipsparseXcsr2csru(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer) { return hipsparseZcsr2csru( handle, m, n, nnz, descrA, csrVal, csrRowPtr, csrColInd, info, pBuffer); } #endif template <> hipsparseStatus_t hipsparseXgpsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const float* ds, const float* dl, const float* d, const float* du, const float* dw, const float* x, int batchCount, size_t* pBufferSizeInBytes) { return hipsparseSgpsvInterleavedBatch_bufferSizeExt( handle, algo, m, ds, dl, d, du, dw, x, batchCount, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgpsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const double* ds, const double* dl, const double* d, const double* du, const double* dw, const double* x, int batchCount, size_t* pBufferSizeInBytes) { return hipsparseDgpsvInterleavedBatch_bufferSizeExt( handle, algo, m, ds, dl, d, du, dw, x, batchCount, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgpsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const hipComplex* ds, const hipComplex* dl, const hipComplex* d, const hipComplex* du, const hipComplex* dw, const hipComplex* x, int batchCount, size_t* pBufferSizeInBytes) { return hipsparseCgpsvInterleavedBatch_bufferSizeExt( handle, algo, m, ds, dl, d, du, dw, x, batchCount, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgpsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const hipDoubleComplex* ds, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, const hipDoubleComplex* dw, const hipDoubleComplex* x, int batchCount, size_t* pBufferSizeInBytes) { return hipsparseZgpsvInterleavedBatch_bufferSizeExt( handle, algo, m, ds, dl, d, du, dw, x, batchCount, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgpsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, float* ds, float* dl, float* d, float* du, float* dw, float* x, int batchCount, void* pBuffer) { return hipsparseSgpsvInterleavedBatch( handle, algo, m, ds, dl, d, du, dw, x, batchCount, pBuffer); } template <> hipsparseStatus_t hipsparseXgpsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, double* ds, double* dl, double* d, double* du, double* dw, double* x, int batchCount, void* pBuffer) { return hipsparseDgpsvInterleavedBatch( handle, algo, m, ds, dl, d, du, dw, x, batchCount, pBuffer); } template <> hipsparseStatus_t hipsparseXgpsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, hipComplex* ds, hipComplex* dl, hipComplex* d, hipComplex* du, hipComplex* dw, hipComplex* x, int batchCount, void* pBuffer) { return hipsparseCgpsvInterleavedBatch( handle, algo, m, ds, dl, d, du, dw, x, batchCount, pBuffer); } template <> hipsparseStatus_t hipsparseXgpsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, hipDoubleComplex* ds, hipDoubleComplex* dl, hipDoubleComplex* d, hipDoubleComplex* du, hipDoubleComplex* dw, hipDoubleComplex* x, int batchCount, void* pBuffer) { return hipsparseZgpsvInterleavedBatch( handle, algo, m, ds, dl, d, du, dw, x, batchCount, pBuffer); } template <> hipsparseStatus_t hipsparseXgtsv2StridedBatch_bufferSizeExt(hipsparseHandle_t handle, int m, const float* dl, const float* d, const float* du, const float* x, int batchCount, int batchStride, size_t* pBufferSizeInBytes) { return hipsparseSgtsv2StridedBatch_bufferSizeExt( handle, m, dl, d, du, x, batchCount, batchStride, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgtsv2StridedBatch_bufferSizeExt(hipsparseHandle_t handle, int m, const double* dl, const double* d, const double* du, const double* x, int batchCount, int batchStride, size_t* pBufferSizeInBytes) { return hipsparseDgtsv2StridedBatch_bufferSizeExt( handle, m, dl, d, du, x, batchCount, batchStride, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgtsv2StridedBatch_bufferSizeExt(hipsparseHandle_t handle, int m, const hipComplex* dl, const hipComplex* d, const hipComplex* du, const hipComplex* x, int batchCount, int batchStride, size_t* pBufferSizeInBytes) { return hipsparseCgtsv2StridedBatch_bufferSizeExt( handle, m, dl, d, du, x, batchCount, batchStride, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgtsv2StridedBatch_bufferSizeExt(hipsparseHandle_t handle, int m, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, const hipDoubleComplex* x, int batchCount, int batchStride, size_t* pBufferSizeInBytes) { return hipsparseZgtsv2StridedBatch_bufferSizeExt( handle, m, dl, d, du, x, batchCount, batchStride, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgtsv2StridedBatch(hipsparseHandle_t handle, int m, const float* dl, const float* d, const float* du, float* x, int batchCount, int batchStride, void* pBuffer) { return hipsparseSgtsv2StridedBatch( handle, m, dl, d, du, x, batchCount, batchStride, pBuffer); } template <> hipsparseStatus_t hipsparseXgtsv2StridedBatch(hipsparseHandle_t handle, int m, const double* dl, const double* d, const double* du, double* x, int batchCount, int batchStride, void* pBuffer) { return hipsparseDgtsv2StridedBatch( handle, m, dl, d, du, x, batchCount, batchStride, pBuffer); } template <> hipsparseStatus_t hipsparseXgtsv2StridedBatch(hipsparseHandle_t handle, int m, const hipComplex* dl, const hipComplex* d, const hipComplex* du, hipComplex* x, int batchCount, int batchStride, void* pBuffer) { return hipsparseCgtsv2StridedBatch( handle, m, dl, d, du, x, batchCount, batchStride, pBuffer); } template <> hipsparseStatus_t hipsparseXgtsv2StridedBatch(hipsparseHandle_t handle, int m, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, hipDoubleComplex* x, int batchCount, int batchStride, void* pBuffer) { return hipsparseZgtsv2StridedBatch( handle, m, dl, d, du, x, batchCount, batchStride, pBuffer); } template <> hipsparseStatus_t hipsparseXgtsv2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const float* dl, const float* d, const float* du, const float* B, int ldb, size_t* pBufferSizeInBytes) { return hipsparseSgtsv2_bufferSizeExt(handle, m, n, dl, d, du, B, ldb, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgtsv2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const double* dl, const double* d, const double* du, const double* B, int ldb, size_t* pBufferSizeInBytes) { return hipsparseDgtsv2_bufferSizeExt(handle, m, n, dl, d, du, B, ldb, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgtsv2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const hipComplex* dl, const hipComplex* d, const hipComplex* du, const hipComplex* B, int ldb, size_t* pBufferSizeInBytes) { return hipsparseCgtsv2_bufferSizeExt(handle, m, n, dl, d, du, B, ldb, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgtsv2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, const hipDoubleComplex* B, int ldb, size_t* pBufferSizeInBytes) { return hipsparseZgtsv2_bufferSizeExt(handle, m, n, dl, d, du, B, ldb, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgtsv2(hipsparseHandle_t handle, int m, int n, const float* dl, const float* d, const float* du, float* B, int ldb, void* pBuffer) { return hipsparseSgtsv2(handle, m, n, dl, d, du, B, ldb, pBuffer); } template <> hipsparseStatus_t hipsparseXgtsv2(hipsparseHandle_t handle, int m, int n, const double* dl, const double* d, const double* du, double* B, int ldb, void* pBuffer) { return hipsparseDgtsv2(handle, m, n, dl, d, du, B, ldb, pBuffer); } template <> hipsparseStatus_t hipsparseXgtsv2(hipsparseHandle_t handle, int m, int n, const hipComplex* dl, const hipComplex* d, const hipComplex* du, hipComplex* B, int ldb, void* pBuffer) { return hipsparseCgtsv2(handle, m, n, dl, d, du, B, ldb, pBuffer); } template <> hipsparseStatus_t hipsparseXgtsv2(hipsparseHandle_t handle, int m, int n, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, hipDoubleComplex* B, int ldb, void* pBuffer) { return hipsparseZgtsv2(handle, m, n, dl, d, du, B, ldb, pBuffer); } template <> hipsparseStatus_t hipsparseXgtsv2_nopivot_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const float* dl, const float* d, const float* du, const float* B, int ldb, size_t* pBufferSizeInBytes) { return hipsparseSgtsv2_nopivot_bufferSizeExt( handle, m, n, dl, d, du, B, ldb, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgtsv2_nopivot_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const double* dl, const double* d, const double* du, const double* B, int ldb, size_t* pBufferSizeInBytes) { return hipsparseDgtsv2_nopivot_bufferSizeExt( handle, m, n, dl, d, du, B, ldb, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgtsv2_nopivot_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const hipComplex* dl, const hipComplex* d, const hipComplex* du, const hipComplex* B, int ldb, size_t* pBufferSizeInBytes) { return hipsparseCgtsv2_nopivot_bufferSizeExt( handle, m, n, dl, d, du, B, ldb, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgtsv2_nopivot_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, const hipDoubleComplex* B, int ldb, size_t* pBufferSizeInBytes) { return hipsparseZgtsv2_nopivot_bufferSizeExt( handle, m, n, dl, d, du, B, ldb, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgtsv2_nopivot(hipsparseHandle_t handle, int m, int n, const float* dl, const float* d, const float* du, float* B, int ldb, void* pBuffer) { return hipsparseSgtsv2_nopivot(handle, m, n, dl, d, du, B, ldb, pBuffer); } template <> hipsparseStatus_t hipsparseXgtsv2_nopivot(hipsparseHandle_t handle, int m, int n, const double* dl, const double* d, const double* du, double* B, int ldb, void* pBuffer) { return hipsparseDgtsv2_nopivot(handle, m, n, dl, d, du, B, ldb, pBuffer); } template <> hipsparseStatus_t hipsparseXgtsv2_nopivot(hipsparseHandle_t handle, int m, int n, const hipComplex* dl, const hipComplex* d, const hipComplex* du, hipComplex* B, int ldb, void* pBuffer) { return hipsparseCgtsv2_nopivot(handle, m, n, dl, d, du, B, ldb, pBuffer); } template <> hipsparseStatus_t hipsparseXgtsv2_nopivot(hipsparseHandle_t handle, int m, int n, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, hipDoubleComplex* B, int ldb, void* pBuffer) { return hipsparseZgtsv2_nopivot(handle, m, n, dl, d, du, B, ldb, pBuffer); } template <> hipsparseStatus_t hipsparseXgtsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const float* dl, const float* d, const float* du, const float* x, int batchCount, size_t* pBufferSizeInBytes) { return hipsparseSgtsvInterleavedBatch_bufferSizeExt( handle, algo, m, dl, d, du, x, batchCount, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgtsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const double* dl, const double* d, const double* du, const double* x, int batchCount, size_t* pBufferSizeInBytes) { return hipsparseDgtsvInterleavedBatch_bufferSizeExt( handle, algo, m, dl, d, du, x, batchCount, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgtsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const hipComplex* dl, const hipComplex* d, const hipComplex* du, const hipComplex* x, int batchCount, size_t* pBufferSizeInBytes) { return hipsparseCgtsvInterleavedBatch_bufferSizeExt( handle, algo, m, dl, d, du, x, batchCount, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgtsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, const hipDoubleComplex* x, int batchCount, size_t* pBufferSizeInBytes) { return hipsparseZgtsvInterleavedBatch_bufferSizeExt( handle, algo, m, dl, d, du, x, batchCount, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgtsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, float* dl, float* d, float* du, float* x, int batchCount, void* pBuffer) { return hipsparseSgtsvInterleavedBatch(handle, algo, m, dl, d, du, x, batchCount, pBuffer); } template <> hipsparseStatus_t hipsparseXgtsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, double* dl, double* d, double* du, double* x, int batchCount, void* pBuffer) { return hipsparseDgtsvInterleavedBatch(handle, algo, m, dl, d, du, x, batchCount, pBuffer); } template <> hipsparseStatus_t hipsparseXgtsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, hipComplex* dl, hipComplex* d, hipComplex* du, hipComplex* x, int batchCount, void* pBuffer) { return hipsparseCgtsvInterleavedBatch(handle, algo, m, dl, d, du, x, batchCount, pBuffer); } template <> hipsparseStatus_t hipsparseXgtsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, hipDoubleComplex* dl, hipDoubleComplex* d, hipDoubleComplex* du, hipDoubleComplex* x, int batchCount, void* pBuffer) { return hipsparseZgtsvInterleavedBatch(handle, algo, m, dl, d, du, x, batchCount, pBuffer); } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXcsrcolor(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const float* fractionToColor, int* ncolors, int* coloring, int* reordering, hipsparseColorInfo_t info) { return hipsparseScsrcolor(handle, m, nnz, descrA, csrValA, csrRowPtrA, csrColIndA, fractionToColor, ncolors, coloring, reordering, info); } template <> hipsparseStatus_t hipsparseXcsrcolor(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const double* fractionToColor, int* ncolors, int* coloring, int* reordering, hipsparseColorInfo_t info) { return hipsparseDcsrcolor(handle, m, nnz, descrA, csrValA, csrRowPtrA, csrColIndA, fractionToColor, ncolors, coloring, reordering, info); } template <> hipsparseStatus_t hipsparseXcsrcolor(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const hipComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, const float* fractionToColor, int* ncolors, int* coloring, int* reordering, hipsparseColorInfo_t info) { return hipsparseCcsrcolor(handle, m, nnz, descrA, csrValA, csrRowPtrA, csrColIndA, fractionToColor, ncolors, coloring, reordering, info); } template <> hipsparseStatus_t hipsparseXcsrcolor(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, const double* fractionToColor, int* ncolors, int* coloring, int* reordering, hipsparseColorInfo_t info) { return hipsparseZcsrcolor(handle, m, nnz, descrA, csrValA, csrRowPtrA, csrColIndA, fractionToColor, ncolors, coloring, reordering, info); } #endif } // namespace hipsparse hipSPARSE-rocm-6.4.3/clients/common/unit.cpp000066400000000000000000000177441501764003400206110ustar00rootroot00000000000000/* ************************************************************************ * 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-6.4.3/clients/common/utility.cpp000066400000000000000000000160311501764003400213210ustar00rootroot00000000000000/* ************************************************************************ * 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-6.4.3/clients/include/000077500000000000000000000000001501764003400172445ustar00rootroot00000000000000hipSPARSE-rocm-6.4.3/clients/include/arg_check.hpp000066400000000000000000000043771501764003400216760ustar00rootroot00000000000000/* ************************************************************************ * 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-6.4.3/clients/include/display.hpp000066400000000000000000000413561501764003400214330ustar00rootroot00000000000000/*! \file */ /* ************************************************************************ * Copyright (C) 2024 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ /*! \file * \brief display.hpp provides common testing utilities. */ #pragma once #ifndef DISPLAY_HPP #define DISPLAY_HPP #include #include #include #include #include #include #include #include static constexpr const char* s_timing_info_perf = "GFlop/s"; static constexpr const char* s_timing_info_bandwidth = "GB/s"; static constexpr const char* s_timing_info_time = "msec"; static constexpr const char* s_analysis_timing_info_time = "analysis msec"; hipsparseStatus_t hipsparse_record_output_legend(const std::string& s); hipsparseStatus_t hipsparse_record_output(const std::string& s); hipsparseStatus_t hipsparse_record_timing(double msec, double gflops, double gbs); bool display_timing_info_is_stdout_disabled(); inline auto& operator<<(std::ostream& out, const hipComplex& z) { std::stringstream ss; ss << '(' << z.x << ',' << z.y << ')'; return out << ss.str(); } inline auto& operator<<(std::ostream& out, const hipDoubleComplex& z) { std::stringstream ss; ss << '(' << z.x << ',' << z.y << ')'; return out << ss.str(); } struct display_key_t { // // Enumerate keys. // typedef enum enum_ { gflops = 0, bandwidth, time_ms, iters, function, ctype, itype, jtype, size, M, N, K, LD, Mb, MbA, MbC, Nb, NbA, NbC, Kb, nrhs, ell_width, ell_nnz, coo_nnz, nnz, nnzA, nnzB, nnzC, nnzb, nnzbA, nnzbC, block_dim, row_block_dim, row_block_dimA, row_block_dimC, col_block_dim, col_block_dimA, col_block_dimC, batch_count, batch_countA, batch_countB, batch_countC, batch_stride, alpha, beta, percentage, threshold, trans, transA, transB, transC, transX, direction, order, format, fill_mode, diag_type, solve_policy, action, partition, algorithm, permute } key_t; static const char* to_str(key_t key_) { switch(key_) { case gflops: { return s_timing_info_perf; } case bandwidth: { return s_timing_info_bandwidth; } case time_ms: { return s_timing_info_time; } case iters: { return "iters"; } case function: { return "function"; } case ctype: { return "ctype"; } case itype: { return "itype"; } case jtype: { return "jtype"; } case size: { return "size"; } case M: { return "M"; } case N: { return "N"; } case K: { return "K"; } case LD: { return "LD"; } case Mb: { return "Mb"; } case MbA: { return "MbA"; } case MbC: { return "MbC"; } case Nb: { return "Nb"; } case NbA: { return "NbA"; } case NbC: { return "NbC"; } case Kb: { return "Kb"; } case nrhs: { return "nrhs"; } case ell_width: { return "ell_width"; } case ell_nnz: { return "ell_nnz"; } case coo_nnz: { return "coo_nnz"; } case nnz: { return "nnz"; } case nnzA: { return "nnzA"; } case nnzB: { return "nnzB"; } case nnzC: { return "nnzC"; } case nnzb: { return "nnzb"; } case nnzbA: { return "nnzbA"; } case nnzbC: { return "nnzbC"; } case block_dim: { return "block_dim"; } case row_block_dim: { return "row_block_dim"; } case row_block_dimA: { return "row_block_dimA"; } case row_block_dimC: { return "row_block_dimC"; } case col_block_dim: { return "col_block_dim"; } case col_block_dimA: { return "col_block_dimA"; } case col_block_dimC: { return "col_block_dimC"; } case batch_count: { return "batch_count"; } case batch_countA: { return "batch_countA"; } case batch_countB: { return "batch_countB"; } case batch_countC: { return "batch_countC"; } case batch_stride: { return "batch_stride"; } case alpha: { return "alpha"; } case beta: { return "beta"; } case percentage: { return "percentage"; } case threshold: { return "threshold"; } case trans: { return "trans"; } case transA: { return "transA"; } case transB: { return "transB"; } case transC: { return "transC"; } case transX: { return "transX"; } case direction: { return "dir"; } case order: { return "order"; } case format: { return "format"; } case fill_mode: { return "uplo"; } case diag_type: { return "diag"; } case solve_policy: { return "solve_policy"; } case action: { return "action"; } case partition: { return "partition"; } case algorithm: { return "algorithm"; } case permute: { return "permute"; } default: { return nullptr; } } } }; template inline const char* display_to_string(S s) { return s; }; template <> inline const char* display_to_string(display_key_t::key_t s) { return display_key_t::to_str(s); }; // // Template to display timing information. // template inline void display_timing_info_legend(std::ostream& out, int n, S name, T t) { out << std::setw(n) << display_to_string(name); } template inline void display_timing_info_legend(std::ostream& out, int n, S name, T t, Ts... ts) { out << std::setw(n) << display_to_string(name); display_timing_info_legend(out, n, ts...); } template inline void display_timing_info_values(std::ostream& out, int n, S name, T t) { out << std::setw(n) << t; } template inline void display_timing_info_values(std::ostream& out, int n, S name, T t, Ts... ts) { out << std::setw(n) << t; display_timing_info_values(out, n, ts...); } template inline void display_timing_info_legend_noresults(std::ostream& out, int n, S name_, T t) { const char* name = display_to_string(name_); if(strcmp(name, s_timing_info_perf) && strcmp(name, s_timing_info_bandwidth) && strcmp(name, s_timing_info_time)) { out << " " << name; } } template inline void display_timing_info_legend_noresults(std::ostream& out, int n, S name_, T t, Ts... ts) { const char* name = display_to_string(name_); if(strcmp(name, s_timing_info_perf) && strcmp(name, s_timing_info_bandwidth) && strcmp(name, s_timing_info_time)) { out << " " << name; } display_timing_info_legend_noresults(out, n, ts...); } template inline void display_timing_info_values_noresults(std::ostream& out, int n, S name_, T t) { const char* name = display_to_string(name_); if(strcmp(name, s_timing_info_perf) && strcmp(name, s_timing_info_bandwidth) && strcmp(name, s_timing_info_time)) { out << " " << t; } } template inline void display_timing_info_values_noresults(std::ostream& out, int n, S name_, T t, Ts... ts) { const char* name = display_to_string(name_); if(strcmp(name, s_timing_info_perf) && strcmp(name, s_timing_info_bandwidth) && strcmp(name, s_timing_info_time)) { out << " " << t; } display_timing_info_values_noresults(out, n, ts...); } template inline void grab_results(double values[3], display_key_t::key_t key, T t) { } template <> inline void grab_results(double values[3], display_key_t::key_t key, double t) { const char* name = display_to_string(key); if(!strcmp(name, s_timing_info_perf)) { values[1] = t; } else if(!strcmp(name, s_timing_info_bandwidth)) { values[2] = t; } else if(!strcmp(name, s_timing_info_time)) { values[0] = t; } } template inline void grab_results(double values[3], const char* name, T t) { } template <> inline void grab_results(double values[3], const char* name, double t) { if(!strcmp(name, s_timing_info_perf)) { values[1] = t; } else if(!strcmp(name, s_timing_info_bandwidth)) { values[2] = t; } else if(!strcmp(name, s_timing_info_time)) { values[0] = t; } } template inline void display_timing_info_grab_results(double values[3], S name, T t) { grab_results(values, name, t); } template inline void display_timing_info_grab_results(double values[3], S name, T t, Ts... ts) { grab_results(values, name, t); display_timing_info_grab_results(values, ts...); } //bool display_timing_info_is_stdout_disabled(); template inline void display_timing_info_generate(std::ostream& out, int n, S name, T t, Ts... ts) { double values[3]{}; display_timing_info_grab_results(values, name, t, ts...); hipsparse_record_timing(values[0], values[1], values[2]); display_timing_info_values(out, n, name, t, ts...); } template inline void display_timing_info_generate_params(std::ostream& out, int n, S name, T t, Ts... ts) { double values[3]{}; display_timing_info_grab_results(values, name, t, ts...); hipsparse_record_timing(values[0], values[1], values[2]); display_timing_info_values_noresults(out, n, name, t, ts...); } template inline void display_timing_info_max_size_strings(int mx[1], S name_, T t) { const char* name = display_to_string(name_); int len = strlen(name); mx[0] = std::max(len, mx[0]); } template inline void display_timing_info_max_size_strings(int mx[1], S name_, T t, Ts... ts) { const char* name = display_to_string(name_); int len = strlen(name); mx[0] = std::max(len, mx[0]); display_timing_info_max_size_strings(mx, ts...); } template inline void display_timing_info_main(S name, Ts... ts) { // // To configure the size of std::setw. // int n = 0; display_timing_info_max_size_strings(&n, name, ts...); // // // n += 4; // // Legend // { std::ostringstream out_legend; out_legend.precision(2); out_legend.setf(std::ios::fixed); out_legend.setf(std::ios::left); if(!display_timing_info_is_stdout_disabled()) { display_timing_info_legend(out_legend, n, name, ts...); std::cout << out_legend.str() << std::endl; } else { // store the string. display_timing_info_legend_noresults(out_legend, n, name, ts...); hipsparse_record_output_legend(out_legend.str()); } } std::ostringstream out; out.precision(2); out.setf(std::ios::fixed); out.setf(std::ios::left); if(!display_timing_info_is_stdout_disabled()) { display_timing_info_generate(out, n, name, ts...); std::cout << out.str() << std::endl; } else { display_timing_info_generate_params(out, n, name, ts...); // store the string. hipsparse_record_output(out.str()); } } inline void hipsparse_get_matrixname(const char* f, char* name) { int n = 0; while(f[n] != '\0') ++n; int cdir = 0; for(int i = 0; i < n; ++i) { if(f[i] == '/' || f[i] == '\\') { cdir = i + 1; } } int ddir = cdir; for(int i = cdir; i < n; ++i) { if(f[i] == '.') { ddir = i; } } if(ddir == cdir) { ddir = n; } for(int i = cdir; i < ddir; ++i) { name[i - cdir] = f[i]; } name[ddir - cdir] = '\0'; } #define display_timing_info(...) \ do \ { \ const char* ctypename = hipsparse_datatype2string(argus.compute_type); \ const char* itypename = hipsparse_indextype2string(argus.index_type_I); \ const char* jtypename = hipsparse_indextype2string(argus.index_type_J); \ \ display_timing_info_main(__VA_ARGS__, \ display_key_t::iters, \ argus.iters, \ "verified", \ (argus.unit_check ? "yes" : "no"), \ display_key_t::function, \ &argus.function_name[0], \ display_key_t::ctype, \ ctypename, \ display_key_t::itype, \ itypename, \ display_key_t::jtype, \ jtypename); \ } while(false) #endif // DISPLAY_HPP hipSPARSE-rocm-6.4.3/clients/include/flops.hpp000066400000000000000000000143431501764003400211050ustar00rootroot00000000000000/*! \file */ /* ************************************************************************ * Copyright (C) 2024 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ /*! \file * \brief flops.hpp provides floating point counts of Sparse Linear Algebra Subprograms * of Level 1, 2 and 3. */ #pragma once #ifndef FLOPS_HPP #define FLOPS_HPP #include "hipsparse.h" // Compute gflops inline double get_gpu_gflops(double gpu_time_used, double gflop_count) { return gflop_count / gpu_time_used * 1e6; } template inline double get_gpu_gflops(double gpu_time_used, F count, Ts... ts) { return get_gpu_gflops(gpu_time_used, count(ts...)); } /* * =========================================================================== * level 1 SPARSE * =========================================================================== */ template constexpr double axpyi_gflop_count(I nnz) { return (2.0 * nnz) / 1e9; } template constexpr double axpby_gflop_count(I nnz) { return (3.0 * nnz) / 1e9; } template constexpr double doti_gflop_count(I nnz) { return (2.0 * nnz) / 1e9; } template constexpr double roti_gflop_count(I nnz) { return (6.0 * nnz) / 1e9; } /* * =========================================================================== * level 2 SPARSE * =========================================================================== */ template constexpr double spmv_gflop_count(J M, I nnz, bool beta = false) { return (2.0 * nnz + (beta ? M : 0)) / 1e9; } template constexpr double csrsv_gflop_count(J M, I nnz, hipsparseDiagType_t diag) { return (2.0 * nnz + M + (diag == HIPSPARSE_DIAG_TYPE_NON_UNIT ? M : 0)) / 1e9; } template constexpr double spsv_gflop_count(J M, I nnz, hipsparseDiagType_t diag) { return csrsv_gflop_count(M, nnz, diag); } template constexpr double gemvi_gflop_count(I M, I nnz) { return (M + 2.0 * nnz * M) / 1e9; } /* * =========================================================================== * level 3 SPARSE * =========================================================================== */ constexpr double bsrmm_gflop_count(int N, int nnzb, int block_dim, int nnz_C, bool beta = false) { return (2.0 * nnzb * block_dim * block_dim * N + (beta ? nnz_C : 0)) / 1e9; } template constexpr double csrmm_gflop_count(J N, I nnz_A, I nnz_C, bool beta = false) { // Multiplication by 2 comes from 1 addition and 1 multiplication in product. Multiplication // by alpha and beta not counted. return (2.0 * nnz_A * N + (beta ? nnz_C : 0)) / 1e9; } template constexpr double gemmi_gflop_count(J M, I nnz_B, I nnz_C, bool beta = false) { // Multiplication by 2 comes from 1 addition and 1 multiplication in product. Multiplication // by alpha and beta not counted. return (2.0 * nnz_B * M + (beta ? nnz_C : 0)) / 1e9; } template constexpr double spmm_gflop_count(J N, I nnz_A, I nnz_C, bool beta = false) { return csrmm_gflop_count(N, nnz_A, nnz_C, beta); } template constexpr double sddmm_gflop_count(J K, I nnz, bool beta = false) { return (size_t(nnz) * ((size_t(K) + (size_t(K) - 1)) + 1 + ((beta) ? 2 : 0))) / 1e9; } /* * =========================================================================== * extra SPARSE * =========================================================================== */ template constexpr double csrgeam_gflop_count(int nnz_A, int nnz_B, int nnz_C, const T* alpha, const T* beta) { // Flop counter double flops = 0.0; if(alpha && beta) { // Count alpha * A flops += static_cast(nnz_A); // Count beta * B flops += static_cast(nnz_B); // Count A + B flops += static_cast(nnz_C); } else if(!alpha) { // Count beta * B flops += static_cast(nnz_B); } else { // Count alpha * A flops += static_cast(nnz_A); } return flops / 1e9; } template constexpr double csrgemm_gflop_count(J M, const I* csr_row_ptr_A, const J* csr_col_ind_A, const I* csr_row_ptr_B, hipsparseIndexBase_t baseA) { // Flop counter double flops = 0.0; // Loop over rows of A for(J i = 0; i < M; ++i) { I row_begin_A = csr_row_ptr_A[i] - baseA; I row_end_A = csr_row_ptr_A[i + 1] - baseA; // Loop over columns of A for(I j = row_begin_A; j < row_end_A; ++j) { // Current column of A J col_A = csr_col_ind_A[j] - baseA; // Count flops generated by A * B flops += 2.0 * (csr_row_ptr_B[col_A + 1] - csr_row_ptr_B[col_A]) + 1.0; } } return flops / 1e9; } #endif // FLOPS_HPP hipSPARSE-rocm-6.4.3/clients/include/gbyte.hpp000066400000000000000000000507661501764003400211050ustar00rootroot00000000000000/*! \file */ /* ************************************************************************ * Copyright (C) 2024 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ /*! \file * \brief gbyte.hpp provides data transfer counts of Sparse Linear Algebra Subprograms * of Level 1, 2 and 3. */ #pragma once #ifndef GBYTE_HPP #define GBYTE_HPP // Compute gbytes inline double get_gpu_gbyte(double gpu_time_used, double gbyte_count) { return gbyte_count / gpu_time_used * 1e6; } template inline double get_gpu_gbyte(double gpu_time_used, F count, Ts... ts) { return get_gpu_gbyte(gpu_time_used, count(ts...)); } inline double get_gpu_time_msec(double gpu_time_used) { return gpu_time_used / 1e3; } /* * =========================================================================== * level 1 SPARSE * =========================================================================== */ template constexpr double axpby_gbyte_count(I nnz) { return (nnz * sizeof(I) + (3.0 * nnz) * sizeof(T)) / 1e9; } template constexpr double doti_gbyte_count(I nnz) { return (nnz * sizeof(I) + nnz * (sizeof(X) + sizeof(Y))) / 1e9; } template constexpr double gthr_gbyte_count(I nnz) { return (nnz * sizeof(I) + (2.0 * nnz) * sizeof(T)) / 1e9; } template constexpr double gthrz_gbyte_count(I nnz) { return (nnz * sizeof(I) + (2.0 * nnz) * sizeof(T)) / 1e9; } template constexpr double roti_gbyte_count(I nnz) { return (nnz * sizeof(I) + (3.0 * nnz) * sizeof(T)) / 1e9; } template constexpr double sctr_gbyte_count(I nnz) { return (nnz * sizeof(I) + (2.0 * nnz) * sizeof(T)) / 1e9; } /* * =========================================================================== * level 2 SPARSE * =========================================================================== */ template constexpr double bsrmv_gbyte_count(J mb, J nb, I nnzb, J block_dim, bool beta = false) { return (sizeof(I) * (mb + 1) + sizeof(J) * nnzb + sizeof(A) * nnzb * block_dim * block_dim + sizeof(Y) * (mb * block_dim + (beta ? mb * block_dim : 0)) + sizeof(X) * (nb * block_dim)) / 1e9; } template constexpr double bsrmv_gbyte_count(J mb, J nb, I nnzb, J block_dim, bool beta = false) { return bsrmv_gbyte_count(mb, nb, nnzb, block_dim, beta); } template constexpr double bsrsv_gbyte_count(int mb, int nnzb, int bsr_dim) { return ((mb + 1 + nnzb) * sizeof(int) + (bsr_dim * (mb + mb + nnzb * bsr_dim)) * sizeof(T)) / 1e9; } template constexpr double coomv_gbyte_count(I M, I N, int64_t nnz, bool beta = false) { return (sizeof(I) * 2.0 * nnz + sizeof(A) * nnz + sizeof(Y) * (M + (beta ? M : 0)) + sizeof(X) * N) / 1e9; } template constexpr double coomv_gbyte_count(I M, I N, int64_t nnz, bool beta = false) { return coomv_gbyte_count(M, N, nnz, beta); } template constexpr double csrsv_gbyte_count(J M, I nnz) { return ((M + 1) * sizeof(I) + nnz * sizeof(J) + (M + M + nnz) * sizeof(T)) / 1e9; } template constexpr double coosv_gbyte_count(I M, int64_t nnz) { return (2 * nnz * sizeof(I) + (M + M + nnz) * sizeof(T)) / 1e9; } template constexpr double csrmv_gbyte_count(J M, J N, I nnz, bool beta = false) { return (sizeof(I) * (M + 1) + sizeof(J) * nnz + sizeof(A) * nnz + sizeof(Y) * (M + (beta ? M : 0)) + sizeof(X) * N) / 1e9; } template constexpr double csrmv_gbyte_count(J M, J N, I nnz, bool beta = false) { return csrmv_gbyte_count(M, N, nnz, beta); } template constexpr double gemvi_gbyte_count(I m, I nnz, bool beta = false) { return ((nnz) * sizeof(I) + (m * nnz + nnz + m + (beta ? m : 0)) * sizeof(T)) / 1e9; } /* * =========================================================================== * level 3 SPARSE * =========================================================================== */ template constexpr double bsrmm_gbyte_count(int Mb, int nnzb, int block_dim, int nnz_B, int nnz_C, bool beta = false) { //reads size_t reads = (Mb + 1 + nnzb) * sizeof(int) + (block_dim * block_dim * nnzb + nnz_B + (beta ? nnz_C : 0)) * sizeof(T); //writes size_t writes = nnz_C * sizeof(T); return (reads + writes) / 1e9; } template constexpr double csrmm_gbyte_count(J M, I nnz_A, I nnz_B, I nnz_C, bool beta = false) { return ((M + 1) * sizeof(I) + nnz_A * sizeof(J) + (nnz_A + nnz_B + nnz_C + (beta ? nnz_C : 0)) * sizeof(T)) / 1e9; } template constexpr double cscmm_gbyte_count(J N, I nnz_A, I nnz_B, I nnz_C, bool beta = false) { return csrmm_gbyte_count(N, nnz_A, nnz_B, nnz_C, beta); } template constexpr double coomm_gbyte_count(int64_t nnz_A, int64_t nnz_B, int64_t nnz_C, bool beta = false) { return (2.0 * nnz_A * sizeof(I) + (nnz_A + nnz_B + nnz_C + (beta ? nnz_C : 0)) * sizeof(T)) / 1e9; } template constexpr double csrmm_batched_gbyte_count(J M, I nnz_A, I nnz_B, I nnz_C, J batch_count_A, J batch_count_B, J batch_count_C, bool beta = false) { // read A matrix size_t readA = batch_count_A * ((M + 1) * sizeof(I) + nnz_A * sizeof(J) + nnz_A * sizeof(T)); // read B matrix size_t readB = batch_count_B * nnz_B * sizeof(T); // read C matrix size_t readC = batch_count_C * (beta ? nnz_C : 0) * sizeof(T); // write C matrix size_t writeC = batch_count_C * nnz_C * sizeof(T); return (readA + readB + readC + writeC) / 1e9; } template constexpr double cscmm_batched_gbyte_count(J N, I nnz_A, I nnz_B, I nnz_C, J batch_count_A, J batch_count_B, J batch_count_C, bool beta = false) { // read A matrix size_t readA = batch_count_A * ((N + 1) * sizeof(I) + nnz_A * sizeof(J) + nnz_A * sizeof(T)); // read B matrix size_t readB = batch_count_B * nnz_B * sizeof(T); // read C matrix size_t readC = batch_count_C * (beta ? nnz_C : 0) * sizeof(T); // write C matrix size_t writeC = batch_count_C * nnz_C * sizeof(T); return (readA + readB + readC + writeC) / 1e9; } template constexpr double coomm_batched_gbyte_count(I M, int64_t nnz_A, int64_t nnz_B, int64_t nnz_C, I batch_count_A, I batch_count_B, I batch_count_C, bool beta = false) { // read A matrix size_t readA = batch_count_A * (nnz_A * sizeof(I) + nnz_A * sizeof(I) + nnz_A * sizeof(T)); // read B matrix size_t readB = batch_count_B * nnz_B * sizeof(T); // read C matrix size_t readC = batch_count_C * (beta ? nnz_C : 0) * sizeof(T); // write C matrix size_t writeC = batch_count_C * nnz_C * sizeof(T); return (readA + readB + readC + writeC) / 1e9; } template constexpr double gemmi_gbyte_count(J N, I nnz_B, I nnz_A, I nnz_C, bool beta = false) { return ((N + 1) * sizeof(I) + nnz_B * sizeof(J) + (nnz_B + nnz_A + nnz_C + (beta ? nnz_C : 0)) * sizeof(T)) / 1e9; } template constexpr double sddmm_csr_gbyte_count(J M, J N, J K, I nnz, bool beta = false) { return ((size_t(M) + 1) * sizeof(I) + size_t(nnz) * sizeof(J) + (size_t(nnz) * (K * 2 + ((beta) ? 1 : 0)) * sizeof(T))) / 1e9; } template constexpr double sddmm_csc_gbyte_count(J M, J N, J K, I nnz, bool beta = false) { return ((size_t(N) + 1) * sizeof(I) + size_t(nnz) * sizeof(J) + (size_t(nnz) * (K * 2 + ((beta) ? 1 : 0)) * sizeof(T))) / 1e9; } template constexpr double sddmm_coo_gbyte_count(J M, J N, J K, I nnz, bool beta = false) { return (size_t(nnz) * 2 * sizeof(I) + size_t(nnz) * (K * 2 + ((beta) ? 1 : 0)) * sizeof(T)) / 1e9; } template constexpr double sddmm_coo_aos_gbyte_count(J M, J N, J K, I nnz, bool beta = false) { return (size_t(nnz) * 2 * sizeof(I) + (size_t(nnz) * (K * 2 + ((beta) ? 1 : 0)) * sizeof(T))) / 1e9; } /* * =========================================================================== * precond SPARSE * =========================================================================== */ template constexpr double bsric0_gbyte_count(int Mb, int block_dim, int nnzb) { return ((Mb + 1 + nnzb) * sizeof(int) + 2.0 * block_dim * block_dim * nnzb * sizeof(T)) / 1e9; } template constexpr double bsrilu0_gbyte_count(int Mb, int block_dim, int nnzb) { return ((Mb + 1 + nnzb) * sizeof(int) + 2.0 * block_dim * block_dim * nnzb * sizeof(T)) / 1e9; } template constexpr double csric0_gbyte_count(int M, int nnz) { return ((M + 1 + nnz) * sizeof(int) + 2.0 * nnz * sizeof(T)) / 1e9; } template constexpr double csrilu0_gbyte_count(int M, int nnz) { return ((M + 1 + nnz) * sizeof(int) + 2.0 * nnz * sizeof(T)) / 1e9; } template constexpr double gtsv_gbyte_count(int M, int N) { return ((3 * M + 2 * M * N) * sizeof(T)) / 1e9; } template constexpr double gtsv_strided_batch_gbyte_count(int M, int N) { return ((3 * M * N + 2 * M * N) * sizeof(T)) / 1e9; } template constexpr double gtsv_interleaved_batch_gbyte_count(int M, int N) { return ((3 * M * N + 2 * M * N) * sizeof(T)) / 1e9; } template constexpr double gpsv_interleaved_batch_gbyte_count(int M, int N) { return ((5 * M * N + 2 * M * N) * sizeof(T)) / 1e9; } /* * =========================================================================== * conversion SPARSE * =========================================================================== */ template constexpr double nnz_gbyte_count(int M, int N, hipsparseDirection_t dir) { return ((M * N) * sizeof(T) + ((dir == HIPSPARSE_DIRECTION_ROW) ? M : N) * sizeof(int)) / 1e9; } template constexpr double bsr2csr_gbyte_count(int Mb, int block_dim, int nnzb) { // reads size_t reads = nnzb * block_dim * block_dim * sizeof(T) + (Mb + 1 + nnzb) * sizeof(int); // writes size_t writes = nnzb * block_dim * block_dim * sizeof(T) + (Mb * block_dim + 1 + nnzb * block_dim * block_dim) * sizeof(int); return (reads + writes) / 1e9; } template constexpr double csr2coo_gbyte_count(int M, int nnz) { return (M + 1 + nnz) * sizeof(int) / 1e9; } template constexpr double coo2csr_gbyte_count(int M, int nnz) { return (M + 1 + nnz) * sizeof(int) / 1e9; } template constexpr double csr2csc_gbyte_count(int M, int N, int nnz, hipsparseAction_t action) { return ((M + N + 2 + 2.0 * nnz) * sizeof(int) + (action == HIPSPARSE_ACTION_NUMERIC ? (2.0 * nnz) * sizeof(T) : 0.0)) / 1e9; } template constexpr double csr2hyb_gbyte_count(int M, int nnz, int ell_nnz, int coo_nnz) { return ((M + 1.0 + ell_nnz + 2.0 * coo_nnz) * sizeof(int) + (nnz + ell_nnz + coo_nnz) * sizeof(T)) / 1e9; } template constexpr double hyb2csr_gbyte_count(int M, int csr_nnz, int ell_nnz, int coo_nnz) { return ((M + 1.0 + csr_nnz + ell_nnz + 2.0 * coo_nnz) * sizeof(int) + (csr_nnz + ell_nnz + coo_nnz) * sizeof(T)) / 1e9; } template constexpr double csr2bsr_gbyte_count(int M, int Mb, int nnz, int nnzb, int block_dim) { // reads size_t reads = (M + 1 + nnz) * sizeof(int) + nnz * sizeof(T); // writes size_t writes = (Mb + 1 + nnzb * block_dim * block_dim) * sizeof(int) + (nnzb * block_dim * block_dim) * sizeof(T); return (reads + writes) / 1e9; } template constexpr double csr2gebsr_gbyte_count(int M, int Mb, int nnz, int nnzb, int row_block_dim, int col_block_dim) { // reads size_t reads = (M + 1 + nnz) * sizeof(int) + nnz * sizeof(T); // writes size_t writes = (Mb + 1 + nnzb * row_block_dim * col_block_dim) * sizeof(int) + (nnzb * row_block_dim * col_block_dim) * sizeof(T); return (reads + writes) / 1e9; } template constexpr double csr2csr_compress_gbyte_count(int M, int nnz_A, int nnz_C) { size_t reads = (M + 1 + nnz_A) * sizeof(int) + nnz_A * sizeof(T); size_t writes = (M + 1 + nnz_C) * sizeof(int) + nnz_C * sizeof(T); return (reads + writes) / 1e9; } template constexpr double csx2dense_gbyte_count(J M, J N, I nnz) { J L = (DIRA == HIPSPARSE_DIRECTION_ROW) ? M : N; size_t read_csx = nnz * sizeof(T) + nnz * sizeof(J) + (L + 1) * sizeof(I); size_t write_dense = M * N * sizeof(T) + nnz * sizeof(T); return (read_csx + write_dense) / 1e9; } template constexpr double dense2csx_gbyte_count(J M, J N, I nnz) { J L = (DIRA == HIPSPARSE_DIRECTION_ROW) ? M : N; size_t write_csx_ptr = (L + 1) * sizeof(I); size_t read_csx_ptr = (L + 1) * sizeof(I); size_t build_csx_ptr = write_csx_ptr + read_csx_ptr; size_t write_csx = nnz * sizeof(T) + nnz * sizeof(J) + (L + 1) * sizeof(I); size_t read_dense = M * N * sizeof(T); return (read_dense + build_csx_ptr + write_csx) / 1e9; } template constexpr double dense2coo_gbyte_count(I M, I N, I nnz) { size_t reads = (M * N) * sizeof(T); size_t writes = 2 * nnz * sizeof(I) + nnz * sizeof(T); return (reads + writes) / 1e9; } template constexpr double coo2dense_gbyte_count(I M, I N, I nnz) { size_t reads = 2 * nnz * sizeof(I) + nnz * sizeof(T); size_t writes = (M * N) * sizeof(T); return (reads + writes) / 1e9; } constexpr double csrsort_gbyte_count(int M, int nnz, bool permute) { return ((2.0 * M + 2.0 + 2.0 * nnz + (permute ? 2.0 * nnz : 0.0)) * sizeof(int)) / 1e9; } constexpr double cscsort_gbyte_count(int N, int nnz, bool permute) { return ((2.0 * N + 2.0 + 2.0 * nnz + (permute ? 2.0 * nnz : 0.0)) * sizeof(int)) / 1e9; } constexpr double coosort_gbyte_count(int nnz, bool permute) { return ((4.0 * nnz + (permute ? 2.0 * nnz : 0.0)) * sizeof(int)) / 1e9; } template constexpr double gebsr2csr_gbyte_count(int Mb, int row_block_dim, int col_block_dim, int nnzb) { // reads size_t reads = nnzb * row_block_dim * col_block_dim * sizeof(T) + (Mb + 1 + nnzb) * sizeof(int); // writes size_t writes = nnzb * row_block_dim * col_block_dim * sizeof(T) + (Mb * row_block_dim + 1 + nnzb * row_block_dim * col_block_dim) * sizeof(int); return (reads + writes) / 1e9; } template constexpr double gebsr2gebsc_gbyte_count( int Mb, int Nb, int nnzb, int row_block_dim, int col_block_dim, hipsparseAction_t action) { return ((Mb + Nb + 2 + 2.0 * nnzb) * sizeof(int) + (action == HIPSPARSE_ACTION_NUMERIC ? (2.0 * nnzb * row_block_dim * col_block_dim) * sizeof(T) : 0.0)) / 1e9; } template constexpr double gebsr2gebsr_gbyte_count(int Mb_A, int Mb_C, int row_block_dim_A, int col_block_dim_A, int row_block_dim_C, int col_block_dim_C, int nnzb_A, int nnzb_C) { // reads size_t reads = nnzb_A * row_block_dim_A * col_block_dim_A * sizeof(T) + (Mb_A + 1 + nnzb_A) * sizeof(int); // writes size_t writes = nnzb_C * row_block_dim_C * col_block_dim_C * sizeof(T) + (Mb_C + 1 + nnzb_C) * sizeof(int); return (reads + writes) / 1e9; } constexpr double identity_gbyte_count(int N) { return N * sizeof(int) / 1e9; } template constexpr double prune_csr2csr_gbyte_count(int M, int nnz_A, int nnz_C) { // reads size_t reads = (M + 1 + nnz_A) * sizeof(int) + nnz_A * sizeof(T); // writes size_t writes = (M + 1 + nnz_C) * sizeof(int) + nnz_C * sizeof(T); return (reads + writes) / 1e9; } template constexpr double prune_csr2csr_by_percentage_gbyte_count(int M, int nnz_A, int nnz_C) { // reads size_t reads = (M + 1 + nnz_A) * sizeof(int) + nnz_A * sizeof(T); // writes size_t writes = (M + 1 + nnz_C) * sizeof(int) + nnz_C * sizeof(T); return (reads + writes) / 1e9; } template constexpr double prune_dense2csr_gbyte_count(int M, int N, int nnz) { size_t reads = M * N * sizeof(T); size_t writes = (M + 1 + nnz) * sizeof(int) + nnz * sizeof(T); return (reads + writes) / 1e9; } template constexpr double prune_dense2csr_by_percentage_gbyte_count(int M, int N, int nnz) { size_t reads = M * N * sizeof(T); size_t writes = (M + 1 + nnz) * sizeof(int) + nnz * sizeof(T); return (reads + writes) / 1e9; } /* * =========================================================================== * extra SPARSE * =========================================================================== */ template constexpr double csrgeam_gbyte_count(int M, int nnz_A, int nnz_B, int nnz_C, const T* alpha, const T* beta) { double size_A = alpha ? (M + 1.0 + nnz_A) * sizeof(int) + nnz_A * sizeof(T) : 0.0; double size_B = beta ? (M + 1.0 + nnz_B) * sizeof(int) + nnz_B * sizeof(T) : 0.0; double size_C = (M + 1.0 + nnz_C) * sizeof(int) + nnz_C * sizeof(T); return (size_A + size_B + size_C) / 1e9; } template constexpr double csrgemm_gbyte_count(J M, J N, J K, I nnz_A, I nnz_B, I nnz_C) { double size_A = (M + 1.0) * sizeof(I) + nnz_A * sizeof(J) + nnz_A * sizeof(T); double size_B = (K + 1.0) * sizeof(I) + nnz_B * sizeof(J) + nnz_B * sizeof(T); double size_C = (M + 1.0) * sizeof(I) + nnz_C * sizeof(J) + nnz_C * sizeof(T); return (size_A + size_B + size_C) / 1e9; } #endif // GBYTE_HPPhipSPARSE-rocm-6.4.3/clients/include/hipsparse.hpp000066400000000000000000003172151501764003400217640ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2018-2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef _HIPSPARSE_HPP_ #define _HIPSPARSE_HPP_ #include namespace hipsparse { template struct floating_traits { using data_t = T; }; template <> struct floating_traits { using data_t = float; }; template <> struct floating_traits { using data_t = double; }; template using floating_data_t = typename floating_traits::data_t; #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXaxpyi(hipsparseHandle_t handle, int nnz, const T* alpha, const T* x_val, const int* x_ind, T* y, hipsparseIndexBase_t idx_base); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template hipsparseStatus_t hipsparseXdoti(hipsparseHandle_t handle, int nnz, const T* x_val, const int* x_ind, const T* y, T* result, hipsparseIndexBase_t idx_base); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template hipsparseStatus_t hipsparseXdotci(hipsparseHandle_t handle, int nnz, const T* x_val, const int* x_ind, const T* y, T* result, hipsparseIndexBase_t idx_base); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXgthr(hipsparseHandle_t handle, int nnz, const T* y, T* x_val, const int* x_ind, hipsparseIndexBase_t idx_base); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXgthrz(hipsparseHandle_t handle, int nnz, T* y, T* x_val, const int* x_ind, hipsparseIndexBase_t idx_base); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXroti(hipsparseHandle_t handle, int nnz, T* x_val, const int* x_ind, T* y, const T* c, const T* s, hipsparseIndexBase_t idx_base); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXsctr(hipsparseHandle_t handle, int nnz, const T* x_val, const int* x_ind, T* y, hipsparseIndexBase_t idx_base); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template hipsparseStatus_t hipsparseXcsrmv(hipsparseHandle_t handle, hipsparseOperation_t trans, int m, int n, int nnz, const T* alpha, const hipsparseMatDescr_t descr, const T* csr_val, const int* csr_row_ptr, const int* csr_col_ind, const T* x, const T* beta, T* y); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXcsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, T* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, int* pBufferSizeInBytes); #endif template hipsparseStatus_t hipsparseXcsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, T* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, size_t* pBufferSizeInBytes); #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXcsrsv2_analysis(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, const T* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXcsrsv2_solve(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const T* alpha, const hipsparseMatDescr_t descrA, const T* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, const T* f, T* x, hipsparseSolvePolicy_t policy, void* pBuffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template hipsparseStatus_t hipsparseXhybmv(hipsparseHandle_t handle, hipsparseOperation_t trans, const T* alpha, const hipsparseMatDescr_t descr, const hipsparseHybMat_t hyb, const T* x, const T* beta, T* y); #endif template hipsparseStatus_t hipsparseXbsrmv(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nb, int nnzb, const T* alpha, const hipsparseMatDescr_t descrA, const T* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, const T* x, const T* beta, T* y); #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXbsrxmv(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t trans, int sizeOfMask, int mb, int nb, int nnzb, const T* alpha, const hipsparseMatDescr_t descr, const T* bsrVal, const int* bsrMaskPtr, const int* bsrRowPtr, const int* bsrEndPtr, const int* bsrColInd, int blockDim, const T* x, const T* beta, T* y); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXbsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, T* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, int* pBufferSizeInBytes); #endif template hipsparseStatus_t hipsparseXbsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, T* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, size_t* pBufferSizeInBytes); #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXbsrsv2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const T* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXbsrsv2_solve(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const T* alpha, const hipsparseMatDescr_t descrA, const T* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, const T* f, T* x, hipsparseSolvePolicy_t policy, void* pBuffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXgemvi_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, int* pBufferSizeInBytes); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXgemvi(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, const T* alpha, const T* A, int lda, int nnz, const T* x, const int* xInd, const T* beta, T* y, hipsparseIndexBase_t idxBase, void* pBuffer); #endif template hipsparseStatus_t hipsparseXbsrmm(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transB, int mb, int n, int kb, int nnzb, const T* alpha, const hipsparseMatDescr_t descr, const T* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const T* B, int ldb, const T* beta, T* C, int ldc); #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template hipsparseStatus_t hipsparseXcsrmm2(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, int nnz, const T* alpha, const hipsparseMatDescr_t descr, const T* csr_val, const int* csr_row_ptr, const int* csr_col_ind, const T* B, int ldb, const T* beta, T* C, int ldc); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXbsrsm2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, T* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, int* pBufferSizeInBytes); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXbsrsm2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, const T* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXbsrsm2_solve(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const T* alpha, const hipsparseMatDescr_t descrA, const T* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, const T* B, int ldb, T* X, int ldx, hipsparseSolvePolicy_t policy, void* pBuffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXcsrsm2_bufferSizeExt(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const T* alpha, const hipsparseMatDescr_t descrA, const T* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const T* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, size_t* pBufferSizeInBytes); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXcsrsm2_analysis(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const T* alpha, const hipsparseMatDescr_t descrA, const T* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const T* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXcsrsm2_solve(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const T* alpha, const hipsparseMatDescr_t descrA, const T* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, T* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXgemmi(hipsparseHandle_t handle, int m, int n, int k, int nnz, const T* alpha, const T* A, int lda, const T* cscValB, const int* cscColPtrB, const int* cscRowIndB, const T* beta, T* C, int ldc); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template hipsparseStatus_t hipsparseXcsrgeam(hipsparseHandle_t handle, int m, int n, const T* alpha, const hipsparseMatDescr_t descrA, int nnzA, const T* csrValA, const int* csrRowPtrA, const int* csrColIndA, const T* beta, const hipsparseMatDescr_t descrB, int nnzB, const T* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, T* csrValC, int* csrRowPtrC, int* csrColIndC); #endif template hipsparseStatus_t hipsparseXcsrgeam2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const T* alpha, const hipsparseMatDescr_t descrA, int nnzA, const T* csrValA, const int* csrRowPtrA, const int* csrColIndA, const T* beta, const hipsparseMatDescr_t descrB, int nnzB, const T* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, const T* csrValC, const int* csrRowPtrC, const int* csrColIndC, size_t* pBufferSizeInBytes); template hipsparseStatus_t hipsparseXcsrgeam2(hipsparseHandle_t handle, int m, int n, const T* alpha, const hipsparseMatDescr_t descrA, int nnzA, const T* csrValA, const int* csrRowPtrA, const int* csrColIndA, const T* beta, const hipsparseMatDescr_t descrB, int nnzB, const T* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, T* csrValC, int* csrRowPtrC, int* csrColIndC, void* pBuffer); #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template hipsparseStatus_t hipsparseXcsrgemm(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, const hipsparseMatDescr_t descrA, int nnzA, const T* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const T* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, T* csrValC, const int* csrRowPtrC, int* csrColIndC); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXcsrgemm2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int k, const T* alpha, const hipsparseMatDescr_t descrA, int nnzA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const int* csrRowPtrB, const int* csrColIndB, const T* beta, const hipsparseMatDescr_t descrD, int nnzD, const int* csrRowPtrD, const int* csrColIndD, csrgemm2Info_t info, size_t* pBufferSizeInBytes); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXcsrgemm2(hipsparseHandle_t handle, int m, int n, int k, const T* alpha, const hipsparseMatDescr_t descrA, int nnzA, const T* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const T* csrValB, const int* csrRowPtrB, const int* csrColIndB, const T* beta, const hipsparseMatDescr_t descrD, int nnzD, const T* csrValD, const int* csrRowPtrD, const int* csrColIndD, const hipsparseMatDescr_t descrC, T* csrValC, const int* csrRowPtrC, int* csrColIndC, const csrgemm2Info_t info, void* pBuffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXbsrilu02_numericBoost( hipsparseHandle_t handle, bsrilu02Info_t info, int enable_boost, double* tol, T* boost_val); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXbsrilu02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, T* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int block_dim, bsrilu02Info_t info, int* pBufferSizeInBytes); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXbsrilu02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, T* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int block_dim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXbsrilu02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, T* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int block_dim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXcsrilu02_numericBoost( hipsparseHandle_t handle, csrilu02Info_t info, int enable_boost, double* tol, T* boost_val); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXcsrilu02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, T* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, int* pBufferSizeInBytes); #endif template hipsparseStatus_t hipsparseXcsrilu02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, T* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, size_t* pBufferSizeInBytes); #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXcsrilu02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const T* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXcsrilu02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, T* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXbsric02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, T* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int block_dim, bsric02Info_t info, int* pBufferSizeInBytes); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXbsric02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const T* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int block_dim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXbsric02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, T* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int block_dim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXcsric02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, T* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, int* pBufferSizeInBytes); #endif template hipsparseStatus_t hipsparseXcsric02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, T* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, size_t* pBufferSizeInBytes); #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXcsric02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const T* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXcsric02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, T* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); #endif template hipsparseStatus_t hipsparseXnnz(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const T* A, int lda, int* nnzPerRowColumn, int* nnzTotalDevHostPtr); #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXnnz_compress(hipsparseHandle_t handle, int m, const hipsparseMatDescr_t descrA, const T* csrValA, const int* csrRowPtrA, int* nnzPerRow, int* nnzC, T tol); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXdense2csr(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const T* A, int ld, const int* nnzPerRow, T* csrVal, int* csrRowPtr, int* csrColInd); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXpruneDense2csr_bufferSize(hipsparseHandle_t handle, int m, int n, const T* A, int lda, const T* threshold, const hipsparseMatDescr_t descr, const T* csrVal, const int* csrRowPtr, const int* csrColInd, size_t* bufferSize); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXpruneDense2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const T* A, int lda, const T* threshold, const hipsparseMatDescr_t descr, const T* csrVal, const int* csrRowPtr, const int* csrColInd, size_t* bufferSize); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXpruneDense2csrNnz(hipsparseHandle_t handle, int m, int n, const T* A, int lda, const T* threshold, const hipsparseMatDescr_t descr, int* csrRowPtr, int* nnzTotalDevHostPtr, void* buffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXpruneDense2csr(hipsparseHandle_t handle, int m, int n, const T* A, int lda, const T* threshold, const hipsparseMatDescr_t descr, T* csrVal, const int* csrRowPtr, int* csrColInd, void* buffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXpruneDense2csrByPercentage_bufferSize(hipsparseHandle_t handle, int m, int n, const T* A, int lda, T percentage, const hipsparseMatDescr_t descr, const T* csrVal, const int* csrRowPtr, const int* csrColInd, pruneInfo_t info, size_t* bufferSize); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXpruneDense2csrByPercentage_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const T* A, int lda, T percentage, const hipsparseMatDescr_t descr, const T* csrVal, const int* csrRowPtr, const int* csrColInd, pruneInfo_t info, size_t* bufferSize); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXpruneDense2csrNnzByPercentage(hipsparseHandle_t handle, int m, int n, const T* A, int lda, T percentage, const hipsparseMatDescr_t descr, int* csrRowPtr, int* nnzTotalDevHostPtr, pruneInfo_t info, void* buffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXpruneDense2csrByPercentage(hipsparseHandle_t handle, int m, int n, const T* A, int lda, T percentage, const hipsparseMatDescr_t descr, T* csrVal, const int* csrRowPtr, int* csrColInd, pruneInfo_t info, void* buffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXdense2csc(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const T* A, int ld, const int* nnzPerColumn, T* cscVal, int* cscRowInd, int* cscColPtr); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXcsr2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const T* csrVal, const int* csrRowPtr, const int* csrColInd, T* A, int ld); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXcsc2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const T* cscVal, const int* cscRowInd, const int* cscColPtr, T* A, int ld); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template hipsparseStatus_t hipsparseXcsr2csc(hipsparseHandle_t handle, int m, int n, int nnz, const T* csr_val, const int* csr_row_ptr, const int* csr_col_ind, T* csc_val, int* csc_row_ind, int* csc_col_ptr, hipsparseAction_t copy_values, hipsparseIndexBase_t idx_base); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template hipsparseStatus_t hipsparseXcsr2hyb(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const T* csr_val, const int* csr_row_ptr, const int* csr_col_ind, hipsparseHybMat_t hyb, int user_ell_width, hipsparseHybPartition_t partition_type); #endif template hipsparseStatus_t hipsparseXgebsr2gebsc_bufferSize(hipsparseHandle_t handle, int mb, int nb, int nnzb, const T* bsr_val, const int* bsr_row_ptr, const int* bsr_col_ind, int row_block_dim, int col_block_dim, size_t* p_buffer_size); template hipsparseStatus_t hipsparseXgebsr2gebsc(hipsparseHandle_t handle, int mb, int nb, int nnzb, const T* bsr_val, const int* bsr_row_ptr, const int* bsr_col_ind, int row_block_dim, int col_block_dim, T* bsc_val, int* bsc_row_ind, int* bsc_col_ptr, hipsparseAction_t copy_values, hipsparseIndexBase_t idx_base, void* temp_buffer); template hipsparseStatus_t hipsparseXcsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const T* csr_val, const int* csr_row_ptr, const int* csr_col_ind, int row_block_dim, int col_block_dim, size_t* p_buffer_size); template hipsparseStatus_t hipsparseXcsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const T* csr_val, const int* csr_row_ptr, const int* csr_col_ind, const hipsparseMatDescr_t bsr_descr, T* bsr_val, int* bsr_row_ptr, int* bsr_col_ind, int row_block_dim, int col_block_dim, void* p_buffer); template hipsparseStatus_t hipsparseXcsr2bsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const T* csrValA, const int* csrRowPtrA, const int* csrColIndA, int blockDim, const hipsparseMatDescr_t descrC, T* bsrValC, int* bsrRowPtrC, int* bsrColIndC); template hipsparseStatus_t hipsparseXbsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const T* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const hipsparseMatDescr_t descrC, T* csrValC, int* csrRowPtrC, int* csrColIndC); template hipsparseStatus_t hipsparseXgebsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const T* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDim, int colBlockDim, const hipsparseMatDescr_t descrC, T* csrValC, int* csrRowPtrC, int* csrColIndC); #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template hipsparseStatus_t hipsparseXhyb2csr(hipsparseHandle_t handle, const hipsparseMatDescr_t descrA, const hipsparseHybMat_t hybA, T* csr_val, int* csr_row_ptr, int* csr_col_ind); #endif template hipsparseStatus_t hipsparseXcsr2csr_compress(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, const T* csrValA, const int* csrColIndA, const int* csrRowPtrA, int nnzA, const int* nnzPerRow, T* csrValC, int* csrColIndC, int* csrRowPtrC, T tol); template hipsparseStatus_t hipsparseXpruneCsr2csr_bufferSize(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const T* csrValA, const int* csrRowPtrA, const int* csrColIndA, const T* threshold, const hipsparseMatDescr_t descrC, const T* csrValC, const int* csrRowPtrC, const int* csrColIndC, size_t* bufferSize); #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXpruneCsr2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const T* csrValA, const int* csrRowPtrA, const int* csrColIndA, const T* threshold, const hipsparseMatDescr_t descrC, const T* csrValC, const int* csrRowPtrC, const int* csrColIndC, size_t* bufferSize); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXpruneCsr2csrNnz(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const T* csrValA, const int* csrRowPtrA, const int* csrColIndA, const T* threshold, const hipsparseMatDescr_t descrC, int* csrRowPtrC, int* nnzTotalDevHostPtr, void* buffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXpruneCsr2csr(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const T* csrValA, const int* csrRowPtrA, const int* csrColIndA, const T* threshold, const hipsparseMatDescr_t descrC, T* csrValC, const int* csrRowPtrC, int* csrColIndC, void* buffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXpruneCsr2csrByPercentage_bufferSize(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const T* csrValA, const int* csrRowPtrA, const int* csrColIndA, T percentage, const hipsparseMatDescr_t descrC, const T* csrValC, const int* csrRowPtrC, const int* csrColIndC, pruneInfo_t info, size_t* bufferSize); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXpruneCsr2csrByPercentage_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const T* csrValA, const int* csrRowPtrA, const int* csrColIndA, T percentage, const hipsparseMatDescr_t descrC, const T* csrValC, const int* csrRowPtrC, const int* csrColIndC, pruneInfo_t info, size_t* bufferSize); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXpruneCsr2csrNnzByPercentage(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const T* csrValA, const int* csrRowPtrA, const int* csrColIndA, T percentage, const hipsparseMatDescr_t descrC, int* csrRowPtrC, int* nnzTotalDevHostPtr, pruneInfo_t info, void* buffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXpruneCsr2csrByPercentage(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const T* csrValA, const int* csrRowPtrA, const int* csrColIndA, T percentage, const hipsparseMatDescr_t descrC, T* csrValC, const int* csrRowPtrC, int* csrColIndC, pruneInfo_t info, void* buffer); #endif template hipsparseStatus_t hipsparseXgebsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const T* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, int rowBlockDimC, int colBlockDimC, int* bufferSize); template hipsparseStatus_t hipsparseXgebsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const T* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, const hipsparseMatDescr_t descrC, T* bsrValC, int* bsrRowPtrC, int* bsrColIndC, int rowBlockDimC, int colBlockDimC, void* buffer); #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXcsru2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnz, T* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, size_t* pBufferSizeInBytes); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXcsru2csr(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, T* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXcsr2csru(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, T* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer); #endif template hipsparseStatus_t hipsparseXgpsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const T* ds, const T* dl, const T* d, const T* du, const T* dw, const T* x, int batchCount, size_t* pBufferSizeInBytes); template hipsparseStatus_t hipsparseXgpsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, T* ds, T* dl, T* d, T* du, T* dw, T* x, int batchCount, void* pBuffer); template hipsparseStatus_t hipsparseXgtsv2StridedBatch_bufferSizeExt(hipsparseHandle_t handle, int m, const T* dl, const T* d, const T* du, const T* x, int batchCount, int batchStride, size_t* pBufferSizeInBytes); template hipsparseStatus_t hipsparseXgtsv2StridedBatch(hipsparseHandle_t handle, int m, const T* dl, const T* d, const T* du, T* x, int batchCount, int batchStride, void* pBuffer); template hipsparseStatus_t hipsparseXgtsv2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const T* dl, const T* d, const T* du, const T* B, int ldb, size_t* pBufferSizeInBytes); template hipsparseStatus_t hipsparseXgtsv2(hipsparseHandle_t handle, int m, int n, const T* dl, const T* d, const T* du, T* B, int ldb, void* pBuffer); template hipsparseStatus_t hipsparseXgtsv2_nopivot_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const T* dl, const T* d, const T* du, const T* B, int ldb, size_t* pBufferSizeInBytes); template hipsparseStatus_t hipsparseXgtsv2_nopivot(hipsparseHandle_t handle, int m, int n, const T* dl, const T* d, const T* du, T* B, int ldb, void* pBuffer); template hipsparseStatus_t hipsparseXgtsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const T* dl, const T* d, const T* du, const T* x, int batchCount, size_t* pBufferSizeInBytes); template hipsparseStatus_t hipsparseXgtsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, T* dl, T* d, T* du, T* x, int batchCount, void* pBuffer); #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXcsrcolor(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const T* csrValA, const int* csrRowPtrA, const int* csrColIndA, const floating_data_t* fractionToColor, int* ncolors, int* coloring, int* reordering, hipsparseColorInfo_t info); #endif } // namespace hipsparse #endif // _HIPSPARSE_HPP_ hipSPARSE-rocm-6.4.3/clients/include/hipsparse_arguments.hpp000066400000000000000000000144621501764003400240470ustar00rootroot00000000000000/*! \file */ /* ************************************************************************ * Copyright (C) 2024 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ /*! \file * \brief hipsparse_arguments.hpp provides a class to parse command arguments in both, * clients and gtest. */ #pragma once #include #include #include #include #include "hipsparse_arguments_support.hpp" #include "hipsparse_datatype2string.hpp" template static T convert_alpha_beta(double r, double i) { return static_cast(r); } struct Arguments { int M; int N; int K; int nnz; int block_dim; int row_block_dimA; int col_block_dimA; int row_block_dimB; int col_block_dimB; int lda; int ldb; int ldc; int batch_count; hipsparseIndexType_t index_type_I; hipsparseIndexType_t index_type_J; hipDataType compute_type; double alpha; double alphai; double beta; double betai; double threshold; double percentage; hipsparseOperation_t transA; hipsparseOperation_t transB; hipsparseIndexBase_t baseA; hipsparseIndexBase_t baseB; hipsparseIndexBase_t baseC; hipsparseIndexBase_t baseD; hipsparseAction_t action; hipsparseHybPartition_t part; hipsparseDiagType_t diag_type; hipsparseFillMode_t fill_mode; hipsparseSolvePolicy_t solve_policy; hipsparseDirection_t dirA; hipsparseOrder_t orderA; hipsparseOrder_t orderB; hipsparseOrder_t orderC; hipsparseFormat_t formatA; hipsparseFormat_t formatB; int csr2csc_alg; int dense2sparse_alg; int sparse2dense_alg; int sddmm_alg; int spgemm_alg; int spmm_alg; int spmv_alg; int spsm_alg; int spsv_alg; int numericboost; double boosttol; double boostval; double boostvali; int ell_width; int permute; int gtsv_alg; int gpsv_alg; int unit_check; int timing; int iters; std::string filename; std::string function_name; Arguments() { this->M = -1; this->N = -1; this->K = -1; this->nnz = -1; this->block_dim = 2; this->row_block_dimA = 2; this->col_block_dimA = 2; this->row_block_dimB = 2; this->col_block_dimB = 2; this->lda = -1; this->ldb = -1; this->ldc = -1; this->batch_count = -1; this->index_type_I = HIPSPARSE_INDEX_32I; this->index_type_J = HIPSPARSE_INDEX_32I; this->compute_type = HIP_R_32F; this->alpha = 0.0; this->alphai = 0.0; this->beta = 0.0; this->betai = 0.0; this->threshold = 0.0; this->percentage = 0.0; this->transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; this->transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; this->baseA = HIPSPARSE_INDEX_BASE_ZERO; this->baseB = HIPSPARSE_INDEX_BASE_ZERO; this->baseC = HIPSPARSE_INDEX_BASE_ZERO; this->baseD = HIPSPARSE_INDEX_BASE_ZERO; this->action = HIPSPARSE_ACTION_NUMERIC; this->part = HIPSPARSE_HYB_PARTITION_AUTO; this->diag_type = HIPSPARSE_DIAG_TYPE_NON_UNIT; this->fill_mode = HIPSPARSE_FILL_MODE_LOWER; this->solve_policy = HIPSPARSE_SOLVE_POLICY_NO_LEVEL; this->dirA = HIPSPARSE_DIRECTION_ROW; this->orderA = HIPSPARSE_ORDER_COL; this->orderB = HIPSPARSE_ORDER_COL; this->orderC = HIPSPARSE_ORDER_COL; this->formatA = HIPSPARSE_FORMAT_COO; this->formatB = HIPSPARSE_FORMAT_COO; this->csr2csc_alg = csr2csc_alg_support::get_default_algorithm(); this->dense2sparse_alg = dense2sparse_alg_support::get_default_algorithm(); this->sparse2dense_alg = sparse2dense_alg_support::get_default_algorithm(); this->sddmm_alg = sddmm_alg_support::get_default_algorithm(); this->spgemm_alg = spgemm_alg_support::get_default_algorithm(); this->spmm_alg = spmm_alg_support::get_default_algorithm(); this->spmv_alg = spmv_alg_support::get_default_algorithm(); this->spsm_alg = spsm_alg_support::get_default_algorithm(); this->spsv_alg = spsv_alg_support::get_default_algorithm(); this->numericboost = 0; this->boosttol = 0.0; this->boostval = 1.0; this->boostvali = 0.0; this->ell_width = 0; this->permute = 0; this->gtsv_alg = 0; this->gpsv_alg = 0; this->unit_check = 1; this->timing = 0; this->iters = 10; this->filename = ""; this->function_name = ""; } template T get_alpha() const { return convert_alpha_beta(alpha, alphai); } template T get_beta() const { return convert_alpha_beta(beta, betai); } template T get_threshold() const { return threshold; } template T get_percentage() const { return percentage; } };hipSPARSE-rocm-6.4.3/clients/include/hipsparse_arguments_support.hpp000066400000000000000000000672741501764003400256540ustar00rootroot00000000000000/*! \file */ /* ************************************************************************ * Copyright (C) 2024 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #include #include #if(defined(CUDART_VERSION)) #define STRINGIFY(x) #x #define TOSTRING(x) STRINGIFY(x) static void print_cuda_12_0_0_to_12_5_1_support_string() { std::cout << "Warning: You are using CUDA version: " << TOSTRING(CUDART_VERSION) << " but this routine is not supported. See CUDA support table for this" << " routine below: " << std::endl; std::string table = " CUDA Version \n" "|11.7.1|11.8.0|12.0.0|12.0.1|...|12.4.1|12.5.0|12.5.1|\n" " |<--------------supported------------->| "; std::cout << table << std::endl; } static void print_cuda_11_3_1_to_12_5_1_support_string() { std::cout << "Warning: You are using CUDA version: " << TOSTRING(CUDART_VERSION) << " but this routine is not supported. See CUDA support table for this" << " routine below: " << std::endl; std::string table = " CUDA Version \n" "|11.2.2|11.3.0|11.3.1|11.4.0|...|12.4.1|12.5.0|12.5.1|\n" " |<--------------supported------------->| "; std::cout << table << std::endl; } static void print_cuda_11_2_0_to_12_5_1_support_string() { std::cout << "Warning: You are using CUDA version: " << TOSTRING(CUDART_VERSION) << " but this routine is not supported. See CUDA support table for this" << " routine below: " << std::endl; std::string table = " CUDA Version \n" "|11.1.0|11.1.1|11.2.0|11.2.1|...|12.4.1|12.5.0|12.5.1|\n" " |<--------------supported------------->| "; std::cout << table << std::endl; } static void print_cuda_10_0_0_to_12_5_1_support_string() { std::cout << "Warning: You are using CUDA version: " << TOSTRING(CUDART_VERSION) << " but this routine is not supported. See CUDA support table for this" << " routine below: " << std::endl; std::string table = " CUDA Version \n" "|10.0|10.1|10.2|....|12.4.1|12.5.0|12.5.1|...\n" "|<---------------supported-------------->| "; std::cout << table << std::endl; } static void print_cuda_10_0_0_to_11_8_0_support_string() { std::cout << "Warning: You are using CUDA version: " << TOSTRING(CUDART_VERSION) << " but this routine is not supported. See CUDA support table for this" << " routine below: " << std::endl; std::string table = " CUDA Version \n" "|10.0|10.1|10.2|....|11.7.0|11.7.1|11.8.0|12.0.0|12.0.1|...\n" "|<--------------supported--------------->| "; std::cout << table << std::endl; } static void print_cuda_10_0_0_to_10_2_0_support_string() { std::cout << "Warning: You are using CUDA version: " << TOSTRING(CUDART_VERSION) << " but this routine is not supported. See CUDA support table for this" << " routine below: " << std::endl; std::string table = " CUDA Version \n" "|10.0|10.1|10.1.1|10.1.2|10.2.0|11.0.1|11.0.2|...\n" "|<---------supported---------->| "; std::cout << table << std::endl; } #undef STRINGIFY #undef TOSTRING #endif struct routine_support { // Level 1 static bool is_axpyi_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) return true; #else return false; #endif } static bool is_doti_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) return true; #else return false; #endif } static bool is_dotci_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) return true; #else return false; #endif } static bool is_gthr_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) return true; #else return false; #endif } static bool is_gthrz_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) return true; #else return false; #endif } static bool is_roti_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) return true; #else return false; #endif } static bool is_sctr_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) return true; #else return false; #endif } // Level2 static bool is_bsrsv2_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) return true; #else return false; #endif } static bool is_coomv_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION > 10010 \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) return true; #else return false; #endif } static bool is_csrmv_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION > 10010 \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) return true; #else return false; #endif } static bool is_csrsv_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11030) return true; #else return false; #endif } static bool is_gemvi_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) return true; #else return false; #endif } static bool is_hybmv_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) return true; #else return false; #endif } // Level3 static bool is_bsrmm_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) return true; #else return false; #endif } static bool is_bsrsm2_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) return true; #else return false; #endif } static bool is_coomm_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) return true; #else return false; #endif } static bool is_cscmm_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) return true; #else return false; #endif } static bool is_csrmm_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) return true; #else return false; #endif } static bool is_coosm_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11031) return true; #else return false; #endif } static bool is_csrsm_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11031) return true; #else return false; #endif } static bool is_gemmi_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) return true; #else return false; #endif } // Extra static bool is_csrgeam_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) return true; #else return false; #endif } static bool is_csrgemm_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) return true; #else return false; #endif } // Precond static bool is_bsric02_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) return true; #else return false; #endif } static bool is_bsrilu02_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) return true; #else return false; #endif } static bool is_csric02_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) return true; #else return false; #endif } static bool is_csrilu02_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) return true; #else return false; #endif } static bool is_gtsv2_supported() { return true; } static bool is_gtsv2_nopivot_supported() { return true; } static bool is_gtsv2_strided_batch_supported() { return true; } static bool is_gtsv_interleaved_batch_supported() { return true; } static bool is_gpsv_interleaved_batch_supported() { return true; } // Conversion static bool is_bsr2csr_supported() { return true; } static bool is_csr2coo_supported() { return true; } static bool is_csr2csc_supported() { return true; } static bool is_csr2hyb_supported() { return true; } static bool is_csr2bsr_supported() { return true; } static bool is_csr2gebsr_supported() { return true; } static bool is_csr2csr_compress_supported() { return true; } static bool is_coo2csr_supported() { return true; } static bool is_hyb2csr_supported() { return true; } static bool is_csr2dense_supported() { return true; } static bool is_csc2dense_supported() { return true; } static bool is_coo2dense_supported() { return true; } static bool is_dense2csr_supported() { return true; } static bool is_dense2csc_supported() { return true; } static bool is_dense2coo_supported() { return true; } static bool is_gebsr2csr_supported() { return true; } static bool is_gebsr2gebsc_supported() { return true; } static bool is_gebsr2gebsr_supported() { return true; } // Level 1 static void print_axpyi_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_11_8_0_support_string(); #endif } static void print_doti_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_10_2_0_support_string(); #endif } static void print_dotci_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_10_2_0_support_string(); #endif } static void print_gthr_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_11_8_0_support_string(); #endif } static void print_gthrz_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_11_8_0_support_string(); #endif } static void print_roti_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_11_8_0_support_string(); #endif } static void print_sctr_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_11_8_0_support_string(); #endif } // Level 2 static void print_bsrsv2_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_coomv_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_csrmv_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_csrsv_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_11_8_0_support_string(); #endif } static void print_gemvi_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_11_8_0_support_string(); #endif } static void print_hybmv_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_10_2_0_support_string(); #endif } // Level 3 static void print_bsrmm_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_bsrsm2_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_coomm_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_cscmm_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_csrmm_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_coosm_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_11_3_1_to_12_5_1_support_string(); #endif } static void print_csrsm_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_11_3_1_to_12_5_1_support_string(); #endif } static void print_gemmi_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_11_8_0_support_string(); #endif } // Extra static void print_csrgeam_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_10_2_0_support_string(); #endif } static void print_csrgemm_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_10_2_0_support_string(); #endif } // Precond static void print_bsric02_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_bsrilu02_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_csric02_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_csrilu02_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_gtsv2_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_gtsv2_nopivot_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_gtsv2_strided_batch_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_gtsv_interleaved_batch_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_gpsv_interleaved_batch_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } // Conversion static void print_bsr2csr_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_csr2coo_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_csr2csc_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_csr2hyb_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_csr2bsr_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_csr2gebsr_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_csr2csr_compress_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_coo2csr_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_hyb2csr_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_csr2dense_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_11_2_0_to_12_5_1_support_string(); #endif } static void print_csc2dense_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_11_2_0_to_12_5_1_support_string(); #endif } static void print_coo2dense_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_11_2_0_to_12_5_1_support_string(); #endif } static void print_dense2csr_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_11_2_0_to_12_5_1_support_string(); #endif } static void print_dense2csc_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_11_2_0_to_12_5_1_support_string(); #endif } static void print_dense2coo_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_11_2_0_to_12_5_1_support_string(); #endif } static void print_gebsr2csr_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_gebsr2gebsc_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_gebsr2gebsr_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } }; struct csr2csc_alg_support { static int get_default_algorithm() { #if(!defined(CUDART_VERSION)) return HIPSPARSE_CSR2CSC_ALG_DEFAULT; #else #if(CUDART_VERSION >= 12000) return HIPSPARSE_CSR2CSC_ALG_DEFAULT; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 12000) return HIPSPARSE_CSR2CSC_ALG1; #else return -1; #endif #endif } static std::string get_description() { #if(!defined(CUDART_VERSION)) return "Indicates what algorithm to use when running csr2csc. Possible choices are " "default: 0, Alg1: 1, Alg2: 2 (default:0)"; #else #if(CUDART_VERSION >= 12000) return "Indicates what algorithm to use when running csr2csc. Possible choices are " "default: 0, Alg1: 1 (default:0)"; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 12000) return "Indicates what algorithm to use when running csr2csc. Possible choices are " "default: 1, Alg1: 1, Alg2: 2 (default:1)"; #else return "No algorithm supported in selected cusparse version"; #endif #endif } static std::vector get_supported_algorithms() { #if(!defined(CUDART_VERSION)) return std::vector( {HIPSPARSE_CSR2CSC_ALG_DEFAULT, HIPSPARSE_CSR2CSC_ALG1, HIPSPARSE_CSR2CSC_ALG2}); #else #if(CUDART_VERSION >= 12000) return std::vector({HIPSPARSE_CSR2CSC_ALG_DEFAULT, HIPSPARSE_CSR2CSC_ALG1}); #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 12000) return std::vector({HIPSPARSE_CSR2CSC_ALG1, HIPSPARSE_CSR2CSC_ALG2}); #endif #endif return std::vector(); } }; struct dense2sparse_alg_support { static int get_default_algorithm() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) return HIPSPARSE_DENSETOSPARSE_ALG_DEFAULT; #else return -1; #endif } static std::string get_description() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) return "Indicates what algorithm to use when running dense2sparse. Possible choices are " "default: 0 (default:0)"; #else return "No algorithm supported in selected cusparse version"; #endif } }; struct sparse2dense_alg_support { static int get_default_algorithm() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) return HIPSPARSE_SPARSETODENSE_ALG_DEFAULT; #else return -1; #endif } static std::string get_description() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) return "Indicates what algorithm to use when running sparse2dense. Possible choices are " "default: 0 (default:0)"; #else return "No algorithm supported in selected cusparse version"; #endif } }; struct sddmm_alg_support { static int get_default_algorithm() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11022) return HIPSPARSE_SDDMM_ALG_DEFAULT; #else return -1; #endif } static std::string get_description() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11022) return "Indicates what algorithm to use when running sddmm. Possible choices are default: " "0 (default:0)"; #else return "No algorithm supported in selected cusparse version"; #endif } }; struct spgemm_alg_support { static int get_default_algorithm() { #if(!defined(CUDART_VERSION)) return HIPSPARSE_SPGEMM_DEFAULT; #else #if(CUDART_VERSION >= 12000) return HIPSPARSE_SPGEMM_DEFAULT; #elif(CUDART_VERSION >= 11031 && CUDART_VERSION < 12000) return HIPSPARSE_SPGEMM_DEFAULT; #elif(CUDART_VERSION >= 11000) return HIPSPARSE_SPGEMM_DEFAULT; #else return -1; #endif #endif } static std::string get_description() { #if(!defined(CUDART_VERSION)) return "Indicates what algorithm to use when running spgemm. Possible choices are default: " "0, Deterministic: 1, Non-Deterministic: 2, Alg1: 3, Alg2: 4, Alg3: 5 (default:0)"; #else #if(CUDART_VERSION >= 12000) return "Indicates what algorithm to use when running spgemm. Possible choices are default: " "0, Deterministic: 1, Non-Deterministic: 2, Alg1: 3, Alg2: 4, Alg3: 5 (default:0)"; #elif(CUDART_VERSION >= 11031 && CUDART_VERSION < 12000) return "Indicates what algorithm to use when running spgemm. Possible choices are default: " "0, Deterministic: 1, Non-Deterministic: 2 (default:0)"; #elif(CUDART_VERSION >= 11000) return "Indicates what algorithm to use when running spgemm. Possible choices are default: " "0 (default:0)"; #else return "No algorithm supported in selected cusparse version"; #endif #endif } }; struct spmm_alg_support { static int get_default_algorithm() { #if(!defined(CUDART_VERSION)) return HIPSPARSE_SPMM_ALG_DEFAULT; #else #if(CUDART_VERSION >= 12000) return HIPSPARSE_SPMM_ALG_DEFAULT; #elif(CUDART_VERSION >= 11021 && CUDART_VERSION < 12000) return HIPSPARSE_SPMM_ALG_DEFAULT; #elif(CUDART_VERSION >= 11003 && CUDART_VERSION < 11021) return HIPSPARSE_SPMM_ALG_DEFAULT; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 11003) return HIPSPARSE_MM_ALG_DEFAULT; #else return -1; #endif #endif } static std::string get_description() { #if(!defined(CUDART_VERSION)) return "Indicates what algorithm to use when running spmm. Possible choices are default: " "0, COO Alg1: 1, COO Alg2: 2, COO Alg3: 3, CSR Alg1: 4, COO Alg4: 5, CSR Alg2: 6, " "CSR Alg3: 12, Blocked ELL Alg1: 13 (default:0)"; #else #if(CUDART_VERSION >= 12000) return "Indicates what algorithm to use when running spmm. Possible choices are default: " "0, COO Alg1: 1, COO Alg2: 2, COO Alg3: 3, CSR Alg1: 4, COO Alg4: 5 CSR Alg2: 6, " "CSR Alg3: 12, Blocked ELL Alg1: 13 (default:0)"; #elif(CUDART_VERSION >= 11021 && CUDART_VERSION < 12000) return "Indicates what algorithm to use when running spmm. Possible choices are default: " "0, COO Alg1: 1, COO Alg2: 2, COO Alg3: 3, CSR Alg1: 4, COO Alg4: 5, CSR Alg2: 6, " "CSR Alg3: 12, Blocked ELL Alg1: 13 (default:0)"; #elif(CUDART_VERSION >= 11003 && CUDART_VERSION < 11021) return "Indicates what algorithm to use when running spmm. Possible choices are default: " "0, COO Alg1: 1, COO Alg2: 2, COO Alg3: 3, CSR Alg1: 4, COO Alg4: 5, CSR Alg2: 6, " "Blocked ELL Alg1: 13 (default:0)"; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 11003) return "Indicates what algorithm to use when running spmm. Possible choices are default: " "0, COO Alg1: 1, COO Alg2: 2, COO Alg3: 3, CSR Alg1: 4 (default:0)"; #else return "No algorithm supported in selected cusparse version"; #endif #endif } }; struct spmv_alg_support { static int get_default_algorithm() { #if(!defined(CUDART_VERSION)) return HIPSPARSE_SPMV_ALG_DEFAULT; #else #if(CUDART_VERSION >= 12000) return HIPSPARSE_SPMV_ALG_DEFAULT; #elif(CUDART_VERSION >= 11021 && CUDART_VERSION < 12000) return HIPSPARSE_SPMV_ALG_DEFAULT; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 11021) return HIPSPARSE_MV_ALG_DEFAULT; #else return -1; #endif #endif } static std::string get_description() { #if(!defined(CUDART_VERSION)) return "Indicates what algorithm to use when running spmv. Possible choices are default: " "0, COO Alg1: 1, CSR Alg1: 2, CSR Alg2: 3, COO Alg2: 4 (default:0)"; #else #if(CUDART_VERSION >= 12000) return "Indicates what algorithm to use when running spmv. Possible choices are default: " "0, COO Alg1: 1, CSR Alg1: 2, CSR Alg2: 3, COO Alg2: 4 (default:0)"; #elif(CUDART_VERSION >= 11021 && CUDART_VERSION < 12000) return "Indicates what algorithm to use when running spmv. Possible choices are default: " "0, COO Alg1: 1, CSR Alg1: 2, CSR Alg2: 3, COO Alg2: 4 (default:0)"; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 11021) return "Indicates what algorithm to use when running spmv. Possible choices are default: " "0, COO Alg: 1, CSR Alg1: 2, CSR Alg2: 3 (default:0)"; #else return "No algorithm supported in selected cusparse version"; #endif #endif } }; struct spsm_alg_support { static int get_default_algorithm() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11031) return HIPSPARSE_SPSM_ALG_DEFAULT; #else return -1; #endif } static std::string get_description() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11031) return "Indicates what algorithm to use when running spsm. Possible choices are default: 0 " "(default:0)"; #else return "No algorithm supported in selected cusparse version"; #endif } }; struct spsv_alg_support { static int get_default_algorithm() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11030) return HIPSPARSE_SPSV_ALG_DEFAULT; #else return -1; #endif } static std::string get_description() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11030) return "Indicates what algorithm to use when running spsv. Possible choices are default: 0 " "(default:0)"; #else return "No algorithm supported in selected cusparse version"; #endif } }; hipSPARSE-rocm-6.4.3/clients/include/hipsparse_datatype2string.hpp000066400000000000000000000311161501764003400251610ustar00rootroot00000000000000/*! \file */ /* ************************************************************************ * Copyright (C) 2019-2024 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #include #include constexpr auto hipsparse_indextype2string(hipsparseIndexType_t type) { switch(type) { case HIPSPARSE_INDEX_16U: return "u16"; case HIPSPARSE_INDEX_32I: return "i32"; case HIPSPARSE_INDEX_64I: return "i64"; } return "invalid"; } constexpr auto hipsparse_datatype2string(hipDataType type) { switch(type) { case HIP_R_32F: return "f32_r"; case HIP_R_64F: return "f64_r"; case HIP_C_32F: return "f32_c"; case HIP_C_64F: return "f64_c"; default: return "invalid"; } } constexpr auto hipsparse_indexbase2string(hipsparseIndexBase_t base) { switch(base) { case HIPSPARSE_INDEX_BASE_ZERO: return "0b"; case HIPSPARSE_INDEX_BASE_ONE: return "1b"; } return "invalid"; } constexpr auto hipsparse_operation2string(hipsparseOperation_t trans) { switch(trans) { case HIPSPARSE_OPERATION_NON_TRANSPOSE: return "NT"; case HIPSPARSE_OPERATION_TRANSPOSE: return "T"; case HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE: return "CT"; } return "invalid"; } constexpr auto hipsparse_direction2string(hipsparseDirection_t direction) { switch(direction) { case HIPSPARSE_DIRECTION_ROW: return "row"; case HIPSPARSE_DIRECTION_COLUMN: return "column"; } return "invalid"; } #if(!defined(CUDART_VERSION)) constexpr auto hipsparse_order2string(hipsparseOrder_t order) { switch(order) { case HIPSPARSE_ORDER_ROW: return "row"; case HIPSPARSE_ORDER_COL: return "col"; } return "invalid"; } #else #if(CUDART_VERSION >= 11000) constexpr auto hipsparse_order2string(hipsparseOrder_t order) { switch(order) { case HIPSPARSE_ORDER_ROW: return "row"; case HIPSPARSE_ORDER_COL: return "col"; } return "invalid"; } #elif(CUDART_VERSION >= 10010) constexpr auto hipsparse_order2string(hipsparseOrder_t order) { switch(order) { case HIPSPARSE_ORDER_COL: return "col"; } return "invalid"; } #endif #endif #if(!defined(CUDART_VERSION)) constexpr auto hipsparse_format2string(hipsparseFormat_t format) { switch(format) { case HIPSPARSE_FORMAT_COO: return "coo"; case HIPSPARSE_FORMAT_COO_AOS: return "coo_aos"; case HIPSPARSE_FORMAT_CSR: return "csr"; case HIPSPARSE_FORMAT_CSC: return "csc"; case HIPSPARSE_FORMAT_BLOCKED_ELL: return "bell"; } return "invalid"; } #else #if(CUDART_VERSION >= 12000) constexpr auto hipsparse_format2string(hipsparseFormat_t format) { switch(format) { case HIPSPARSE_FORMAT_COO: return "coo"; case HIPSPARSE_FORMAT_CSR: return "csr"; case HIPSPARSE_FORMAT_CSC: return "csc"; case HIPSPARSE_FORMAT_BLOCKED_ELL: return "bell"; } return "invalid"; } #elif(CUDART_VERSION >= 11021 && CUDART_VERSION < 12000) constexpr auto hipsparse_format2string(hipsparseFormat_t format) { switch(format) { case HIPSPARSE_FORMAT_COO: return "coo"; case HIPSPARSE_FORMAT_COO_AOS: return "coo_aos"; case HIPSPARSE_FORMAT_CSR: return "csr"; case HIPSPARSE_FORMAT_CSC: return "csc"; case HIPSPARSE_FORMAT_BLOCKED_ELL: return "bell"; } return "invalid"; } #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 11021) constexpr auto hipsparse_format2string(hipsparseFormat_t format) { switch(format) { case HIPSPARSE_FORMAT_COO: return "coo"; case HIPSPARSE_FORMAT_COO_AOS: return "coo_aos"; case HIPSPARSE_FORMAT_CSR: return "csr"; } return "invalid"; } #endif #endif constexpr auto hipsparse_action2string(hipsparseAction_t action) { switch(action) { case HIPSPARSE_ACTION_SYMBOLIC: return "sym"; case HIPSPARSE_ACTION_NUMERIC: return "num"; } return "invalid"; } constexpr auto hipsparse_partition2string(hipsparseHybPartition_t part) { switch(part) { case HIPSPARSE_HYB_PARTITION_AUTO: return "auto"; case HIPSPARSE_HYB_PARTITION_USER: return "user"; case HIPSPARSE_HYB_PARTITION_MAX: return "max"; } return "invalid"; } constexpr auto hipsparse_diagtype2string(hipsparseDiagType_t diag_type) { switch(diag_type) { case HIPSPARSE_DIAG_TYPE_NON_UNIT: return "ND"; case HIPSPARSE_DIAG_TYPE_UNIT: return "UD"; } return "invalid"; } constexpr auto hipsparse_fillmode2string(hipsparseFillMode_t fill_mode) { switch(fill_mode) { case HIPSPARSE_FILL_MODE_LOWER: return "L"; case HIPSPARSE_FILL_MODE_UPPER: return "U"; } return "invalid"; } constexpr auto hipsparse_solvepolicy2string(hipsparseSolvePolicy_t policy) { switch(policy) { case HIPSPARSE_SOLVE_POLICY_NO_LEVEL: return "no_level"; case HIPSPARSE_SOLVE_POLICY_USE_LEVEL: return "use_level"; } return "invalid"; } #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11022) constexpr auto hipsparse_sddmmalg2string(hipsparseSDDMMAlg_t alg) { switch(alg) { case HIPSPARSE_SDDMM_ALG_DEFAULT: return "default"; } return "invalid"; } #endif #if(!defined(CUDART_VERSION)) constexpr auto hipsparse_spmmalg2string(hipsparseSpMMAlg_t alg) { switch(alg) { case HIPSPARSE_SPMM_ALG_DEFAULT: return "default"; case HIPSPARSE_SPMM_COO_ALG1: return "coo_alg1"; case HIPSPARSE_SPMM_COO_ALG2: return "coo_alg2"; case HIPSPARSE_SPMM_COO_ALG3: return "coo_alg3"; case HIPSPARSE_SPMM_COO_ALG4: return "coo_alg4"; case HIPSPARSE_SPMM_CSR_ALG1: return "csr_alg1"; case HIPSPARSE_SPMM_CSR_ALG2: return "csr_alg2"; case HIPSPARSE_SPMM_CSR_ALG3: return "csr_alg3"; case HIPSPARSE_SPMM_BLOCKED_ELL_ALG1: return "bell_alg1"; } return "invalid"; } #else #if(CUDART_VERSION >= 12000) constexpr auto hipsparse_spmmalg2string(hipsparseSpMMAlg_t alg) { switch(alg) { case HIPSPARSE_SPMM_ALG_DEFAULT: return "default"; case HIPSPARSE_SPMM_COO_ALG1: return "coo_alg1"; case HIPSPARSE_SPMM_COO_ALG2: return "coo_alg2"; case HIPSPARSE_SPMM_COO_ALG3: return "coo_alg3"; case HIPSPARSE_SPMM_COO_ALG4: return "coo_alg4"; case HIPSPARSE_SPMM_CSR_ALG1: return "csr_alg1"; case HIPSPARSE_SPMM_CSR_ALG2: return "csr_alg2"; case HIPSPARSE_SPMM_CSR_ALG3: return "csr_alg3"; case HIPSPARSE_SPMM_BLOCKED_ELL_ALG1: return "bell_alg1"; } return "invalid"; } #elif(CUDART_VERSION >= 11021 && CUDART_VERSION < 12000) constexpr auto hipsparse_spmmalg2string(hipsparseSpMMAlg_t alg) { switch(alg) { case HIPSPARSE_SPMM_ALG_DEFAULT: return "default"; case HIPSPARSE_SPMM_COO_ALG1: return "coo_alg1"; case HIPSPARSE_SPMM_COO_ALG2: return "coo_alg2"; case HIPSPARSE_SPMM_COO_ALG3: return "coo_alg3"; case HIPSPARSE_SPMM_COO_ALG4: return "coo_alg4"; case HIPSPARSE_SPMM_CSR_ALG1: return "csr_alg1"; case HIPSPARSE_SPMM_CSR_ALG2: return "csr_alg2"; case HIPSPARSE_SPMM_CSR_ALG3: return "csr_alg3"; case HIPSPARSE_SPMM_BLOCKED_ELL_ALG1: return "bell_alg1"; } return "invalid"; } #elif(CUDART_VERSION >= 11003 && CUDART_VERSION < 11021) constexpr auto hipsparse_spmmalg2string(hipsparseSpMMAlg_t alg) { switch(alg) { case HIPSPARSE_SPMM_ALG_DEFAULT: return "default"; case HIPSPARSE_SPMM_COO_ALG1: return "coo_alg1"; case HIPSPARSE_SPMM_COO_ALG2: return "coo_alg2"; case HIPSPARSE_SPMM_COO_ALG3: return "coo_alg3"; case HIPSPARSE_SPMM_COO_ALG4: return "coo_alg4"; case HIPSPARSE_SPMM_CSR_ALG1: return "csr_alg1"; case HIPSPARSE_SPMM_CSR_ALG2: return "csr_alg2"; case HIPSPARSE_SPMM_BLOCKED_ELL_ALG1: return "bell_alg1"; } return "invalid"; } #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 11003) constexpr auto hipsparse_spmmalg2string(hipsparseSpMMAlg_t alg) { switch(alg) { case HIPSPARSE_MM_ALG_DEFAULT: return "default"; case HIPSPARSE_COOMM_ALG1: return "coo_alg1"; case HIPSPARSE_COOMM_ALG2: return "coo_alg2"; case HIPSPARSE_COOMM_ALG3: return "coo_alg3"; case HIPSPARSE_CSRMM_ALG1: return "csr_alg1"; } return "invalid"; } #endif #endif #if(!defined(CUDART_VERSION)) constexpr auto hipsparse_spmvalg2string(hipsparseSpMVAlg_t alg) { switch(alg) { case HIPSPARSE_SPMV_ALG_DEFAULT: return "default"; case HIPSPARSE_SPMV_COO_ALG1: return "coo_alg1"; case HIPSPARSE_SPMV_COO_ALG2: return "coo_alg2"; case HIPSPARSE_SPMV_CSR_ALG1: return "csr_alg1"; case HIPSPARSE_SPMV_CSR_ALG2: return "csr_alg2"; } return "invalid"; } #else #if(CUDART_VERSION >= 12000) constexpr auto hipsparse_spmvalg2string(hipsparseSpMVAlg_t alg) { switch(alg) { case HIPSPARSE_SPMV_ALG_DEFAULT: return "default"; case HIPSPARSE_SPMV_COO_ALG1: return "coo_alg1"; case HIPSPARSE_SPMV_COO_ALG2: return "coo_alg2"; case HIPSPARSE_SPMV_CSR_ALG1: return "csr_alg1"; case HIPSPARSE_SPMV_CSR_ALG2: return "csr_alg2"; } return "invalid"; } #elif(CUDART_VERSION >= 11021 && CUDART_VERSION < 12000) constexpr auto hipsparse_spmvalg2string(hipsparseSpMVAlg_t alg) { switch(alg) { case HIPSPARSE_SPMV_ALG_DEFAULT: return "default"; case HIPSPARSE_SPMV_COO_ALG1: return "coo_alg1"; case HIPSPARSE_SPMV_COO_ALG2: return "coo_alg2"; case HIPSPARSE_SPMV_CSR_ALG1: return "csr_alg1"; case HIPSPARSE_SPMV_CSR_ALG2: return "csr_alg2"; } return "invalid"; } #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 11021) constexpr auto hipsparse_spmvalg2string(hipsparseSpMVAlg_t alg) { switch(alg) { case HIPSPARSE_MV_ALG_DEFAULT: return "default"; case HIPSPARSE_COOMV_ALG: return "coo_alg1"; case HIPSPARSE_CSRMV_ALG1: return "csr_alg1"; case HIPSPARSE_CSRMV_ALG2: return "csr_alg2"; } return "invalid"; } #endif #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11031) constexpr auto hipsparse_spsmalg2string(hipsparseSpSMAlg_t alg) { switch(alg) { case HIPSPARSE_SPSM_ALG_DEFAULT: return "default"; } return "invalid"; } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11030) constexpr auto hipsparse_spsvalg2string(hipsparseSpSVAlg_t alg) { switch(alg) { case HIPSPARSE_SPSV_ALG_DEFAULT: return "default"; } return "invalid"; } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) constexpr auto hipsparse_sparsetodensealg2string(hipsparseSparseToDenseAlg_t alg) { switch(alg) { case HIPSPARSE_SPARSETODENSE_ALG_DEFAULT: return "default"; } return "invalid"; } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) constexpr auto hipsparse_densetosparsealg2string(hipsparseDenseToSparseAlg_t alg) { switch(alg) { case HIPSPARSE_DENSETOSPARSE_ALG_DEFAULT: return "default"; } return "invalid"; } #endifhipSPARSE-rocm-6.4.3/clients/include/hipsparse_test_unique_ptr.hpp000066400000000000000000000241061501764003400252700ustar00rootroot00000000000000/* ************************************************************************ * 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-6.4.3/clients/include/testing_axpby.hpp000066400000000000000000000177661501764003400226560ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_AXPBY_HPP #define TESTING_AXPBY_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include using namespace hipsparse_test; void testing_axpby_bad_arg(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) int64_t size = 100; int64_t nnz = 100; float alpha = 3.7f; float beta = 1.2f; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipDataType dataType = HIP_R_32F; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * nnz), device_free}; auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * size), device_free}; float* dx_val = (float*)dx_val_managed.get(); int* dx_ind = (int*)dx_ind_managed.get(); float* dy = (float*)dy_managed.get(); // Structures hipsparseSpVecDescr_t x; hipsparseDnVecDescr_t y; verify_hipsparse_status_success( hipsparseCreateSpVec(&x, size, nnz, dx_ind, dx_val, idxType, idxBase, dataType), "Success"); verify_hipsparse_status_success(hipsparseCreateDnVec(&y, size, dy, dataType), "Success"); // Axpby verify_hipsparse_status_invalid_handle(hipsparseAxpby(nullptr, &alpha, x, &beta, y)); verify_hipsparse_status_invalid_pointer(hipsparseAxpby(handle, nullptr, x, &beta, y), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseAxpby(handle, &alpha, nullptr, &beta, y), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseAxpby(handle, &alpha, x, nullptr, y), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseAxpby(handle, &alpha, x, &beta, nullptr), "Error: y is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpVec(x), "Success"); verify_hipsparse_status_success(hipsparseDestroyDnVec(y), "Success"); #endif } template hipsparseStatus_t testing_axpby(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) I size = argus.N; I nnz = argus.nnz; T alpha = make_DataType(argus.alpha); T beta = make_DataType(argus.beta); hipsparseIndexBase_t idxBase = argus.baseA; // Index and data type hipsparseIndexType_t idxType = getIndexType(); hipDataType dataType = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hx_ind(nnz); std::vector hx_val(nnz); std::vector hy(size); std::vector hy_gold(size); // Initial Data on CPU srand(12345ULL); hipsparseInitIndex(hx_ind.data(), nnz, 1, size); hipsparseInit(hx_val, 1, nnz); hipsparseInit(hy, 1, size); hy_gold = hy; // Allocate memory on device auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz), device_free}; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * size), device_free}; I* dx_ind = (I*)dx_ind_managed.get(); T* dx_val = (T*)dx_val_managed.get(); T* dy = (T*)dy_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dx_ind, hx_ind.data(), sizeof(I) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx_val, hx_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy, hy.data(), sizeof(T) * size, hipMemcpyHostToDevice)); // Create structures hipsparseSpVecDescr_t x; hipsparseDnVecDescr_t y; CHECK_HIPSPARSE_ERROR( hipsparseCreateSpVec(&x, size, nnz, dx_ind, dx_val, idxType, idxBase, dataType)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&y, size, dy, dataType)); if(argus.unit_check) { // Axpby CHECK_HIPSPARSE_ERROR(hipsparseAxpby(handle, &alpha, x, &beta, y)); // Copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hy.data(), dy, sizeof(T) * size, hipMemcpyDeviceToHost)); // CPU for(int64_t i = 0; i < size; ++i) { hy_gold[i] = testing_mult(beta, hy_gold[i]); } for(int64_t i = 0; i < nnz; ++i) { hy_gold[hx_ind[i] - idxBase] = testing_fma(alpha, hx_val[i], hy_gold[hx_ind[i] - idxBase]); } // Verify results against host unit_check_general(1, size, 1, hy_gold.data(), hy.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseAxpby(handle, &alpha, x, &beta, y)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseAxpby(handle, &alpha, x, &beta, y)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = axpby_gflop_count(nnz); double gbyte_count = axpby_gbyte_count(nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); display_timing_info(display_key_t::size, size, display_key_t::nnz, nnz, display_key_t::alpha, alpha, display_key_t::beta, beta, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIPSPARSE_ERROR(hipsparseDestroySpVec(x)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_AXPBY_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_axpyi.hpp000066400000000000000000000177611501764003400226600ustar00rootroot00000000000000/* ************************************************************************ * 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 "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include using namespace hipsparse; using namespace hipsparse_test; template void testing_axpyi_bad_arg(void) { #if(!defined(CUDART_VERSION)) int nnz = 100; int safe_size = 100; T alpha = 0.6; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dxVal_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dxInd_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; T* dxVal = (T*)dxVal_managed.get(); int* dxInd = (int*)dxInd_managed.get(); T* dy = (T*)dy_managed.get(); verify_hipsparse_status_invalid_pointer( hipsparseXaxpyi(handle, nnz, &alpha, dxVal, (int*)nullptr, dy, idx_base), "Error: xInd is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXaxpyi(handle, nnz, &alpha, (T*)nullptr, dxInd, dy, idx_base), "Error: xVal is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXaxpyi(handle, nnz, &alpha, dxVal, dxInd, (T*)nullptr, idx_base), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXaxpyi(handle, nnz, (T*)nullptr, dxVal, dxInd, dy, idx_base), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXaxpyi((hipsparseHandle_t) nullptr, nnz, &alpha, dxVal, dxInd, dy, idx_base)); #endif } template hipsparseStatus_t testing_axpyi(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int N = argus.N; int nnz = argus.nnz; T h_alpha = make_DataType(argus.alpha); hipsparseIndexBase_t idx_base = argus.baseA; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hxInd(nnz); std::vector hxVal(nnz); std::vector hy_1(N); std::vector hy_2(N); std::vector hy_gold(N); // Initial Data on CPU srand(12345ULL); hipsparseInitIndex(hxInd.data(), nnz, 1, N); hipsparseInit(hxVal, 1, nnz); hipsparseInit(hy_1, 1, N); // copy vector is easy in STL; hy_gold = hx: save a copy in hy_gold which will be output of CPU hy_2 = hy_1; hy_gold = hy_1; // allocate memory on device auto dxInd_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dxVal_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * N), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * N), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dxInd = (int*)dxInd_managed.get(); T* dxVal = (T*)dxVal_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dxInd, hxInd.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dxVal, hxVal.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_1, hy_1.data(), sizeof(T) * N, hipMemcpyHostToDevice)); if(argus.unit_check) { CHECK_HIP_ERROR(hipMemcpy(dy_2, hy_2.data(), sizeof(T) * N, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXaxpyi(handle, nnz, &h_alpha, dxVal, dxInd, dy_1, idx_base)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXaxpyi(handle, nnz, d_alpha, dxVal, dxInd, dy_2, idx_base)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hy_1.data(), dy_1, sizeof(T) * N, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_2.data(), dy_2, sizeof(T) * N, hipMemcpyDeviceToHost)); // CPU for(int i = 0; i < nnz; ++i) { hy_gold[hxInd[i] - idx_base] = hy_gold[hxInd[i] - idx_base] + testing_mult(h_alpha, hxVal[i]); } unit_check_general(1, N, 1, hy_gold.data(), hy_1.data()); unit_check_general(1, N, 1, hy_gold.data(), hy_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXaxpyi(handle, nnz, &h_alpha, dxVal, dxInd, dy_1, idx_base)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXaxpyi(handle, nnz, &h_alpha, dxVal, dxInd, dy_1, idx_base)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = axpyi_gflop_count(nnz); double gbyte_count = axpby_gbyte_count(nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); display_timing_info(display_key_t::size, N, display_key_t::nnz, nnz, display_key_t::alpha, h_alpha, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_AXPYI_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_bsr2csr.hpp000066400000000000000000000621271501764003400231020ustar00rootroot00000000000000/* ************************************************************************ * 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 "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_bsr2csr_bad_arg(void) { #if(!defined(CUDART_VERSION)) int m = 1; int n = 1; int safe_size = 1; int block_dim = 2; hipsparseIndexBase_t csr_idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexBase_t bsr_idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseDirection_t dir = HIPSPARSE_DIRECTION_ROW; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_csr_descr(new descr_struct); hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; std::unique_ptr unique_ptr_bsr_descr(new descr_struct); hipsparseMatDescr_t bsr_descr = unique_ptr_bsr_descr->descr; hipsparseSetMatIndexBase(csr_descr, csr_idx_base); hipsparseSetMatIndexBase(bsr_descr, bsr_idx_base); auto bsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto bsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto bsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto csr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* bsr_row_ptr = (int*)bsr_row_ptr_managed.get(); int* bsr_col_ind = (int*)bsr_col_ind_managed.get(); T* bsr_val = (T*)bsr_val_managed.get(); int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* csr_col_ind = (int*)csr_col_ind_managed.get(); T* csr_val = (T*)csr_val_managed.get(); int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(bsr_row_ptr, local_ptr, sizeof(int) * (1 + 1), hipMemcpyHostToDevice)); verify_hipsparse_status_invalid_handle(hipsparseXbsr2csr((hipsparseHandle_t) nullptr, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind)); verify_hipsparse_status_invalid_pointer(hipsparseXbsr2csr(handle, dir, m, n, (hipsparseMatDescr_t) nullptr, bsr_val, bsr_row_ptr, bsr_col_ind, block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: bsr_descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsr2csr(handle, dir, m, n, bsr_descr, (T*)nullptr, bsr_row_ptr, bsr_col_ind, block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: bsr_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsr2csr(handle, dir, m, n, bsr_descr, bsr_val, (int*)nullptr, bsr_col_ind, block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: bsr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, (int*)nullptr, block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: bsr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, block_dim, (hipsparseMatDescr_t) nullptr, csr_val, csr_row_ptr, csr_col_ind), "Error: csr_descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, block_dim, csr_descr, (T*)nullptr, csr_row_ptr, csr_col_ind), "Error: csr_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, block_dim, csr_descr, csr_val, (int*)nullptr, csr_col_ind), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, block_dim, csr_descr, csr_val, csr_row_ptr, (int*)nullptr), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_size(hipsparseXbsr2csr(handle, dir, -1, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: m is invalid"); verify_hipsparse_status_invalid_size(hipsparseXbsr2csr(handle, dir, m, -1, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: n is invalid"); verify_hipsparse_status_invalid_size(hipsparseXbsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, -1, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: block_dim is invalid"); #endif } template hipsparseStatus_t testing_bsr2csr(Arguments argus) { int m = argus.M; int n = argus.N; int block_dim = argus.block_dim; hipsparseIndexBase_t bsr_idx_base = argus.baseA; hipsparseIndexBase_t csr_idx_base = argus.baseB; hipsparseDirection_t dir = argus.dirA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_csr_descr(new descr_struct); hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; std::unique_ptr unique_ptr_bsr_descr(new descr_struct); hipsparseMatDescr_t bsr_descr = unique_ptr_bsr_descr->descr; hipsparseSetMatIndexBase(csr_descr, csr_idx_base); hipsparseSetMatIndexBase(bsr_descr, bsr_idx_base); if(m == 0 || n == 0 || block_dim == 1) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse does not support m == 0 or n == 0 for bsr2csr // cusparse does not support asynchronous execution if block_dim == 1 return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector csr_row_ptr; std::vector csr_col_ind; std::vector csr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, n, nnz, csr_row_ptr, csr_col_ind, csr_val, csr_idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // m and n can be modifed if we read in a matrix from a file int mb = (m + block_dim - 1) / block_dim; int nb = (n + block_dim - 1) / block_dim; // Host BSR matrix std::vector hbsr_row_ptr; std::vector hbsr_col_ind; std::vector hbsr_val; // Convert CSR matrix to BSR int nnzb; host_csr_to_bsr(dir, m, n, block_dim, nnzb, csr_idx_base, csr_row_ptr, csr_col_ind, csr_val, bsr_idx_base, hbsr_row_ptr, hbsr_col_ind, hbsr_val); // Determine the size of the output CSR matrix based on the size of the input BSR matrix m = mb * block_dim; n = nb * block_dim; // Host CSR matrix std::vector hcsr_row_ptr(m + 1); std::vector hcsr_col_ind(nnzb * block_dim * block_dim); std::vector hcsr_val(nnzb * block_dim * block_dim); // Allocate memory on the device auto dbsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb + 1)), device_free}; auto dbsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnzb), device_free}; auto dbsr_val_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * nnzb * block_dim * block_dim), device_free}; auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{ device_malloc(sizeof(int) * nnzb * block_dim * block_dim), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * nnzb * block_dim * block_dim), device_free}; int* dbsr_row_ptr = (int*)dbsr_row_ptr_managed.get(); int* dbsr_col_ind = (int*)dbsr_col_ind_managed.get(); T* dbsr_val = (T*)dbsr_val_managed.get(); int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); // Copy data from host to device CHECK_HIP_ERROR(hipMemcpy( dbsr_row_ptr, hbsr_row_ptr.data(), sizeof(int) * (mb + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dbsr_col_ind, hbsr_col_ind.data(), sizeof(int) * nnzb, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dbsr_val, hbsr_val.data(), sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyHostToDevice)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseXbsr2csr(handle, dir, mb, nb, bsr_descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind)); // Copy output from device to host CHECK_HIP_ERROR(hipMemcpy( hcsr_row_ptr.data(), dcsr_row_ptr, sizeof(int) * (m + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hcsr_col_ind.data(), dcsr_col_ind, sizeof(int) * nnzb * block_dim * block_dim, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hcsr_val.data(), dcsr_val, sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyDeviceToHost)); // Host computed bsr2csr conversion std::vector hcsr_row_ptr_gold(m + 1); std::vector hcsr_col_ind_gold(nnzb * block_dim * block_dim, 0); std::vector hcsr_val_gold(nnzb * block_dim * block_dim); // Host bsr2csr host_bsr_to_csr(dir, mb, nb, block_dim, bsr_idx_base, hbsr_row_ptr, hbsr_col_ind, hbsr_val, csr_idx_base, hcsr_row_ptr_gold, hcsr_col_ind_gold, hcsr_val_gold); // Unit check unit_check_general(1, m + 1, 1, hcsr_row_ptr_gold.data(), hcsr_row_ptr.data()); unit_check_general( 1, nnzb * block_dim * block_dim, 1, hcsr_col_ind_gold.data(), hcsr_col_ind.data()); unit_check_general( 1, nnzb * block_dim * block_dim, 1, hcsr_val_gold.data(), hcsr_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXbsr2csr(handle, dir, mb, nb, bsr_descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXbsr2csr(handle, dir, mb, nb, bsr_descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = bsr2csr_gbyte_count(mb, block_dim, nnzb); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::Mb, mb, display_key_t::Nb, nb, display_key_t::block_dim, block_dim, display_key_t::nnzb, nnzb, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_BSR2CSR_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_bsric02.hpp000066400000000000000000001137151501764003400227660ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_BSRIC02_HPP #define TESTING_BSRIC02_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_bsric02_bad_arg(void) { #if(!defined(CUDART_VERSION)) int mb = 100; int nnzb = 100; int block_dim = 4; int safe_size = 100; hipsparseDirection_t dirA = HIPSPARSE_DIRECTION_COLUMN; hipsparseSolvePolicy_t policy = HIPSPARSE_SOLVE_POLICY_USE_LEVEL; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_bsric02(new bsric02_struct); bsric02Info_t info = unique_ptr_bsric02->info; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); void* dbuffer = (void*)dbuffer_managed.get(); int size; int position; verify_hipsparse_status_invalid_pointer( hipsparseXbsric02_bufferSize( handle, dirA, mb, nnzb, descr, dval, (int*)nullptr, dcol, block_dim, info, &size), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsric02_bufferSize( handle, dirA, mb, nnzb, descr, dval, dptr, (int*)nullptr, block_dim, info, &size), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsric02_bufferSize( handle, dirA, mb, nnzb, descr, (T*)nullptr, dptr, dcol, block_dim, info, &size), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsric02_bufferSize( handle, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info, (int*)nullptr), "Error: size is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsric02_bufferSize(handle, dirA, mb, nnzb, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, block_dim, info, &size), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsric02_bufferSize(handle, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, (bsric02Info_t) nullptr, &size), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXbsric02_bufferSize((hipsparseHandle_t) nullptr, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info, &size)); verify_hipsparse_status_invalid_pointer(hipsparseXbsric02_analysis(handle, dirA, mb, nnzb, descr, dval, (int*)nullptr, dcol, block_dim, info, policy, dbuffer), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsric02_analysis(handle, dirA, mb, nnzb, descr, dval, dptr, (int*)nullptr, block_dim, info, policy, dbuffer), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsric02_analysis(handle, dirA, mb, nnzb, descr, (T*)nullptr, dptr, dcol, block_dim, info, policy, dbuffer), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsric02_analysis(handle, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info, policy, (void*)nullptr), "Error: dbuffer is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsric02_analysis(handle, dirA, mb, nnzb, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, block_dim, info, policy, dbuffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsric02_analysis(handle, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, (bsric02Info_t) nullptr, policy, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXbsric02_analysis((hipsparseHandle_t) nullptr, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info, policy, dbuffer)); verify_hipsparse_status_invalid_pointer(hipsparseXbsric02(handle, dirA, mb, nnzb, descr, dval, (int*)nullptr, dcol, block_dim, info, policy, dbuffer), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsric02(handle, dirA, mb, nnzb, descr, dval, dptr, (int*)nullptr, block_dim, info, policy, dbuffer), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsric02(handle, dirA, mb, nnzb, descr, dval, dptr, (int*)nullptr, block_dim, info, policy, dbuffer), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsric02(handle, dirA, mb, nnzb, descr, (T*)nullptr, dptr, dcol, block_dim, info, policy, dbuffer), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsric02(handle, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info, policy, (void*)nullptr), "Error: dbuffer is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsric02(handle, dirA, mb, nnzb, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, block_dim, info, policy, dbuffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsric02(handle, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, (bsric02Info_t) nullptr, policy, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXbsric02((hipsparseHandle_t) nullptr, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info, policy, dbuffer)); verify_hipsparse_status_invalid_pointer( hipsparseXbsric02_zeroPivot(handle, info, (int*)nullptr), "Error: position is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsric02_zeroPivot(handle, (bsric02Info_t) nullptr, &position), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXbsric02_zeroPivot((hipsparseHandle_t) nullptr, info, &position)); #endif } template hipsparseStatus_t testing_bsric02(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) int m = argus.M; int block_dim = argus.block_dim; hipsparseDirection_t dir = argus.dirA; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseSolvePolicy_t policy = argus.solve_policy; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_bsric02(new bsric02_struct); bsric02Info_t info = unique_ptr_bsric02->info; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); if(m == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse does not support m == 0 for csr2bsr return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, m, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // m can be modifed if we read in a matrix from a file int mb = (m + block_dim - 1) / block_dim; // allocate memory on device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dbsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb + 1)), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); int* dbsr_row_ptr = (int*)dbsr_row_ptr_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_val, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); // Convert to BSR int nnzb; CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsrNnz(handle, dir, m, m, descr, dcsr_row_ptr, dcsr_col_ind, block_dim, descr, dbsr_row_ptr, &nnzb)); auto dbsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnzb), device_free}; auto dbsr_val_1_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * nnzb * block_dim * block_dim), device_free}; auto dbsr_val_2_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * nnzb * block_dim * block_dim), device_free}; auto d_analysis_pivot_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; auto d_solve_pivot_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dbsr_col_ind = (int*)dbsr_col_ind_managed.get(); T* dbsr_val_1 = (T*)dbsr_val_1_managed.get(); T* dbsr_val_2 = (T*)dbsr_val_2_managed.get(); int* d_analysis_pivot_2 = (int*)d_analysis_pivot_2_managed.get(); int* d_solve_pivot_2 = (int*)d_solve_pivot_2_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsr(handle, dir, m, m, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, block_dim, descr, dbsr_val_1, dbsr_row_ptr, dbsr_col_ind)); CHECK_HIP_ERROR(hipMemcpy( dbsr_val_2, dbsr_val_1, sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyDeviceToDevice)); // Host BSR matrix std::vector hbsr_row_ptr(mb + 1); std::vector hbsr_col_ind(nnzb); std::vector hbsr_val(nnzb * block_dim * block_dim); std::vector hbsr_val_orig(nnzb * block_dim * block_dim); // Copy device BSR matrix to host CHECK_HIP_ERROR(hipMemcpy( hbsr_row_ptr.data(), dbsr_row_ptr, sizeof(int) * (mb + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hbsr_col_ind.data(), dbsr_col_ind, sizeof(int) * nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsr_val.data(), dbsr_val_1, sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsr_val_orig.data(), dbsr_val_1, sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyDeviceToHost)); // Obtain bsric02 buffer size int bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseXbsric02_bufferSize(handle, dir, mb, nnzb, descr, dbsr_val_1, dbsr_row_ptr, dbsr_col_ind, block_dim, info, &bufferSize)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * bufferSize), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); int h_analysis_pivot_gold; int h_analysis_pivot_1; int h_analysis_pivot_2; int h_solve_pivot_gold; int h_solve_pivot_1; int h_solve_pivot_2; hipsparseStatus_t status_analysis_1; hipsparseStatus_t status_analysis_2; hipsparseStatus_t status_solve_1; hipsparseStatus_t status_solve_2; if(argus.unit_check) { // bsric02 analysis - host mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXbsric02_analysis(handle, dir, mb, nnzb, descr, dbsr_val_1, dbsr_row_ptr, dbsr_col_ind, block_dim, info, policy, dbuffer)); // Get pivot status_analysis_1 = hipsparseXbsric02_zeroPivot(handle, info, &h_analysis_pivot_1); if(h_analysis_pivot_1 != -1) { verify_hipsparse_status_zero_pivot(status_analysis_1, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); } // bsric02 analysis - device mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXbsric02_analysis(handle, dir, mb, nnzb, descr, dbsr_val_2, dbsr_row_ptr, dbsr_col_ind, block_dim, info, policy, dbuffer)); // Get pivot status_analysis_2 = hipsparseXbsric02_zeroPivot(handle, info, d_analysis_pivot_2); if(h_analysis_pivot_1 != -1) { verify_hipsparse_status_zero_pivot(status_analysis_2, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); } // bsric02 solve - host mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXbsric02(handle, dir, mb, nnzb, descr, dbsr_val_1, dbsr_row_ptr, dbsr_col_ind, block_dim, info, policy, dbuffer)); // Get pivot status_solve_1 = hipsparseXbsric02_zeroPivot(handle, info, &h_solve_pivot_1); if(h_solve_pivot_1 != -1) { verify_hipsparse_status_zero_pivot(status_solve_1, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); } // bsric02 solve - device mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXbsric02(handle, dir, mb, nnzb, descr, dbsr_val_2, dbsr_row_ptr, dbsr_col_ind, block_dim, info, policy, dbuffer)); // Get pivot status_solve_2 = hipsparseXbsric02_zeroPivot(handle, info, d_solve_pivot_2); if(h_solve_pivot_1 != -1) { verify_hipsparse_status_zero_pivot(status_solve_2, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); } // Copy output from device to CPU std::vector result_1(block_dim * block_dim * nnzb); std::vector result_2(block_dim * block_dim * nnzb); CHECK_HIP_ERROR(hipMemcpy(result_1.data(), dbsr_val_1, sizeof(T) * block_dim * block_dim * nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(result_2.data(), dbsr_val_2, sizeof(T) * block_dim * block_dim * nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(&h_analysis_pivot_2, d_analysis_pivot_2, sizeof(int), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(&h_solve_pivot_2, d_solve_pivot_2, sizeof(int), hipMemcpyDeviceToHost)); // Host csric02 int numerical_pivot; int structural_pivot; host_bsric02(dir, mb, block_dim, hbsr_row_ptr, hbsr_col_ind, hbsr_val, idx_base, &structural_pivot, &numerical_pivot); h_analysis_pivot_gold = structural_pivot; // Solve pivot gives the first numerical or structural non-invertible block if(structural_pivot == -1) { h_solve_pivot_gold = numerical_pivot; } else if(numerical_pivot == -1) { h_solve_pivot_gold = structural_pivot; } else { h_solve_pivot_gold = std::min(numerical_pivot, structural_pivot); } #ifndef __HIP_PLATFORM_NVIDIA__ // Do not check pivots in cusparse unit_check_general(1, 1, 1, &h_analysis_pivot_gold, &h_analysis_pivot_1); unit_check_general(1, 1, 1, &h_analysis_pivot_gold, &h_analysis_pivot_2); unit_check_general(1, 1, 1, &h_solve_pivot_gold, &h_solve_pivot_1); unit_check_general(1, 1, 1, &h_solve_pivot_gold, &h_solve_pivot_2); #endif if(h_analysis_pivot_gold == -1 && h_solve_pivot_gold == -1) { unit_check_near(1, nnzb * block_dim * block_dim, 1, hbsr_val.data(), result_1.data()); unit_check_near(1, nnzb * block_dim * block_dim, 1, hbsr_val.data(), result_2.data()); } } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIP_ERROR(hipMemcpy(dbsr_val_1, hbsr_val_orig.data(), sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyHostToDevice)); CHECK_HIPSPARSE_ERROR(hipsparseXbsric02(handle, dir, mb, nnzb, descr, dbsr_val_1, dbsr_row_ptr, dbsr_col_ind, block_dim, info, policy, dbuffer)); } // Solve run double gpu_time_used = 0; for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIP_ERROR(hipMemcpy(dbsr_val_1, hbsr_val_orig.data(), sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyHostToDevice)); double temp = get_time_us(); CHECK_HIPSPARSE_ERROR(hipsparseXbsric02(handle, dir, mb, nnzb, descr, dbsr_val_1, dbsr_row_ptr, dbsr_col_ind, block_dim, info, policy, dbuffer)); gpu_time_used += (get_time_us() - temp); } gpu_time_used = gpu_time_used / number_hot_calls; double gbyte_count = bsric0_gbyte_count(mb, block_dim, nnzb); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::Mb, mb, display_key_t::nnzb, nnzb, display_key_t::block_dim, block_dim, display_key_t::direction, hipsparse_direction2string(dir), display_key_t::solve_policy, hipsparse_solvepolicy2string(policy), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_BSRIC02_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_bsrilu02.hpp000066400000000000000000001161631501764003400231640ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_BSRILU02_HPP #define TESTING_BSRILU02_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_bsrilu02_bad_arg(void) { #if(!defined(CUDART_VERSION)) int mb = 100; int nnzb = 100; int block_dim = 4; int safe_size = 100; hipsparseDirection_t dirA = HIPSPARSE_DIRECTION_COLUMN; hipsparseSolvePolicy_t policy = HIPSPARSE_SOLVE_POLICY_USE_LEVEL; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_bsrilu02(new bsrilu02_struct); bsrilu02Info_t info = unique_ptr_bsrilu02->info; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; auto dboost_tol_managed = hipsparse_unique_ptr{device_malloc(sizeof(double)), device_free}; auto dboost_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); void* dbuffer = (void*)dbuffer_managed.get(); double* dboost_tol = (double*)dboost_tol_managed.get(); T* dboost_val = (T*)dboost_val_managed.get(); int size; int position; verify_hipsparse_status_invalid_pointer( hipsparseXbsrilu02_bufferSize( handle, dirA, mb, nnzb, descr, dval, (int*)nullptr, dcol, block_dim, info, &size), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsrilu02_bufferSize( handle, dirA, mb, nnzb, descr, dval, dptr, (int*)nullptr, block_dim, info, &size), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsrilu02_bufferSize( handle, dirA, mb, nnzb, descr, (T*)nullptr, dptr, dcol, block_dim, info, &size), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsrilu02_bufferSize( handle, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info, (int*)nullptr), "Error: size is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsrilu02_bufferSize(handle, dirA, mb, nnzb, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, block_dim, info, &size), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrilu02_bufferSize(handle, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, (bsrilu02Info_t) nullptr, &size), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXbsrilu02_bufferSize((hipsparseHandle_t) nullptr, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info, &size)); verify_hipsparse_status_invalid_handle(hipsparseXbsrilu02_numericBoost( (hipsparseHandle_t) nullptr, info, 1, dboost_tol, dboost_val)); verify_hipsparse_status_invalid_pointer( hipsparseXbsrilu02_numericBoost( handle, (bsrilu02Info_t) nullptr, 1, dboost_tol, dboost_val), "Error: info is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsrilu02_numericBoost(handle, info, 1, (double*)nullptr, dboost_val), "Error: boost_tol is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsrilu02_numericBoost(handle, info, 1, dboost_tol, (T*)nullptr), "Error: boost_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrilu02_analysis(handle, dirA, mb, nnzb, descr, dval, (int*)nullptr, dcol, block_dim, info, policy, dbuffer), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrilu02_analysis(handle, dirA, mb, nnzb, descr, dval, dptr, (int*)nullptr, block_dim, info, policy, dbuffer), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrilu02_analysis(handle, dirA, mb, nnzb, descr, (T*)nullptr, dptr, dcol, block_dim, info, policy, dbuffer), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrilu02_analysis(handle, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info, policy, (void*)nullptr), "Error: dbuffer is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsrilu02_analysis(handle, dirA, mb, nnzb, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, block_dim, info, policy, dbuffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrilu02_analysis(handle, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, (bsrilu02Info_t) nullptr, policy, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXbsrilu02_analysis((hipsparseHandle_t) nullptr, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info, policy, dbuffer)); verify_hipsparse_status_invalid_pointer(hipsparseXbsrilu02(handle, dirA, mb, nnzb, descr, dval, (int*)nullptr, dcol, block_dim, info, policy, dbuffer), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrilu02(handle, dirA, mb, nnzb, descr, dval, dptr, (int*)nullptr, block_dim, info, policy, dbuffer), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrilu02(handle, dirA, mb, nnzb, descr, (T*)nullptr, dptr, dcol, block_dim, info, policy, dbuffer), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrilu02(handle, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info, policy, (void*)nullptr), "Error: dbuffer is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrilu02(handle, dirA, mb, nnzb, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, block_dim, info, policy, dbuffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrilu02(handle, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, (bsrilu02Info_t) nullptr, policy, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXbsrilu02((hipsparseHandle_t) nullptr, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info, policy, dbuffer)); verify_hipsparse_status_invalid_pointer( hipsparseXbsrilu02_zeroPivot(handle, info, (int*)nullptr), "Error: position is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsrilu02_zeroPivot(handle, (bsrilu02Info_t) nullptr, &position), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXbsrilu02_zeroPivot((hipsparseHandle_t) nullptr, info, &position)); #endif } template hipsparseStatus_t testing_bsrilu02(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) int m = argus.M; int block_dim = argus.block_dim; int boost = argus.numericboost; double boost_tol = argus.boosttol; T boost_val = make_DataType(argus.boostval, argus.boostvali); hipsparseDirection_t dir = argus.dirA; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseSolvePolicy_t policy = argus.solve_policy; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_bsrilu02(new bsrilu02_struct); bsrilu02Info_t info = unique_ptr_bsrilu02->info; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); if(m == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse does not support m == 0 for csr2bsr return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, m, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // m can be modifed if we read in a matrix from a file int mb = (m + block_dim - 1) / block_dim; // allocate memory on device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dbsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb + 1)), device_free}; auto boost_tol_managed = hipsparse_unique_ptr{device_malloc(sizeof(double)), device_free}; auto boost_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); int* dbsr_row_ptr = (int*)dbsr_row_ptr_managed.get(); double* dboost_tol = (double*)boost_tol_managed.get(); T* dboost_val = (T*)boost_val_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_val, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); // Convert to BSR int nnzb; CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsrNnz(handle, dir, m, m, descr, dcsr_row_ptr, dcsr_col_ind, block_dim, descr, dbsr_row_ptr, &nnzb)); auto dbsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnzb), device_free}; auto dbsr_val_1_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * nnzb * block_dim * block_dim), device_free}; auto dbsr_val_2_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * nnzb * block_dim * block_dim), device_free}; auto d_analysis_pivot_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; auto d_solve_pivot_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dbsr_col_ind = (int*)dbsr_col_ind_managed.get(); T* dbsr_val_1 = (T*)dbsr_val_1_managed.get(); T* dbsr_val_2 = (T*)dbsr_val_2_managed.get(); int* d_analysis_pivot_2 = (int*)d_analysis_pivot_2_managed.get(); int* d_solve_pivot_2 = (int*)d_solve_pivot_2_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsr(handle, dir, m, m, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, block_dim, descr, dbsr_val_1, dbsr_row_ptr, dbsr_col_ind)); CHECK_HIP_ERROR(hipMemcpy( dbsr_val_2, dbsr_val_1, sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyDeviceToDevice)); // Host BSR matrix std::vector hbsr_row_ptr(mb + 1); std::vector hbsr_col_ind(nnzb); std::vector hbsr_val(nnzb * block_dim * block_dim); std::vector hbsr_val_orig(nnzb * block_dim * block_dim); // Copy device BSR matrix to host CHECK_HIP_ERROR(hipMemcpy( hbsr_row_ptr.data(), dbsr_row_ptr, sizeof(int) * (mb + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hbsr_col_ind.data(), dbsr_col_ind, sizeof(int) * nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsr_val.data(), dbsr_val_1, sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsr_val_orig.data(), dbsr_val_1, sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyDeviceToHost)); // Obtain bsrilu02 buffer size int bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseXbsrilu02_bufferSize(handle, dir, mb, nnzb, descr, dbsr_val_1, dbsr_row_ptr, dbsr_col_ind, block_dim, info, &bufferSize)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * bufferSize), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); int h_analysis_pivot_gold; int h_analysis_pivot_1; int h_analysis_pivot_2; int h_solve_pivot_gold; int h_solve_pivot_1; int h_solve_pivot_2; if(argus.unit_check) { hipsparseStatus_t status_analysis_1; hipsparseStatus_t status_analysis_2; hipsparseStatus_t status_solve_1; hipsparseStatus_t status_solve_2; CHECK_HIP_ERROR(hipMemcpy(dboost_tol, &boost_tol, sizeof(double), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dboost_val, &boost_val, sizeof(T), hipMemcpyHostToDevice)); // bsrilu02 analysis - host mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXbsrilu02_analysis(handle, dir, mb, nnzb, descr, dbsr_val_1, dbsr_row_ptr, dbsr_col_ind, block_dim, info, policy, dbuffer)); // Get pivot status_analysis_1 = hipsparseXbsrilu02_zeroPivot(handle, info, &h_analysis_pivot_1); if(h_analysis_pivot_1 != -1) { verify_hipsparse_status_zero_pivot(status_analysis_1, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); } // bsrilu02 analysis - device mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXbsrilu02_analysis(handle, dir, mb, nnzb, descr, dbsr_val_2, dbsr_row_ptr, dbsr_col_ind, block_dim, info, policy, dbuffer)); // Get pivot status_analysis_2 = hipsparseXbsrilu02_zeroPivot(handle, info, d_analysis_pivot_2); if(h_analysis_pivot_1 != -1) { verify_hipsparse_status_zero_pivot(status_analysis_2, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); } // bsrilu02 solve - host mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseXbsrilu02_numericBoost(handle, info, boost, &boost_tol, &boost_val)); CHECK_HIPSPARSE_ERROR(hipsparseXbsrilu02(handle, dir, mb, nnzb, descr, dbsr_val_1, dbsr_row_ptr, dbsr_col_ind, block_dim, info, policy, dbuffer)); // Get pivot status_solve_1 = hipsparseXbsrilu02_zeroPivot(handle, info, &h_solve_pivot_1); if(h_solve_pivot_1 != -1) { verify_hipsparse_status_zero_pivot(status_solve_1, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); } // bsrilu02 solve - device mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseXbsrilu02_numericBoost(handle, info, boost, dboost_tol, dboost_val)); CHECK_HIPSPARSE_ERROR(hipsparseXbsrilu02(handle, dir, mb, nnzb, descr, dbsr_val_2, dbsr_row_ptr, dbsr_col_ind, block_dim, info, policy, dbuffer)); // Get pivot status_solve_2 = hipsparseXbsrilu02_zeroPivot(handle, info, d_solve_pivot_2); if(h_solve_pivot_1 != -1) { verify_hipsparse_status_zero_pivot(status_solve_2, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); } // Copy output from device to CPU std::vector result_1(block_dim * block_dim * nnzb); std::vector result_2(block_dim * block_dim * nnzb); CHECK_HIP_ERROR(hipMemcpy(result_1.data(), dbsr_val_1, sizeof(T) * block_dim * block_dim * nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(result_2.data(), dbsr_val_2, sizeof(T) * block_dim * block_dim * nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(&h_analysis_pivot_2, d_analysis_pivot_2, sizeof(int), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(&h_solve_pivot_2, d_solve_pivot_2, sizeof(int), hipMemcpyDeviceToHost)); // Host bsrilu02 int numerical_pivot; int structural_pivot; host_bsrilu02(dir, mb, block_dim, hbsr_row_ptr, hbsr_col_ind, hbsr_val, idx_base, &structural_pivot, &numerical_pivot, boost, boost_tol, boost_val); h_analysis_pivot_gold = structural_pivot; // Solve pivot gives the first numerical or structural non-invertible block if(structural_pivot == -1) { h_solve_pivot_gold = numerical_pivot; } else if(numerical_pivot == -1) { h_solve_pivot_gold = structural_pivot; } else { h_solve_pivot_gold = std::min(numerical_pivot, structural_pivot); } unit_check_general(1, 1, 1, &h_analysis_pivot_gold, &h_analysis_pivot_1); unit_check_general(1, 1, 1, &h_analysis_pivot_gold, &h_analysis_pivot_2); unit_check_general(1, 1, 1, &h_solve_pivot_gold, &h_solve_pivot_1); unit_check_general(1, 1, 1, &h_solve_pivot_gold, &h_solve_pivot_2); if(h_analysis_pivot_gold == -1 && h_solve_pivot_gold == -1) { unit_check_near(1, nnzb * block_dim * block_dim, 1, hbsr_val.data(), result_1.data()); unit_check_near(1, nnzb * block_dim * block_dim, 1, hbsr_val.data(), result_2.data()); } } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseXbsrilu02_numericBoost(handle, info, 0, (double*)nullptr, (T*)nullptr)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIP_ERROR(hipMemcpy(dbsr_val_1, hbsr_val_orig.data(), sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyHostToDevice)); CHECK_HIPSPARSE_ERROR(hipsparseXbsrilu02(handle, dir, mb, nnzb, descr, dbsr_val_1, dbsr_row_ptr, dbsr_col_ind, block_dim, info, policy, dbuffer)); } double gpu_time_used = 0; // Solve run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIP_ERROR(hipMemcpy(dbsr_val_1, hbsr_val_orig.data(), sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyHostToDevice)); double temp = get_time_us(); CHECK_HIPSPARSE_ERROR(hipsparseXbsrilu02(handle, dir, mb, nnzb, descr, dbsr_val_1, dbsr_row_ptr, dbsr_col_ind, block_dim, info, policy, dbuffer)); gpu_time_used += (get_time_us() - temp); } gpu_time_used = gpu_time_used / number_hot_calls; double gbyte_count = bsrilu0_gbyte_count(mb, block_dim, nnzb); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::Mb, mb, display_key_t::nnzb, nnzb, display_key_t::block_dim, block_dim, display_key_t::direction, hipsparse_direction2string(dir), display_key_t::solve_policy, hipsparse_solvepolicy2string(policy), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_BSRILU02_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_bsrmm.hpp000066400000000000000000001160731501764003400226420ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_BSRMM_HPP #define TESTING_BSRMM_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_bsrmm_bad_arg(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; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; auto dbsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dbsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dbsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dC_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* dbsr_row_ptr = (int*)dbsr_row_ptr_managed.get(); int* dbsr_col_ind = (int*)dbsr_col_ind_managed.get(); T* dbsr_val = (T*)dbsr_val_managed.get(); T* dB = (T*)dB_managed.get(); T* dC = (T*)dC_managed.get(); verify_hipsparse_status_invalid_handle(hipsparseXbsrmm((hipsparseHandle_t) nullptr, dirA, transA, transB, mb, n, kb, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, &beta, dC, ldc)); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, (T*)nullptr, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, &beta, dC, ldc), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, &alpha, (hipsparseMatDescr_t) nullptr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, &beta, dC, ldc), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, &alpha, descr, (T*)nullptr, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, &beta, dC, ldc), "Error: dbsr_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, &alpha, descr, dbsr_val, (int*)nullptr, dbsr_col_ind, block_dim, dB, ldb, &beta, dC, ldc), "Error: dbsr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, (int*)nullptr, block_dim, dB, ldb, &beta, dC, ldc), "Error: dbsr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, (T*)nullptr, ldb, &beta, dC, ldc), "Error: dB is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, (T*)nullptr, dC, ldc), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, &beta, (T*)nullptr, ldc), "Error: dC is nullptr"); verify_hipsparse_status_invalid_size(hipsparseXbsrmm(handle, dirA, transA, transB, -1, n, kb, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, &beta, dC, ldc), "Error: mb is invalid"); verify_hipsparse_status_invalid_size(hipsparseXbsrmm(handle, dirA, transA, transB, mb, -1, kb, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, &beta, dC, ldc), "Error: n is invalid"); verify_hipsparse_status_invalid_size(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, -1, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, &beta, dC, ldc), "Error: kb is invalid"); verify_hipsparse_status_invalid_size(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, 0, dB, ldb, &beta, dC, ldc), "Error: block_dim is invalid"); // Test not implemented (mapped to hiparse internal error) verify_hipsparse_status_not_supported(hipsparseXbsrmm(handle, dirA, HIPSPARSE_OPERATION_TRANSPOSE, transB, mb, n, kb, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, &beta, dC, ldc), "Error: Passed value for transA is not supported"); verify_hipsparse_status_not_supported(hipsparseXbsrmm(handle, dirA, HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE, transB, mb, n, kb, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, &beta, dC, ldc), "Error: Passed value for transA is not supported"); verify_hipsparse_status_not_supported(hipsparseXbsrmm(handle, dirA, transA, HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE, mb, n, kb, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, &beta, dC, ldc), "Error: Passed value for transB is not supported"); #endif } template hipsparseStatus_t testing_bsrmm(Arguments argus) { int m = argus.M; int n = argus.N; int k = argus.K; int block_dim = argus.block_dim; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseDirection_t dirA = argus.dirA; hipsparseOperation_t transA = argus.transA; hipsparseOperation_t transB = argus.transB; hipsparseIndexBase_t idx_base = argus.baseA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); if(m == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse does not support m == 0 for csr2bsr return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector csr_row_ptr; std::vector csr_col_ind; std::vector csr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, k, nnz, csr_row_ptr, csr_col_ind, csr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // m and k can be modifed if we read in a matrix from a file int mb = (m + block_dim - 1) / block_dim; int kb = (k + block_dim - 1) / block_dim; // Allocate memory on device for CSR matrix and BSR row pointer array auto dcsr_row_ptrA_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_indA_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_valA_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dbsr_row_ptrA_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb + 1)), device_free}; int* dcsr_row_ptrA = (int*)dcsr_row_ptrA_managed.get(); int* dcsr_col_indA = (int*)dcsr_col_indA_managed.get(); T* dcsr_valA = (T*)dcsr_valA_managed.get(); int* dbsr_row_ptrA = (int*)dbsr_row_ptrA_managed.get(); // Copy CSR from host to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptrA, csr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_indA, csr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_valA, csr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); // Convert CSR to BSR int nnzb; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsrNnz(handle, dirA, m, k, descr, dcsr_row_ptrA, dcsr_col_indA, block_dim, descr, dbsr_row_ptrA, &nnzb)); auto dbsr_col_indA_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnzb), device_free}; auto dbsr_valA_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * nnzb * block_dim * block_dim), device_free}; int* dbsr_col_indA = (int*)dbsr_col_indA_managed.get(); T* dbsr_valA = (T*)dbsr_valA_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsr(handle, dirA, m, k, descr, dcsr_valA, dcsr_row_ptrA, dcsr_col_indA, block_dim, descr, dbsr_valA, dbsr_row_ptrA, dbsr_col_indA)); // Host BSR matrix std::vector hbsr_row_ptrA(mb + 1); std::vector hbsr_col_indA(nnzb); std::vector hbsr_valA(nnzb * block_dim * block_dim); // Copy BSR matrix to host CHECK_HIP_ERROR(hipMemcpy( hbsr_row_ptrA.data(), dbsr_row_ptrA, sizeof(int) * (mb + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hbsr_col_indA.data(), dbsr_col_indA, sizeof(int) * nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsr_valA.data(), dbsr_valA, sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyDeviceToHost)); m = mb * block_dim; k = kb * block_dim; // Some matrix properties int ldb = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : n; int ldc = m; int ncol_B = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE ? n : k); int nnz_B = ldb * ncol_B; int nnz_C = ldc * n; // Allocate host memory for dense matrices std::vector hB(nnz_B); std::vector hC_1(nnz_C); std::vector hC_2(nnz_C); std::vector hC_gold(nnz_C); hipsparseInit(hB, ldb, ncol_B); hipsparseInit(hC_1, ldc, n); // copy vector is easy in STL; hC_gold = hC_1: save a copy in hy_gold which will be output of // CPU hC_gold = hC_1; hC_2 = hC_1; // allocate memory on device auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_B), device_free}; auto dC_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_C), device_free}; auto dC_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_C), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; T* dB = (T*)dB_managed.get(); T* dC_1 = (T*)dC_1_managed.get(); T* dC_2 = (T*)dC_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // Copy data from host to device CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_1, hC_1.data(), sizeof(T) * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_2, hC_2.data(), sizeof(T) * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); if(argus.unit_check) { // Testing using host pointer mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, &h_alpha, descr, dbsr_valA, dbsr_row_ptrA, dbsr_col_indA, block_dim, dB, ldb, &h_beta, dC_1, ldc)); // Testing using device pointer mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, d_alpha, descr, dbsr_valA, dbsr_row_ptrA, dbsr_col_indA, block_dim, dB, ldb, d_beta, dC_2, ldc)); // Copy output from device to host CHECK_HIP_ERROR(hipMemcpy(hC_1.data(), dC_1, sizeof(T) * nnz_C, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hC_2.data(), dC_2, sizeof(T) * nnz_C, hipMemcpyDeviceToHost)); // Host bsrmm host_bsrmm(mb, n, kb, block_dim, dirA, transA, transB, h_alpha, hbsr_row_ptrA, hbsr_col_indA, hbsr_valA, hB, ldb, h_beta, hC_gold, ldc, idx_base); // Unit check unit_check_near(1, nnz_C, 1, hC_gold.data(), hC_1.data()); unit_check_near(1, nnz_C, 1, hC_gold.data(), hC_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, &h_alpha, descr, dbsr_valA, dbsr_row_ptrA, dbsr_col_indA, block_dim, dB, ldb, &h_beta, dC_1, ldc)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, &h_alpha, descr, dbsr_valA, dbsr_row_ptrA, dbsr_col_indA, block_dim, dB, ldb, &h_beta, dC_1, ldc)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = bsrmm_gflop_count(n, nnzb, block_dim, m * n, h_beta != make_DataType(0.0)); double gbyte_count = bsrmm_gbyte_count( mb, nnzb, block_dim, k * n, m * n, h_beta != make_DataType(0.0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::K, k, display_key_t::direction, dirA, display_key_t::transA, transA, display_key_t::transB, transB, display_key_t::nnzb, nnzb, display_key_t::block_dim, block_dim, display_key_t::nnzB, nnz_B, display_key_t::nnzC, nnz_C, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_BSRMM_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_bsrmv.hpp000066400000000000000000000725251501764003400226560ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_BSRMV_HPP #define TESTING_BSRMV_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_bsrmv_bad_arg(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(); // Test hipsparseXbsrmv verify_hipsparse_status_invalid_handle(hipsparseXbsrmv((hipsparseHandle_t) nullptr, dirA, transA, safe_size, safe_size, safe_size, &alpha, descr, dval, dptr, dcol, safe_dim, dx, &beta, dy)); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmv(handle, dirA, transA, safe_size, safe_size, safe_size, (T*)nullptr, descr, dval, dptr, dcol, safe_dim, dx, &beta, dy), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmv(handle, dirA, transA, safe_size, safe_size, safe_size, &alpha, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, safe_dim, dx, &beta, dy), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmv(handle, dirA, transA, safe_size, safe_size, safe_size, &alpha, descr, (T*)nullptr, dptr, dcol, safe_dim, dx, &beta, dy), "Error: bsr_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmv(handle, dirA, transA, safe_size, safe_size, safe_size, &alpha, descr, dval, (int*)nullptr, dcol, safe_dim, dx, &beta, dy), "Error: bsr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmv(handle, dirA, transA, safe_size, safe_size, safe_size, &alpha, descr, dval, dptr, (int*)nullptr, safe_dim, dx, &beta, dy), "Error: bsr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmv(handle, dirA, transA, safe_size, safe_size, safe_size, &alpha, descr, dval, dptr, dcol, safe_dim, (T*)nullptr, &beta, dy), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmv(handle, dirA, transA, safe_size, safe_size, safe_size, &alpha, descr, dval, dptr, dcol, safe_dim, dx, (T*)nullptr, dy), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmv(handle, dirA, transA, safe_size, safe_size, safe_size, &alpha, descr, dval, dptr, dcol, safe_dim, dx, &beta, (T*)nullptr), "Error: y is nullptr"); verify_hipsparse_status_invalid_size(hipsparseXbsrmv(handle, dirA, transA, -1, safe_size, safe_size, &alpha, descr, dval, dptr, dcol, safe_dim, dx, &beta, dy), "Error: mb is invalid"); verify_hipsparse_status_invalid_size(hipsparseXbsrmv(handle, dirA, transA, safe_size, -1, safe_size, &alpha, descr, dval, dptr, dcol, safe_dim, dx, &beta, dy), "Error: nb is invalid"); verify_hipsparse_status_invalid_size(hipsparseXbsrmv(handle, dirA, transA, safe_size, safe_size, -1, &alpha, descr, dval, dptr, dcol, safe_dim, dx, &beta, dy), "Error: nnzb is invalid"); verify_hipsparse_status_invalid_size(hipsparseXbsrmv(handle, dirA, transA, safe_size, safe_size, safe_size, &alpha, descr, dval, dptr, dcol, -1, dx, &beta, dy), "Error: block_dim is invalid"); #endif } template hipsparseStatus_t testing_bsrmv(Arguments argus) { int m = argus.M; int n = argus.N; int block_dim = argus.block_dim; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseDirection_t dir = argus.dirA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); int mb = (m + block_dim - 1) / block_dim; int nb = (n + block_dim - 1) / block_dim; if(block_dim == 1 || mb == 0 || nb == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse only accepts block_dim > 1 return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } mb = (m + block_dim - 1) / block_dim; nb = (n + block_dim - 1) / block_dim; std::vector hx(nb * block_dim); std::vector hy_1(mb * block_dim); std::vector hy_2(mb * block_dim); std::vector hy_gold(mb * block_dim); hipsparseInit(hx, 1, nb * block_dim); hipsparseInit(hy_1, 1, mb * block_dim); // copy vector is easy in STL; hy_gold = hx: save a copy in hy_gold which will be output of CPU hy_2 = hy_1; hy_gold = hy_1; // allocate memory on device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dbsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb + 1)), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nb * block_dim), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * mb * block_dim), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * mb * block_dim), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); int* dbsr_row_ptr = (int*)dbsr_row_ptr_managed.get(); T* dx = (T*)dx_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_val, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx, hx.data(), sizeof(T) * n, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_1, hy_1.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // Convert to BSR int nnzb; CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsrNnz(handle, dir, m, n, descr, dcsr_row_ptr, dcsr_col_ind, block_dim, descr, dbsr_row_ptr, &nnzb)); auto dbsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnzb), device_free}; auto dbsr_val_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * nnzb * block_dim * block_dim), device_free}; int* dbsr_col_ind = (int*)dbsr_col_ind_managed.get(); T* dbsr_val = (T*)dbsr_val_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsr(handle, dir, m, n, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, block_dim, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind)); if(argus.unit_check) { CHECK_HIP_ERROR(hipMemcpy(dy_2, hy_2.data(), sizeof(T) * m, hipMemcpyHostToDevice)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXbsrmv(handle, dir, transA, mb, nb, nnzb, &h_alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dx, &h_beta, dy_1)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXbsrmv(handle, dir, transA, mb, nb, nnzb, d_alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dx, d_beta, dy_2)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hy_1.data(), dy_1, sizeof(T) * m, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_2.data(), dy_2, sizeof(T) * m, hipMemcpyDeviceToHost)); // Host bsrmv std::vector hbsr_row_ptr(mb + 1); std::vector hbsr_col_ind(nnzb); std::vector hbsr_val(nnzb * block_dim * block_dim); CHECK_HIP_ERROR(hipMemcpy( hbsr_row_ptr.data(), dbsr_row_ptr, sizeof(int) * (mb + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hbsr_col_ind.data(), dbsr_col_ind, sizeof(int) * nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsr_val.data(), dbsr_val, sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyDeviceToHost)); host_bsrmv(dir, transA, mb, nb, nnzb, h_alpha, hbsr_row_ptr.data(), hbsr_col_ind.data(), hbsr_val.data(), block_dim, hx.data(), h_beta, hy_gold.data(), idx_base); unit_check_near(1, m, 1, hy_gold.data(), hy_1.data()); unit_check_near(1, m, 1, hy_gold.data(), hy_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXbsrmv(handle, dir, transA, mb, nb, nnzb, &h_alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dx, &h_beta, dy_1)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXbsrmv(handle, dir, transA, mb, nb, nnzb, &h_alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dx, &h_beta, dy_1)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = spmv_gflop_count(m, nnzb * block_dim * block_dim, h_beta != make_DataType(0.0)); double gbyte_count = bsrmv_gbyte_count(mb, nb, nnzb, block_dim, h_beta != make_DataType(0.0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::block_dim, block_dim, display_key_t::direction, hipsparse_direction2string(dir), display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_BSRMV_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_bsrsm2.hpp000066400000000000000000001530361501764003400227320ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_BSRSM2_HPP #define TESTING_BSRSM2_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include using namespace hipsparse; using namespace hipsparse_test; void testing_bsrsm2_bad_arg(void) { #if(!defined(CUDART_VERSION)) int mb = 100; int nrhs = 100; int nnzb = 100; int block_dim = 100; int safe_size = 100; float alpha = 0.6; int ldb = 100; int ldx = 100; hipsparseDirection_t dirA = HIPSPARSE_DIRECTION_ROW; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transX = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseSolvePolicy_t policy = HIPSPARSE_SOLVE_POLICY_USE_LEVEL; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_info(new bsrsm2_struct); bsrsm2Info_t info = unique_ptr_info->info; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dX_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); float* dval = (float*)dval_managed.get(); float* dB = (float*)dB_managed.get(); float* dX = (float*)dX_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // testing hipsparseXbsrsm2_bufferSize int size; verify_hipsparse_status_invalid_handle(hipsparseXbsrsm2_bufferSize(nullptr, dirA, transA, transX, mb, nrhs, nnzb, descr, dval, dptr, dcol, block_dim, info, &size)); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_bufferSize(handle, dirA, transA, transX, mb, nrhs, nnzb, nullptr, dval, dptr, dcol, block_dim, info, &size), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_bufferSize(handle, dirA, transA, transX, mb, nrhs, nnzb, descr, (float*)nullptr, dptr, dcol, block_dim, info, &size), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_bufferSize(handle, dirA, transA, transX, mb, nrhs, nnzb, descr, dval, nullptr, dcol, block_dim, info, &size), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_bufferSize(handle, dirA, transA, transX, mb, nrhs, nnzb, descr, dval, dptr, nullptr, block_dim, info, &size), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_bufferSize(handle, dirA, transA, transX, mb, nrhs, nnzb, descr, dval, dptr, dcol, block_dim, nullptr, &size), "Error: info is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_bufferSize(handle, dirA, transA, transX, mb, nrhs, nnzb, descr, dval, dptr, dcol, block_dim, info, nullptr), "Error: size is nullptr"); // testing hipsparseXbsrsm2_analysis verify_hipsparse_status_invalid_handle(hipsparseXbsrsm2_analysis(nullptr, dirA, transA, transX, mb, nrhs, nnzb, descr, dval, dptr, dcol, block_dim, info, policy, dbuf)); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_analysis(handle, dirA, transA, transX, mb, nrhs, nnzb, nullptr, dval, dptr, dcol, block_dim, info, policy, dbuf), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_analysis(handle, dirA, transA, transX, mb, nrhs, nnzb, descr, (const float*)nullptr, dptr, dcol, block_dim, info, policy, dbuf), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_analysis(handle, dirA, transA, transX, mb, nrhs, nnzb, descr, dval, nullptr, dcol, block_dim, info, policy, dbuf), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_analysis(handle, dirA, transA, transX, mb, nrhs, nnzb, descr, dval, dptr, nullptr, block_dim, info, policy, dbuf), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_analysis(handle, dirA, transA, transX, mb, nrhs, nnzb, descr, dval, dptr, dcol, block_dim, nullptr, policy, dbuf), "Error: info is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_analysis(handle, dirA, transA, transX, mb, nrhs, nnzb, descr, dval, dptr, dcol, block_dim, info, policy, nullptr), "Error: dbuf is nullptr"); // testing hipsparseXbsrsm2_solve verify_hipsparse_status_invalid_handle(hipsparseXbsrsm2_solve(nullptr, dirA, transA, transX, mb, nrhs, nnzb, &alpha, descr, dval, dptr, dcol, block_dim, info, dB, ldb, dX, ldx, policy, dbuf)); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_solve(handle, dirA, transA, transX, mb, nrhs, nnzb, (const float*)nullptr, descr, dval, dptr, dcol, block_dim, info, dB, ldb, dX, ldx, policy, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_solve(handle, dirA, transA, transX, mb, nrhs, nnzb, &alpha, nullptr, dval, dptr, dcol, block_dim, info, dB, ldb, dX, ldx, policy, dbuf), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_solve(handle, dirA, transA, transX, mb, nrhs, nnzb, &alpha, descr, (const float*)nullptr, dptr, dcol, block_dim, info, dB, ldb, dX, ldx, policy, dbuf), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_solve(handle, dirA, transA, transX, mb, nrhs, nnzb, &alpha, descr, dval, nullptr, dcol, block_dim, info, dB, ldb, dX, ldx, policy, dbuf), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_solve(handle, dirA, transA, transX, mb, nrhs, nnzb, &alpha, descr, dval, dptr, nullptr, block_dim, info, dB, ldb, dX, ldx, policy, dbuf), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_solve(handle, dirA, transA, transX, mb, nrhs, nnzb, &alpha, descr, dval, dptr, dcol, block_dim, nullptr, dB, ldb, dX, ldx, policy, dbuf), "Error: info is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_solve(handle, dirA, transA, transX, mb, nrhs, nnzb, &alpha, descr, dval, dptr, dcol, block_dim, info, (const float*)nullptr, ldb, dX, ldx, policy, dbuf), "Error: dB is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_solve(handle, dirA, transA, transX, mb, nrhs, nnzb, &alpha, descr, dval, dptr, dcol, block_dim, info, dB, ldb, (float*)nullptr, ldx, policy, dbuf), "Error: dX is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_solve(handle, dirA, transA, transX, mb, nrhs, nnzb, &alpha, descr, dval, dptr, dcol, block_dim, info, dB, ldb, dX, ldx, policy, nullptr), "Error: dbuf is nullptr"); #endif } template hipsparseStatus_t testing_bsrsm2(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) int m = argus.M; int nrhs = argus.N; int block_dim = argus.block_dim; T h_alpha = make_DataType(argus.alpha); hipsparseDirection_t dir = argus.dirA; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseOperation_t transA = argus.transA; hipsparseOperation_t transX = argus.transB; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_bsrsm2_info(new bsrsm2_struct); bsrsm2Info_t info = unique_ptr_bsrsm2_info->info; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); if(m == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse does not support m == 0 for csr2bsr return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, m, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } int mb = (m + block_dim - 1) / block_dim; int ldb = (transX == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? mb * block_dim : nrhs; int ldx = (transX == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? mb * block_dim : nrhs; int64_t nrowB = (transX == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? mb * block_dim : nrhs; int64_t ncolB = (transX == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? nrhs : mb * block_dim; int64_t nrowX = nrowB; int64_t ncolX = ncolB; std::vector hB(nrowB * ncolB); std::vector hX_1(nrowX * ncolX); std::vector hX_2(nrowX * ncolX); std::vector hX_gold(nrowX * ncolX); hipsparseInit(hB, nrowB, ncolB); // Allocate memory on device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dbsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb + 1)), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nrowB * ncolB), device_free}; auto dX_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nrowX * ncolX), device_free}; auto dX_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nrowX * ncolX), device_free}; auto dalpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto dpos_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); int* dbsr_row_ptr = (int*)dbsr_row_ptr_managed.get(); T* dB = (T*)dB_managed.get(); T* dX_1 = (T*)dX_1_managed.get(); T* dX_2 = (T*)dX_2_managed.get(); T* dalpha = (T*)dalpha_managed.get(); int* dposition = (int*)dpos_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_val, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * nrowB * ncolB, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dalpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); // Convert to BSR int nnzb; CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsrNnz(handle, dir, m, m, descr, dcsr_row_ptr, dcsr_col_ind, block_dim, descr, dbsr_row_ptr, &nnzb)); auto dbsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnzb), device_free}; auto dbsr_val_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * nnzb * block_dim * block_dim), device_free}; int* dbsr_col_ind = (int*)dbsr_col_ind_managed.get(); T* dbsr_val = (T*)dbsr_val_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsr(handle, dir, m, m, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, block_dim, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind)); // Obtain bsrsm2 buffer size int bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseXbsrsm2_bufferSize(handle, dir, transA, transX, mb, nrhs, nnzb, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, &bufferSize)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * bufferSize), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); // bsrsm2 analysis CHECK_HIPSPARSE_ERROR(hipsparseXbsrsm2_analysis(handle, dir, transA, transX, mb, nrhs, nnzb, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer)); int pos_analysis; hipsparseXbsrsm2_zeroPivot(handle, info, &pos_analysis); if(argus.unit_check) { // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXbsrsm2_solve(handle, dir, transA, transX, mb, nrhs, nnzb, &h_alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, dB, ldb, dX_1, ldx, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer)); int hposition_1; hipsparseStatus_t pivot_status_1 = hipsparseXbsrsm2_zeroPivot(handle, info, &hposition_1); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXbsrsm2_solve(handle, dir, transA, transX, mb, nrhs, nnzb, dalpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, dB, ldb, dX_2, ldx, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer)); hipsparseStatus_t pivot_status_2 = hipsparseXbsrsm2_zeroPivot(handle, info, dposition); // Copy output from device to CPU int hposition_2; CHECK_HIP_ERROR( hipMemcpy(hX_1.data(), dX_1, sizeof(T) * nrowX * ncolX, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hX_2.data(), dX_2, sizeof(T) * nrowX * ncolX, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(&hposition_2, dposition, sizeof(int), hipMemcpyDeviceToHost)); // Host bsrsm2 std::vector hbsr_row_ptr(mb + 1); std::vector hbsr_col_ind(nnzb); std::vector hbsr_val(nnzb * block_dim * block_dim); CHECK_HIP_ERROR(hipMemcpy( hbsr_row_ptr.data(), dbsr_row_ptr, sizeof(int) * (mb + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hbsr_col_ind.data(), dbsr_col_ind, sizeof(int) * nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsr_val.data(), dbsr_val, sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyDeviceToHost)); int struct_position_gold; int numeric_position_gold; CHECK_HIP_ERROR(hipDeviceSynchronize()); host_bsrsm(mb, nrhs, nnzb, dir, transA, transX, h_alpha, hbsr_row_ptr.data(), hbsr_col_ind.data(), hbsr_val.data(), block_dim, hB.data(), ldb, hX_gold.data(), ldx, HIPSPARSE_DIAG_TYPE_NON_UNIT, HIPSPARSE_FILL_MODE_LOWER, idx_base, &struct_position_gold, &numeric_position_gold); unit_check_general(1, 1, 1, &struct_position_gold, &pos_analysis); unit_check_general(1, 1, 1, &numeric_position_gold, &hposition_1); unit_check_general(1, 1, 1, &numeric_position_gold, &hposition_2); if(hposition_1 != -1) { verify_hipsparse_status_zero_pivot(pivot_status_1, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); return HIPSPARSE_STATUS_SUCCESS; } if(hposition_2 != -1) { verify_hipsparse_status_zero_pivot(pivot_status_2, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); return HIPSPARSE_STATUS_SUCCESS; } unit_check_near(nrowX, ncolX, ldx, hX_gold.data(), hX_1.data()); unit_check_near(nrowX, ncolX, ldx, hX_gold.data(), hX_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXbsrsm2_solve(handle, dir, transA, transX, mb, nrhs, nnzb, &h_alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, dB, ldb, dX_1, ldx, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXbsrsm2_solve(handle, dir, transA, transX, mb, nrhs, nnzb, &h_alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, dB, ldb, dX_1, ldx, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = csrsv_gflop_count(m, size_t(nnzb) * block_dim * block_dim, HIPSPARSE_DIAG_TYPE_NON_UNIT) * nrhs; double gbyte_count = bsrsv_gbyte_count(mb, nnzb, block_dim) * nrhs; double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::nnz, nnzb * block_dim * block_dim, display_key_t::nrhs, nrhs, display_key_t::block_dim, block_dim, display_key_t::alpha, h_alpha, display_key_t::transA, hipsparse_operation2string(transA), display_key_t::transX, hipsparse_operation2string(transX), display_key_t::diag_type, hipsparse_diagtype2string(HIPSPARSE_DIAG_TYPE_NON_UNIT), display_key_t::fill_mode, hipsparse_fillmode2string(HIPSPARSE_FILL_MODE_LOWER), display_key_t::solve_policy, hipsparse_solvepolicy2string(HIPSPARSE_SOLVE_POLICY_USE_LEVEL), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_BSRSV2_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_bsrsv2.hpp000066400000000000000000001272351501764003400227450ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_BSRSV2_HPP #define TESTING_BSRSV2_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_bsrsv2_bad_arg(void) { #if(!defined(CUDART_VERSION)) int m = 100; int nnz = 100; int block_dim = 2; int safe_size = 100; T h_alpha = 0.6; hipsparseDirection_t dirA = HIPSPARSE_DIRECTION_COLUMN; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseSolvePolicy_t policy = HIPSPARSE_SOLVE_POLICY_USE_LEVEL; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_bsrsv2_info(new bsrsv2_struct); bsrsv2Info_t info = unique_ptr_bsrsv2_info->info; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dx = (T*)dx_managed.get(); T* dy = (T*)dy_managed.get(); void* dbuffer = (void*)dbuffer_managed.get(); int size; int position; verify_hipsparse_status_invalid_pointer( hipsparseXbsrsv2_bufferSize( handle, dirA, transA, m, nnz, descr, dval, (int*)nullptr, dcol, block_dim, info, &size), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsrsv2_bufferSize( handle, dirA, transA, m, nnz, descr, dval, dptr, (int*)nullptr, block_dim, info, &size), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsrsv2_bufferSize( handle, dirA, transA, m, nnz, descr, (T*)nullptr, dptr, dcol, block_dim, info, &size), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsrsv2_bufferSize( handle, dirA, transA, m, nnz, descr, dval, dptr, dcol, block_dim, info, (int*)nullptr), "Error: size is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsrsv2_bufferSize(handle, dirA, transA, m, nnz, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, block_dim, info, &size), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_bufferSize(handle, dirA, transA, m, nnz, descr, dval, dptr, dcol, block_dim, (bsrsv2Info_t) nullptr, &size), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXbsrsv2_bufferSize((hipsparseHandle_t) nullptr, dirA, transA, m, nnz, descr, dval, dptr, dcol, block_dim, info, &size)); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_analysis(handle, dirA, transA, m, nnz, descr, dval, (int*)nullptr, dcol, block_dim, info, policy, dbuffer), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_analysis(handle, dirA, transA, m, nnz, descr, dval, dptr, (int*)nullptr, block_dim, info, policy, dbuffer), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_analysis(handle, dirA, transA, m, nnz, descr, (T*)nullptr, dptr, dcol, block_dim, info, policy, dbuffer), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_analysis(handle, dirA, transA, m, nnz, descr, dval, dptr, dcol, block_dim, info, policy, (void*)nullptr), "Error: dbuffer is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_analysis(handle, dirA, transA, m, nnz, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, block_dim, info, policy, dbuffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_analysis(handle, dirA, transA, m, nnz, descr, dval, dptr, dcol, block_dim, (bsrsv2Info_t) nullptr, policy, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXbsrsv2_analysis((hipsparseHandle_t) nullptr, dirA, transA, m, nnz, descr, dval, dptr, dcol, block_dim, info, policy, dbuffer)); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_solve(handle, dirA, transA, m, nnz, &h_alpha, descr, dval, (int*)nullptr, dcol, block_dim, info, dx, dy, policy, dbuffer), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_solve(handle, dirA, transA, m, nnz, &h_alpha, descr, dval, dptr, (int*)nullptr, block_dim, info, dx, dy, policy, dbuffer), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_solve(handle, dirA, transA, m, nnz, &h_alpha, descr, (T*)nullptr, dptr, dcol, block_dim, info, dx, dy, policy, dbuffer), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_solve(handle, dirA, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, block_dim, info, (T*)nullptr, dy, policy, dbuffer), "Error: dx is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_solve(handle, dirA, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, block_dim, info, dx, (T*)nullptr, policy, dbuffer), "Error: dy is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_solve(handle, dirA, transA, m, nnz, (T*)nullptr, descr, dval, dptr, dcol, block_dim, info, dx, dy, policy, dbuffer), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_solve(handle, dirA, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, block_dim, info, dx, dy, policy, (void*)nullptr), "Error: dbuffer is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_solve(handle, dirA, transA, m, nnz, &h_alpha, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, block_dim, info, dx, dy, policy, dbuffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_solve(handle, dirA, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, block_dim, (bsrsv2Info_t) nullptr, dx, dy, policy, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXbsrsv2_solve((hipsparseHandle_t) nullptr, dirA, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, block_dim, info, dx, dy, policy, dbuffer)); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_zeroPivot(handle, info, (int*)nullptr), "Error: position is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsrsv2_zeroPivot(handle, (bsrsv2Info_t) nullptr, &position), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXbsrsv2_zeroPivot((hipsparseHandle_t) nullptr, info, &position)); #endif } template hipsparseStatus_t testing_bsrsv2(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) int m = argus.M; int block_dim = argus.block_dim; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseDirection_t dir = argus.dirA; hipsparseOperation_t trans = argus.transA; hipsparseDiagType_t diag_type = argus.diag_type; hipsparseFillMode_t fill_mode = argus.fill_mode; hipsparseSolvePolicy_t policy = argus.solve_policy; T h_alpha = make_DataType(argus.alpha); std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_bsrsv2_info(new bsrsv2_struct); bsrsv2Info_t info = unique_ptr_bsrsv2_info->info; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); // Set matrix diag type CHECK_HIPSPARSE_ERROR(hipsparseSetMatDiagType(descr, diag_type)); // Set matrix fill mode CHECK_HIPSPARSE_ERROR(hipsparseSetMatFillMode(descr, fill_mode)); if(m == 0 || block_dim == 1) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse does not support m == 0 for csr2bsr // cusparse does not support asynchronous execution if block_dim == 1 return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, m, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } int mb = (m + block_dim - 1) / block_dim; std::vector hx(mb * block_dim); std::vector hy_1(mb * block_dim); std::vector hy_2(mb * block_dim); std::vector hy_gold(mb * block_dim); hipsparseInit(hx, 1, mb * block_dim); // Allocate memory on device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dbsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb + 1)), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * mb * block_dim), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * mb * block_dim), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * mb * block_dim), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_position_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); int* dbsr_row_ptr = (int*)dbsr_row_ptr_managed.get(); T* dx = (T*)dx_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); int* d_position = (int*)d_position_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_val, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx, hx.data(), sizeof(T) * mb * block_dim, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dy_1, hy_1.data(), sizeof(T) * mb * block_dim, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); // Convert to BSR int nnzb; CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsrNnz(handle, dir, m, m, descr, dcsr_row_ptr, dcsr_col_ind, block_dim, descr, dbsr_row_ptr, &nnzb)); auto dbsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnzb), device_free}; auto dbsr_val_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * nnzb * block_dim * block_dim), device_free}; int* dbsr_col_ind = (int*)dbsr_col_ind_managed.get(); T* dbsr_val = (T*)dbsr_val_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsr(handle, dir, m, m, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, block_dim, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind)); // Obtain bsrsv2 buffer size int bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseXbsrsv2_bufferSize(handle, dir, trans, mb, nnzb, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, &bufferSize)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * bufferSize), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); // bsrsv2 analysis CHECK_HIPSPARSE_ERROR(hipsparseXbsrsv2_analysis(handle, dir, trans, mb, nnzb, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, policy, dbuffer)); if(argus.unit_check) { CHECK_HIP_ERROR( hipMemcpy(dy_2, hy_2.data(), sizeof(T) * mb * block_dim, hipMemcpyHostToDevice)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXbsrsv2_solve(handle, dir, trans, mb, nnzb, &h_alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, dx, dy_1, policy, dbuffer)); int hposition_1; hipsparseStatus_t pivot_status_1; pivot_status_1 = hipsparseXbsrsv2_zeroPivot(handle, info, &hposition_1); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXbsrsv2_solve(handle, dir, trans, mb, nnzb, d_alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, dx, dy_2, policy, dbuffer)); hipsparseStatus_t pivot_status_2; pivot_status_2 = hipsparseXbsrsv2_zeroPivot(handle, info, d_position); // Copy output from device to CPU int hposition_2; CHECK_HIP_ERROR( hipMemcpy(hy_1.data(), dy_1, sizeof(T) * mb * block_dim, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hy_2.data(), dy_2, sizeof(T) * mb * block_dim, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(&hposition_2, d_position, sizeof(int), hipMemcpyDeviceToHost)); // Host bsrsv2 std::vector hbsr_row_ptr(mb + 1); std::vector hbsr_col_ind(nnzb); std::vector hbsr_val(nnzb * block_dim * block_dim); CHECK_HIP_ERROR(hipMemcpy( hbsr_row_ptr.data(), dbsr_row_ptr, sizeof(int) * (mb + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hbsr_col_ind.data(), dbsr_col_ind, sizeof(int) * nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsr_val.data(), dbsr_val, sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyDeviceToHost)); int struct_position_gold; int position_gold; bsrsv(trans, dir, mb, nnzb, h_alpha, hbsr_row_ptr.data(), hbsr_col_ind.data(), hbsr_val.data(), block_dim, hx.data(), hy_gold.data(), diag_type, fill_mode, idx_base, &struct_position_gold, &position_gold); unit_check_general(1, 1, 1, &position_gold, &hposition_1); unit_check_general(1, 1, 1, &position_gold, &hposition_2); if(hposition_1 != -1) { verify_hipsparse_status_zero_pivot(pivot_status_1, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); return HIPSPARSE_STATUS_SUCCESS; } if(hposition_2 != -1) { verify_hipsparse_status_zero_pivot(pivot_status_2, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); return HIPSPARSE_STATUS_SUCCESS; } unit_check_near(1, mb * block_dim, 1, hy_gold.data(), hy_1.data()); unit_check_near(1, mb * block_dim, 1, hy_gold.data(), hy_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXbsrsv2_solve(handle, dir, trans, mb, nnzb, &h_alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, dx, dy_1, policy, dbuffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXbsrsv2_solve(handle, dir, trans, mb, nnzb, &h_alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, dx, dy_1, policy, dbuffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = csrsv_gflop_count(mb * block_dim, size_t(nnzb) * block_dim * block_dim, diag_type); double gbyte_count = bsrsv_gbyte_count(mb, nnzb, block_dim); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::nnz, nnzb * block_dim * block_dim, display_key_t::alpha, h_alpha, display_key_t::trans, hipsparse_operation2string(trans), display_key_t::diag_type, hipsparse_diagtype2string(diag_type), display_key_t::fill_mode, hipsparse_fillmode2string(fill_mode), display_key_t::solve_policy, hipsparse_solvepolicy2string(policy), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_BSRSV2_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_bsrxmv.hpp000066400000000000000000000726041501764003400230440ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_BSRXMV_HPP #define TESTING_BSRXMV_HPP #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_bsrxmv_bad_arg(void) { #if(!defined(CUDART_VERSION)) int safe_size = 100; int safe_dim = 2; T alpha = make_DataType(0.6); T beta = make_DataType(0.2); hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseDirection_t dirA = HIPSPARSE_DIRECTION_COLUMN; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dend_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dmask_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* dptr = (int*)dptr_managed.get(); int* dend_ptr = (int*)dend_ptr_managed.get(); int* dmask_ptr = (int*)dmask_ptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dx = (T*)dx_managed.get(); T* dy = (T*)dy_managed.get(); // Test hipsparseXbsrxmv verify_hipsparse_status_invalid_handle(hipsparseXbsrxmv(nullptr, dirA, transA, safe_size, safe_size, safe_size, safe_size, &alpha, descr, dval, dmask_ptr, dptr, dend_ptr, dcol, safe_dim, dx, &beta, dy)); verify_hipsparse_status_invalid_pointer(hipsparseXbsrxmv(handle, dirA, transA, safe_size, safe_size, safe_size, safe_size, (T*)nullptr, descr, dval, dmask_ptr, dptr, dend_ptr, dcol, safe_dim, dx, &beta, dy), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrxmv(handle, dirA, transA, safe_size, safe_size, safe_size, safe_size, &alpha, nullptr, dval, dmask_ptr, dptr, dend_ptr, dcol, safe_dim, dx, &beta, dy), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrxmv(handle, dirA, transA, safe_size, safe_size, safe_size, safe_size, &alpha, descr, (T*)nullptr, dmask_ptr, dptr, dend_ptr, dcol, safe_dim, dx, &beta, dy), "Error: bsr_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrxmv(handle, dirA, transA, safe_size, safe_size, safe_size, safe_size, &alpha, descr, dval, nullptr, dptr, dend_ptr, dcol, safe_dim, dx, &beta, dy), "Error: bsr_mask_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrxmv(handle, dirA, transA, safe_size, safe_size, safe_size, safe_size, &alpha, descr, dval, dmask_ptr, nullptr, dend_ptr, dcol, safe_dim, dx, &beta, dy), "Error: bsr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrxmv(handle, dirA, transA, safe_size, safe_size, safe_size, safe_size, &alpha, descr, dval, dmask_ptr, dptr, nullptr, dcol, safe_dim, dx, &beta, dy), "Error: bsr_end_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrxmv(handle, dirA, transA, safe_size, safe_size, safe_size, safe_size, &alpha, descr, dval, dmask_ptr, dptr, dend_ptr, nullptr, safe_dim, dx, &beta, dy), "Error: bsr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrxmv(handle, dirA, transA, safe_size, safe_size, safe_size, safe_size, &alpha, descr, dval, dmask_ptr, dptr, dend_ptr, dcol, safe_dim, (T*)nullptr, &beta, dy), "Error: xy is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrxmv(handle, dirA, transA, safe_size, safe_size, safe_size, safe_size, &alpha, descr, dval, dmask_ptr, dptr, dend_ptr, dcol, safe_dim, dx, (T*)nullptr, dy), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrxmv(handle, dirA, transA, safe_size, safe_size, safe_size, safe_size, &alpha, descr, dval, dmask_ptr, dptr, dend_ptr, dcol, safe_dim, dx, &beta, (T*)nullptr), "Error: y is nullptr"); verify_hipsparse_status_invalid_size(hipsparseXbsrxmv(handle, dirA, transA, -1, safe_size, safe_size, safe_size, &alpha, descr, dval, dmask_ptr, dptr, dend_ptr, dcol, safe_dim, dx, &beta, dy), "Error: sizeOfMask is invalid"); verify_hipsparse_status_invalid_size(hipsparseXbsrxmv(handle, dirA, transA, safe_size, -1, safe_size, safe_size, &alpha, descr, dval, dmask_ptr, dptr, dend_ptr, dcol, safe_dim, dx, &beta, dy), "Error: mb is invalid"); verify_hipsparse_status_invalid_size(hipsparseXbsrxmv(handle, dirA, transA, safe_size, safe_size, -1, safe_size, &alpha, descr, dval, dmask_ptr, dptr, dend_ptr, dcol, safe_dim, dx, &beta, dy), "Error: nb is invalid"); verify_hipsparse_status_invalid_size(hipsparseXbsrxmv(handle, dirA, transA, safe_size, safe_size, safe_size, -1, &alpha, descr, dval, dmask_ptr, dptr, dend_ptr, dcol, safe_dim, dx, &beta, dy), "Error: nnzb is invalid"); verify_hipsparse_status_invalid_size(hipsparseXbsrxmv(handle, dirA, transA, safe_size, safe_size, safe_size, safe_size, &alpha, descr, dval, dmask_ptr, dptr, dend_ptr, dcol, -1, dx, &beta, dy), "Error: block_dim is invalid"); #endif } template hipsparseStatus_t testing_bsrxmv(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) hipsparseDirection_t dir = HIPSPARSE_DIRECTION_COLUMN; hipsparseOperation_t trans = HIPSPARSE_OPERATION_NON_TRANSPOSE; static constexpr int size_of_mask = 1; static constexpr int mb = 2; static constexpr int nb = 3; static constexpr int nnzb = 5; static constexpr int block_dim = 2; T h_alpha = make_DataType(2.0); T h_beta = make_DataType(1.0); // clang-format off std::vector hbsr_val = {make_DataType(1.0), make_DataType(2.0), make_DataType(3.0), make_DataType(4.0), make_DataType(5.0), make_DataType(6.0), make_DataType(7.0), make_DataType(8.0), make_DataType(9.0), make_DataType(10.0), make_DataType(11.0), make_DataType(12.0), make_DataType(13.0), make_DataType(14.0), make_DataType(15.0), make_DataType(16.0), make_DataType(17.0), make_DataType(18.0), make_DataType(19.0), make_DataType(20.0)}; std::vector hbsr_mask_ptr = {2}; std::vector hbsr_row_ptr = {1, 4}; std::vector hbsr_end_ptr = {1, 5}; std::vector hbsr_col_ind = {1, 2, 1, 2, 3}; std::vector hx = {make_DataType(1.0), make_DataType(1.0), make_DataType(1.0), make_DataType(1.0), make_DataType(1.0), make_DataType(1.0)}; std::vector hy = { make_DataType(2.0), make_DataType(2.0), make_DataType(2.0), make_DataType(2.0)}; std::vector hyref = {make_DataType(2.0), make_DataType(2.0), make_DataType(58.0), make_DataType(62.0)}; // clang-format on auto dbsr_val_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * block_dim * block_dim * nnzb), device_free}; auto dbsr_mask_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * size_of_mask), device_free}; auto dbsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * mb), device_free}; auto dbsr_end_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * mb), device_free}; auto dbsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnzb), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * block_dim * nb), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * block_dim * mb), device_free}; T* dbsr_val = (T*)dbsr_val_managed.get(); int* dbsr_mask_ptr = (int*)dbsr_mask_ptr_managed.get(); int* dbsr_row_ptr = (int*)dbsr_row_ptr_managed.get(); int* dbsr_end_ptr = (int*)dbsr_end_ptr_managed.get(); int* dbsr_col_ind = (int*)dbsr_col_ind_managed.get(); T* dx = (T*)dx_managed.get(); T* dy = (T*)dy_managed.get(); CHECK_HIP_ERROR(hipMemcpy(dbsr_val, hbsr_val.data(), sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy( dbsr_mask_ptr, hbsr_mask_ptr.data(), sizeof(int) * size_of_mask, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dbsr_row_ptr, hbsr_row_ptr.data(), sizeof(int) * mb, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dbsr_end_ptr, hbsr_end_ptr.data(), sizeof(int) * mb, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dbsr_col_ind, hbsr_col_ind.data(), sizeof(int) * nnzb, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx, hx.data(), sizeof(T) * nb * block_dim, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy, hy.data(), sizeof(T) * mb * block_dim, hipMemcpyHostToDevice)); std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ONE; CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); hipsparseStatus_t status = hipsparseXbsrxmv(handle, dir, trans, size_of_mask, mb, nb, nnzb, &h_alpha, descr, dbsr_val, dbsr_mask_ptr, dbsr_row_ptr, dbsr_end_ptr, dbsr_col_ind, block_dim, dx, &h_beta, dy); verify_hipsparse_status_success(status, "bsrxmv failed."); CHECK_HIP_ERROR(hipMemcpy(hy.data(), dy, sizeof(T) * mb * block_dim, hipMemcpyDeviceToHost)); unit_check_near(1, mb * block_dim, 1, hyref.data(), hy.data()); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_BSRXMV_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_const_dnmat_descr.hpp000066400000000000000000000125121501764003400252040ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2023 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CONST_DNMAT_DESCR_HPP #define TESTING_CONST_DNMAT_DESCR_HPP #include "hipsparse_test_unique_ptr.hpp" #ifdef GOOGLE_TEST #include #endif #include using namespace hipsparse_test; void testing_const_dnmat_descr_bad_arg(void) { #if(!defined(CUDART_VERSION)) int64_t rows = 100; int64_t cols = 100; int64_t ld = 100; hipsparseOrder_t order = HIPSPARSE_ORDER_ROW; hipDataType dataType = HIP_R_32F; // Allocate memory on device auto val_data_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * rows * cols), device_free}; const float* val_data = (const float*)val_data_managed.get(); hipsparseConstDnMatDescr_t x; // hipsparseCreateConstDnMat verify_hipsparse_status_invalid_pointer( hipsparseCreateConstDnMat(nullptr, rows, cols, ld, val_data, dataType, order), "Error: x is nullptr"); verify_hipsparse_status_invalid_size( hipsparseCreateConstDnMat(&x, -1, cols, ld, val_data, dataType, order), "Error: rows is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateConstDnMat(&x, rows, -1, ld, val_data, dataType, order), "Error: cols is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateConstDnMat(&x, rows, cols, -1, val_data, dataType, order), "Error: ld is < 0"); verify_hipsparse_status_invalid_pointer( hipsparseCreateConstDnMat(&x, rows, cols, ld, nullptr, dataType, order), "Error: val_data is nullptr"); // hipsparseDestroyDnVec verify_hipsparse_status_invalid_pointer(hipsparseDestroyDnMat(nullptr), "Error: x is nullptr"); // Create valid descriptor verify_hipsparse_status_success( hipsparseCreateConstDnMat(&x, rows, cols, ld, val_data, dataType, order), "Success"); // hipsparseConstDnMatGet const void* data; verify_hipsparse_status_invalid_pointer( hipsparseConstDnMatGet(nullptr, &rows, &cols, &ld, &data, &dataType, &order), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstDnMatGet(x, nullptr, &cols, &ld, &data, &dataType, &order), "Error: rows is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstDnMatGet(x, &rows, nullptr, &ld, &data, &dataType, &order), "Error: cols is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstDnMatGet(x, &rows, &cols, nullptr, &data, &dataType, &order), "Error: ld is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstDnMatGet(x, &rows, &cols, &ld, nullptr, &dataType, &order), "Error: data is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstDnMatGet(x, &rows, &cols, &ld, &data, nullptr, &order), "Error: dataType is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstDnMatGet(x, &rows, &cols, &ld, &data, &dataType, nullptr), "Error: order is nullptr"); // hipsparseConstDnMatGetValues verify_hipsparse_status_invalid_pointer(hipsparseConstDnMatGetValues(nullptr, &data), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstDnMatGetValues(x, nullptr), "Error: val is nullptr"); int batch_count = 100; int64_t batch_stride = 100; // hipsparseDnMatGetStridedBatch verify_hipsparse_status_invalid_pointer( hipsparseDnMatGetStridedBatch(nullptr, &batch_count, &batch_stride), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDnMatGetStridedBatch(x, nullptr, &batch_stride), "Error: batch_count is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseDnMatGetStridedBatch(x, &batch_count, nullptr), "Error: batch_stride is nullptr"); // Destroy valid descriptor verify_hipsparse_status_success(hipsparseDestroyDnVec(x), "Success"); #endif } #endif // TESTING_CONST_DNMAT_DESCR_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_const_dnvec_descr.hpp000066400000000000000000000075361501764003400252120ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2023 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CONST_DNVEC_DESCR_HPP #define TESTING_CONST_DNVEC_DESCR_HPP #include "hipsparse_test_unique_ptr.hpp" #ifdef GOOGLE_TEST #include #endif #include using namespace hipsparse_test; void testing_const_dnvec_descr_bad_arg(void) { #if(!defined(CUDART_VERSION)) int64_t size = 100; hipDataType dataType = HIP_R_32F; // Allocate memory on device auto val_data_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * size), device_free}; const float* val_data = (float*)val_data_managed.get(); hipsparseConstDnVecDescr_t x; // hipsparseCreateConstDnVec verify_hipsparse_status_invalid_pointer( hipsparseCreateConstDnVec(nullptr, size, val_data, dataType), "Error: x is nullptr"); verify_hipsparse_status_invalid_size(hipsparseCreateConstDnVec(&x, -1, val_data, dataType), "Error: size is < 0"); verify_hipsparse_status_invalid_pointer(hipsparseCreateConstDnVec(&x, size, nullptr, dataType), "Error: val_data is nullptr"); // hipsparseDestroyDnVec verify_hipsparse_status_invalid_pointer(hipsparseDestroyDnVec(nullptr), "Error: x is nullptr"); // Create valid descriptor verify_hipsparse_status_success(hipsparseCreateConstDnVec(&x, size, val_data, dataType), "Success"); // hipsparseConstDnVecGet const void* data; verify_hipsparse_status_invalid_pointer( hipsparseConstDnVecGet(nullptr, &size, &data, &dataType), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstDnVecGet(x, nullptr, &data, &dataType), "Error: size is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstDnVecGet(x, &size, nullptr, &dataType), "Error: val_data is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstDnVecGet(x, &size, &data, nullptr), "Error: dataType is nullptr"); // hipsparseConstDnVecGetValues verify_hipsparse_status_invalid_pointer(hipsparseConstDnVecGetValues(nullptr, &data), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstDnVecGetValues(x, nullptr), "Error: val is nullptr"); // Destroy valid descriptor verify_hipsparse_status_success(hipsparseDestroyDnVec(x), "Success"); #endif } #endif // TESTING_CONST_DNVEC_DESCR_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_const_spmat_descr.hpp000066400000000000000000001361651501764003400252400ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2023 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CONST_SPMAT_DESCR_HPP #define TESTING_CONST_SPMAT_DESCR_HPP #include "hipsparse_test_unique_ptr.hpp" #ifdef GOOGLE_TEST #include #endif #include #include using namespace hipsparse_test; void testing_const_spmat_descr_bad_arg(void) { #if(!defined(CUDART_VERSION)) int64_t rows = 100; int64_t cols = 100; int64_t nnz = 100; int64_t ell_cols = 10; int64_t ell_blocksize = 2; hipsparseIndexType_t rowType = HIPSPARSE_INDEX_32I; hipsparseIndexType_t colType = HIPSPARSE_INDEX_32I; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipDataType dataType = HIP_R_32F; hipsparseFormat_t format = HIPSPARSE_FORMAT_CSR; // Allocate memory on device auto row_data_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto col_data_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto val_data_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * nnz), device_free}; const int* row_data = (int*)row_data_managed.get(); const int* col_data = (int*)col_data_managed.get(); const float* val_data = (float*)val_data_managed.get(); hipsparseConstSpMatDescr_t A; // hipsparseCreateConstCoo verify_hipsparse_status_invalid_pointer( hipsparseCreateConstCoo( nullptr, rows, cols, nnz, row_data, col_data, val_data, rowType, idxBase, dataType), "Error: A is nullptr"); verify_hipsparse_status_invalid_size( hipsparseCreateConstCoo( &A, -1, cols, nnz, row_data, col_data, val_data, rowType, idxBase, dataType), "Error: rows is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateConstCoo( &A, rows, -1, nnz, row_data, col_data, val_data, rowType, idxBase, dataType), "Error: cols is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateConstCoo( &A, rows, cols, -1, row_data, col_data, val_data, rowType, idxBase, dataType), "Error: nnz is < 0"); verify_hipsparse_status_invalid_pointer( hipsparseCreateConstCoo( &A, rows, cols, nnz, nullptr, col_data, val_data, rowType, idxBase, dataType), "Error: row_data is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCreateConstCoo( &A, rows, cols, nnz, row_data, nullptr, val_data, rowType, idxBase, dataType), "Error: col_data is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCreateConstCoo( &A, rows, cols, nnz, row_data, col_data, nullptr, rowType, idxBase, dataType), "Error: val_data is nullptr"); // hipsparseCreateConstCsr verify_hipsparse_status_invalid_pointer(hipsparseCreateConstCsr(nullptr, rows, cols, nnz, row_data, col_data, val_data, rowType, colType, idxBase, dataType), "Error: A is nullptr"); verify_hipsparse_status_invalid_size( hipsparseCreateConstCsr( &A, -1, cols, nnz, row_data, col_data, val_data, rowType, colType, idxBase, dataType), "Error: rows is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateConstCsr( &A, rows, -1, nnz, row_data, col_data, val_data, rowType, colType, idxBase, dataType), "Error: cols is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateConstCsr( &A, rows, cols, -1, row_data, col_data, val_data, rowType, colType, idxBase, dataType), "Error: nnz is < 0"); verify_hipsparse_status_invalid_pointer( hipsparseCreateConstCsr( &A, rows, cols, nnz, nullptr, col_data, val_data, rowType, colType, idxBase, dataType), "Error: row_data is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCreateConstCsr( &A, rows, cols, nnz, row_data, nullptr, val_data, rowType, colType, idxBase, dataType), "Error: col_data is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCreateConstCsr( &A, rows, cols, nnz, row_data, col_data, nullptr, rowType, colType, idxBase, dataType), "Error: val_data is nullptr"); // hipsparseCreateConstCsc verify_hipsparse_status_invalid_pointer(hipsparseCreateConstCsc(nullptr, rows, cols, nnz, row_data, col_data, val_data, rowType, colType, idxBase, dataType), "Error: A is nullptr"); verify_hipsparse_status_invalid_size( hipsparseCreateConstCsc( &A, -1, cols, nnz, row_data, col_data, val_data, rowType, colType, idxBase, dataType), "Error: rows is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateConstCsc( &A, rows, -1, nnz, row_data, col_data, val_data, rowType, colType, idxBase, dataType), "Error: cols is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateConstCsc( &A, rows, cols, -1, row_data, col_data, val_data, rowType, colType, idxBase, dataType), "Error: nnz is < 0"); verify_hipsparse_status_invalid_pointer( hipsparseCreateConstCsc( &A, rows, cols, nnz, nullptr, col_data, val_data, rowType, colType, idxBase, dataType), "Error: row_data is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCreateConstCsc( &A, rows, cols, nnz, row_data, nullptr, val_data, rowType, colType, idxBase, dataType), "Error: col_data is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCreateConstCsc( &A, rows, cols, nnz, row_data, col_data, nullptr, rowType, colType, idxBase, dataType), "Error: val_data is nullptr"); // hipsparseCreateConstBlockedEll verify_hipsparse_status_invalid_pointer(hipsparseCreateConstBlockedEll(nullptr, rows, cols, ell_blocksize, ell_cols, col_data, val_data, colType, idxBase, dataType), "Error: A is nullptr"); verify_hipsparse_status_invalid_size( hipsparseCreateConstBlockedEll( &A, -1, cols, ell_blocksize, ell_cols, col_data, val_data, colType, idxBase, dataType), "Error: rows is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateConstBlockedEll( &A, rows, -1, ell_blocksize, ell_cols, col_data, val_data, colType, idxBase, dataType), "Error: cols is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateConstBlockedEll( &A, rows, cols, -1, ell_cols, col_data, val_data, colType, idxBase, dataType), "Error: ell_blocksize is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateConstBlockedEll( &A, rows, cols, ell_blocksize, -1, col_data, val_data, colType, idxBase, dataType), "Error: ell_cols is < 0"); verify_hipsparse_status_invalid_pointer( hipsparseCreateConstBlockedEll( &A, rows, cols, ell_blocksize, ell_cols, nullptr, val_data, colType, idxBase, dataType), "Error: ellColInd is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCreateConstBlockedEll( &A, rows, cols, ell_blocksize, ell_cols, col_data, nullptr, colType, idxBase, dataType), "Error: ellValue is nullptr"); // hipsparseDestroySpMat verify_hipsparse_status_invalid_pointer(hipsparseDestroySpMat(nullptr), "Error: A is nullptr"); // Create valid descriptors hipsparseConstSpMatDescr_t coo; hipsparseConstSpMatDescr_t csr; hipsparseConstSpMatDescr_t csc; hipsparseConstSpMatDescr_t bell; verify_hipsparse_status_success(hipsparseCreateConstBlockedEll(&bell, rows, cols, ell_blocksize, ell_cols, col_data, val_data, colType, idxBase, dataType), "Success"); verify_hipsparse_status_success( hipsparseCreateConstCoo( &coo, rows, cols, nnz, row_data, col_data, val_data, rowType, idxBase, dataType), "Success"); verify_hipsparse_status_success(hipsparseCreateConstCsr(&csr, rows, cols, nnz, row_data, col_data, val_data, rowType, colType, idxBase, dataType), "Success"); verify_hipsparse_status_success(hipsparseCreateConstCsc(&csc, rows, cols, nnz, row_data, col_data, val_data, rowType, colType, idxBase, dataType), "Success"); const void* row_ptr; const void* col_ptr; const void* val_ptr; // hipsparseConstCooGet verify_hipsparse_status_invalid_pointer(hipsparseConstCooGet(nullptr, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &idxBase, &dataType), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstCooGet( coo, nullptr, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &idxBase, &dataType), "Error: rows is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstCooGet( coo, &rows, nullptr, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &idxBase, &dataType), "Error: cols is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCooGet(coo, &rows, &cols, nullptr, &row_ptr, &col_ptr, &val_ptr, &rowType, &idxBase, &dataType), "Error: nnz is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstCooGet( coo, &rows, &cols, &nnz, nullptr, &col_ptr, &val_ptr, &rowType, &idxBase, &dataType), "Error: row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstCooGet( coo, &rows, &cols, &nnz, &row_ptr, nullptr, &val_ptr, &rowType, &idxBase, &dataType), "Error: col_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstCooGet( coo, &rows, &cols, &nnz, &row_ptr, &col_ptr, nullptr, &rowType, &idxBase, &dataType), "Error: val_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstCooGet( coo, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, nullptr, &idxBase, &dataType), "Error: rowType is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstCooGet( coo, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, nullptr, &dataType), "Error: idxBase is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstCooGet( coo, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &idxBase, nullptr), "Error: dataType is nullptr"); // hipsparseConstCsrGet verify_hipsparse_status_invalid_pointer(hipsparseConstCsrGet(nullptr, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &colType, &idxBase, &dataType), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCsrGet(csr, nullptr, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &colType, &idxBase, &dataType), "Error: rows is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCsrGet(csr, &rows, nullptr, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &colType, &idxBase, &dataType), "Error: cols is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCsrGet(csr, &rows, &cols, nullptr, &row_ptr, &col_ptr, &val_ptr, &rowType, &colType, &idxBase, &dataType), "Error: nnz is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCsrGet(csr, &rows, &cols, &nnz, nullptr, &col_ptr, &val_ptr, &rowType, &colType, &idxBase, &dataType), "Error: row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCsrGet(csr, &rows, &cols, &nnz, &row_ptr, nullptr, &val_ptr, &rowType, &colType, &idxBase, &dataType), "Error: col_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCsrGet(csr, &rows, &cols, &nnz, &row_ptr, &col_ptr, nullptr, &rowType, &colType, &idxBase, &dataType), "Error: val_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCsrGet(csr, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, nullptr, &colType, &idxBase, &dataType), "Error: rowType is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCsrGet(csr, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, nullptr, &idxBase, &dataType), "Error: colType is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCsrGet(csr, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &colType, nullptr, &dataType), "Error: idxBase is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCsrGet(csr, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &colType, &idxBase, nullptr), "Error: dataType is nullptr"); // hipsparseConstCsrGet verify_hipsparse_status_invalid_pointer(hipsparseConstCscGet(nullptr, &rows, &cols, &nnz, &col_ptr, &row_ptr, &val_ptr, &colType, &rowType, &idxBase, &dataType), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCscGet(csc, nullptr, &cols, &nnz, &col_ptr, &row_ptr, &val_ptr, &colType, &rowType, &idxBase, &dataType), "Error: rows is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCscGet(csc, &rows, nullptr, &nnz, &col_ptr, &row_ptr, &val_ptr, &colType, &rowType, &idxBase, &dataType), "Error: cols is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCscGet(csc, &rows, &cols, nullptr, &col_ptr, &row_ptr, &val_ptr, &colType, &rowType, &idxBase, &dataType), "Error: nnz is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCscGet(csc, &rows, &cols, &nnz, nullptr, &row_ptr, &val_ptr, &colType, &rowType, &idxBase, &dataType), "Error: col_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCscGet(csc, &rows, &cols, &nnz, &col_ptr, nullptr, &val_ptr, &colType, &rowType, &idxBase, &dataType), "Error: row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCscGet(csc, &rows, &cols, &nnz, &col_ptr, &row_ptr, nullptr, &colType, &rowType, &idxBase, &dataType), "Error: val_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCscGet(csc, &rows, &cols, &nnz, &col_ptr, &row_ptr, &val_ptr, nullptr, &rowType, &idxBase, &dataType), "Error: colType is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCscGet(csc, &rows, &cols, &nnz, &col_ptr, &row_ptr, &val_ptr, &colType, nullptr, &idxBase, &dataType), "Error: rowType is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCscGet(csc, &rows, &cols, &nnz, &col_ptr, &row_ptr, &val_ptr, &colType, &rowType, nullptr, &dataType), "Error: idxBase is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCscGet(csc, &rows, &cols, &nnz, &col_ptr, &row_ptr, &val_ptr, &colType, &rowType, &idxBase, nullptr), "Error: dataType is nullptr"); // hipsparseConstBlockedEllGet verify_hipsparse_status_invalid_pointer(hipsparseConstBlockedEllGet(nullptr, &rows, &cols, &ell_blocksize, &ell_cols, &col_ptr, &val_ptr, &colType, &idxBase, &dataType), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstBlockedEllGet(bell, nullptr, &cols, &ell_blocksize, &ell_cols, &col_ptr, &val_ptr, &colType, &idxBase, &dataType), "Error: rows is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstBlockedEllGet(bell, &rows, nullptr, &ell_blocksize, &ell_cols, &col_ptr, &val_ptr, &colType, &idxBase, &dataType), "Error: cols is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstBlockedEllGet(bell, &rows, &cols, nullptr, &ell_cols, &col_ptr, &val_ptr, &colType, &idxBase, &dataType), "Error: ell_blocksize is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstBlockedEllGet(bell, &rows, &cols, &ell_blocksize, nullptr, &col_ptr, &val_ptr, &colType, &idxBase, &dataType), "Error: ell_cols is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstBlockedEllGet(bell, &rows, &cols, &ell_blocksize, &ell_cols, nullptr, &val_ptr, &colType, &idxBase, &dataType), "Error: ellColInd"); verify_hipsparse_status_invalid_pointer(hipsparseConstBlockedEllGet(bell, &rows, &cols, &ell_blocksize, &ell_cols, &col_ptr, nullptr, &colType, &idxBase, &dataType), "Error: ellValue is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstBlockedEllGet(bell, &rows, &cols, &ell_blocksize, &ell_cols, &col_ptr, &val_ptr, nullptr, &idxBase, &dataType), "Error: ellIdxType is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstBlockedEllGet(bell, &rows, &cols, &ell_blocksize, &ell_cols, &col_ptr, &val_ptr, &colType, nullptr, &dataType), "Error: idxBase is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstBlockedEllGet(bell, &rows, &cols, &ell_blocksize, &ell_cols, &col_ptr, &val_ptr, &colType, &idxBase, nullptr), "Error: valueType is nullptr"); // hipsparseSpMatGetSize verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetSize(nullptr, &rows, &cols, &nnz), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetSize(coo, nullptr, &cols, &nnz), "Error: rows is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetSize(coo, &rows, nullptr, &nnz), "Error: cols is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetSize(coo, &rows, &cols, nullptr), "Error: nnz is nullptr"); // hipsparseSpMatGetFormat verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetFormat(nullptr, &format), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetFormat(coo, nullptr), "Error: format is nullptr"); // hipsparseSpMatGetIndexBase verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetIndexBase(nullptr, &idxBase), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetIndexBase(coo, nullptr), "Error: idxBase is nullptr"); // hipsparseConstSpMatGetValues verify_hipsparse_status_invalid_pointer(hipsparseConstSpMatGetValues(nullptr, &val_ptr), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstSpMatGetValues(coo, nullptr), "Error: val_ptr is nullptr"); int batch_count = 100; // hipsparseSpMatGetStridedBatch verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetStridedBatch(nullptr, &batch_count), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetStridedBatch(coo, nullptr), "Error: batch count is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetStridedBatch(csr, nullptr), "Error: batch count is nullptr"); // Destroy valid descriptors verify_hipsparse_status_success(hipsparseDestroySpMat(coo), "Success"); verify_hipsparse_status_success(hipsparseDestroySpMat(csc), "Success"); verify_hipsparse_status_success(hipsparseDestroySpMat(csr), "Success"); verify_hipsparse_status_success(hipsparseDestroySpMat(bell), "Success"); #endif } #endif // TESTING_CONST_SPMAT_DESCR_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_const_spvec_descr.hpp000066400000000000000000000132551501764003400252260ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2023 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CONST_SPVEC_DESCR_HPP #define TESTING_CONST_SPVEC_DESCR_HPP #include "hipsparse_test_unique_ptr.hpp" #ifdef GOOGLE_TEST #include #endif #include using namespace hipsparse_test; void testing_const_spvec_descr_bad_arg(void) { #if(!defined(CUDART_VERSION)) int64_t size = 100; int64_t nnz = 100; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipDataType dataType = HIP_R_32F; // Allocate memory on device auto idx_data_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto val_data_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * nnz), device_free}; const int* idx_data = (const int*)idx_data_managed.get(); const float* val_data = (const float*)val_data_managed.get(); hipsparseConstSpVecDescr_t x; // hipsparseCreateConstSpVec verify_hipsparse_status_invalid_pointer( hipsparseCreateConstSpVec( nullptr, size, nnz, idx_data, val_data, idxType, idxBase, dataType), "Error: x is nullptr"); verify_hipsparse_status_invalid_size( hipsparseCreateConstSpVec(&x, -1, nnz, idx_data, val_data, idxType, idxBase, dataType), "Error: size is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateConstSpVec(&x, size, -1, idx_data, val_data, idxType, idxBase, dataType), "Error: nnz is < 0"); verify_hipsparse_status_invalid_pointer( hipsparseCreateConstSpVec(&x, size, nnz, nullptr, val_data, idxType, idxBase, dataType), "Error: idx_data is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCreateConstSpVec(&x, size, nnz, idx_data, nullptr, idxType, idxBase, dataType), "Error: val_data is nullptr"); // hipsparseDestroySpVec verify_hipsparse_status_invalid_pointer(hipsparseDestroySpVec(nullptr), "Error: x is nullptr"); // Create valid descriptor verify_hipsparse_status_success( hipsparseCreateConstSpVec(&x, size, nnz, idx_data, val_data, idxType, idxBase, dataType), "Success"); // hipsparseConstSpVecGet const void* idx; const void* data; verify_hipsparse_status_invalid_pointer( hipsparseConstSpVecGet(nullptr, &size, &nnz, &idx, &data, &idxType, &idxBase, &dataType), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstSpVecGet(x, nullptr, &nnz, &idx, &data, &idxType, &idxBase, &dataType), "Error: size is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstSpVecGet(x, &size, nullptr, &idx, &data, &idxType, &idxBase, &dataType), "Error: nnz is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstSpVecGet(x, &size, &nnz, nullptr, &data, &idxType, &idxBase, &dataType), "Error: idx is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstSpVecGet(x, &size, &nnz, &idx, nullptr, &idxType, &idxBase, &dataType), "Error: val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstSpVecGet(x, &size, &nnz, &idx, &data, nullptr, &idxBase, &dataType), "Error: idxType is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstSpVecGet(x, &size, &nnz, &idx, &data, &idxType, nullptr, &dataType), "Error: idxBase is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstSpVecGet(x, &size, &nnz, &idx, &data, &idxType, &idxBase, nullptr), "Error: dataType is nullptr"); // hipsparseSpVecGetIndexBase verify_hipsparse_status_invalid_pointer(hipsparseSpVecGetIndexBase(nullptr, &idxBase), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpVecGetIndexBase(x, nullptr), "Error: idxBase is nullptr"); // hipsparseConstSpVecGetValues verify_hipsparse_status_invalid_pointer(hipsparseConstSpVecGetValues(nullptr, &data), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstSpVecGetValues(x, nullptr), "Error: val is nullptr"); // Destroy valid descriptor verify_hipsparse_status_success(hipsparseDestroySpVec(x), "Success"); #endif } #endif // TESTING_CONST_SPVEC_DESCR_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_coo2csr.hpp000066400000000000000000000147541501764003400230770ustar00rootroot00000000000000/* ************************************************************************ * 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 "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; void testing_coo2csr_bad_arg(void) { #if(!defined(CUDART_VERSION)) int m = 100; int nnz = 100; int safe_size = 100; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto coo_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; int* coo_row_ind = (int*)coo_row_ind_managed.get(); int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); verify_hipsparse_status_invalid_pointer( hipsparseXcoo2csr(handle, (int*)nullptr, nnz, m, csr_row_ptr, idx_base), "Error: coo_row_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcoo2csr(handle, coo_row_ind, nnz, m, (int*)nullptr, idx_base), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXcoo2csr((hipsparseHandle_t) nullptr, coo_row_ind, nnz, m, csr_row_ptr, idx_base)); #endif } template hipsparseStatus_t testing_coo2csr(Arguments argus) { int m = argus.M; int n = argus.N; hipsparseIndexBase_t idx_base = argus.baseA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; if(m == 0 || n == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcoo_row_ind; std::vector hcoo_col_ind; std::vector hcoo_val; // Read or construct CSR matrix int nnz = 0; if(!generate_coo_matrix(filename, m, n, nnz, hcoo_row_ind, hcoo_col_ind, hcoo_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hcsr_row_ptr(m + 1); std::vector hcsr_row_ptr_gold(m + 1, 0); // Allocate memory on the device auto dcoo_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; int* dcoo_row_ind = (int*)dcoo_row_ind_managed.get(); int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); // Copy data from host to device CHECK_HIP_ERROR( hipMemcpy(dcoo_row_ind, hcoo_row_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR( hipsparseXcoo2csr(handle, dcoo_row_ind, nnz, m, dcsr_row_ptr, idx_base)); // Copy output from device to host CHECK_HIP_ERROR(hipMemcpy( hcsr_row_ptr.data(), dcsr_row_ptr, sizeof(int) * (m + 1), hipMemcpyDeviceToHost)); // CPU // coo2csr on host for(int i = 0; i < nnz; ++i) { ++hcsr_row_ptr_gold[hcoo_row_ind[i] + 1 - idx_base]; } hcsr_row_ptr_gold[0] = idx_base; for(int i = 0; i < m; ++i) { hcsr_row_ptr_gold[i + 1] += hcsr_row_ptr_gold[i]; } // Unit check unit_check_general(1, m + 1, 1, hcsr_row_ptr_gold.data(), hcsr_row_ptr.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXcoo2csr(handle, dcoo_row_ind, nnz, m, dcsr_row_ptr, idx_base)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXcoo2csr(handle, dcoo_row_ind, nnz, m, dcsr_row_ptr, idx_base)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = coo2csr_gbyte_count(m, nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_COO2CSR_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_coosort.hpp000066400000000000000000000320601501764003400232030ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2018-2019 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_COOSORT_HPP #define TESTING_COOSORT_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; void testing_coosort_bad_arg(void) { #if(!defined(CUDART_VERSION)) int m = 100; int n = 100; int nnz = 100; int safe_size = 100; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; size_t buffer_size = 0; auto coo_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto coo_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto perm_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto buffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* coo_row_ind = (int*)coo_row_ind_managed.get(); int* coo_col_ind = (int*)coo_col_ind_managed.get(); int* perm = (int*)perm_managed.get(); void* buffer = (void*)buffer_managed.get(); verify_hipsparse_status_invalid_pointer( hipsparseXcoosort_bufferSizeExt( handle, m, n, nnz, (int*)nullptr, coo_col_ind, &buffer_size), "Error: coo_row_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcoosort_bufferSizeExt( handle, m, n, nnz, coo_row_ind, (int*)nullptr, &buffer_size), "Error: coo_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcoosort_bufferSizeExt( handle, m, n, nnz, coo_row_ind, coo_col_ind, (size_t*)nullptr), "Error: buffer_size is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcoosort_bufferSizeExt( (hipsparseHandle_t) nullptr, m, n, nnz, coo_row_ind, coo_col_ind, &buffer_size)); verify_hipsparse_status_invalid_pointer( hipsparseXcoosortByRow(handle, m, n, nnz, (int*)nullptr, coo_col_ind, perm, buffer), "Error: coo_row_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcoosortByRow(handle, m, n, nnz, coo_row_ind, (int*)nullptr, perm, buffer), "Error: coo_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcoosortByRow(handle, m, n, nnz, coo_row_ind, coo_col_ind, perm, (int*)nullptr), "Error: buffer is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcoosortByRow( (hipsparseHandle_t) nullptr, m, n, nnz, coo_row_ind, coo_col_ind, perm, buffer)); verify_hipsparse_status_invalid_pointer( hipsparseXcoosortByColumn(handle, m, n, nnz, (int*)nullptr, coo_col_ind, perm, buffer), "Error: coo_row_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcoosortByColumn(handle, m, n, nnz, coo_row_ind, (int*)nullptr, perm, buffer), "Error: coo_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcoosortByColumn(handle, m, n, nnz, coo_row_ind, coo_col_ind, perm, (int*)nullptr), "Error: buffer is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcoosortByColumn( (hipsparseHandle_t) nullptr, m, n, nnz, coo_row_ind, coo_col_ind, perm, buffer)); #endif } hipsparseStatus_t testing_coosort(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int m = argus.M; int n = argus.N; int by_row = (argus.transA == HIPSPARSE_OPERATION_NON_TRANSPOSE); int permute = argus.permute; hipsparseIndexBase_t idx_base = argus.baseA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; if(m == 0 || n == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcoo_row_ind; std::vector hcoo_col_ind; std::vector hcoo_val; // Read or construct CSR matrix int nnz = 0; if(!generate_coo_matrix(filename, m, n, nnz, hcoo_row_ind, hcoo_col_ind, hcoo_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Unsort COO columns std::vector hcoo_row_ind_unsorted(nnz); std::vector hcoo_col_ind_unsorted(nnz); std::vector hcoo_val_unsorted(nnz); hcoo_row_ind_unsorted = hcoo_row_ind; hcoo_col_ind_unsorted = hcoo_col_ind; hcoo_val_unsorted = hcoo_val; for(int i = 0; i < nnz; ++i) { int rng = rand() % nnz; int temp_row = hcoo_row_ind_unsorted[i]; int temp_col = hcoo_col_ind_unsorted[i]; float temp_val = hcoo_val_unsorted[i]; hcoo_row_ind_unsorted[i] = hcoo_row_ind_unsorted[rng]; hcoo_col_ind_unsorted[i] = hcoo_col_ind_unsorted[rng]; hcoo_val_unsorted[i] = hcoo_val_unsorted[rng]; hcoo_row_ind_unsorted[rng] = temp_row; hcoo_col_ind_unsorted[rng] = temp_col; hcoo_val_unsorted[rng] = temp_val; } // If coosort by column, sort host arrays by column if(!by_row) { std::vector hperm(nnz); for(int i = 0; i < nnz; ++i) { hperm[i] = i; } std::sort(hperm.begin(), hperm.end(), [&](const int& a, const int& b) { if(hcoo_col_ind_unsorted[a] < hcoo_col_ind_unsorted[b]) { return true; } else if(hcoo_col_ind_unsorted[a] == hcoo_col_ind_unsorted[b]) { return (hcoo_row_ind_unsorted[a] < hcoo_row_ind_unsorted[b]); } else { return false; } }); for(int i = 0; i < nnz; ++i) { hcoo_row_ind[i] = hcoo_row_ind_unsorted[hperm[i]]; hcoo_col_ind[i] = hcoo_col_ind_unsorted[hperm[i]]; hcoo_val[i] = hcoo_val_unsorted[hperm[i]]; } } // Allocate memory on the device auto dcoo_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcoo_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcoo_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * nnz), device_free}; auto dcoo_val_sorted_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * nnz), device_free}; auto dperm_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; int* dcoo_row_ind = (int*)dcoo_row_ind_managed.get(); int* dcoo_col_ind = (int*)dcoo_col_ind_managed.get(); float* dcoo_val = (float*)dcoo_val_managed.get(); float* dcoo_val_sorted = (float*)dcoo_val_sorted_managed.get(); // Set permutation vector, if asked for int* dperm = permute ? (int*)dperm_managed.get() : nullptr; // Copy data from host to device CHECK_HIP_ERROR(hipMemcpy( dcoo_row_ind, hcoo_row_ind_unsorted.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy( dcoo_col_ind, hcoo_col_ind_unsorted.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcoo_val, hcoo_val_unsorted.data(), sizeof(float) * nnz, hipMemcpyHostToDevice)); // Obtain buffer size size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseXcoosort_bufferSizeExt( handle, m, n, nnz, dcoo_row_ind, dcoo_col_ind, &bufferSize)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * bufferSize), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); if(permute) { // Initialize perm with identity permutation CHECK_HIPSPARSE_ERROR(hipsparseCreateIdentityPermutation(handle, nnz, dperm)); } if(argus.unit_check) { // Sort CSR columns if(by_row) { CHECK_HIPSPARSE_ERROR(hipsparseXcoosortByRow( handle, m, n, nnz, dcoo_row_ind, dcoo_col_ind, dperm, dbuffer)); } else { CHECK_HIPSPARSE_ERROR(hipsparseXcoosortByColumn( handle, m, n, nnz, dcoo_row_ind, dcoo_col_ind, dperm, dbuffer)); } if(permute) { // Sort CSR values CHECK_HIPSPARSE_ERROR(hipsparseSgthr( handle, nnz, dcoo_val, dcoo_val_sorted, dperm, HIPSPARSE_INDEX_BASE_ZERO)); } // Copy output from device to host CHECK_HIP_ERROR(hipMemcpy( hcoo_row_ind_unsorted.data(), dcoo_row_ind, sizeof(int) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcoo_col_ind_unsorted.data(), dcoo_col_ind, sizeof(int) * nnz, hipMemcpyDeviceToHost)); if(permute) { CHECK_HIP_ERROR(hipMemcpy(hcoo_val_unsorted.data(), dcoo_val_sorted, sizeof(float) * nnz, hipMemcpyDeviceToHost)); } // Unit check unit_check_general(1, nnz, 1, hcoo_row_ind.data(), hcoo_row_ind_unsorted.data()); unit_check_general(1, nnz, 1, hcoo_col_ind.data(), hcoo_col_ind_unsorted.data()); if(permute) { unit_check_general(1, nnz, 1, hcoo_val.data(), hcoo_val_unsorted.data()); } } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { if(by_row) { CHECK_HIPSPARSE_ERROR(hipsparseXcoosortByRow( handle, m, n, nnz, dcoo_row_ind, dcoo_col_ind, dperm, dbuffer)); } else { CHECK_HIPSPARSE_ERROR(hipsparseXcoosortByColumn( handle, m, n, nnz, dcoo_row_ind, dcoo_col_ind, dperm, dbuffer)); } } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { if(by_row) { CHECK_HIPSPARSE_ERROR(hipsparseXcoosortByRow( handle, m, n, nnz, dcoo_row_ind, dcoo_col_ind, dperm, dbuffer)); } else { CHECK_HIPSPARSE_ERROR(hipsparseXcoosortByColumn( handle, m, n, nnz, dcoo_row_ind, dcoo_col_ind, dperm, dbuffer)); } } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = coosort_gbyte_count(nnz, permute); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::permute, (permute ? "yes" : "no"), display_key_t::direction, (by_row ? "row" : "column"), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_COOSORT_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_csc2dense.hpp000066400000000000000000000040221501764003400233610ustar00rootroot00000000000000/* ************************************************************************ * 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) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_COLUMN; testing_csx2dense_bad_arg(hipsparseXcsc2dense); #endif } template hipsparseStatus_t testing_csc2dense(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_COLUMN; return testing_csx2dense(argus, hipsparseXcsc2dense, hipsparseXdense2csc); #else return HIPSPARSE_STATUS_SUCCESS; #endif } #endif // TESTING_CSC2DENSE hipSPARSE-rocm-6.4.3/clients/include/testing_cscsort.hpp000066400000000000000000000271271501764003400232030ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2019 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSCSORT_HPP #define TESTING_CSCSORT_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; void testing_cscsort_bad_arg(void) { #if(!defined(CUDART_VERSION)) int m = 100; int n = 100; int nnz = 100; int safe_size = 100; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; size_t buffer_size = 0; auto csc_col_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csc_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto perm_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto buffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* csc_col_ptr = (int*)csc_col_ptr_managed.get(); int* csc_row_ind = (int*)csc_row_ind_managed.get(); int* perm = (int*)perm_managed.get(); void* buffer = (void*)buffer_managed.get(); verify_hipsparse_status_invalid_pointer( hipsparseXcscsort_bufferSizeExt( handle, m, n, nnz, (int*)nullptr, csc_row_ind, &buffer_size), "Error: csc_col_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcscsort_bufferSizeExt( handle, m, n, nnz, csc_col_ptr, (int*)nullptr, &buffer_size), "Error: csc_row_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcscsort_bufferSizeExt( handle, m, n, nnz, csc_col_ptr, csc_row_ind, (size_t*)nullptr), "Error: buffer_size is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcscsort_bufferSizeExt( (hipsparseHandle_t) nullptr, m, n, nnz, csc_col_ptr, csc_row_ind, &buffer_size)); verify_hipsparse_status_invalid_pointer( hipsparseXcscsort(handle, m, n, nnz, descr, (int*)nullptr, csc_row_ind, perm, buffer), "Error: csc_col_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcscsort(handle, m, n, nnz, descr, csc_col_ptr, (int*)nullptr, perm, buffer), "Error: csc_row_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcscsort(handle, m, n, nnz, descr, csc_col_ptr, csc_row_ind, perm, (int*)nullptr), "Error: buffer is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcscsort(handle, m, n, nnz, (hipsparseMatDescr_t) nullptr, csc_col_ptr, csc_row_ind, perm, buffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcscsort( (hipsparseHandle_t) nullptr, m, n, nnz, descr, csc_col_ptr, csc_row_ind, perm, buffer)); #endif } hipsparseStatus_t testing_cscsort(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int m = argus.M; int n = argus.N; int permute = argus.permute; hipsparseIndexBase_t idx_base = argus.baseA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); if(m == 0 || n == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcsc_col_ptr; std::vector hcsc_row_ind; std::vector hcsc_val; // Read or construct CSC matrix int nnz = 0; if(!generate_csr_matrix(filename, n, m, nnz, hcsc_col_ptr, hcsc_row_ind, hcsc_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Unsort CSC columns std::vector hperm(nnz); std::vector hcsc_row_ind_unsorted(nnz); std::vector hcsc_val_unsorted(nnz); hcsc_row_ind_unsorted = hcsc_row_ind; hcsc_val_unsorted = hcsc_val; for(int i = 0; i < n; ++i) { int col_begin = hcsc_col_ptr[i] - idx_base; int col_end = hcsc_col_ptr[i + 1] - idx_base; int col_nnz = col_end - col_begin; for(int j = col_begin; j < col_end; ++j) { int rng = col_begin + rand() % col_nnz; int temp_row = hcsc_row_ind_unsorted[j]; float temp_val = hcsc_val_unsorted[j]; hcsc_row_ind_unsorted[j] = hcsc_row_ind_unsorted[rng]; hcsc_val_unsorted[j] = hcsc_val_unsorted[rng]; hcsc_row_ind_unsorted[rng] = temp_row; hcsc_val_unsorted[rng] = temp_val; } } // Allocate memory on the device auto dcsc_col_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (n + 1)), device_free}; auto dcsc_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsc_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * nnz), device_free}; auto dcsc_val_sorted_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * nnz), device_free}; auto dperm_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; int* dcsc_col_ptr = (int*)dcsc_col_ptr_managed.get(); int* dcsc_row_ind = (int*)dcsc_row_ind_managed.get(); float* dcsc_val = (float*)dcsc_val_managed.get(); float* dcsc_val_sorted = (float*)dcsc_val_sorted_managed.get(); // Set permutation vector, if asked for #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse does not allow nullptr int* dperm = (int*)dperm_managed.get(); #else int* dperm = permute ? (int*)dperm_managed.get() : nullptr; #endif // Copy data from host to device CHECK_HIP_ERROR( hipMemcpy(dcsc_col_ptr, hcsc_col_ptr.data(), sizeof(int) * (n + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy( dcsc_row_ind, hcsc_row_ind_unsorted.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsc_val, hcsc_val_unsorted.data(), sizeof(float) * nnz, hipMemcpyHostToDevice)); // Obtain buffer size size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseXcscsort_bufferSizeExt( handle, m, n, nnz, dcsc_col_ptr, dcsc_row_ind, &bufferSize)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * bufferSize), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); if(permute) { // Initialize perm with identity permutation CHECK_HIPSPARSE_ERROR(hipsparseCreateIdentityPermutation(handle, nnz, dperm)); } if(argus.unit_check) { // Sort CSC columns CHECK_HIPSPARSE_ERROR(hipsparseXcscsort( handle, m, n, nnz, descr, dcsc_col_ptr, dcsc_row_ind, dperm, dbuffer)); if(permute) { // Sort CSC values CHECK_HIPSPARSE_ERROR(hipsparseSgthr( handle, nnz, dcsc_val, dcsc_val_sorted, dperm, HIPSPARSE_INDEX_BASE_ZERO)); } // Copy output from device to host CHECK_HIP_ERROR(hipMemcpy( hcsc_row_ind_unsorted.data(), dcsc_row_ind, sizeof(int) * nnz, hipMemcpyDeviceToHost)); if(permute) { CHECK_HIP_ERROR(hipMemcpy(hcsc_val_unsorted.data(), dcsc_val_sorted, sizeof(float) * nnz, hipMemcpyDeviceToHost)); } // Unit check unit_check_general(1, nnz, 1, hcsc_row_ind.data(), hcsc_row_ind_unsorted.data()); if(permute) { unit_check_general(1, nnz, 1, hcsc_val.data(), hcsc_val_unsorted.data()); } } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcscsort( handle, m, n, nnz, descr, dcsc_col_ptr, dcsc_row_ind, dperm, dbuffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcscsort( handle, m, n, nnz, descr, dcsc_col_ptr, dcsc_row_ind, dperm, dbuffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = cscsort_gbyte_count(n, nnz, permute); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::permute, (permute ? "yes" : "no"), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSCSORT_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_csr2bsr.hpp000066400000000000000000001036401501764003400230760ustar00rootroot00000000000000/* ************************************************************************ * 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 "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csr2bsr_bad_arg(void) { #if(!defined(CUDART_VERSION)) int m = 1; int n = 1; int safe_size = 1; int block_dim = 2; hipsparseIndexBase_t csr_idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexBase_t bsr_idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseDirection_t dir = HIPSPARSE_DIRECTION_ROW; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_csr_descr(new descr_struct); hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; std::unique_ptr unique_ptr_bsr_descr(new descr_struct); hipsparseMatDescr_t bsr_descr = unique_ptr_bsr_descr->descr; hipsparseSetMatIndexBase(csr_descr, csr_idx_base); hipsparseSetMatIndexBase(bsr_descr, bsr_idx_base); auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto csr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto bsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto bsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto bsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* csr_col_ind = (int*)csr_col_ind_managed.get(); T* csr_val = (T*)csr_val_managed.get(); int* bsr_row_ptr = (int*)bsr_row_ptr_managed.get(); int* bsr_col_ind = (int*)bsr_col_ind_managed.get(); T* bsr_val = (T*)bsr_val_managed.get(); int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(csr_row_ptr, local_ptr, sizeof(int) * (1 + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(bsr_row_ptr, local_ptr, sizeof(int) * (1 + 1), hipMemcpyHostToDevice)); int bsr_nnzb; verify_hipsparse_status_invalid_handle(hipsparseXcsr2bsrNnz(nullptr, dir, m, n, csr_descr, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_row_ptr, &bsr_nnzb)); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsrNnz(handle, dir, m, n, nullptr, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_row_ptr, &bsr_nnzb), "Error: csr_descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsrNnz(handle, dir, m, n, csr_descr, nullptr, csr_col_ind, block_dim, bsr_descr, bsr_row_ptr, &bsr_nnzb), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsrNnz(handle, dir, m, n, csr_descr, csr_row_ptr, csr_col_ind, block_dim, nullptr, bsr_row_ptr, &bsr_nnzb), "Error: bsr_descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsrNnz(handle, dir, m, n, csr_descr, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, nullptr, &bsr_nnzb), "Error: bsr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsrNnz(handle, dir, m, n, csr_descr, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_row_ptr, nullptr), "Error: bsr_nnzb is nullptr"); verify_hipsparse_status_invalid_size(hipsparseXcsr2bsrNnz(handle, dir, -1, n, csr_descr, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_row_ptr, &bsr_nnzb), "Error: m is invalid"); verify_hipsparse_status_invalid_size(hipsparseXcsr2bsrNnz(handle, dir, m, -1, csr_descr, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_row_ptr, &bsr_nnzb), "Error: n is invalid"); verify_hipsparse_status_invalid_size(hipsparseXcsr2bsrNnz(handle, dir, m, n, csr_descr, csr_row_ptr, csr_col_ind, -1, bsr_descr, bsr_row_ptr, &bsr_nnzb), "Error: block_dim is invalid"); verify_hipsparse_status_invalid_handle(hipsparseXcsr2bsr(nullptr, dir, m, n, csr_descr, csr_val, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind)); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsr(handle, dir, m, n, nullptr, csr_val, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind), "Error: csr_descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsr(handle, dir, m, n, csr_descr, (T*)nullptr, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind), "Error: csr_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsr(handle, dir, m, n, csr_descr, csr_val, nullptr, csr_col_ind, block_dim, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsr(handle, dir, m, n, csr_descr, csr_val, csr_row_ptr, nullptr, block_dim, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsr(handle, dir, m, n, csr_descr, csr_val, csr_row_ptr, csr_col_ind, block_dim, nullptr, bsr_val, bsr_row_ptr, bsr_col_ind), "Error: bsr_descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsr(handle, dir, m, n, csr_descr, csr_val, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, (T*)nullptr, bsr_row_ptr, bsr_col_ind), "Error: bsr_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsr(handle, dir, m, n, csr_descr, csr_val, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_val, nullptr, bsr_col_ind), "Error: bsr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsr(handle, dir, m, n, csr_descr, csr_val, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_val, bsr_row_ptr, nullptr), "Error: bsr_col_ind is nullptr"); verify_hipsparse_status_invalid_size(hipsparseXcsr2bsr(handle, dir, -1, n, csr_descr, csr_val, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind), "Error: m is invalid"); verify_hipsparse_status_invalid_size(hipsparseXcsr2bsr(handle, dir, m, -1, csr_descr, csr_val, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind), "Error: n is invalid"); verify_hipsparse_status_invalid_size(hipsparseXcsr2bsr(handle, dir, m, n, csr_descr, csr_val, csr_row_ptr, csr_col_ind, -1, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind), "Error: block_dim is invalid"); #endif } template hipsparseStatus_t testing_csr2bsr(Arguments argus) { int m = argus.M; int n = argus.N; int block_dim = argus.block_dim; hipsparseIndexBase_t csr_idx_base = argus.baseA; hipsparseIndexBase_t bsr_idx_base = argus.baseB; hipsparseDirection_t dir = argus.dirA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_csr_descr(new descr_struct); hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; std::unique_ptr unique_ptr_bsr_descr(new descr_struct); hipsparseMatDescr_t bsr_descr = unique_ptr_bsr_descr->descr; hipsparseSetMatIndexBase(csr_descr, csr_idx_base); hipsparseSetMatIndexBase(bsr_descr, bsr_idx_base); if(m == 0 || n == 0 || block_dim == 1) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse does not support m == 0 or n == 0 for csr2bsr // cusparse does not support asynchronous execution if block_dim == 1 return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix( filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, csr_idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } int mb = (m + block_dim - 1) / block_dim; int nb = (n + block_dim - 1) / block_dim; // Allocate memory on the device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dbsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb + 1)), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); int* dbsr_row_ptr = (int*)dbsr_row_ptr_managed.get(); // Copy data from host to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_val, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); // Obtain BSR nnzb first on the host and then using the device and ensure they give the same results CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); int hbsr_nnzb; CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsrNnz(handle, dir, m, n, csr_descr, dcsr_row_ptr, dcsr_col_ind, block_dim, bsr_descr, dbsr_row_ptr, &hbsr_nnzb)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); auto dbsr_nnzb_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dbsr_nnzb = (int*)dbsr_nnzb_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsrNnz(handle, dir, m, n, csr_descr, dcsr_row_ptr, dcsr_col_ind, block_dim, bsr_descr, dbsr_row_ptr, dbsr_nnzb)); int hbsr_nnzb_copied_from_device; CHECK_HIP_ERROR( hipMemcpy(&hbsr_nnzb_copied_from_device, dbsr_nnzb, sizeof(int), hipMemcpyDeviceToHost)); // Check that using host and device pointer mode gives the same result unit_check_general(1, 1, 1, &hbsr_nnzb_copied_from_device, &hbsr_nnzb); // Allocate memory on the device auto dbsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * hbsr_nnzb), device_free}; auto dbsr_val_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * hbsr_nnzb * block_dim * block_dim), device_free}; int* dbsr_col_ind = (int*)dbsr_col_ind_managed.get(); T* dbsr_val = (T*)dbsr_val_managed.get(); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsr(handle, dir, m, n, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, block_dim, bsr_descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind)); // Copy output from device to host std::vector hbsr_row_ptr(mb + 1); std::vector hbsr_col_ind(hbsr_nnzb); std::vector hbsr_val(hbsr_nnzb * block_dim * block_dim); CHECK_HIP_ERROR(hipMemcpy( hbsr_row_ptr.data(), dbsr_row_ptr, sizeof(int) * (mb + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hbsr_col_ind.data(), dbsr_col_ind, sizeof(int) * hbsr_nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsr_val.data(), dbsr_val, sizeof(T) * hbsr_nnzb * block_dim * block_dim, hipMemcpyDeviceToHost)); // Host csr2bsr conversion std::vector hbsr_row_ptr_gold(mb + 1); std::vector hbsr_col_ind_gold(hbsr_nnzb, 0); std::vector hbsr_val_gold(hbsr_nnzb * block_dim * block_dim); // call host csr2bsr here int bsr_nnzb_gold; host_csr_to_bsr(dir, m, n, block_dim, bsr_nnzb_gold, csr_idx_base, hcsr_row_ptr, hcsr_col_ind, hcsr_val, bsr_idx_base, hbsr_row_ptr_gold, hbsr_col_ind_gold, hbsr_val_gold); // Unit check unit_check_general(1, 1, 1, &bsr_nnzb_gold, &hbsr_nnzb); unit_check_general(1, mb + 1, 1, hbsr_row_ptr_gold.data(), hbsr_row_ptr.data()); unit_check_general(1, hbsr_nnzb, 1, hbsr_col_ind_gold.data(), hbsr_col_ind.data()); unit_check_general( 1, hbsr_nnzb * block_dim * block_dim, 1, hbsr_val_gold.data(), hbsr_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsr(handle, dir, m, n, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, block_dim, bsr_descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsr(handle, dir, m, n, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, block_dim, bsr_descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = csr2bsr_gbyte_count(m, mb, nnz, hbsr_nnzb, block_dim); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::Mb, mb, display_key_t::Nb, nb, display_key_t::block_dim, block_dim, display_key_t::nnzb, hbsr_nnzb, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSR2BSR_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_csr2coo.hpp000066400000000000000000000146131501764003400230710ustar00rootroot00000000000000/* ************************************************************************ * 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 "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; void testing_csr2coo_bad_arg(void) { #if(!defined(CUDART_VERSION)) int m = 100; int nnz = 100; int safe_size = 100; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto coo_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* coo_row_ind = (int*)coo_row_ind_managed.get(); verify_hipsparse_status_invalid_pointer( hipsparseXcsr2coo(handle, (int*)nullptr, nnz, m, coo_row_ind, idx_base), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsr2coo(handle, csr_row_ptr, nnz, m, (int*)nullptr, idx_base), "Error: coo_row_ind is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXcsr2coo((hipsparseHandle_t) nullptr, csr_row_ptr, nnz, m, coo_row_ind, idx_base)); #endif } template hipsparseStatus_t testing_csr2coo(Arguments argus) { int m = argus.M; int n = argus.N; hipsparseIndexBase_t idx_base = argus.baseA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Allocate memory on the device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcoo_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcoo_row_ind = (int*)dcoo_row_ind_managed.get(); // Copy data from host to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR( hipsparseXcsr2coo(handle, dcsr_row_ptr, nnz, m, dcoo_row_ind, idx_base)); // Copy output from device to host std::vector hcoo_row_ind(nnz); CHECK_HIP_ERROR( hipMemcpy(hcoo_row_ind.data(), dcoo_row_ind, sizeof(int) * nnz, hipMemcpyDeviceToHost)); // CPU conversion to COO std::vector hcoo_row_ind_gold(nnz); for(int i = 0; i < m; ++i) { int row_begin = hcsr_row_ptr[i] - idx_base; int row_end = hcsr_row_ptr[i + 1] - idx_base; for(int j = row_begin; j < row_end; ++j) { hcoo_row_ind_gold[j] = i + idx_base; } } // Unit check unit_check_general(1, nnz, 1, hcoo_row_ind_gold.data(), hcoo_row_ind.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXcsr2coo(handle, dcsr_row_ptr, nnz, m, dcoo_row_ind, idx_base)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXcsr2coo(handle, dcsr_row_ptr, nnz, m, dcoo_row_ind, idx_base)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = csr2coo_gbyte_count(m, nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSR2COO_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_csr2csc.hpp000066400000000000000000000426541501764003400230670ustar00rootroot00000000000000/* ************************************************************************ * 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 "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csr2csc_bad_arg(void) { #if(!defined(CUDART_VERSION)) int m = 100; int n = 100; int nnz = 100; int safe_size = 100; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto csc_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csc_col_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csc_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* csr_col_ind = (int*)csr_col_ind_managed.get(); T* csr_val = (T*)csr_val_managed.get(); int* csc_row_ind = (int*)csc_row_ind_managed.get(); int* csc_col_ptr = (int*)csc_col_ptr_managed.get(); T* csc_val = (T*)csc_val_managed.get(); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csc(handle, m, n, nnz, csr_val, (int*)nullptr, csr_col_ind, csc_val, csc_row_ind, csc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csc(handle, m, n, nnz, csr_val, csr_row_ptr, (int*)nullptr, csc_val, csc_row_ind, csc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csc(handle, m, n, nnz, (T*)nullptr, csr_row_ptr, csr_col_ind, csc_val, csc_row_ind, csc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO), "Error: csr_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csc(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, (int*)nullptr, csc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO), "Error: csc_row_ind is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csc(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, csc_row_ind, (int*)nullptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO), "Error: csc_col_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csc(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, (T*)nullptr, csc_row_ind, csc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO), "Error: csc_val is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsr2csc((hipsparseHandle_t) nullptr, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, csc_row_ind, csc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO)); #endif } template hipsparseStatus_t testing_csr2csc(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) int m = argus.M; int n = argus.N; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseAction_t action = argus.action; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Allocate memory on the device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dcsc_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsc_col_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (n + 1)), device_free}; auto dcsc_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); int* dcsc_row_ind = (int*)dcsc_row_ind_managed.get(); int* dcsc_col_ptr = (int*)dcsc_col_ptr_managed.get(); T* dcsc_val = (T*)dcsc_val_managed.get(); // Reset CSC arrays CHECK_HIP_ERROR(hipMemset(dcsc_row_ind, 0, sizeof(int) * nnz)); CHECK_HIP_ERROR(hipMemset(dcsc_col_ptr, 0, sizeof(int) * (n + 1))); CHECK_HIP_ERROR(hipMemset(dcsc_val, 0, sizeof(T) * nnz)); // Copy data from host to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_val, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2csc(handle, m, n, nnz, dcsr_val, dcsr_row_ptr, dcsr_col_ind, dcsc_val, dcsc_row_ind, dcsc_col_ptr, action, idx_base)); // Copy output from device to host std::vector hcsc_row_ind(nnz); std::vector hcsc_col_ptr(n + 1); std::vector hcsc_val(nnz); CHECK_HIP_ERROR( hipMemcpy(hcsc_row_ind.data(), dcsc_row_ind, sizeof(int) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcsc_col_ptr.data(), dcsc_col_ptr, sizeof(int) * (n + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsc_val.data(), dcsc_val, sizeof(T) * nnz, hipMemcpyDeviceToHost)); // Host csr2csc conversion std::vector hcsc_row_ind_gold(nnz); std::vector hcsc_col_ptr_gold(n + 1, 0); std::vector hcsc_val_gold(nnz); // Determine nnz per column for(int i = 0; i < nnz; ++i) { ++hcsc_col_ptr_gold[hcsr_col_ind[i] + 1 - idx_base]; } // Scan for(int i = 0; i < n; ++i) { hcsc_col_ptr_gold[i + 1] += hcsc_col_ptr_gold[i]; } // Fill row indices and values for(int i = 0; i < m; ++i) { for(int j = hcsr_row_ptr[i]; j < hcsr_row_ptr[i + 1]; ++j) { int col = hcsr_col_ind[j - idx_base] - idx_base; int idx = hcsc_col_ptr_gold[col]; hcsc_row_ind_gold[idx] = i + idx_base; hcsc_val_gold[idx] = hcsr_val[j - idx_base]; ++hcsc_col_ptr_gold[col]; } } // Shift column pointer array for(int i = n; i > 0; --i) { hcsc_col_ptr_gold[i] = hcsc_col_ptr_gold[i - 1] + idx_base; } hcsc_col_ptr_gold[0] = idx_base; // Unit check unit_check_general(1, nnz, 1, hcsc_row_ind_gold.data(), hcsc_row_ind.data()); unit_check_general(1, n + 1, 1, hcsc_col_ptr_gold.data(), hcsc_col_ptr.data()); // If action == HIPSPARSE_ACTION_NUMERIC also check values if(action == HIPSPARSE_ACTION_NUMERIC) { unit_check_general(1, nnz, 1, hcsc_val_gold.data(), hcsc_val.data()); } } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2csc(handle, m, n, nnz, dcsr_val, dcsr_row_ptr, dcsr_col_ind, dcsc_val, dcsc_row_ind, dcsc_col_ptr, action, idx_base)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2csc(handle, m, n, nnz, dcsr_val, dcsr_row_ptr, dcsr_col_ind, dcsc_val, dcsc_row_ind, dcsc_col_ptr, action, idx_base)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = csr2csc_gbyte_count(m, n, nnz, action); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::action, hipsparse_action2string(action), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSR2CSC_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_csr2csc_ex2.hpp000066400000000000000000000636431501764003400236460ustar00rootroot00000000000000/* ************************************************************************ * 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 "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csr2csc_ex2_bad_arg(void) { #if(!defined(CUDART_VERSION)) int m = 100; int n = 100; int nnz = 100; int safe_size = 100; size_t buffer_size = 0; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto csc_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csc_col_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csc_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto buffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* csr_col_ind = (int*)csr_col_ind_managed.get(); T* csr_val = (T*)csr_val_managed.get(); int* csc_row_ind = (int*)csc_row_ind_managed.get(); int* csc_col_ptr = (int*)csc_col_ptr_managed.get(); T* csc_val = (T*)csc_val_managed.get(); void* buffer = (void*)buffer_managed.get(); verify_hipsparse_status_invalid_handle( hipsparseCsr2cscEx2_bufferSize((hipsparseHandle_t) nullptr, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, csc_col_ptr, csc_row_ind, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, &buffer_size)); verify_hipsparse_status_invalid_pointer( hipsparseCsr2cscEx2_bufferSize(handle, m, n, nnz, csr_val, (int*)nullptr, csr_col_ind, csc_val, csc_col_ptr, csc_row_ind, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, &buffer_size), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCsr2cscEx2_bufferSize(handle, m, n, nnz, csr_val, csr_row_ptr, (int*)nullptr, csc_val, csc_col_ptr, csc_row_ind, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, &buffer_size), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCsr2cscEx2_bufferSize(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, csc_col_ptr, csc_row_ind, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, (size_t*)nullptr), "Error: buffer_size is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseCsr2cscEx2((hipsparseHandle_t) nullptr, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, csc_col_ptr, csc_row_ind, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, buffer)); verify_hipsparse_status_invalid_pointer(hipsparseCsr2cscEx2(handle, m, n, nnz, csr_val, (int*)nullptr, csr_col_ind, csc_val, csc_col_ptr, csc_row_ind, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, buffer), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsr2cscEx2(handle, m, n, nnz, csr_val, csr_row_ptr, (int*)nullptr, csc_val, csc_col_ptr, csc_row_ind, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, buffer), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsr2cscEx2(handle, m, n, nnz, (T*)nullptr, csr_row_ptr, csr_col_ind, csc_val, csc_col_ptr, csc_row_ind, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, buffer), "Error: csr_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsr2cscEx2(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, (int*)nullptr, csc_row_ind, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, buffer), "Error: csc_col_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsr2cscEx2(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, csc_col_ptr, (int*)nullptr, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, buffer), "Error: csc_row_ind is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsr2cscEx2(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, (T*)nullptr, csc_col_ptr, csc_row_ind, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, buffer), "Error: csc_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsr2cscEx2(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, csc_col_ptr, csc_row_ind, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, (T*)nullptr), "Error: buffer is nullptr"); #endif } template hipsparseStatus_t testing_csr2csc_ex2(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) int m = argus.M; int n = argus.N; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseAction_t action = argus.action; hipsparseCsr2CscAlg_t alg = static_cast(argus.csr2csc_alg); std::string filename = argus.filename; hipDataType dataType = getDataType(); std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Allocate memory on the device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dcsc_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsc_col_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (n + 1)), device_free}; auto dcsc_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); int* dcsc_row_ind = (int*)dcsc_row_ind_managed.get(); int* dcsc_col_ptr = (int*)dcsc_col_ptr_managed.get(); T* dcsc_val = (T*)dcsc_val_managed.get(); // Reset CSC arrays CHECK_HIP_ERROR(hipMemset(dcsc_row_ind, 0, sizeof(int) * nnz)); CHECK_HIP_ERROR(hipMemset(dcsc_col_ptr, 0, sizeof(int) * (n + 1))); CHECK_HIP_ERROR(hipMemset(dcsc_val, 0, sizeof(T) * nnz)); // Copy data from host to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_val, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseCsr2cscEx2_bufferSize(handle, m, n, nnz, dcsr_val, dcsr_row_ptr, dcsr_col_ind, dcsc_val, dcsc_col_ptr, dcsc_row_ind, dataType, action, idx_base, alg, &bufferSize)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * bufferSize), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseCsr2cscEx2(handle, m, n, nnz, dcsr_val, dcsr_row_ptr, dcsr_col_ind, dcsc_val, dcsc_col_ptr, dcsc_row_ind, dataType, action, idx_base, alg, dbuffer)); // Copy output from device to host std::vector hcsc_row_ind(nnz); std::vector hcsc_col_ptr(n + 1); std::vector hcsc_val(nnz); CHECK_HIP_ERROR( hipMemcpy(hcsc_row_ind.data(), dcsc_row_ind, sizeof(int) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcsc_col_ptr.data(), dcsc_col_ptr, sizeof(int) * (n + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsc_val.data(), dcsc_val, sizeof(T) * nnz, hipMemcpyDeviceToHost)); // Host csr2csc conversion std::vector hcsc_row_ind_gold(nnz); std::vector hcsc_col_ptr_gold(n + 1, 0); std::vector hcsc_val_gold(nnz); // Determine nnz per column for(int i = 0; i < nnz; ++i) { ++hcsc_col_ptr_gold[hcsr_col_ind[i] + 1 - idx_base]; } // Scan for(int i = 0; i < n; ++i) { hcsc_col_ptr_gold[i + 1] += hcsc_col_ptr_gold[i]; } // Fill row indices and values for(int i = 0; i < m; ++i) { for(int j = hcsr_row_ptr[i]; j < hcsr_row_ptr[i + 1]; ++j) { int col = hcsr_col_ind[j - idx_base] - idx_base; int idx = hcsc_col_ptr_gold[col]; hcsc_row_ind_gold[idx] = i + idx_base; hcsc_val_gold[idx] = hcsr_val[j - idx_base]; ++hcsc_col_ptr_gold[col]; } } // Shift column pointer array for(int i = n; i > 0; --i) { hcsc_col_ptr_gold[i] = hcsc_col_ptr_gold[i - 1] + idx_base; } hcsc_col_ptr_gold[0] = idx_base; // Unit check unit_check_general(1, nnz, 1, hcsc_row_ind_gold.data(), hcsc_row_ind.data()); unit_check_general(1, n + 1, 1, hcsc_col_ptr_gold.data(), hcsc_col_ptr.data()); // If action == HIPSPARSE_ACTION_NUMERIC also check values if(action == HIPSPARSE_ACTION_NUMERIC) { unit_check_general(1, nnz, 1, hcsc_val_gold.data(), hcsc_val.data()); } } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseCsr2cscEx2(handle, m, n, nnz, dcsr_val, dcsr_row_ptr, dcsr_col_ind, dcsc_val, dcsc_col_ptr, dcsc_row_ind, dataType, action, idx_base, alg, dbuffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseCsr2cscEx2(handle, m, n, nnz, dcsr_val, dcsr_row_ptr, dcsr_col_ind, dcsc_val, dcsc_col_ptr, dcsc_row_ind, dataType, action, idx_base, alg, dbuffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = csr2csc_gbyte_count(m, n, nnz, action); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::action, hipsparse_action2string(action), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSR2CSC_EX2_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_csr2csr_compress.hpp000066400000000000000000000744651501764003400250260ustar00rootroot00000000000000/* ************************************************************************ * 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 "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csr2csr_compress_bad_arg(void) { #if(!defined(CUDART_VERSION)) int m = 1; int n = 1; int nnz_A = 1; int safe_size = 1; T tol = make_DataType(0); hipsparseIndexBase_t csr_idx_base = HIPSPARSE_INDEX_BASE_ZERO; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_csr_descr(new descr_struct); hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; hipsparseSetMatIndexBase(csr_descr, csr_idx_base); auto csr_row_ptr_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto csr_col_ind_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto csr_row_ptr_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto csr_col_ind_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto nnz_per_row_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto nnz_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* csr_row_ptr_A = (int*)csr_row_ptr_A_managed.get(); int* csr_col_ind_A = (int*)csr_col_ind_A_managed.get(); T* csr_val_A = (T*)csr_val_A_managed.get(); int* csr_row_ptr_C = (int*)csr_row_ptr_C_managed.get(); int* csr_col_ind_C = (int*)csr_col_ind_C_managed.get(); T* csr_val_C = (T*)csr_val_C_managed.get(); int* nnz_per_row = (int*)nnz_per_row_managed.get(); int* nnz_C = (int*)nnz_C_managed.get(); int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(csr_row_ptr_A, local_ptr, sizeof(int) * (1 + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(csr_row_ptr_C, local_ptr, sizeof(int) * (1 + 1), hipMemcpyHostToDevice)); int local_nnz[1] = {1}; CHECK_HIP_ERROR(hipMemcpy(nnz_per_row, local_nnz, sizeof(int), hipMemcpyHostToDevice)); verify_hipsparse_status_invalid_handle(hipsparseXnnz_compress( nullptr, m, csr_descr, csr_val_A, csr_row_ptr_A, nnz_per_row, nnz_C, tol)); verify_hipsparse_status_invalid_pointer( hipsparseXnnz_compress( handle, m, nullptr, csr_val_A, csr_row_ptr_A, nnz_per_row, nnz_C, tol), "Error: Matrix descriptor is invalid"); verify_hipsparse_status_invalid_pointer( hipsparseXnnz_compress(handle, m, csr_descr, csr_val_A, nullptr, nnz_per_row, nnz_C, tol), "Error: CSR row pointer array is invalid"); verify_hipsparse_status_invalid_pointer( hipsparseXnnz_compress(handle, m, csr_descr, csr_val_A, csr_row_ptr_A, nullptr, nnz_C, tol), "Error: Number of elements per row array is invalid"); verify_hipsparse_status_invalid_pointer( hipsparseXnnz_compress( handle, m, csr_descr, csr_val_A, csr_row_ptr_A, nnz_per_row, nullptr, tol), "Error: Total number of elements pointer is invalid"); verify_hipsparse_status_invalid_size( hipsparseXnnz_compress( handle, -1, csr_descr, csr_val_A, csr_row_ptr_A, nnz_per_row, nnz_C, tol), "Error: Matrix size is invalid"); verify_hipsparse_status_invalid_size(hipsparseXnnz_compress(handle, m, csr_descr, csr_val_A, csr_row_ptr_A, nnz_per_row, nnz_C, make_DataType(-1)), "Error: Tolerance is invalid"); verify_hipsparse_status_invalid_handle(hipsparseXcsr2csr_compress(nullptr, m, n, csr_descr, csr_val_A, csr_col_ind_A, csr_row_ptr_A, nnz_A, nnz_per_row, csr_val_C, csr_col_ind_C, csr_row_ptr_C, tol)); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csr_compress(handle, m, n, nullptr, csr_val_A, csr_col_ind_A, csr_row_ptr_A, nnz_A, nnz_per_row, csr_val_C, csr_col_ind_C, csr_row_ptr_C, tol), "Error: Matrix descriptor is invalid"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csr_compress(handle, m, n, csr_descr, (const T*)nullptr, csr_col_ind_A, csr_row_ptr_A, nnz_A, nnz_per_row, csr_val_C, csr_col_ind_C, csr_row_ptr_C, tol), "Error: CSR matrix values array is invalid"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csr_compress(handle, m, n, csr_descr, csr_val_A, nullptr, csr_row_ptr_A, nnz_A, nnz_per_row, csr_val_C, csr_col_ind_C, csr_row_ptr_C, tol), "Error: CSR matrix column indices array is invalid"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csr_compress(handle, m, n, csr_descr, csr_val_A, csr_col_ind_A, nullptr, nnz_A, nnz_per_row, csr_val_C, csr_col_ind_C, csr_row_ptr_C, tol), "Error: CSR matrix row pointer array is invalid"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csr_compress(handle, m, n, csr_descr, csr_val_A, csr_col_ind_A, csr_row_ptr_A, nnz_A, nullptr, csr_val_C, csr_col_ind_C, csr_row_ptr_C, tol), "Error: Number of elements per row array is invalid"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csr_compress(handle, m, n, csr_descr, csr_val_A, csr_col_ind_A, csr_row_ptr_A, nnz_A, nnz_per_row, (T*)nullptr, csr_col_ind_C, csr_row_ptr_C, tol), "Error: CSR matrix values array is invalid"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csr_compress(handle, m, n, csr_descr, csr_val_A, csr_col_ind_A, csr_row_ptr_A, nnz_A, nnz_per_row, csr_val_C, nullptr, csr_row_ptr_C, tol), "Error: CSR matrix column indices array is invalid"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csr_compress(handle, m, n, csr_descr, csr_val_A, csr_col_ind_A, csr_row_ptr_A, nnz_A, nnz_per_row, csr_val_C, csr_col_ind_C, nullptr, tol), "Error: CSR matrix row pointer array is invalid"); verify_hipsparse_status_invalid_size(hipsparseXcsr2csr_compress(handle, -1, n, csr_descr, csr_val_A, csr_col_ind_A, csr_row_ptr_A, nnz_A, nnz_per_row, csr_val_C, csr_col_ind_C, csr_row_ptr_C, tol), "Error: Matrix size is invalid"); verify_hipsparse_status_invalid_size(hipsparseXcsr2csr_compress(handle, m, -1, csr_descr, csr_val_A, csr_col_ind_A, csr_row_ptr_A, nnz_A, nnz_per_row, csr_val_C, csr_col_ind_C, csr_row_ptr_C, tol), "Error: Matrix size is invalid"); verify_hipsparse_status_invalid_size(hipsparseXcsr2csr_compress(handle, m, n, csr_descr, csr_val_A, csr_col_ind_A, csr_row_ptr_A, -1, nnz_per_row, csr_val_C, csr_col_ind_C, csr_row_ptr_C, tol), "Error: Matrix size is invalid"); verify_hipsparse_status_invalid_value(hipsparseXcsr2csr_compress(handle, m, n, csr_descr, csr_val_A, csr_col_ind_A, csr_row_ptr_A, nnz_A, nnz_per_row, csr_val_C, csr_col_ind_C, csr_row_ptr_C, static_cast(-1)), "Error: Tolerance is invalid"); #endif } template hipsparseStatus_t testing_csr2csr_compress(Arguments argus) { int m = argus.M; int n = argus.N; T tol = make_DataType(argus.alpha); hipsparseIndexBase_t idx_base = argus.baseA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_csr_descr(new descr_struct); hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; hipsparseSetMatIndexBase(csr_descr, idx_base); hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE); srand(12345ULL); // Host structures std::vector hcsr_row_ptr_A; std::vector hcsr_col_ind_A; std::vector hcsr_val_A; // Read or construct CSR matrix int hnnz_A = 0; if(!generate_csr_matrix( filename, m, n, hnnz_A, hcsr_row_ptr_A, hcsr_col_ind_A, hcsr_val_A, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Allocate memory on the device auto dcsr_row_ptr_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * hnnz_A), device_free}; auto dcsr_val_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * hnnz_A), device_free}; auto dcsr_row_ptr_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dnnz_per_row_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * m), device_free}; int* dcsr_row_ptr_A = (int*)dcsr_row_ptr_A_managed.get(); int* dcsr_col_ind_A = (int*)dcsr_col_ind_A_managed.get(); T* dcsr_val_A = (T*)dcsr_val_A_managed.get(); int* dcsr_row_ptr_C = (int*)dcsr_row_ptr_C_managed.get(); int* dnnz_per_row = (int*)dnnz_per_row_managed.get(); // Copy data from host to device CHECK_HIP_ERROR(hipMemcpy( dcsr_row_ptr_A, hcsr_row_ptr_A.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy( dcsr_col_ind_A, hcsr_col_ind_A.data(), sizeof(int) * hnnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_val_A, hcsr_val_A.data(), sizeof(T) * hnnz_A, hipMemcpyHostToDevice)); if(argus.unit_check) { // Use both host and device pointers for nnz_C and confirm they give the same answer CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); int hnnz_C; CHECK_HIPSPARSE_ERROR(hipsparseXnnz_compress( handle, m, csr_descr, dcsr_val_A, dcsr_row_ptr_A, dnnz_per_row, &hnnz_C, tol)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); auto dnnz_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dnnz_C = (int*)dnnz_C_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseXnnz_compress( handle, m, csr_descr, dcsr_val_A, dcsr_row_ptr_A, dnnz_per_row, dnnz_C, tol)); int hnnz_C_copied_from_device; CHECK_HIP_ERROR( hipMemcpy(&hnnz_C_copied_from_device, dnnz_C, sizeof(int), hipMemcpyDeviceToHost)); unit_check_general(1, 1, 1, &hnnz_C_copied_from_device, &hnnz_C); if(hnnz_C == 0) { return HIPSPARSE_STATUS_SUCCESS; } // Allocate device memory for compressed CSR columns indices and values auto dcsr_col_ind_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * hnnz_C), device_free}; auto dcsr_val_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * hnnz_C), device_free}; int* dcsr_col_ind_C = (int*)dcsr_col_ind_C_managed.get(); T* dcsr_val_C = (T*)dcsr_val_C_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseXcsr2csr_compress(handle, m, n, csr_descr, dcsr_val_A, dcsr_col_ind_A, dcsr_row_ptr_A, hnnz_A, dnnz_per_row, dcsr_val_C, dcsr_col_ind_C, dcsr_row_ptr_C, tol)); // Copy output from device to host std::vector hcsr_row_ptr_C(m + 1); std::vector hcsr_col_ind_C(hnnz_C); std::vector hcsr_val_C(hnnz_C); CHECK_HIP_ERROR(hipMemcpy( hcsr_row_ptr_C.data(), dcsr_row_ptr_C, sizeof(int) * (m + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcsr_col_ind_C.data(), dcsr_col_ind_C, sizeof(int) * hnnz_C, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val_C.data(), dcsr_val_C, sizeof(T) * hnnz_C, hipMemcpyDeviceToHost)); // Host csr2csc conversion std::vector hcsr_row_ptr_C_gold; std::vector hcsr_col_ind_C_gold; std::vector hcsr_val_gold; // Call host conversion here host_csr_to_csr_compress(m, n, hcsr_row_ptr_A, hcsr_col_ind_A, hcsr_val_A, hcsr_row_ptr_C_gold, hcsr_col_ind_C_gold, hcsr_val_gold, idx_base, tol); // Unit check unit_check_general(1, m + 1, 1, hcsr_row_ptr_C_gold.data(), hcsr_row_ptr_C.data()); unit_check_general(1, hnnz_C, 1, hcsr_col_ind_C_gold.data(), hcsr_col_ind_C.data()); unit_check_general(1, hnnz_C, 1, hcsr_val_gold.data(), hcsr_val_C.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); int hnnz_C; CHECK_HIPSPARSE_ERROR(hipsparseXnnz_compress( handle, m, csr_descr, dcsr_val_A, dcsr_row_ptr_A, dnnz_per_row, &hnnz_C, tol)); // Allocate device memory for compressed CSR columns indices and values auto dcsr_col_ind_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * hnnz_C), device_free}; auto dcsr_val_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * hnnz_C), device_free}; int* dcsr_col_ind_C = (int*)dcsr_col_ind_C_managed.get(); T* dcsr_val_C = (T*)dcsr_val_C_managed.get(); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2csr_compress(handle, m, n, csr_descr, dcsr_val_A, dcsr_col_ind_A, dcsr_row_ptr_A, hnnz_A, dnnz_per_row, dcsr_val_C, dcsr_col_ind_C, dcsr_row_ptr_C, tol)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2csr_compress(handle, m, n, csr_descr, dcsr_val_A, dcsr_col_ind_A, dcsr_row_ptr_A, hnnz_A, dnnz_per_row, dcsr_val_C, dcsr_col_ind_C, dcsr_row_ptr_C, tol)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = csr2csr_compress_gbyte_count(m, hnnz_A, hnnz_C); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnzA, hnnz_A, display_key_t::nnzC, hnnz_C, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSR2CSR_COMPRESS_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_csr2dense.hpp000066400000000000000000000040141501764003400234010ustar00rootroot00000000000000/* ************************************************************************ * 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) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_ROW; testing_csx2dense_bad_arg(hipsparseXcsr2dense); #endif } template hipsparseStatus_t testing_csr2dense(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_ROW; return testing_csx2dense(argus, hipsparseXcsr2dense, hipsparseXdense2csr); #else return HIPSPARSE_STATUS_SUCCESS; #endif } #endif // TESTING_CSR2DENSE hipSPARSE-rocm-6.4.3/clients/include/testing_csr2gebsr.hpp000066400000000000000000000612031501764003400234100ustar00rootroot00000000000000/* ************************************************************************ * 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 "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csr2gebsr_bad_arg(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 = 1; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto csr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* csr_col_ind = (int*)csr_col_ind_managed.get(); T* csr_val = (T*)csr_val_managed.get(); auto bsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto bsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto bsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto buffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; void* buffer = buffer_managed.get(); int* bsr_row_ptr = (int*)bsr_row_ptr_managed.get(); int* bsr_col_ind = (int*)bsr_col_ind_managed.get(); T* bsr_val = (T*)bsr_val_managed.get(); { // int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(csr_row_ptr, local_ptr, sizeof(int) * (1 + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(bsr_row_ptr, local_ptr, sizeof(int) * (1 + 1), hipMemcpyHostToDevice)); } // std::unique_ptr unique_ptr_csr_descr(new descr_struct); hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; std::unique_ptr unique_ptr_bsr_descr(new descr_struct); hipsparseMatDescr_t bsr_descr = unique_ptr_bsr_descr->descr; hipsparseSetMatIndexBase(csr_descr, csr_idx_base); hipsparseSetMatIndexBase(bsr_descr, bsr_idx_base); // // Declaration of arguments. // hipsparseDirection_t arg_direction; int arg_m; int arg_n; hipsparseMatDescr_t arg_csr_descr; const T* arg_csr_val; const int* arg_csr_row_ptr; const int* arg_csr_col_ind; hipsparseMatDescr_t arg_bsr_descr; T* arg_bsr_val; int* arg_bsr_row_ptr; int* arg_bsr_col_ind; int arg_row_block_dim; int arg_col_block_dim; void* arg_p_buffer; int* arg_bsr_nnz_devhost; size_t* arg_p_buffer_size; int hbsr_nnzb; size_t buffer_size; // // Macro to set arguments. // #define ARGSET \ arg_direction = HIPSPARSE_DIRECTION_ROW; \ arg_m = safe_size; \ arg_n = safe_size; \ arg_csr_descr = csr_descr; \ arg_csr_val = (T*)csr_val; \ arg_csr_row_ptr = csr_row_ptr; \ arg_csr_col_ind = csr_col_ind; \ arg_bsr_descr = bsr_descr; \ arg_bsr_val = (T*)bsr_val; \ arg_bsr_row_ptr = bsr_row_ptr; \ arg_bsr_col_ind = bsr_col_ind; \ arg_row_block_dim = safe_size; \ arg_col_block_dim = safe_size; \ arg_p_buffer = (void*)((T*)buffer); \ arg_bsr_nnz_devhost = &hbsr_nnzb; \ arg_p_buffer_size = &buffer_size // // BUFFER_SIZE ############ // #define CALL_ARG_BUFFER_SIZE \ arg_direction, arg_m, arg_n, arg_csr_descr, arg_csr_val, arg_csr_row_ptr, arg_csr_col_ind, \ arg_row_block_dim, arg_col_block_dim, arg_p_buffer_size #define CALL_BUFFER_SIZE hipsparseXcsr2gebsr_bufferSize(handle, CALL_ARG_BUFFER_SIZE) { ARGSET; status = hipsparseXcsr2gebsr_bufferSize(nullptr, CALL_ARG_BUFFER_SIZE); verify_hipsparse_status_invalid_handle(status); } { ARGSET; arg_m = -1; status = CALL_BUFFER_SIZE; verify_hipsparse_status_invalid_size(status, "Error: m is invalid"); } { ARGSET; arg_n = -1; status = CALL_BUFFER_SIZE; verify_hipsparse_status_invalid_size(status, "Error: n is invalid"); } { ARGSET; arg_csr_descr = nullptr; status = CALL_BUFFER_SIZE; verify_hipsparse_status_invalid_pointer(status, "Error: csr_descr is nullptr"); } { ARGSET; arg_csr_val = nullptr; status = CALL_BUFFER_SIZE; verify_hipsparse_status_invalid_pointer(status, "Error: csr_val is nullptr"); } { ARGSET; arg_csr_row_ptr = nullptr; status = CALL_BUFFER_SIZE; verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr is nullptr"); } { ARGSET; arg_csr_col_ind = nullptr; status = CALL_BUFFER_SIZE; verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind is nullptr"); } { ARGSET; arg_row_block_dim = -1; status = CALL_BUFFER_SIZE; verify_hipsparse_status_invalid_size(status, "Error: row_block_dim is invalid"); } { ARGSET; arg_col_block_dim = -1; status = CALL_BUFFER_SIZE; verify_hipsparse_status_invalid_size(status, "Error: col_block_dim is invalid"); } { ARGSET; arg_p_buffer_size = nullptr; status = CALL_BUFFER_SIZE; verify_hipsparse_status_invalid_pointer(status, "Error: p_buffer_size is nullptr"); } #undef CALL_ARG_BUFFER_SIZE #undef CALL_BUFFER_SIZE // // NNZ ############ // #define CALL_ARG_NNZ \ arg_direction, arg_m, arg_n, arg_csr_descr, arg_csr_row_ptr, arg_csr_col_ind, arg_bsr_descr, \ arg_bsr_row_ptr, arg_row_block_dim, arg_col_block_dim, arg_bsr_nnz_devhost, arg_p_buffer #define CALL_NNZ hipsparseXcsr2gebsrNnz(handle, CALL_ARG_NNZ) { ARGSET; status = hipsparseXcsr2gebsrNnz(nullptr, CALL_ARG_NNZ); verify_hipsparse_status_invalid_handle(status); } { ARGSET; arg_m = -1; status = CALL_NNZ; verify_hipsparse_status_invalid_size(status, "Error: m is invalid"); } { ARGSET; arg_n = -1; status = CALL_NNZ; verify_hipsparse_status_invalid_size(status, "Error: n is invalid"); } { ARGSET; arg_csr_descr = nullptr; status = CALL_NNZ; verify_hipsparse_status_invalid_pointer(status, "Error: csr_descr is nullptr"); } { ARGSET; arg_csr_row_ptr = nullptr; status = CALL_NNZ; verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr is nullptr"); } { ARGSET; arg_bsr_descr = nullptr; status = CALL_NNZ; verify_hipsparse_status_invalid_pointer(status, "Error: bsr_descr is nullptr"); } { ARGSET; arg_bsr_row_ptr = nullptr; status = CALL_NNZ; verify_hipsparse_status_invalid_pointer(status, "Error: bsr_row_ptr is nullptr"); } { ARGSET; arg_row_block_dim = -1; status = CALL_NNZ; verify_hipsparse_status_invalid_size(status, "Error: row_block_dim is invalid"); } { ARGSET; arg_col_block_dim = -1; status = CALL_NNZ; verify_hipsparse_status_invalid_size(status, "Error: col_block_dim is invalid"); } { ARGSET; arg_bsr_nnz_devhost = nullptr; status = CALL_NNZ; verify_hipsparse_status_invalid_pointer(status, "Error: bsr_nnz_devhost is nullptr"); } #undef CALL_NNZ #undef CALL_ARG_NNZ #undef ARGSET #define ARGSET \ arg_direction = HIPSPARSE_DIRECTION_ROW; \ arg_m = safe_size; \ arg_n = safe_size; \ arg_csr_descr = csr_descr; \ arg_csr_val = (T*)csr_val; \ arg_csr_row_ptr = csr_row_ptr; \ arg_csr_col_ind = csr_col_ind; \ arg_bsr_descr = bsr_descr; \ arg_bsr_val = (T*)bsr_val; \ arg_bsr_row_ptr = bsr_row_ptr; \ arg_bsr_col_ind = bsr_col_ind; \ arg_row_block_dim = safe_size; \ arg_col_block_dim = safe_size; \ arg_p_buffer = (void*)((T*)buffer); \ arg_p_buffer_size = &buffer_size #define CALL_ARG_FUNC \ arg_direction, arg_m, arg_n, arg_csr_descr, arg_csr_val, arg_csr_row_ptr, arg_csr_col_ind, \ arg_bsr_descr, arg_bsr_val, arg_bsr_row_ptr, arg_bsr_col_ind, arg_row_block_dim, \ arg_col_block_dim, arg_p_buffer #define CALL_FUNC hipsparseXcsr2gebsr(handle, CALL_ARG_FUNC) { ARGSET; status = hipsparseXcsr2gebsr(nullptr, CALL_ARG_FUNC); verify_hipsparse_status_invalid_handle(status); } { ARGSET; arg_m = -1; status = CALL_FUNC; verify_hipsparse_status_invalid_size(status, "Error: m is invalid"); } { ARGSET; arg_n = -1; status = CALL_FUNC; verify_hipsparse_status_invalid_size(status, "Error: n is invalid"); } { ARGSET; arg_csr_descr = nullptr; status = CALL_FUNC; verify_hipsparse_status_invalid_pointer(status, "Error: csr_descr is nullptr"); } { ARGSET; arg_csr_val = nullptr; status = CALL_FUNC; verify_hipsparse_status_invalid_pointer(status, "Error: csr_val is nullptr"); } { ARGSET; arg_csr_row_ptr = nullptr; status = CALL_FUNC; verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr is nullptr"); } { ARGSET; arg_csr_col_ind = nullptr; status = CALL_FUNC; verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind is nullptr"); } { ARGSET; arg_bsr_descr = nullptr; status = CALL_FUNC; verify_hipsparse_status_invalid_pointer(status, "Error: bsr_descr is nullptr"); } { ARGSET; arg_bsr_val = nullptr; status = CALL_FUNC; verify_hipsparse_status_invalid_pointer(status, "Error: bsr_val is nullptr"); } { ARGSET; arg_bsr_row_ptr = nullptr; status = CALL_FUNC; verify_hipsparse_status_invalid_pointer(status, "Error: bsr_row_ptr is nullptr"); } { ARGSET; arg_bsr_col_ind = nullptr; status = CALL_FUNC; verify_hipsparse_status_invalid_pointer(status, "Error: bsr_col_ind is nullptr"); } { ARGSET; arg_row_block_dim = -1; status = CALL_FUNC; verify_hipsparse_status_invalid_size(status, "Error: row_block_dim is invalid"); } { ARGSET; arg_col_block_dim = -1; status = CALL_FUNC; verify_hipsparse_status_invalid_size(status, "Error: col_block_dim is invalid"); } #undef CALL_FUNC #undef CALL_ARG_FUNC #undef ARGSET #endif } template hipsparseStatus_t testing_csr2gebsr(Arguments argus) { int m = argus.M; int n = argus.N; hipsparseIndexBase_t csr_idx_base = argus.baseA; hipsparseIndexBase_t bsr_idx_base = argus.baseB; hipsparseDirection_t dir = argus.dirA; int row_block_dim = argus.row_block_dimA; int col_block_dim = argus.col_block_dimA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_csr_descr(new descr_struct); hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; std::unique_ptr unique_ptr_bsr_descr(new descr_struct); hipsparseMatDescr_t bsr_descr = unique_ptr_bsr_descr->descr; hipsparseSetMatIndexBase(csr_descr, csr_idx_base); hipsparseSetMatIndexBase(bsr_descr, bsr_idx_base); if(row_block_dim == 1 || m == 0 || n == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // Do not test cusparse with block dim 1 return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix( filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, csr_idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } int mb = (m + row_block_dim - 1) / row_block_dim; int nb = (n + col_block_dim - 1) / col_block_dim; // Allocate memory on the device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dbsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb + 1)), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); int* dbsr_row_ptr = (int*)dbsr_row_ptr_managed.get(); // Copy data from host to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_val, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); size_t buffer_size; CHECK_HIPSPARSE_ERROR(hipsparseXcsr2gebsr_bufferSize(handle, dir, m, n, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, row_block_dim, col_block_dim, &buffer_size)); auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(buffer_size), device_free}; void* dbuffer = dbuffer_managed.get(); int hbsr_nnzb; CHECK_HIPSPARSE_ERROR(hipsparseXcsr2gebsrNnz(handle, dir, m, n, csr_descr, dcsr_row_ptr, dcsr_col_ind, bsr_descr, dbsr_row_ptr, row_block_dim, col_block_dim, &hbsr_nnzb, dbuffer)); // Allocate memory on the device auto dbsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * hbsr_nnzb), device_free}; auto dbsr_val_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * hbsr_nnzb * row_block_dim * col_block_dim), device_free}; int* dbsr_col_ind = (int*)dbsr_col_ind_managed.get(); T* dbsr_val = (T*)dbsr_val_managed.get(); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2gebsr(handle, dir, m, n, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, bsr_descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, row_block_dim, col_block_dim, dbuffer)); // Copy output from device to host std::vector hbsr_row_ptr(mb + 1); std::vector hbsr_col_ind(hbsr_nnzb); std::vector hbsr_val(hbsr_nnzb * row_block_dim * col_block_dim); CHECK_HIP_ERROR(hipMemcpy( hbsr_row_ptr.data(), dbsr_row_ptr, sizeof(int) * (mb + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hbsr_col_ind.data(), dbsr_col_ind, sizeof(int) * hbsr_nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsr_val.data(), dbsr_val, sizeof(T) * hbsr_nnzb * row_block_dim * col_block_dim, hipMemcpyDeviceToHost)); // Host csr2gebsr conversion std::vector hbsr_row_ptr_gold(mb + 1); std::vector hbsr_col_ind_gold(hbsr_nnzb, 0); std::vector hbsr_val_gold(hbsr_nnzb * row_block_dim * col_block_dim); // call host csr2gebsr here int bsr_nnzb_gold; host_csr_to_gebsr(dir, m, n, row_block_dim, col_block_dim, bsr_nnzb_gold, csr_idx_base, hcsr_row_ptr, hcsr_col_ind, hcsr_val, bsr_idx_base, hbsr_row_ptr_gold, hbsr_col_ind_gold, hbsr_val_gold); // Unit check unit_check_general(1, 1, 1, &bsr_nnzb_gold, &hbsr_nnzb); unit_check_general(1, mb + 1, 1, hbsr_row_ptr_gold.data(), hbsr_row_ptr.data()); unit_check_general(1, hbsr_nnzb, 1, hbsr_col_ind_gold.data(), hbsr_col_ind.data()); unit_check_general( 1, hbsr_nnzb * row_block_dim * col_block_dim, 1, hbsr_val_gold.data(), hbsr_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2gebsr(handle, dir, m, n, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, bsr_descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, row_block_dim, col_block_dim, dbuffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2gebsr(handle, dir, m, n, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, bsr_descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, row_block_dim, col_block_dim, dbuffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = csr2gebsr_gbyte_count(m, mb, nnz, hbsr_nnzb, row_block_dim, col_block_dim); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::Mb, mb, display_key_t::Nb, nb, display_key_t::row_block_dim, row_block_dim, display_key_t::col_block_dim, col_block_dim, display_key_t::nnzb, hbsr_nnzb, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSR2GEBSR_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_csr2hyb.hpp000066400000000000000000000431221501764003400230700ustar00rootroot00000000000000/* ************************************************************************ * 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 "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; #define ELL_IND_ROW(i, el, m, width) (el) * (m) + (i) #define ELL_IND_EL(i, el, m, width) (el) + (width) * (i) #define ELL_IND(i, el, m, width) ELL_IND_ROW(i, el, m, width) template void testing_csr2hyb_bad_arg(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) int m = 100; int n = 100; int safe_size = 100; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_hyb(new hyb_struct); hipsparseHybMat_t hyb = unique_ptr_hyb->hyb; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* csr_col_ind = (int*)csr_col_ind_managed.get(); T* csr_val = (T*)csr_val_managed.get(); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2hyb(handle, m, n, descr, csr_val, (int*)nullptr, csr_col_ind, hyb, 0, HIPSPARSE_HYB_PARTITION_AUTO), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2hyb(handle, m, n, descr, csr_val, csr_row_ptr, (int*)nullptr, hyb, 0, HIPSPARSE_HYB_PARTITION_AUTO), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2hyb(handle, m, n, descr, (T*)nullptr, csr_row_ptr, csr_col_ind, hyb, 0, HIPSPARSE_HYB_PARTITION_AUTO), "Error: csr_val is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsr2hyb((hipsparseHandle_t) nullptr, m, n, descr, csr_val, csr_row_ptr, csr_col_ind, hyb, 0, HIPSPARSE_HYB_PARTITION_AUTO)); #endif } template hipsparseStatus_t testing_csr2hyb(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) int m = argus.M; int n = argus.N; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseHybPartition_t part = argus.part; int user_ell_width = argus.ell_width; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); std::unique_ptr unique_ptr_hyb(new hyb_struct); hipsparseHybMat_t hyb = unique_ptr_hyb->hyb; srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } if(m == 0 || n == 0) { return HIPSPARSE_STATUS_SUCCESS; } // Allocate memory on the device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); // Copy data from host to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_val, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); // User given ELL width check hipsparseStatus_t status; if(part == HIPSPARSE_HYB_PARTITION_USER) { // ELL width -33 means we take a reasonable pre-computed width if(user_ell_width == -33) { user_ell_width = nnz / m; } // Test invalid user_ell_width int max_allowed_ell_nnz_per_row = (2 * nnz - 1) / m + 1; if(user_ell_width < 0 || user_ell_width > max_allowed_ell_nnz_per_row) { status = hipsparseXcsr2hyb(handle, m, n, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, hyb, user_ell_width, part); verify_hipsparse_status_invalid_value( status, "Error: user_ell_width < 0 || user_ell_width > max_ell_width"); return HIPSPARSE_STATUS_SUCCESS; } } // Max width check if(part == HIPSPARSE_HYB_PARTITION_MAX) { // Compute max ELL width int ell_max_width = 0; for(int i = 0; i < m; ++i) { ell_max_width = std::max(hcsr_row_ptr[i + 1] - hcsr_row_ptr[i], ell_max_width); } int width_limit = (2 * nnz - 1) / m + 1; if(ell_max_width > width_limit) { status = hipsparseXcsr2hyb(handle, m, n, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, hyb, user_ell_width, part); verify_hipsparse_status_invalid_value(status, "ell_max_width > width_limit"); return HIPSPARSE_STATUS_SUCCESS; } } // Host structures for verification std::vector hhyb_ell_col_ind_gold; std::vector hhyb_ell_val_gold; std::vector hhyb_coo_row_ind_gold; std::vector hhyb_coo_col_ind_gold; std::vector hhyb_coo_val_gold; // Host csr2hyb conversion int ell_width = 0; int ell_nnz = 0; int coo_nnz = 0; if(part == HIPSPARSE_HYB_PARTITION_AUTO || part == HIPSPARSE_HYB_PARTITION_USER) { if(part == HIPSPARSE_HYB_PARTITION_AUTO) { // ELL width is average nnz per row ell_width = (nnz - 1) / m + 1; } else { // User given ELL width ell_width = user_ell_width; } ell_nnz = ell_width * m; // Determine COO nnz for(int i = 0; i < m; ++i) { int row_nnz = hcsr_row_ptr[i + 1] - hcsr_row_ptr[i]; if(row_nnz > ell_width) { coo_nnz += row_nnz - ell_width; } } } else if(part == HIPSPARSE_HYB_PARTITION_MAX) { // Determine max nnz per row for(int i = 0; i < m; ++i) { int row_nnz = hcsr_row_ptr[i + 1] - hcsr_row_ptr[i]; ell_width = (row_nnz > ell_width) ? row_nnz : ell_width; } ell_nnz = ell_width * m; } // Allocate host memory // ELL hhyb_ell_col_ind_gold.resize(ell_nnz); hhyb_ell_val_gold.resize(ell_nnz); // COO hhyb_coo_row_ind_gold.resize(coo_nnz); hhyb_coo_col_ind_gold.resize(coo_nnz); hhyb_coo_val_gold.resize(coo_nnz); // Fill HYB int coo_idx = 0; for(int i = 0; i < m; ++i) { int p = 0; for(int j = hcsr_row_ptr[i] - idx_base; j < hcsr_row_ptr[i + 1] - idx_base; ++j) { if(p < ell_width) { int idx = ELL_IND(i, p++, m, ell_width); hhyb_ell_col_ind_gold[idx] = hcsr_col_ind[j]; hhyb_ell_val_gold[idx] = hcsr_val[j]; } else { hhyb_coo_row_ind_gold[coo_idx] = i + idx_base; hhyb_coo_col_ind_gold[coo_idx] = hcsr_col_ind[j]; hhyb_coo_val_gold[coo_idx] = hcsr_val[j]; ++coo_idx; } } for(int j = hcsr_row_ptr[i + 1] - hcsr_row_ptr[i]; j < ell_width; ++j) { int idx = ELL_IND(i, p++, m, ell_width); hhyb_ell_col_ind_gold[idx] = -1; hhyb_ell_val_gold[idx] = make_DataType(0.0); } } // Allocate verification structures std::vector hhyb_ell_col_ind(ell_nnz); std::vector hhyb_ell_val(ell_nnz); std::vector hhyb_coo_row_ind(coo_nnz); std::vector hhyb_coo_col_ind(coo_nnz); std::vector hhyb_coo_val(coo_nnz); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2hyb( handle, m, n, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, hyb, user_ell_width, part)); // Copy output from device to host testhyb* dhyb = (testhyb*)hyb; // Check if sizes match unit_check_general(1, 1, 1, &m, &dhyb->m); unit_check_general(1, 1, 1, &n, &dhyb->n); unit_check_general(1, 1, 1, &ell_width, &dhyb->ell_width); unit_check_general(1, 1, 1, &ell_nnz, &dhyb->ell_nnz); unit_check_general(1, 1, 1, &coo_nnz, &dhyb->coo_nnz); CHECK_HIP_ERROR(hipMemcpy(hhyb_ell_col_ind.data(), dhyb->ell_col_ind, sizeof(int) * ell_nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hhyb_ell_val.data(), dhyb->ell_val, sizeof(T) * ell_nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hhyb_coo_row_ind.data(), dhyb->coo_row_ind, sizeof(int) * coo_nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hhyb_coo_col_ind.data(), dhyb->coo_col_ind, sizeof(int) * coo_nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hhyb_coo_val.data(), dhyb->coo_val, sizeof(T) * coo_nnz, hipMemcpyDeviceToHost)); // Unit check unit_check_general(1, ell_nnz, 1, hhyb_ell_col_ind_gold.data(), hhyb_ell_col_ind.data()); unit_check_general(1, ell_nnz, 1, hhyb_ell_val_gold.data(), hhyb_ell_val.data()); unit_check_general(1, coo_nnz, 1, hhyb_coo_row_ind_gold.data(), hhyb_coo_row_ind.data()); unit_check_general(1, coo_nnz, 1, hhyb_coo_col_ind_gold.data(), hhyb_coo_col_ind.data()); unit_check_general(1, coo_nnz, 1, hhyb_coo_val_gold.data(), hhyb_coo_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2hyb(handle, m, n, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, hyb, user_ell_width, part)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2hyb(handle, m, n, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, hyb, user_ell_width, part)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = csr2hyb_gbyte_count(m, nnz, ell_nnz, coo_nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::ell_nnz, ell_nnz, display_key_t::coo_nnz, coo_nnz, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSR2HYB_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_csrcolor.hpp000066400000000000000000000317541501764003400233520ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSRCOLOR_HPP #define TESTING_CSRCOLOR_HPP #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csrcolor_bad_arg(void) { #if(!defined(CUDART_VERSION)) static constexpr int M = 10; static constexpr int NNZ = 10; floating_data_t fractionToColor = make_DataType>(1.0); hipsparseStatus_t status; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; auto m_coloring = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; auto m_reordering = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; auto m_csr_val = hipsparse_unique_ptr{device_malloc(sizeof(T) * 1), device_free}; auto m_csr_row_ptr = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; auto m_csr_col_ind = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; T* d_csr_val = (T*)m_csr_val.get(); int* d_coloring = (int*)m_coloring.get(); int* d_reordering = (int*)m_reordering.get(); int* d_csr_row_ptr = (int*)m_csr_row_ptr.get(); int* d_csr_col_ind = (int*)m_csr_col_ind.get(); int ncolors; hipsparseColorInfo_t colorInfo = (hipsparseColorInfo_t)0x4; status = hipsparseXcsrcolor(handle, M, NNZ, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, &fractionToColor, &ncolors, d_coloring, d_reordering, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected.u"); status = hipsparseXcsrcolor(handle, M, NNZ, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, &fractionToColor, &ncolors, nullptr, d_reordering, colorInfo); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected.u"); status = hipsparseXcsrcolor(handle, M, NNZ, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, &fractionToColor, nullptr, d_coloring, d_reordering, colorInfo); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected.u"); status = hipsparseXcsrcolor(handle, M, NNZ, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, nullptr, &ncolors, d_coloring, d_reordering, colorInfo); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected.u"); status = hipsparseXcsrcolor(handle, M, NNZ, descr, d_csr_val, d_csr_row_ptr, nullptr, &fractionToColor, &ncolors, d_coloring, d_reordering, colorInfo); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected.u"); status = hipsparseXcsrcolor(handle, M, NNZ, descr, d_csr_val, nullptr, d_csr_col_ind, &fractionToColor, &ncolors, d_coloring, d_reordering, colorInfo); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected.u"); status = hipsparseXcsrcolor(handle, M, NNZ, descr, nullptr, d_csr_row_ptr, d_csr_col_ind, &fractionToColor, &ncolors, d_coloring, d_reordering, colorInfo); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected.u"); status = hipsparseXcsrcolor(handle, M, NNZ, nullptr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, &fractionToColor, &ncolors, d_coloring, d_reordering, colorInfo); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected.u"); status = hipsparseXcsrcolor(nullptr, M, NNZ, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, &fractionToColor, &ncolors, d_coloring, d_reordering, colorInfo); verify_hipsparse_status_invalid_handle(status); status = hipsparseXcsrcolor(handle, -1, NNZ, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, &fractionToColor, &ncolors, d_coloring, d_reordering, colorInfo); verify_hipsparse_status_invalid_value(status, "Error: an invalid value must be detected.u"); status = hipsparseXcsrcolor(handle, M, -1, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, &fractionToColor, &ncolors, d_coloring, d_reordering, colorInfo); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid value must be detected.u"); #endif } template hipsparseStatus_t testing_csrcolor() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) // Determine absolute path of test matrix // Matrices are stored at the same path in matrices directory std::string filename = get_filename("nos3.bin"); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; // Host structures std::vector hrow_ptr; std::vector hcol_ind; std::vector hval; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; // Initial Data on CPU srand(12345ULL); floating_data_t fractionToColor = make_DataType>(1.0); int m; int k; int nnz; if(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(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(drow_ptr, hrow_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol_ind, hcol_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hval.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); int ncolors; CHECK_HIPSPARSE_ERROR(hipsparseXcsrcolor(handle, m, nnz, descr, dval, drow_ptr, dcol_ind, &fractionToColor, &ncolors, dcoloring, dreordering, colorInfo)); hipsparseDestroyColorInfo(colorInfo); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRCOLOR_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_csrgeam.hpp000066400000000000000000001731131501764003400231410ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSRGEAM_HPP #define TESTING_CSRGEAM_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csrgeam_bad_arg(void) { #if(!defined(CUDART_VERSION)) int safe_size = 1; T alpha = 1.0; T beta = 1.0; int nnz_C; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = unique_ptr_descr_A->descr; std::unique_ptr unique_ptr_descr_B(new descr_struct); hipsparseMatDescr_t descr_B = unique_ptr_descr_B->descr; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; auto dAptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dAcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dAval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dBptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dBcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dBval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dCptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dCcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dCval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* dAptr = (int*)dAptr_managed.get(); int* dAcol = (int*)dAcol_managed.get(); T* dAval = (T*)dAval_managed.get(); int* dBptr = (int*)dBptr_managed.get(); int* dBcol = (int*)dBcol_managed.get(); T* dBval = (T*)dBval_managed.get(); int* dCptr = (int*)dCptr_managed.get(); int* dCcol = (int*)dCcol_managed.get(); T* dCval = (T*)dCval_managed.get(); const int M = safe_size; std::vector hcsr_row_ptr_C(M + 1); hcsr_row_ptr_C[0] = 0; hcsr_row_ptr_C[1] = 1; CHECK_HIP_ERROR( hipMemcpy(dCptr, hcsr_row_ptr_C.data(), sizeof(int) * (M + 1), hipMemcpyHostToDevice)); // testing hipsparseXcsrgeamNnz verify_hipsparse_status_invalid_handle(hipsparseXcsrgeamNnz(nullptr, safe_size, safe_size, descr_A, safe_size, dAptr, dAcol, descr_B, safe_size, dBptr, dBcol, descr_C, dCptr, &nnz_C)); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeamNnz(handle, safe_size, safe_size, nullptr, safe_size, dAptr, dAcol, descr_B, safe_size, dBptr, dBcol, descr_C, dCptr, &nnz_C), "Error: invalid descr_A pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeamNnz(handle, safe_size, safe_size, descr_A, safe_size, nullptr, dAcol, descr_B, safe_size, dBptr, dBcol, descr_C, dCptr, &nnz_C), "Error: invalid dAptr pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeamNnz(handle, safe_size, safe_size, descr_A, safe_size, dAptr, nullptr, descr_B, safe_size, dBptr, dBcol, descr_C, dCptr, &nnz_C), "Error: invalid dAcol pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeamNnz(handle, safe_size, safe_size, descr_A, safe_size, dAptr, dAcol, nullptr, safe_size, dBptr, dBcol, descr_C, dCptr, &nnz_C), "Error: invalid descr_B pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeamNnz(handle, safe_size, safe_size, descr_A, safe_size, dAptr, dAcol, descr_B, safe_size, nullptr, dBcol, descr_C, dCptr, &nnz_C), "Error: invalid dBptr pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeamNnz(handle, safe_size, safe_size, descr_A, safe_size, dAptr, dAcol, descr_B, safe_size, dBptr, nullptr, descr_C, dCptr, &nnz_C), "Error: invalid dBcol pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeamNnz(handle, safe_size, safe_size, descr_A, safe_size, dAptr, dAcol, descr_B, safe_size, dBptr, dBcol, nullptr, dCptr, &nnz_C), "Error: invalid descr_C pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeamNnz(handle, safe_size, safe_size, descr_A, safe_size, dAptr, dAcol, descr_B, safe_size, dBptr, dBcol, descr_C, nullptr, &nnz_C), "Error: invalid dCptr pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeamNnz(handle, safe_size, safe_size, descr_A, safe_size, dAptr, dAcol, descr_B, safe_size, dBptr, dBcol, descr_C, dCptr, nullptr), "Error: invalid nnz_C pointer"); // testing hipsparseXcsrgeam verify_hipsparse_status_invalid_handle(hipsparseXcsrgeam(nullptr, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol)); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam(handle, safe_size, safe_size, (T*)nullptr, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: invalid alpha pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam(handle, safe_size, safe_size, &alpha, nullptr, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: invalid descr_A pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam(handle, safe_size, safe_size, &alpha, descr_A, safe_size, (T*)nullptr, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: invalid dAval pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, nullptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: invalid dAptr pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, nullptr, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: invalid dAcol pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, (T*)nullptr, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: invalid beta pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, nullptr, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: invalid descr_B pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, (T*)nullptr, dBptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: invalid dBval pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, nullptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: invalid dBptr pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, nullptr, descr_C, dCval, dCptr, dCcol), "Error: invalid dBcol pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, nullptr, dCval, dCptr, dCcol), "Error: invalid descr_C pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, (T*)nullptr, dCptr, dCcol), "Error: invalid dCval pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, nullptr, dCcol), "Error: invalid dCptr pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, nullptr), "Error: invalid dCcol pointer"); // testing invalid sizes verify_hipsparse_status_invalid_size(hipsparseXcsrgeamNnz(handle, -1, safe_size, descr_A, safe_size, dAptr, dAcol, descr_B, safe_size, dBptr, dBcol, descr_C, dCptr, &nnz_C), "Error: invalid M size"); verify_hipsparse_status_invalid_size(hipsparseXcsrgeamNnz(handle, safe_size, -1, descr_A, safe_size, dAptr, dAcol, descr_B, safe_size, dBptr, dBcol, descr_C, dCptr, &nnz_C), "Error: invalid N size"); verify_hipsparse_status_invalid_size(hipsparseXcsrgeamNnz(handle, safe_size, safe_size, descr_A, -1, dAptr, dAcol, descr_B, safe_size, dBptr, dBcol, descr_C, dCptr, &nnz_C), "Error: invalid nnz_A size"); verify_hipsparse_status_invalid_size(hipsparseXcsrgeamNnz(handle, safe_size, safe_size, descr_A, safe_size, dAptr, dAcol, descr_B, -1, dBptr, dBcol, descr_C, dCptr, &nnz_C), "Error: invalid nnz_B size"); verify_hipsparse_status_invalid_size(hipsparseXcsrgeam(handle, -1, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: invalid M size"); verify_hipsparse_status_invalid_size(hipsparseXcsrgeam(handle, safe_size, -1, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: invalid N size"); verify_hipsparse_status_invalid_size(hipsparseXcsrgeam(handle, safe_size, safe_size, &alpha, descr_A, -1, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: invalid nnz_A size"); verify_hipsparse_status_invalid_size(hipsparseXcsrgeam(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, -1, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: invalid nnz_B size"); #endif } template hipsparseStatus_t testing_csrgeam(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) int M = argus.M; int N = argus.N; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseIndexBase_t idx_base_A = argus.baseA; hipsparseIndexBase_t idx_base_B = argus.baseB; hipsparseIndexBase_t idx_base_C = argus.baseC; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = unique_ptr_descr_A->descr; std::unique_ptr unique_ptr_descr_B(new descr_struct); hipsparseMatDescr_t descr_B = unique_ptr_descr_B->descr; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_A, idx_base_A)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_B, idx_base_B)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_C, idx_base_C)); srand(12345ULL); // Host structures std::vector hcsr_row_ptr_A; std::vector hcsr_col_ind_A; std::vector hcsr_val_A; // Read or construct CSR matrix int nnz_A = 0; if(!generate_csr_matrix( filename, M, N, nnz_A, hcsr_row_ptr_A, hcsr_col_ind_A, hcsr_val_A, idx_base_A)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // B = A int nnz_B = nnz_A; std::vector hcsr_row_ptr_B(M + 1, 0); std::vector hcsr_col_ind_B(nnz_B); std::vector hcsr_val_B(nnz_B); for(int i = 0; i < M + 1; ++i) { hcsr_row_ptr_B[i] = hcsr_row_ptr_A[i] - idx_base_A + idx_base_B; } for(int i = 0; i < nnz_A; ++i) { hcsr_col_ind_B[i] = hcsr_col_ind_A[i] - idx_base_A + idx_base_B; } hcsr_val_B = hcsr_val_A; // Allocate memory on device auto dAptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; auto dAcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz_A), device_free}; auto dAval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_A), device_free}; auto dBptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; auto dBcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz_B), device_free}; auto dBval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_B), device_free}; auto dCptr_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; auto dCptr_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; int* dAptr = (int*)dAptr_managed.get(); int* dAcol = (int*)dAcol_managed.get(); T* dAval = (T*)dAval_managed.get(); int* dBptr = (int*)dBptr_managed.get(); int* dBcol = (int*)dBcol_managed.get(); T* dBval = (T*)dBval_managed.get(); int* dCptr_1 = (int*)dCptr_1_managed.get(); int* dCptr_2 = (int*)dCptr_2_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dAptr, hcsr_row_ptr_A.data(), sizeof(int) * (M + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dAcol, hcsr_col_ind_A.data(), sizeof(int) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dAval, hcsr_val_A.data(), sizeof(T) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dBptr, hcsr_row_ptr_B.data(), sizeof(int) * (M + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dBcol, hcsr_col_ind_B.data(), sizeof(int) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dBval, hcsr_val_B.data(), sizeof(T) * nnz_B, hipMemcpyHostToDevice)); // hipsparse pointer mode host int hnnz_C_1; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgeamNnz(handle, M, N, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, descr_C, dCptr_1, &hnnz_C_1)); // Allocate result matrix auto dCcol_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * hnnz_C_1), device_free}; auto dCval_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * hnnz_C_1), device_free}; auto dCcol_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * hnnz_C_1), device_free}; auto dCval_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * hnnz_C_1), device_free}; int* dCcol_1 = (int*)dCcol_1_managed.get(); T* dCval_1 = (T*)dCval_1_managed.get(); int* dCcol_2 = (int*)dCcol_2_managed.get(); T* dCval_2 = (T*)dCval_2_managed.get(); // hipsparse pointer mode device auto dalpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto dbeta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto dnnz_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; T* d_alpha = (T*)dalpha_managed.get(); T* d_beta = (T*)dbeta_managed.get(); int* dnnz_C = (int*)dnnz_C_managed.get(); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgeamNnz(handle, M, N, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, descr_C, dCptr_2, dnnz_C)); // Copy output from device to CPU int hnnz_C_2; CHECK_HIP_ERROR(hipMemcpy(&hnnz_C_2, dnnz_C, sizeof(int), hipMemcpyDeviceToHost)); if(argus.unit_check) { // Compute csrgeam CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgeam(handle, M, N, &h_alpha, descr_A, nnz_A, dAval, dAptr, dAcol, &h_beta, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval_1, dCptr_1, dCcol_1)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgeam(handle, M, N, d_alpha, descr_A, nnz_A, dAval, dAptr, dAcol, d_beta, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval_2, dCptr_2, dCcol_2)); // Copy output from device to CPU std::vector hcsr_row_ptr_C_1(M + 1); std::vector hcsr_col_ind_C_1(hnnz_C_1); std::vector hcsr_val_C_1(hnnz_C_1); std::vector hcsr_row_ptr_C_2(M + 1); std::vector hcsr_col_ind_C_2(hnnz_C_2); std::vector hcsr_val_C_2(hnnz_C_2); CHECK_HIP_ERROR(hipMemcpy( hcsr_row_ptr_C_1.data(), dCptr_1, sizeof(int) * (M + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcsr_col_ind_C_1.data(), dCcol_1, sizeof(int) * hnnz_C_1, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val_C_1.data(), dCval_1, sizeof(T) * hnnz_C_1, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcsr_row_ptr_C_2.data(), dCptr_2, sizeof(int) * (M + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcsr_col_ind_C_2.data(), dCcol_2, sizeof(int) * hnnz_C_2, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val_C_2.data(), dCval_2, sizeof(T) * hnnz_C_2, hipMemcpyDeviceToHost)); // Compute csrgeam host solution std::vector hcsr_row_ptr_C_gold(M + 1); int nnz_C_gold = host_csrgeam_nnz(M, N, h_alpha, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), h_beta, hcsr_row_ptr_B.data(), hcsr_col_ind_B.data(), hcsr_row_ptr_C_gold.data(), idx_base_A, idx_base_B, idx_base_C); std::vector hcsr_col_ind_C_gold(nnz_C_gold); std::vector hcsr_val_C_gold(nnz_C_gold); host_csrgeam(M, N, h_alpha, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), hcsr_val_A.data(), h_beta, hcsr_row_ptr_B.data(), hcsr_col_ind_B.data(), hcsr_val_B.data(), hcsr_row_ptr_C_gold.data(), hcsr_col_ind_C_gold.data(), hcsr_val_C_gold.data(), idx_base_A, idx_base_B, idx_base_C); // Check nnz of C unit_check_general(1, 1, 1, &nnz_C_gold, &hnnz_C_1); unit_check_general(1, 1, 1, &nnz_C_gold, &hnnz_C_2); // Check structure and entries of C unit_check_general(1, M + 1, 1, hcsr_row_ptr_C_gold.data(), hcsr_row_ptr_C_1.data()); unit_check_general(1, M + 1, 1, hcsr_row_ptr_C_gold.data(), hcsr_row_ptr_C_2.data()); unit_check_general(1, nnz_C_gold, 1, hcsr_col_ind_C_gold.data(), hcsr_col_ind_C_1.data()); unit_check_general(1, nnz_C_gold, 1, hcsr_col_ind_C_gold.data(), hcsr_col_ind_C_2.data()); unit_check_near(1, nnz_C_gold, 1, hcsr_val_C_gold.data(), hcsr_val_C_1.data()); unit_check_near(1, nnz_C_gold, 1, hcsr_val_C_gold.data(), hcsr_val_C_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrgeam(handle, M, N, &h_alpha, descr_A, nnz_A, dAval, dAptr, dAcol, &h_beta, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval_1, dCptr_1, dCcol_1)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrgeam(handle, M, N, &h_alpha, descr_A, nnz_A, dAval, dAptr, dAcol, &h_beta, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval_1, dCptr_1, dCcol_1)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = csrgeam_gflop_count(nnz_A, nnz_B, hnnz_C_1, &h_alpha, &h_beta); double gbyte_count = csrgeam_gbyte_count(M, nnz_A, nnz_B, hnnz_C_1, &h_alpha, &h_beta); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, M, display_key_t::N, N, display_key_t::nnzA, nnz_A, display_key_t::nnzB, nnz_B, display_key_t::nnzC, hnnz_C_1, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRGEAM_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_csrgeam2.hpp000066400000000000000000002054241501764003400232240ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSRGEAM2_HPP #define TESTING_CSRGEAM2_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csrgeam2_bad_arg(void) { #if(!defined(CUDART_VERSION)) int safe_size = 1; T alpha = 1.0; T beta = 1.0; int nnz_C; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = unique_ptr_descr_A->descr; std::unique_ptr unique_ptr_descr_B(new descr_struct); hipsparseMatDescr_t descr_B = unique_ptr_descr_B->descr; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; auto dAptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dAcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dAval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dBptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dBcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dBval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dCptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dCcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dCval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* dAptr = (int*)dAptr_managed.get(); int* dAcol = (int*)dAcol_managed.get(); T* dAval = (T*)dAval_managed.get(); int* dBptr = (int*)dBptr_managed.get(); int* dBcol = (int*)dBcol_managed.get(); T* dBval = (T*)dBval_managed.get(); int* dCptr = (int*)dCptr_managed.get(); int* dCcol = (int*)dCcol_managed.get(); T* dCval = (T*)dCval_managed.get(); void* dbuffer = dbuf_managed.get(); const int M = safe_size; std::vector hcsr_row_ptr_C(M + 1); hcsr_row_ptr_C[0] = 0; hcsr_row_ptr_C[1] = 1; CHECK_HIP_ERROR( hipMemcpy(dCptr, hcsr_row_ptr_C.data(), sizeof(int) * (M + 1), hipMemcpyHostToDevice)); // skip bufferSizeExt as there is no implementation in rocsparse // testing hipsparseXcsrgeam2Nnz verify_hipsparse_status_invalid_handle(hipsparseXcsrgeam2Nnz(nullptr, safe_size, safe_size, descr_A, safe_size, dAptr, dAcol, descr_B, safe_size, dBptr, dBcol, descr_C, dCptr, &nnz_C, dbuffer)); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2Nnz(handle, safe_size, safe_size, nullptr, safe_size, dAptr, dAcol, descr_B, safe_size, dBptr, dBcol, descr_C, dCptr, &nnz_C, dbuffer), "Error: invalid descr_A pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2Nnz(handle, safe_size, safe_size, descr_A, safe_size, nullptr, dAcol, descr_B, safe_size, dBptr, dBcol, descr_C, dCptr, &nnz_C, dbuffer), "Error: invalid dAptr pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2Nnz(handle, safe_size, safe_size, descr_A, safe_size, dAptr, nullptr, descr_B, safe_size, dBptr, dBcol, descr_C, dCptr, &nnz_C, dbuffer), "Error: invalid dAcol pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2Nnz(handle, safe_size, safe_size, descr_A, safe_size, dAptr, dAcol, nullptr, safe_size, dBptr, dBcol, descr_C, dCptr, &nnz_C, dbuffer), "Error: invalid descr_B pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2Nnz(handle, safe_size, safe_size, descr_A, safe_size, dAptr, dAcol, descr_B, safe_size, nullptr, dBcol, descr_C, dCptr, &nnz_C, dbuffer), "Error: invalid dBptr pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2Nnz(handle, safe_size, safe_size, descr_A, safe_size, dAptr, dAcol, descr_B, safe_size, dBptr, nullptr, descr_C, dCptr, &nnz_C, dbuffer), "Error: invalid dBcol pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2Nnz(handle, safe_size, safe_size, descr_A, safe_size, dAptr, dAcol, descr_B, safe_size, dBptr, dBcol, nullptr, dCptr, &nnz_C, dbuffer), "Error: invalid descr_C pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2Nnz(handle, safe_size, safe_size, descr_A, safe_size, dAptr, dAcol, descr_B, safe_size, dBptr, dBcol, descr_C, nullptr, &nnz_C, dbuffer), "Error: invalid dCptr pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2Nnz(handle, safe_size, safe_size, descr_A, safe_size, dAptr, dAcol, descr_B, safe_size, dBptr, dBcol, descr_C, dCptr, nullptr, dbuffer), "Error: invalid nnz_C pointer"); // testing hipsparseXcsrgeam2 verify_hipsparse_status_invalid_handle(hipsparseXcsrgeam2(nullptr, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol, dbuffer)); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2(handle, safe_size, safe_size, (T*)nullptr, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol, dbuffer), "Error: invalid alpha pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2(handle, safe_size, safe_size, &alpha, nullptr, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol, dbuffer), "Error: invalid descr_A pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2(handle, safe_size, safe_size, &alpha, descr_A, safe_size, (T*)nullptr, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol, dbuffer), "Error: invalid dAval pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, nullptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol, dbuffer), "Error: invalid dAptr pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, nullptr, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol, dbuffer), "Error: invalid dAcol pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, (T*)nullptr, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol, dbuffer), "Error: invalid beta pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, nullptr, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol, dbuffer), "Error: invalid descr_B pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, (T*)nullptr, dBptr, dBcol, descr_C, dCval, dCptr, dCcol, dbuffer), "Error: invalid dBval pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, nullptr, dBcol, descr_C, dCval, dCptr, dCcol, dbuffer), "Error: invalid dBptr pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, nullptr, descr_C, dCval, dCptr, dCcol, dbuffer), "Error: invalid dBcol pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, nullptr, dCval, dCptr, dCcol, dbuffer), "Error: invalid descr_C pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, (T*)nullptr, dCptr, dCcol, dbuffer), "Error: invalid dCval pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, nullptr, dCcol, dbuffer), "Error: invalid dCptr pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, nullptr, dbuffer), "Error: invalid dCcol pointer"); // testing invalid sizes verify_hipsparse_status_invalid_size(hipsparseXcsrgeam2Nnz(handle, -1, safe_size, descr_A, safe_size, dAptr, dAcol, descr_B, safe_size, dBptr, dBcol, descr_C, dCptr, &nnz_C, dbuffer), "Error: invalid M size"); verify_hipsparse_status_invalid_size(hipsparseXcsrgeam2Nnz(handle, safe_size, -1, descr_A, safe_size, dAptr, dAcol, descr_B, safe_size, dBptr, dBcol, descr_C, dCptr, &nnz_C, dbuffer), "Error: invalid N size"); verify_hipsparse_status_invalid_size(hipsparseXcsrgeam2Nnz(handle, safe_size, safe_size, descr_A, -1, dAptr, dAcol, descr_B, safe_size, dBptr, dBcol, descr_C, dCptr, &nnz_C, dbuffer), "Error: invalid nnz_A size"); verify_hipsparse_status_invalid_size(hipsparseXcsrgeam2Nnz(handle, safe_size, safe_size, descr_A, safe_size, dAptr, dAcol, descr_B, -1, dBptr, dBcol, descr_C, dCptr, &nnz_C, dbuffer), "Error: invalid nnz_B size"); verify_hipsparse_status_invalid_size(hipsparseXcsrgeam2(handle, -1, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol, dbuffer), "Error: invalid M size"); verify_hipsparse_status_invalid_size(hipsparseXcsrgeam2(handle, safe_size, -1, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol, dbuffer), "Error: invalid N size"); verify_hipsparse_status_invalid_size(hipsparseXcsrgeam2(handle, safe_size, safe_size, &alpha, descr_A, -1, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol, dbuffer), "Error: invalid nnz_A size"); verify_hipsparse_status_invalid_size(hipsparseXcsrgeam2(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, -1, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol, dbuffer), "Error: invalid nnz_B size"); #endif } template hipsparseStatus_t testing_csrgeam2(Arguments argus) { int M = argus.M; int N = argus.N; hipsparseIndexBase_t idx_base_A = argus.baseA; hipsparseIndexBase_t idx_base_B = argus.baseB; hipsparseIndexBase_t idx_base_C = argus.baseC; std::string filename = argus.filename; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = unique_ptr_descr_A->descr; std::unique_ptr unique_ptr_descr_B(new descr_struct); hipsparseMatDescr_t descr_B = unique_ptr_descr_B->descr; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_A, idx_base_A)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_B, idx_base_B)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_C, idx_base_C)); srand(12345ULL); // Host structures std::vector hcsr_row_ptr_A; std::vector hcsr_col_ind_A; std::vector hcsr_val_A; // Read or construct CSR matrix int nnz_A = 0; if(!generate_csr_matrix( filename, M, N, nnz_A, hcsr_row_ptr_A, hcsr_col_ind_A, hcsr_val_A, idx_base_A)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // B = A so that we can compute the square of A int nnz_B = nnz_A; std::vector hcsr_row_ptr_B(M + 1, 0); std::vector hcsr_col_ind_B(nnz_B); std::vector hcsr_val_B(nnz_B); for(int i = 0; i < M + 1; ++i) { hcsr_row_ptr_B[i] = hcsr_row_ptr_A[i] - idx_base_A + idx_base_B; } for(int i = 0; i < nnz_A; ++i) { hcsr_col_ind_B[i] = hcsr_col_ind_A[i] - idx_base_A + idx_base_B; } hcsr_val_B = hcsr_val_A; // Allocate memory on device auto dAptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; auto dAcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz_A), device_free}; auto dAval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_A), device_free}; auto dBptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; auto dBcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz_B), device_free}; auto dBval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_B), device_free}; auto dCptr_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; auto dCptr_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; auto dalpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto dbeta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dAptr = (int*)dAptr_managed.get(); int* dAcol = (int*)dAcol_managed.get(); T* dAval = (T*)dAval_managed.get(); int* dBptr = (int*)dBptr_managed.get(); int* dBcol = (int*)dBcol_managed.get(); T* dBval = (T*)dBval_managed.get(); int* dCptr_1 = (int*)dCptr_1_managed.get(); int* dCptr_2 = (int*)dCptr_2_managed.get(); T* dalpha = (T*)dalpha_managed.get(); T* dbeta = (T*)dbeta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dAptr, hcsr_row_ptr_A.data(), sizeof(int) * (M + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dAcol, hcsr_col_ind_A.data(), sizeof(int) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dAval, hcsr_val_A.data(), sizeof(T) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dBptr, hcsr_row_ptr_B.data(), sizeof(int) * (M + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dBcol, hcsr_col_ind_B.data(), sizeof(int) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dBval, hcsr_val_B.data(), sizeof(T) * nnz_B, hipMemcpyHostToDevice)); // Obtain csrgeam2 buffer size size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgeam2_bufferSizeExt(handle, M, N, &h_alpha, descr_A, nnz_A, dAval, dAptr, dAcol, &h_beta, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, (T*)nullptr, dCptr_1, (int*)nullptr, &bufferSize)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * bufferSize), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); // hipsparse pointer mode host int hnnz_C_1; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgeam2Nnz(handle, M, N, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, descr_C, dCptr_1, &hnnz_C_1, dbuffer)); // Allocate result matrix auto dCcol_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * hnnz_C_1), device_free}; auto dCval_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * hnnz_C_1), device_free}; int* dCcol_1 = (int*)dCcol_1_managed.get(); T* dCval_1 = (T*)dCval_1_managed.get(); CHECK_HIP_ERROR(hipMemcpy(dalpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dbeta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // hipsparse pointer mode device auto dCcol_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * hnnz_C_1), device_free}; auto dCval_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * hnnz_C_1), device_free}; auto dnnz_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dCcol_2 = (int*)dCcol_2_managed.get(); T* dCval_2 = (T*)dCval_2_managed.get(); int* dnnz_C = (int*)dnnz_C_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgeam2Nnz(handle, M, N, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, descr_C, dCptr_2, dnnz_C, dbuffer)); // Copy output from device to CPU int hnnz_C_2; CHECK_HIP_ERROR(hipMemcpy(&hnnz_C_2, dnnz_C, sizeof(int), hipMemcpyDeviceToHost)); if(argus.unit_check) { // Compute csrgeam2 CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgeam2(handle, M, N, &h_alpha, descr_A, nnz_A, dAval, dAptr, dAcol, &h_beta, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval_1, dCptr_1, dCcol_1, dbuffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgeam2(handle, M, N, dalpha, descr_A, nnz_A, dAval, dAptr, dAcol, dbeta, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval_2, dCptr_2, dCcol_2, dbuffer)); // Copy output from device to CPU std::vector hcsr_row_ptr_C_1(M + 1); std::vector hcsr_row_ptr_C_2(M + 1); std::vector hcsr_col_ind_C_1(hnnz_C_1); std::vector hcsr_col_ind_C_2(hnnz_C_2); std::vector hcsr_val_C_1(hnnz_C_1); std::vector hcsr_val_C_2(hnnz_C_2); CHECK_HIP_ERROR(hipMemcpy( hcsr_row_ptr_C_1.data(), dCptr_1, sizeof(int) * (M + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcsr_row_ptr_C_2.data(), dCptr_2, sizeof(int) * (M + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcsr_col_ind_C_1.data(), dCcol_1, sizeof(int) * hnnz_C_1, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcsr_col_ind_C_2.data(), dCcol_2, sizeof(int) * hnnz_C_2, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val_C_1.data(), dCval_1, sizeof(T) * hnnz_C_1, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val_C_2.data(), dCval_2, sizeof(T) * hnnz_C_2, hipMemcpyDeviceToHost)); // Compute csrgemm host solution std::vector hcsr_row_ptr_C_gold(M + 1); int nnz_C_gold = host_csrgeam_nnz(M, N, h_alpha, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), h_beta, hcsr_row_ptr_B.data(), hcsr_col_ind_B.data(), hcsr_row_ptr_C_gold.data(), idx_base_A, idx_base_B, idx_base_C); std::vector hcsr_col_ind_C_gold(nnz_C_gold); std::vector hcsr_val_C_gold(nnz_C_gold); host_csrgeam(M, N, h_alpha, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), hcsr_val_A.data(), h_beta, hcsr_row_ptr_B.data(), hcsr_col_ind_B.data(), hcsr_val_B.data(), hcsr_row_ptr_C_gold.data(), hcsr_col_ind_C_gold.data(), hcsr_val_C_gold.data(), idx_base_A, idx_base_B, idx_base_C); // Check nnz of C unit_check_general(1, 1, 1, &nnz_C_gold, &hnnz_C_1); unit_check_general(1, 1, 1, &nnz_C_gold, &hnnz_C_2); // Check structure and entries of C unit_check_general(1, M + 1, 1, hcsr_row_ptr_C_gold.data(), hcsr_row_ptr_C_1.data()); unit_check_general(1, M + 1, 1, hcsr_row_ptr_C_gold.data(), hcsr_row_ptr_C_2.data()); unit_check_general(1, nnz_C_gold, 1, hcsr_col_ind_C_gold.data(), hcsr_col_ind_C_1.data()); unit_check_general(1, nnz_C_gold, 1, hcsr_col_ind_C_gold.data(), hcsr_col_ind_C_2.data()); unit_check_near(1, nnz_C_gold, 1, hcsr_val_C_gold.data(), hcsr_val_C_1.data()); unit_check_near(1, nnz_C_gold, 1, hcsr_val_C_gold.data(), hcsr_val_C_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrgeam2(handle, M, N, &h_alpha, descr_A, nnz_A, dAval, dAptr, dAcol, &h_beta, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval_1, dCptr_1, dCcol_1, dbuffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrgeam2(handle, M, N, &h_alpha, descr_A, nnz_A, dAval, dAptr, dAcol, &h_beta, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval_1, dCptr_1, dCcol_1, dbuffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = csrgeam_gflop_count(nnz_A, nnz_B, hnnz_C_1, &h_alpha, &h_beta); double gbyte_count = csrgeam_gbyte_count(M, nnz_A, nnz_B, hnnz_C_1, &h_alpha, &h_beta); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, M, display_key_t::N, N, display_key_t::nnzA, nnz_A, display_key_t::nnzB, nnz_B, display_key_t::nnzC, hnnz_C_1, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRGEAM2_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_csrgemm.hpp000066400000000000000000001557011501764003400231600ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2019 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSRGEMM_HPP #define TESTING_CSRGEMM_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csrgemm_bad_arg(void) { #if(!defined(CUDART_VERSION)) int M = 1; int N = 1; int K = 1; int nnz_A = 1; int nnz_B = 1; hipsparseOperation_t trans_A = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t trans_B = HIPSPARSE_OPERATION_NON_TRANSPOSE; int safe_size = 1; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = unique_ptr_descr_A->descr; std::unique_ptr unique_ptr_descr_B(new descr_struct); hipsparseMatDescr_t descr_B = unique_ptr_descr_B->descr; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; auto dAptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dAcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dAval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dBptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dBcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dBval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dCptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dCcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dCval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* dAptr = (int*)dAptr_managed.get(); int* dAcol = (int*)dAcol_managed.get(); T* dAval = (T*)dAval_managed.get(); int* dBptr = (int*)dBptr_managed.get(); int* dBcol = (int*)dBcol_managed.get(); T* dBval = (T*)dBval_managed.get(); int* dCptr = (int*)dCptr_managed.get(); int* dCcol = (int*)dCcol_managed.get(); T* dCval = (T*)dCval_managed.get(); std::vector hcsr_row_ptr_C(M + 1); hcsr_row_ptr_C[0] = 0; hcsr_row_ptr_C[1] = 1; CHECK_HIP_ERROR( hipMemcpy(dCptr, hcsr_row_ptr_C.data(), sizeof(int) * (M + 1), hipMemcpyHostToDevice)); // testing hipsparseXcsrgemmNnz int nnz_C; verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemmNnz(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, (int*)nullptr, dAcol, descr_B, nnz_B, dBptr, dBcol, descr_C, dCptr, &nnz_C), "Error: dAptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemmNnz(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAptr, (int*)nullptr, descr_B, nnz_B, dBptr, dBcol, descr_C, dCptr, &nnz_C), "Error: dAcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemmNnz(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, (int*)nullptr, dBcol, descr_C, dCptr, &nnz_C), "Error: dBptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemmNnz(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, (int*)nullptr, descr_C, dCptr, &nnz_C), "Error: dBcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemmNnz(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, descr_C, (int*)nullptr, &nnz_C), "Error: dCptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemmNnz(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, descr_C, dCptr, (int*)nullptr), "Error: nnz_C is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemmNnz(handle, trans_A, trans_B, M, N, K, (hipsparseMatDescr_t) nullptr, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, descr_C, dCptr, &nnz_C), "Error: descr_A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemmNnz(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAptr, dAcol, (hipsparseMatDescr_t) nullptr, nnz_B, dBptr, dBcol, descr_C, dCptr, &nnz_C), "Error: descr_B is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemmNnz(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, (hipsparseMatDescr_t) nullptr, dCptr, &nnz_C), "Error: descr_C is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrgemmNnz((hipsparseHandle_t) nullptr, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, descr_C, dCptr, &nnz_C)); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, (T*)nullptr, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: dAval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAval, (int*)nullptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: dAptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAval, dAptr, (int*)nullptr, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: dAcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, (T*)nullptr, dBptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: dBval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, (int*)nullptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: dBptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, (int*)nullptr, descr_C, dCval, dCptr, dCcol), "Error: dBcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, (T*)nullptr, dCptr, dCcol), "Error: dCval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval, (int*)nullptr, dCcol), "Error: dCptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval, dCptr, (int*)nullptr), "Error: dCcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, (hipsparseMatDescr_t) nullptr, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: descr_A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAval, dAptr, dAcol, (hipsparseMatDescr_t) nullptr, nnz_B, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: descr_B is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, (hipsparseMatDescr_t) nullptr, dCval, dCptr, dCcol), "Error: descr_C is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrgemm((hipsparseHandle_t) nullptr, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol)); #endif } static int csrgemm_nnz(int m, int n, int k, const int* csr_row_ptr_A, const int* csr_col_ind_A, const int* csr_row_ptr_B, const int* csr_col_ind_B, int* csr_row_ptr_C, hipsparseIndexBase_t idx_base_A, hipsparseIndexBase_t idx_base_B, hipsparseIndexBase_t idx_base_C) { std::vector nnz(n, -1); // Index base csr_row_ptr_C[0] = idx_base_C; // Loop over rows of A for(int i = 0; i < m; ++i) { // Initialize csr row pointer with previous row offset csr_row_ptr_C[i + 1] = csr_row_ptr_C[i]; int row_begin_A = csr_row_ptr_A[i] - idx_base_A; int row_end_A = csr_row_ptr_A[i + 1] - idx_base_A; // Loop over columns of A for(int j = row_begin_A; j < row_end_A; ++j) { // Current column of A int col_A = csr_col_ind_A[j] - idx_base_A; int row_begin_B = csr_row_ptr_B[col_A] - idx_base_B; int row_end_B = csr_row_ptr_B[col_A + 1] - idx_base_B; // Loop over columns of B in row col_A for(int l = row_begin_B; l < row_end_B; ++l) { // Current column of B int col_B = csr_col_ind_B[l] - idx_base_B; // Check if a new nnz is generated if(nnz[col_B] != i) { nnz[col_B] = i; ++csr_row_ptr_C[i + 1]; } } } } return csr_row_ptr_C[m] - idx_base_C; } template static void csrgemm(int m, int n, int k, const int* csr_row_ptr_A, const int* csr_col_ind_A, const T* csr_val_A, const int* csr_row_ptr_B, const int* csr_col_ind_B, const T* csr_val_B, const int* csr_row_ptr_C, int* csr_col_ind_C, T* csr_val_C, hipsparseIndexBase_t idx_base_A, hipsparseIndexBase_t idx_base_B, hipsparseIndexBase_t idx_base_C) { std::vector nnz(n, -1); // Loop over rows of A for(int i = 0; i < m; ++i) { int row_begin_A = csr_row_ptr_A[i] - idx_base_A; int row_end_A = csr_row_ptr_A[i + 1] - idx_base_A; int row_begin_C = csr_row_ptr_C[i] - idx_base_C; int row_end_C = row_begin_C; // Loop over columns of A for(int j = row_begin_A; j < row_end_A; ++j) { // Current column of A int col_A = csr_col_ind_A[j] - idx_base_A; // Current value of A T val_A = csr_val_A[j]; int row_begin_B = csr_row_ptr_B[col_A] - idx_base_B; int row_end_B = csr_row_ptr_B[col_A + 1] - idx_base_B; // Loop over columns of B in row col_A for(int l = row_begin_B; l < row_end_B; ++l) { // Current column of B int col_B = csr_col_ind_B[l] - idx_base_B; // Current value of B T val_B = csr_val_B[l]; // Check if a new nnz is generated or if the product is appended if(nnz[col_B] < row_begin_C) { nnz[col_B] = row_end_C; csr_col_ind_C[row_end_C] = col_B + idx_base_C; csr_val_C[row_end_C] = testing_mult(val_A, val_B); ++row_end_C; } else { csr_val_C[nnz[col_B]] = csr_val_C[nnz[col_B]] + testing_mult(val_A, val_B); } } } } // Sort column indices within each row for(int i = 0; i < m; ++i) { int row_begin = csr_row_ptr_C[i] - idx_base_C; int row_end = csr_row_ptr_C[i + 1] - idx_base_C; for(int j = row_begin; j < row_end; ++j) { for(int jj = row_begin; jj < row_end - 1; ++jj) { if(csr_col_ind_C[jj] > csr_col_ind_C[jj + 1]) { // swap elements int ind = csr_col_ind_C[jj]; T val = csr_val_C[jj]; csr_col_ind_C[jj] = csr_col_ind_C[jj + 1]; csr_val_C[jj] = csr_val_C[jj + 1]; csr_col_ind_C[jj + 1] = ind; csr_val_C[jj + 1] = val; } } } } } template hipsparseStatus_t testing_csrgemm(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) int M = argus.M; int N = argus.N; int K = argus.K; hipsparseOperation_t trans_A = argus.transA; hipsparseOperation_t trans_B = argus.transB; hipsparseIndexBase_t idx_base_A = argus.baseA; hipsparseIndexBase_t idx_base_B = argus.baseB; hipsparseIndexBase_t idx_base_C = argus.baseC; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = unique_ptr_descr_A->descr; std::unique_ptr unique_ptr_descr_B(new descr_struct); hipsparseMatDescr_t descr_B = unique_ptr_descr_B->descr; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_A, idx_base_A)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_B, idx_base_B)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_C, idx_base_C)); srand(12345ULL); // Host structures std::vector hcsr_row_ptr_A; std::vector hcsr_col_ind_A; std::vector hcsr_val_A; // Read or construct CSR matrix int nnz_A = 0; if(!generate_csr_matrix( filename, M, K, nnz_A, hcsr_row_ptr_A, hcsr_col_ind_A, hcsr_val_A, idx_base_A)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // B = A^T so that we can compute the square of A N = M; int nnz_B = nnz_A; std::vector hcsr_row_ptr_B(K + 1, 0); std::vector hcsr_col_ind_B(nnz_B); std::vector hcsr_val_B(nnz_B); // B = A^T transpose_csr(M, K, nnz_A, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), hcsr_val_A.data(), hcsr_row_ptr_B.data(), hcsr_col_ind_B.data(), hcsr_val_B.data(), idx_base_A, idx_base_B); // Allocate memory on device auto dAptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; auto dAcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz_A), device_free}; auto dAval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_A), device_free}; auto dBptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (K + 1)), device_free}; auto dBcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz_B), device_free}; auto dBval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_B), device_free}; auto dCptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; int* dAptr = (int*)dAptr_managed.get(); int* dAcol = (int*)dAcol_managed.get(); T* dAval = (T*)dAval_managed.get(); int* dBptr = (int*)dBptr_managed.get(); int* dBcol = (int*)dBcol_managed.get(); T* dBval = (T*)dBval_managed.get(); int* dCptr = (int*)dCptr_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dAptr, hcsr_row_ptr_A.data(), sizeof(int) * (M + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dAcol, hcsr_col_ind_A.data(), sizeof(int) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dAval, hcsr_val_A.data(), sizeof(T) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dBptr, hcsr_row_ptr_B.data(), sizeof(int) * (K + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dBcol, hcsr_col_ind_B.data(), sizeof(int) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dBval, hcsr_val_B.data(), sizeof(T) * nnz_B, hipMemcpyHostToDevice)); // csrgemm nnz // hipsparse pointer mode host int hnnz_C_1; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgemmNnz(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, descr_C, dCptr, &hnnz_C_1)); // Allocate result matrix auto dCcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * hnnz_C_1), device_free}; auto dCval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * hnnz_C_1), device_free}; int* dCcol = (int*)dCcol_managed.get(); T* dCval = (T*)dCval_managed.get(); // hipsparse pointer mode device auto dnnz_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dnnz_C = (int*)dnnz_C_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgemmNnz(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, descr_C, dCptr, dnnz_C)); // Copy output from device to CPU int hnnz_C_2; CHECK_HIP_ERROR(hipMemcpy(&hnnz_C_2, dnnz_C, sizeof(int), hipMemcpyDeviceToHost)); if(argus.unit_check) { // Compute csrgemm CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol)); // Copy output from device to CPU std::vector hcsr_row_ptr_C(M + 1); std::vector hcsr_col_ind_C(hnnz_C_1); std::vector hcsr_val_C(hnnz_C_1); CHECK_HIP_ERROR( hipMemcpy(hcsr_row_ptr_C.data(), dCptr, sizeof(int) * (M + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_col_ind_C.data(), dCcol, sizeof(int) * hnnz_C_1, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val_C.data(), dCval, sizeof(T) * hnnz_C_1, hipMemcpyDeviceToHost)); // Compute csrgemm host solution std::vector hcsr_row_ptr_C_gold(M + 1); int nnz_C_gold = csrgemm_nnz(M, N, K, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), hcsr_row_ptr_B.data(), hcsr_col_ind_B.data(), hcsr_row_ptr_C_gold.data(), idx_base_A, idx_base_B, idx_base_C); std::vector hcsr_col_ind_C_gold(nnz_C_gold); std::vector hcsr_val_C_gold(nnz_C_gold); csrgemm(M, N, K, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), hcsr_val_A.data(), hcsr_row_ptr_B.data(), hcsr_col_ind_B.data(), hcsr_val_B.data(), hcsr_row_ptr_C_gold.data(), hcsr_col_ind_C_gold.data(), hcsr_val_C_gold.data(), idx_base_A, idx_base_B, idx_base_C); // Check nnz of C unit_check_general(1, 1, 1, &nnz_C_gold, &hnnz_C_1); unit_check_general(1, 1, 1, &nnz_C_gold, &hnnz_C_2); // Check structure and entries of C unit_check_general(1, M + 1, 1, hcsr_row_ptr_C_gold.data(), hcsr_row_ptr_C.data()); unit_check_general(1, nnz_C_gold, 1, hcsr_col_ind_C_gold.data(), hcsr_col_ind_C.data()); unit_check_near(1, nnz_C_gold, 1, hcsr_val_C_gold.data(), hcsr_val_C.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = csrgemm_gflop_count( M, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), hcsr_row_ptr_B.data(), idx_base_A); double gbyte_count = csrgemm_gbyte_count(M, N, K, nnz_A, nnz_B, hnnz_C_1); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::transA, hipsparse_operation2string(trans_A), display_key_t::transB, hipsparse_operation2string(trans_B), display_key_t::M, M, display_key_t::N, N, display_key_t::K, K, display_key_t::nnzA, nnz_A, display_key_t::nnzB, nnz_B, display_key_t::nnzC, hnnz_C_1, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRGEMM_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_csrgemm2_a.hpp000066400000000000000000002443671501764003400235510ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2019 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSRGEMM2_A_HPP #define TESTING_CSRGEMM2_A_HPP #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csrgemm2_a_bad_arg(void) { #if(!defined(CUDART_VERSION)) int M = 1; int N = 1; int K = 1; int nnz_A = 1; int nnz_B = 1; int safe_size = 1; T alpha = 1.0; size_t size; int nnz_C; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = unique_ptr_descr_A->descr; std::unique_ptr unique_ptr_descr_B(new descr_struct); hipsparseMatDescr_t descr_B = unique_ptr_descr_B->descr; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; std::unique_ptr unique_ptr_csrgemm2(new csrgemm2_struct); csrgemm2Info_t info = unique_ptr_csrgemm2->info; auto dAptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dAcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dAval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dBptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dBcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dBval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dCptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dCcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dCval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* dAptr = (int*)dAptr_managed.get(); int* dAcol = (int*)dAcol_managed.get(); T* dAval = (T*)dAval_managed.get(); int* dBptr = (int*)dBptr_managed.get(); int* dBcol = (int*)dBcol_managed.get(); T* dBval = (T*)dBval_managed.get(); int* dCptr = (int*)dCptr_managed.get(); int* dCcol = (int*)dCcol_managed.get(); T* dCval = (T*)dCval_managed.get(); void* dbuffer = (void*)dbuffer_managed.get(); std::vector hcsr_row_ptr_C(M + 1); hcsr_row_ptr_C[0] = 0; hcsr_row_ptr_C[1] = 1; CHECK_HIP_ERROR( hipMemcpy(dCptr, hcsr_row_ptr_C.data(), sizeof(int) * (M + 1), hipMemcpyHostToDevice)); // Scenario: alpha != 0 and beta == 0 verify_hipsparse_status_invalid_handle( hipsparseXcsrgemm2_bufferSizeExt((hipsparseHandle_t) nullptr, M, N, K, &alpha, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (int*)nullptr, (int*)nullptr, info, &size)); verify_hipsparse_status_invalid_pointer( hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, K, (T*)nullptr, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (int*)nullptr, (int*)nullptr, info, &size), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, K, &alpha, (hipsparseMatDescr_t) nullptr, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (int*)nullptr, (int*)nullptr, info, &size), "Error: descr_A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, K, &alpha, descr_A, nnz_A, (int*)nullptr, dAcol, descr_B, nnz_B, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (int*)nullptr, (int*)nullptr, info, &size), "Error: dAptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, K, &alpha, descr_A, nnz_A, dAptr, (int*)nullptr, descr_B, nnz_B, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (int*)nullptr, (int*)nullptr, info, &size), "Error: dAcol is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, K, &alpha, descr_A, nnz_A, dAptr, dAcol, (hipsparseMatDescr_t) nullptr, nnz_B, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (int*)nullptr, (int*)nullptr, info, &size), "Error: descr_B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, K, &alpha, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, (int*)nullptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (int*)nullptr, (int*)nullptr, info, &size), "Error: dBptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, K, &alpha, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, (int*)nullptr, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (int*)nullptr, (int*)nullptr, info, &size), "Error: dBcol is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, K, &alpha, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (int*)nullptr, (int*)nullptr, (csrgemm2Info_t) nullptr, &size), "Error: info is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, K, &alpha, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (int*)nullptr, (int*)nullptr, info, (size_t*)nullptr), "Error: size is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrgemm2Nnz((hipsparseHandle_t) nullptr, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, nullptr, 0, nullptr, nullptr, descr_C, dCptr, &nnz_C, info, dbuffer)); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2Nnz(handle, M, N, K, (hipsparseMatDescr_t) nullptr, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, nullptr, 0, nullptr, nullptr, descr_C, dCptr, &nnz_C, info, dbuffer), "Error: descr_A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2Nnz(handle, M, N, K, descr_A, nnz_A, (int*)nullptr, dAcol, descr_B, nnz_B, dBptr, dBcol, nullptr, 0, nullptr, nullptr, descr_C, dCptr, &nnz_C, info, dbuffer), "Error: dAptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2Nnz(handle, M, N, K, descr_A, nnz_A, dAptr, (int*)nullptr, descr_B, nnz_B, dBptr, dBcol, nullptr, 0, nullptr, nullptr, descr_C, dCptr, &nnz_C, info, dbuffer), "Error: dAcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2Nnz(handle, M, N, K, descr_A, nnz_A, dAptr, dAcol, (hipsparseMatDescr_t) nullptr, nnz_B, dBptr, dBcol, nullptr, 0, nullptr, nullptr, descr_C, dCptr, &nnz_C, info, dbuffer), "Error: descr_B is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2Nnz(handle, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, (int*)nullptr, dBcol, nullptr, 0, nullptr, nullptr, descr_C, dCptr, &nnz_C, info, dbuffer), "Error: dBptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2Nnz(handle, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, (int*)nullptr, nullptr, 0, nullptr, nullptr, descr_C, dCptr, &nnz_C, info, dbuffer), "Error: dBcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2Nnz(handle, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, nullptr, 0, nullptr, nullptr, (hipsparseMatDescr_t) nullptr, dCptr, &nnz_C, info, dbuffer), "Error: descr_C is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2Nnz(handle, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, nullptr, 0, nullptr, nullptr, descr_C, (int*)nullptr, &nnz_C, info, dbuffer), "Error: dCptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2Nnz(handle, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, nullptr, 0, nullptr, nullptr, descr_C, dCptr, (int*)nullptr, info, dbuffer), "Error: nnz_C is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2Nnz(handle, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, nullptr, 0, nullptr, nullptr, descr_C, dCptr, &nnz_C, (csrgemm2Info_t) nullptr, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2Nnz(handle, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, nullptr, 0, nullptr, nullptr, descr_C, dCptr, &nnz_C, info, (void*)nullptr), "Error: dbuffer is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrgemm2((hipsparseHandle_t) nullptr, M, N, K, &alpha, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (T*)nullptr, (int*)nullptr, (int*)nullptr, descr_C, dCval, dCptr, dCcol, info, dbuffer)); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2(handle, M, N, K, (T*)nullptr, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (T*)nullptr, (int*)nullptr, (int*)nullptr, descr_C, dCval, dCptr, dCcol, info, dbuffer), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2(handle, M, N, K, &alpha, (hipsparseMatDescr_t) nullptr, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (T*)nullptr, (int*)nullptr, (int*)nullptr, descr_C, dCval, dCptr, dCcol, info, dbuffer), "Error: descr_A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2(handle, M, N, K, &alpha, descr_A, nnz_A, (T*)nullptr, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (T*)nullptr, (int*)nullptr, (int*)nullptr, descr_C, dCval, dCptr, dCcol, info, dbuffer), "Error: dAval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2(handle, M, N, K, &alpha, descr_A, nnz_A, dAval, (int*)nullptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (T*)nullptr, (int*)nullptr, (int*)nullptr, descr_C, dCval, dCptr, dCcol, info, dbuffer), "Error: dAptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2(handle, M, N, K, &alpha, descr_A, nnz_A, dAval, dAptr, (int*)nullptr, descr_B, nnz_B, dBval, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (T*)nullptr, (int*)nullptr, (int*)nullptr, descr_C, dCval, dCptr, dCcol, info, dbuffer), "Error: dAcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2(handle, M, N, K, &alpha, descr_A, nnz_A, dAval, dAptr, dAcol, (hipsparseMatDescr_t) nullptr, nnz_B, dBval, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (T*)nullptr, (int*)nullptr, (int*)nullptr, descr_C, dCval, dCptr, dCcol, info, dbuffer), "Error: descr_B is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2(handle, M, N, K, &alpha, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, (T*)nullptr, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (T*)nullptr, (int*)nullptr, (int*)nullptr, descr_C, dCval, dCptr, dCcol, info, dbuffer), "Error: dBval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2(handle, M, N, K, &alpha, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, (int*)nullptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (T*)nullptr, (int*)nullptr, (int*)nullptr, descr_C, dCval, dCptr, dCcol, info, dbuffer), "Error: dBptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2(handle, M, N, K, &alpha, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, (int*)nullptr, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (T*)nullptr, (int*)nullptr, (int*)nullptr, descr_C, dCval, dCptr, dCcol, info, dbuffer), "Error: dBcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2(handle, M, N, K, &alpha, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (T*)nullptr, (int*)nullptr, (int*)nullptr, (hipsparseMatDescr_t) nullptr, dCval, dCptr, dCcol, info, dbuffer), "Error: descr_C is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2(handle, M, N, K, &alpha, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (T*)nullptr, (int*)nullptr, (int*)nullptr, descr_C, (T*)nullptr, dCptr, dCcol, info, dbuffer), "Error: dCval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2(handle, M, N, K, &alpha, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (T*)nullptr, (int*)nullptr, (int*)nullptr, descr_C, dCval, (int*)nullptr, dCcol, info, dbuffer), "Error: dCptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2(handle, M, N, K, &alpha, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (T*)nullptr, (int*)nullptr, (int*)nullptr, descr_C, dCval, dCptr, (int*)nullptr, info, dbuffer), "Error: dCcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2(handle, M, N, K, &alpha, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (T*)nullptr, (int*)nullptr, (int*)nullptr, descr_C, dCval, dCptr, dCcol, (csrgemm2Info_t) nullptr, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2(handle, M, N, K, &alpha, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (T*)nullptr, (int*)nullptr, (int*)nullptr, descr_C, dCval, dCptr, dCcol, info, (void*)nullptr), "Error: dbuffer is nullptr"); #endif } template hipsparseStatus_t testing_csrgemm2_a(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int M = argus.M; int N = argus.N; int K = argus.K; hipsparseIndexBase_t idx_base_A = argus.baseA; hipsparseIndexBase_t idx_base_B = argus.baseB; hipsparseIndexBase_t idx_base_C = argus.baseC; std::string filename = argus.filename; T alpha = make_DataType(argus.alpha); T* h_alpha = α std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = unique_ptr_descr_A->descr; std::unique_ptr unique_ptr_descr_B(new descr_struct); hipsparseMatDescr_t descr_B = unique_ptr_descr_B->descr; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; std::unique_ptr unique_ptr_descr_D(new descr_struct); hipsparseMatDescr_t descr_D = unique_ptr_descr_D->descr; std::unique_ptr unique_ptr_csrgemm2(new csrgemm2_struct); csrgemm2Info_t info = unique_ptr_csrgemm2->info; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_A, idx_base_A)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_B, idx_base_B)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_C, idx_base_C)); if(M == 0 || N == 0 || K == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcsr_row_ptr_A; std::vector hcsr_col_ind_A; std::vector hcsr_val_A; // Read or construct CSR matrix int nnz_A = 0; if(!generate_csr_matrix( filename, M, K, nnz_A, hcsr_row_ptr_A, hcsr_col_ind_A, hcsr_val_A, idx_base_A)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hcsr_row_ptr_B; std::vector hcsr_col_ind_B; std::vector hcsr_val_B; std::vector hcsr_row_ptr_D; std::vector hcsr_col_ind_D; std::vector hcsr_val_D; // B = A^T so that we can compute the square of A N = M; int nnz_B = nnz_A; hcsr_row_ptr_B.resize(K + 1, 0); hcsr_col_ind_B.resize(nnz_B); hcsr_val_B.resize(nnz_B); // B = A^T transpose_csr(M, K, nnz_A, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), hcsr_val_A.data(), hcsr_row_ptr_B.data(), hcsr_col_ind_B.data(), hcsr_val_B.data(), idx_base_A, idx_base_B); // Allocate memory on device int one = 1; int safe_K = std::max(K, one); int safe_nnz_A = std::max(nnz_A, one); int safe_nnz_B = std::max(nnz_B, one); auto dAptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; auto dAcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_nnz_A), device_free}; auto dAval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_nnz_A), device_free}; auto dBptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_K + 1)), device_free}; auto dBcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_nnz_B), device_free}; auto dBval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_nnz_B), device_free}; auto dCptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; auto dalpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dAptr = (int*)dAptr_managed.get(); int* dAcol = (int*)dAcol_managed.get(); T* dAval = (T*)dAval_managed.get(); int* dBptr = (int*)dBptr_managed.get(); int* dBcol = (int*)dBcol_managed.get(); T* dBval = (T*)dBval_managed.get(); int* dCptr = (int*)dCptr_managed.get(); T* dalpha = (T*)dalpha_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dAptr, hcsr_row_ptr_A.data(), sizeof(int) * (M + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dAcol, hcsr_col_ind_A.data(), sizeof(int) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dAval, hcsr_val_A.data(), sizeof(T) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dBptr, hcsr_row_ptr_B.data(), sizeof(int) * (K + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dBcol, hcsr_col_ind_B.data(), sizeof(int) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dBval, hcsr_val_B.data(), sizeof(T) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dalpha, h_alpha, sizeof(T), hipMemcpyHostToDevice)); // Obtain csrgemm2 buffer size size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, K, h_alpha, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, (T*)nullptr, descr_D, 0, nullptr, nullptr, info, &bufferSize)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * bufferSize), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); // csrgemm2 nnz // hipsparse pointer mode host int hnnz_C_1; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgemm2Nnz(handle, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, descr_D, 0, nullptr, nullptr, descr_C, dCptr, &hnnz_C_1, info, dbuffer)); // Allocate result matrix int safe_nnz_C = std::max(hnnz_C_1, one); auto dCcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_nnz_C), device_free}; auto dCval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_nnz_C), device_free}; int* dCcol = (int*)dCcol_managed.get(); T* dCval = (T*)dCval_managed.get(); if(argus.unit_check) { // hipsparse pointer mode device auto dnnz_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dnnz_C = (int*)dnnz_C_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgemm2Nnz(handle, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, descr_D, 0, nullptr, nullptr, descr_C, dCptr, dnnz_C, info, dbuffer)); // Compute csrgemm host solution std::vector hcsr_row_ptr_C_gold(M + 1); double cpu_time_used = get_time_us(); int nnz_C_gold = host_csrgemm2_nnz(M, N, K, h_alpha, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), hcsr_row_ptr_B.data(), hcsr_col_ind_B.data(), (T*)nullptr, hcsr_row_ptr_D.data(), hcsr_col_ind_D.data(), hcsr_row_ptr_C_gold.data(), idx_base_A, idx_base_B, idx_base_C, HIPSPARSE_INDEX_BASE_ZERO); // If nnz_C == 0, we are done if(nnz_C_gold == 0) { return HIPSPARSE_STATUS_SUCCESS; } std::vector hcsr_col_ind_C_gold(nnz_C_gold); std::vector hcsr_val_C_gold(nnz_C_gold); host_csrgemm2(M, N, K, h_alpha, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), hcsr_val_A.data(), hcsr_row_ptr_B.data(), hcsr_col_ind_B.data(), hcsr_val_B.data(), (T*)nullptr, hcsr_row_ptr_D.data(), hcsr_col_ind_D.data(), hcsr_val_D.data(), hcsr_row_ptr_C_gold.data(), hcsr_col_ind_C_gold.data(), hcsr_val_C_gold.data(), idx_base_A, idx_base_B, idx_base_C, HIPSPARSE_INDEX_BASE_ZERO); cpu_time_used = get_time_us() - cpu_time_used; // Copy output from device to CPU int hnnz_C_2; CHECK_HIP_ERROR(hipMemcpy(&hnnz_C_2, dnnz_C, sizeof(int), hipMemcpyDeviceToHost)); // Check nnz of C unit_check_general(1, 1, 1, &nnz_C_gold, &hnnz_C_1); unit_check_general(1, 1, 1, &nnz_C_gold, &hnnz_C_2); // Compute csrgemm2 CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgemm2(handle, M, N, K, h_alpha, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, (T*)nullptr, descr_D, 0, (T*)nullptr, nullptr, nullptr, descr_C, dCval, dCptr, dCcol, info, dbuffer)); // Copy output from device to CPU std::vector hcsr_row_ptr_C(M + 1); std::vector hcsr_col_ind_C(nnz_C_gold); std::vector hcsr_val_C_1(nnz_C_gold); std::vector hcsr_val_C_2(nnz_C_gold); CHECK_HIP_ERROR( hipMemcpy(hcsr_row_ptr_C.data(), dCptr, sizeof(int) * (M + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcsr_col_ind_C.data(), dCcol, sizeof(int) * nnz_C_gold, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val_C_1.data(), dCval, sizeof(T) * nnz_C_gold, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemset(dCval, 0, sizeof(T) * nnz_C_gold)); // Check structure and entries of C unit_check_general(1, M + 1, 1, hcsr_row_ptr_C_gold.data(), hcsr_row_ptr_C.data()); unit_check_general(1, nnz_C_gold, 1, hcsr_col_ind_C_gold.data(), hcsr_col_ind_C.data()); unit_check_near(1, nnz_C_gold, 1, hcsr_val_C_gold.data(), hcsr_val_C_1.data()); #ifdef __HIP_PLATFORM_AMD__ // Device pointer mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgemm2(handle, M, N, K, dalpha, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, (T*)nullptr, descr_D, 0, (T*)nullptr, nullptr, nullptr, descr_C, dCval, dCptr, dCcol, info, dbuffer)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val_C_2.data(), dCval, sizeof(T) * nnz_C_gold, hipMemcpyDeviceToHost)); // Check device pointer results unit_check_near(1, nnz_C_gold, 1, hcsr_val_C_gold.data(), hcsr_val_C_2.data()); #endif } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRGEMM2_A_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_csrgemm2_b.hpp000066400000000000000000001450121501764003400235350ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2019 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSRGEMM2_B_HPP #define TESTING_CSRGEMM2_B_HPP #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csrgemm2_b_bad_arg(void) { #if(!defined(CUDART_VERSION)) int M = 1; int N = 1; int nnz_D = 1; int safe_size = 1; T beta = 1.0; hipsparseStatus_t status; size_t size; int nnz_C; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; std::unique_ptr unique_ptr_descr_D(new descr_struct); hipsparseMatDescr_t descr_D = unique_ptr_descr_D->descr; std::unique_ptr unique_ptr_csrgemm2(new csrgemm2_struct); csrgemm2Info_t info = unique_ptr_csrgemm2->info; auto dDptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dDcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dDval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dCptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dCcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dCval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* dDptr = (int*)dDptr_managed.get(); int* dDcol = (int*)dDcol_managed.get(); T* dDval = (T*)dDval_managed.get(); int* dCptr = (int*)dCptr_managed.get(); int* dCcol = (int*)dCcol_managed.get(); T* dCval = (T*)dCval_managed.get(); void* dbuffer = (void*)dbuffer_managed.get(); std::vector hcsr_row_ptr_C(M + 1); hcsr_row_ptr_C[0] = 0; hcsr_row_ptr_C[1] = 1; CHECK_HIP_ERROR( hipMemcpy(dCptr, hcsr_row_ptr_C.data(), sizeof(int) * (M + 1), hipMemcpyHostToDevice)); // Scenario: alpha == 0 and beta != 0 // testing hipsparseXcsrgemm2_bufferSizeExt // testing for(nullptr == handle) { status = hipsparseXcsrgemm2_bufferSizeExt(nullptr, M, N, 0, (T*)nullptr, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr, nullptr, &beta, descr_D, nnz_D, dDptr, dDcol, info, &size); verify_hipsparse_status_invalid_handle(status); } // testing for(nullptr == beta) { status = hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, 0, (T*)nullptr, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr, nullptr, (T*)nullptr, descr_D, nnz_D, dDptr, dDcol, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: beta is nullptr"); } // testing for(nullptr == descr_D) { status = hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, 0, (T*)nullptr, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr, nullptr, &beta, nullptr, nnz_D, dDptr, dDcol, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: descr_D is nullptr"); } // testing for(nullptr == dDptr) { status = hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, 0, (T*)nullptr, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr, nullptr, &beta, descr_D, nnz_D, nullptr, dDcol, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: dDptr is nullptr"); } // testing for(nullptr == dDcol) { status = hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, 0, (T*)nullptr, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr, nullptr, &beta, descr_D, nnz_D, dDptr, nullptr, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: dDcol is nullptr"); } // testing for(nullptr == info) { status = hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, 0, (T*)nullptr, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr, nullptr, &beta, descr_D, nnz_D, dDptr, dDcol, nullptr, &size); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing for(nullptr == size) { status = hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, 0, (T*)nullptr, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr, nullptr, &beta, descr_D, nnz_D, dDptr, dDcol, info, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: size is nullptr"); } // testing hipsparseXcsrgemm2Nnz // testing for(nullptr == handle) { status = hipsparseXcsrgemm2Nnz(nullptr, M, N, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr, nullptr, descr_D, nnz_D, dDptr, dDcol, descr_C, dCptr, &nnz_C, info, dbuffer); verify_hipsparse_status_invalid_handle(status); } // testing for(nullptr == descr_D) { status = hipsparseXcsrgemm2Nnz(handle, M, N, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr, nnz_D, dDptr, dDcol, descr_C, dCptr, &nnz_C, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_D is nullptr"); } // testing for(nullptr == dDptr) { status = hipsparseXcsrgemm2Nnz(handle, M, N, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr, nullptr, descr_D, nnz_D, nullptr, dDcol, descr_C, dCptr, &nnz_C, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dDptr is nullptr"); } // testing for(nullptr == dDcol) { status = hipsparseXcsrgemm2Nnz(handle, M, N, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr, nullptr, descr_D, nnz_D, dDptr, nullptr, descr_C, dCptr, &nnz_C, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dDcol is nullptr"); } // testing for(nullptr == descr_C) { status = hipsparseXcsrgemm2Nnz(handle, M, N, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr, nullptr, descr_D, nnz_D, dDptr, dDcol, nullptr, dCptr, &nnz_C, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_C is nullptr"); } // testing for(nullptr == dCptr) { status = hipsparseXcsrgemm2Nnz(handle, M, N, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr, nullptr, descr_D, nnz_D, dDptr, dDcol, descr_C, nullptr, &nnz_C, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dCptr is nullptr"); } // testing for(nullptr == nnz_C) { status = hipsparseXcsrgemm2Nnz(handle, M, N, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr, nullptr, descr_D, nnz_D, dDptr, dDcol, descr_C, dCptr, nullptr, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: nnz_C is nullptr"); } // testing for(nullptr == info) { status = hipsparseXcsrgemm2Nnz(handle, M, N, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr, nullptr, descr_D, nnz_D, dDptr, dDcol, descr_C, dCptr, &nnz_C, nullptr, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing hipsparseXcsrgemm2 // testing for(nullptr == handle) { status = hipsparseXcsrgemm2(nullptr, M, N, 0, (T*)nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, &beta, descr_D, nnz_D, dDval, dDptr, dDcol, descr_C, dCval, dCptr, dCcol, info, dbuffer); verify_hipsparse_status_invalid_handle(status); } // testing for(nullptr == beta) { status = hipsparseXcsrgemm2(handle, M, N, 0, (T*)nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, (T*)nullptr, descr_D, nnz_D, dDval, dDptr, dDcol, descr_C, dCval, dCptr, dCcol, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: beta is nullptr"); } // testing for(nullptr == descr_D) { status = hipsparseXcsrgemm2(handle, M, N, 0, (T*)nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, &beta, nullptr, nnz_D, dDval, dDptr, dDcol, descr_C, dCval, dCptr, dCcol, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_D is nullptr"); } // testing for(nullptr == dDval) { status = hipsparseXcsrgemm2(handle, M, N, 0, (T*)nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, &beta, descr_D, nnz_D, (T*)nullptr, dDptr, dDcol, descr_C, dCval, dCptr, dCcol, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dDval is nullptr"); } // testing for(nullptr == dDptr) { status = hipsparseXcsrgemm2(handle, M, N, 0, (T*)nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, &beta, descr_D, nnz_D, dDval, nullptr, dDcol, descr_C, dCval, dCptr, dCcol, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dDptr is nullptr"); } // testing for(nullptr == dDcol) { status = hipsparseXcsrgemm2(handle, M, N, 0, (T*)nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, &beta, descr_D, nnz_D, dDval, dDptr, nullptr, descr_C, dCval, dCptr, dCcol, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dDcol is nullptr"); } // testing for(nullptr == descr_C) { status = hipsparseXcsrgemm2(handle, M, N, 0, (T*)nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, &beta, descr_D, nnz_D, dDval, dDptr, dDcol, nullptr, dCval, dCptr, dCcol, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_C is nullptr"); } // testing for(nullptr == dCval) { status = hipsparseXcsrgemm2(handle, M, N, 0, (T*)nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, &beta, descr_D, nnz_D, dDval, dDptr, dDcol, descr_C, (T*)nullptr, dCptr, dCcol, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dCval is nullptr"); } // testing for(nullptr == dCptr) { status = hipsparseXcsrgemm2(handle, M, N, 0, (T*)nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, &beta, descr_D, nnz_D, dDval, dDptr, dDcol, descr_C, dCval, nullptr, dCcol, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dCptr is nullptr"); } // testing for(nullptr == dCcol) { status = hipsparseXcsrgemm2(handle, M, N, 0, (T*)nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, &beta, descr_D, nnz_D, dDval, dDptr, dDcol, descr_C, dCval, dCptr, nullptr, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dCcol is nullptr"); } // testing for(nullptr == info) { status = hipsparseXcsrgemm2(handle, M, N, 0, (T*)nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, &beta, descr_D, nnz_D, dDval, dDptr, dDcol, descr_C, dCval, dCptr, dCcol, nullptr, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } #endif } template hipsparseStatus_t testing_csrgemm2_b(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int M = argus.M; int N = argus.N; hipsparseIndexBase_t idx_base_C = argus.baseC; hipsparseIndexBase_t idx_base_D = argus.baseD; std::string filename = argus.filename; T beta = make_DataType(argus.beta); T* h_beta = β std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = unique_ptr_descr_A->descr; std::unique_ptr unique_ptr_descr_B(new descr_struct); hipsparseMatDescr_t descr_B = unique_ptr_descr_B->descr; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; std::unique_ptr unique_ptr_descr_D(new descr_struct); hipsparseMatDescr_t descr_D = unique_ptr_descr_D->descr; std::unique_ptr unique_ptr_csrgemm2(new csrgemm2_struct); csrgemm2Info_t info = unique_ptr_csrgemm2->info; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_C, idx_base_C)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_D, idx_base_D)); srand(12345ULL); // Host structures std::vector hcsr_row_ptr_D; std::vector hcsr_col_ind_D; std::vector hcsr_val_D; // Read or construct CSR matrix int nnz_D = 0; if(!generate_csr_matrix( filename, M, N, nnz_D, hcsr_row_ptr_D, hcsr_col_ind_D, hcsr_val_D, idx_base_D)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hcsr_row_ptr_A; std::vector hcsr_col_ind_A; std::vector hcsr_val_A; std::vector hcsr_row_ptr_B; std::vector hcsr_col_ind_B; std::vector hcsr_val_B; // Allocate memory on device int one = 1; int safe_nnz_D = std::max(nnz_D, one); auto dDptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; auto dDcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_nnz_D), device_free}; auto dDval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_nnz_D), device_free}; auto dCptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; auto dbeta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dDptr = (int*)dDptr_managed.get(); int* dDcol = (int*)dDcol_managed.get(); T* dDval = (T*)dDval_managed.get(); int* dCptr = (int*)dCptr_managed.get(); T* dbeta = (T*)dbeta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dDptr, hcsr_row_ptr_D.data(), sizeof(int) * (M + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dDcol, hcsr_col_ind_D.data(), sizeof(int) * nnz_D, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dDval, hcsr_val_D.data(), sizeof(T) * nnz_D, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dbeta, h_beta, sizeof(T), hipMemcpyHostToDevice)); // Obtain csrgemm2 buffer size size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, 0, (T*)nullptr, descr_A, 0, nullptr, nullptr, descr_B, 0, nullptr, nullptr, h_beta, descr_D, nnz_D, dDptr, dDcol, info, &bufferSize)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * bufferSize), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); // csrgemm2 nnz // hipsparse pointer mode host int hnnz_C_1; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgemm2Nnz(handle, M, N, 0, descr_A, 0, nullptr, nullptr, descr_B, 0, nullptr, nullptr, descr_D, nnz_D, dDptr, dDcol, descr_C, dCptr, &hnnz_C_1, info, dbuffer)); // Allocate result matrix int safe_nnz_C = std::max(hnnz_C_1, one); auto dCcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_nnz_C), device_free}; auto dCval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_nnz_C), device_free}; int* dCcol = (int*)dCcol_managed.get(); T* dCval = (T*)dCval_managed.get(); if(argus.unit_check) { // hipsparse pointer mode device auto dnnz_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dnnz_C = (int*)dnnz_C_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgemm2Nnz(handle, M, N, 0, descr_A, 0, nullptr, nullptr, descr_B, 0, nullptr, nullptr, descr_D, nnz_D, dDptr, dDcol, descr_C, dCptr, dnnz_C, info, dbuffer)); // Compute csrgemm host solution std::vector hcsr_row_ptr_C_gold(M + 1); double cpu_time_used = get_time_us(); int nnz_C_gold = host_csrgemm2_nnz(M, N, 0, (T*)nullptr, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), hcsr_row_ptr_B.data(), hcsr_col_ind_B.data(), h_beta, hcsr_row_ptr_D.data(), hcsr_col_ind_D.data(), hcsr_row_ptr_C_gold.data(), HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ZERO, idx_base_C, idx_base_D); // If nnz_C == 0, we are done if(nnz_C_gold == 0) { return HIPSPARSE_STATUS_SUCCESS; } std::vector hcsr_col_ind_C_gold(nnz_C_gold); std::vector hcsr_val_C_gold(nnz_C_gold); host_csrgemm2(M, N, 0, (T*)nullptr, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), hcsr_val_A.data(), hcsr_row_ptr_B.data(), hcsr_col_ind_B.data(), hcsr_val_B.data(), h_beta, hcsr_row_ptr_D.data(), hcsr_col_ind_D.data(), hcsr_val_D.data(), hcsr_row_ptr_C_gold.data(), hcsr_col_ind_C_gold.data(), hcsr_val_C_gold.data(), HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ZERO, idx_base_C, idx_base_D); cpu_time_used = get_time_us() - cpu_time_used; // Copy output from device to CPU int hnnz_C_2; CHECK_HIP_ERROR(hipMemcpy(&hnnz_C_2, dnnz_C, sizeof(int), hipMemcpyDeviceToHost)); // Check nnz of C unit_check_general(1, 1, 1, &nnz_C_gold, &hnnz_C_1); unit_check_general(1, 1, 1, &nnz_C_gold, &hnnz_C_2); // Compute csrgemm2 CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgemm2(handle, M, N, 0, (T*)nullptr, descr_A, 0, (T*)nullptr, nullptr, nullptr, descr_B, 0, (T*)nullptr, nullptr, nullptr, h_beta, descr_D, nnz_D, dDval, dDptr, dDcol, descr_C, dCval, dCptr, dCcol, info, dbuffer)); // Copy output from device to CPU std::vector hcsr_row_ptr_C(M + 1); std::vector hcsr_col_ind_C(nnz_C_gold); std::vector hcsr_val_C_1(nnz_C_gold); std::vector hcsr_val_C_2(nnz_C_gold); CHECK_HIP_ERROR( hipMemcpy(hcsr_row_ptr_C.data(), dCptr, sizeof(int) * (M + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcsr_col_ind_C.data(), dCcol, sizeof(int) * nnz_C_gold, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val_C_1.data(), dCval, sizeof(T) * nnz_C_gold, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemset(dCval, 0, sizeof(T) * nnz_C_gold)); // Check structure and entries of C unit_check_general(1, M + 1, 1, hcsr_row_ptr_C_gold.data(), hcsr_row_ptr_C.data()); unit_check_general(1, nnz_C_gold, 1, hcsr_col_ind_C_gold.data(), hcsr_col_ind_C.data()); unit_check_near(1, nnz_C_gold, 1, hcsr_val_C_gold.data(), hcsr_val_C_1.data()); #ifdef __HIP_PLATFORM_AMD__ // Device pointer mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgemm2(handle, M, N, 0, (T*)nullptr, descr_A, 0, (T*)nullptr, nullptr, nullptr, descr_B, 0, (T*)nullptr, nullptr, nullptr, dbeta, descr_D, nnz_D, dDval, dDptr, dDcol, descr_C, dCval, dCptr, dCcol, info, dbuffer)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val_C_2.data(), dCval, sizeof(T) * nnz_C_gold, hipMemcpyDeviceToHost)); // Check device pointer results unit_check_near(1, nnz_C_gold, 1, hcsr_val_C_gold.data(), hcsr_val_C_2.data()); #endif } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRGEMM2_B_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_csric02.hpp000066400000000000000000000405771501764003400227740ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSRIC0_HPP #define TESTING_CSRIC0_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csric02_bad_arg(void) { #if(!defined(CUDART_VERSION)) int m = 100; int nnz = 100; int safe_size = 100; hipsparseSolvePolicy_t policy = HIPSPARSE_SOLVE_POLICY_USE_LEVEL; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_csric02(new csric02_struct); csric02Info_t info = unique_ptr_csric02->info; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); void* dbuffer = (void*)dbuffer_managed.get(); int size; int position; verify_hipsparse_status_invalid_pointer( hipsparseXcsric02_bufferSize(handle, m, nnz, descr, dval, (int*)nullptr, dcol, info, &size), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02_bufferSize(handle, m, nnz, descr, dval, dptr, (int*)nullptr, info, &size), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02_bufferSize(handle, m, nnz, descr, (T*)nullptr, dptr, dcol, info, &size), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02_bufferSize(handle, m, nnz, descr, dval, dptr, dcol, info, (int*)nullptr), "Error: size is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02_bufferSize( handle, m, nnz, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, info, &size), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02_bufferSize( handle, m, nnz, descr, dval, dptr, dcol, (csric02Info_t) nullptr, &size), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsric02_bufferSize( (hipsparseHandle_t) nullptr, m, nnz, descr, dval, dptr, dcol, info, &size)); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02_analysis( handle, m, nnz, descr, dval, (int*)nullptr, dcol, info, policy, dbuffer), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02_analysis( handle, m, nnz, descr, dval, dptr, (int*)nullptr, info, policy, dbuffer), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02_analysis( handle, m, nnz, descr, (T*)nullptr, dptr, dcol, info, policy, dbuffer), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02_analysis( handle, m, nnz, descr, dval, dptr, dcol, info, policy, (void*)nullptr), "Error: dbuffer is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02_analysis( handle, m, nnz, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, info, policy, dbuffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02_analysis( handle, m, nnz, descr, dval, dptr, dcol, (csric02Info_t) nullptr, policy, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsric02_analysis( (hipsparseHandle_t) nullptr, m, nnz, descr, dval, dptr, dcol, info, policy, dbuffer)); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02(handle, m, nnz, descr, dval, (int*)nullptr, dcol, info, policy, dbuffer), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02(handle, m, nnz, descr, dval, dptr, (int*)nullptr, info, policy, dbuffer), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02(handle, m, nnz, descr, (T*)nullptr, dptr, dcol, info, policy, dbuffer), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02(handle, m, nnz, descr, dval, dptr, dcol, info, policy, (void*)nullptr), "Error: dbuffer is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02( handle, m, nnz, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, info, policy, dbuffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02( handle, m, nnz, descr, dval, dptr, dcol, (csric02Info_t) nullptr, policy, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsric02( (hipsparseHandle_t) nullptr, m, nnz, descr, dval, dptr, dcol, info, policy, dbuffer)); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02_zeroPivot(handle, info, (int*)nullptr), "Error: position is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02_zeroPivot(handle, (csric02Info_t) nullptr, &position), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXcsric02_zeroPivot((hipsparseHandle_t) nullptr, info, &position)); #endif } template hipsparseStatus_t testing_csric02(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) int m = argus.M; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseSolvePolicy_t policy = argus.solve_policy; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_csric02(new csric02_struct); csric02Info_t info = unique_ptr_csric02->info; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); if(m == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse only accepts m > 1 return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, m, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hcsr_val_orig(hcsr_val); // Allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dval_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dval_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto d_analysis_pivot_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; auto d_solve_pivot_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval_1 = (T*)dval_1_managed.get(); T* dval_2 = (T*)dval_2_managed.get(); int* d_analysis_pivot_2 = (int*)d_analysis_pivot_2_managed.get(); int* d_solve_pivot_2 = (int*)d_solve_pivot_2_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval_1, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval_2, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); // Obtain csric02 buffer size int bufferSize; CHECK_HIPSPARSE_ERROR( hipsparseXcsric02_bufferSize(handle, m, nnz, descr, dval_1, dptr, dcol, info, &bufferSize)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * bufferSize), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); int h_analysis_pivot_gold; int h_analysis_pivot_1; int h_analysis_pivot_2; int h_solve_pivot_gold; int h_solve_pivot_1; int h_solve_pivot_2; hipsparseStatus_t status_analysis_1; hipsparseStatus_t status_analysis_2; hipsparseStatus_t status_solve_1; hipsparseStatus_t status_solve_2; if(argus.unit_check) { // csric02 analysis - host mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsric02_analysis( handle, m, nnz, descr, dval_1, dptr, dcol, info, policy, dbuffer)); // Get pivot status_analysis_1 = hipsparseXcsric02_zeroPivot(handle, info, &h_analysis_pivot_1); if(h_analysis_pivot_1 != -1) { verify_hipsparse_status_zero_pivot(status_analysis_1, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); } // csric02 analysis - device mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsric02_analysis( handle, m, nnz, descr, dval_2, dptr, dcol, info, policy, dbuffer)); // Get pivot status_analysis_2 = hipsparseXcsric02_zeroPivot(handle, info, d_analysis_pivot_2); if(h_analysis_pivot_1 != -1) { verify_hipsparse_status_zero_pivot(status_analysis_2, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); } // csric02 solve - host mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseXcsric02(handle, m, nnz, descr, dval_1, dptr, dcol, info, policy, dbuffer)); // Get pivot status_solve_1 = hipsparseXcsric02_zeroPivot(handle, info, &h_solve_pivot_1); if(h_solve_pivot_1 != -1) { verify_hipsparse_status_zero_pivot(status_solve_1, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); } // csric02 solve - device mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseXcsric02(handle, m, nnz, descr, dval_2, dptr, dcol, info, policy, dbuffer)); // Get pivot status_solve_2 = hipsparseXcsric02_zeroPivot(handle, info, d_solve_pivot_2); if(h_solve_pivot_1 != -1) { verify_hipsparse_status_zero_pivot(status_solve_2, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); } // Copy output from device to CPU std::vector result_1(nnz); std::vector result_2(nnz); CHECK_HIP_ERROR(hipMemcpy(result_1.data(), dval_1, sizeof(T) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(result_2.data(), dval_2, sizeof(T) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(&h_analysis_pivot_2, d_analysis_pivot_2, sizeof(int), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(&h_solve_pivot_2, d_solve_pivot_2, sizeof(int), hipMemcpyDeviceToHost)); // Host csric02 csric0(m, hcsr_row_ptr.data(), hcsr_col_ind.data(), hcsr_val.data(), idx_base, h_analysis_pivot_gold, h_solve_pivot_gold); #ifndef __HIP_PLATFORM_NVIDIA__ // Do not check pivots in cusparse unit_check_general(1, 1, 1, &h_analysis_pivot_gold, &h_analysis_pivot_1); unit_check_general(1, 1, 1, &h_analysis_pivot_gold, &h_analysis_pivot_2); unit_check_general(1, 1, 1, &h_solve_pivot_gold, &h_solve_pivot_1); unit_check_general(1, 1, 1, &h_solve_pivot_gold, &h_solve_pivot_2); #endif if(h_analysis_pivot_gold == -1 && h_solve_pivot_gold == -1) { unit_check_near(1, nnz, 1, hcsr_val.data(), result_1.data()); unit_check_near(1, nnz, 1, hcsr_val.data(), result_2.data()); } } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIP_ERROR( hipMemcpy(dval_1, hcsr_val_orig.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIPSPARSE_ERROR(hipsparseXcsric02( handle, m, nnz, descr, dval_1, dptr, dcol, info, policy, dbuffer)); } double gpu_time_used = 0; // Solve run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIP_ERROR( hipMemcpy(dval_1, hcsr_val_orig.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); double temp = get_time_us(); CHECK_HIPSPARSE_ERROR(hipsparseXcsric02( handle, m, nnz, descr, dval_1, dptr, dcol, info, policy, dbuffer)); gpu_time_used += (get_time_us() - temp); } gpu_time_used = gpu_time_used / number_hot_calls; double gbyte_count = csric0_gbyte_count(m, nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::nnz, nnz, display_key_t::solve_policy, hipsparse_solvepolicy2string(policy), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRIC0_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_csrilu02.hpp000066400000000000000000000420561501764003400231640ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2018-2019 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSRILU0_HPP #define TESTING_CSRILU0_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csrilu02_bad_arg(void) { #if(!defined(CUDART_VERSION)) int m = 100; int nnz = 100; int safe_size = 100; hipsparseSolvePolicy_t policy = HIPSPARSE_SOLVE_POLICY_USE_LEVEL; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_csrilu02(new csrilu02_struct); csrilu02Info_t info = unique_ptr_csrilu02->info; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; auto dboost_tol_managed = hipsparse_unique_ptr{device_malloc(sizeof(double)), device_free}; auto dboost_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); void* dbuffer = (void*)dbuffer_managed.get(); double* dboost_tol = (double*)dboost_tol_managed.get(); T* dboost_val = (T*)dboost_val_managed.get(); int size; int position; verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02_bufferSize( handle, m, nnz, descr, dval, (int*)nullptr, dcol, info, &size), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02_bufferSize( handle, m, nnz, descr, dval, dptr, (int*)nullptr, info, &size), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02_bufferSize(handle, m, nnz, descr, (T*)nullptr, dptr, dcol, info, &size), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02_bufferSize(handle, m, nnz, descr, dval, dptr, dcol, info, (int*)nullptr), "Error: size is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02_bufferSize( handle, m, nnz, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, info, &size), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02_bufferSize( handle, m, nnz, descr, dval, dptr, dcol, (csrilu02Info_t) nullptr, &size), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrilu02_bufferSize( (hipsparseHandle_t) nullptr, m, nnz, descr, dval, dptr, dcol, info, &size)); verify_hipsparse_status_invalid_handle(hipsparseXcsrilu02_numericBoost( (hipsparseHandle_t) nullptr, info, 1, dboost_tol, dboost_val)); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02_numericBoost( handle, (csrilu02Info_t) nullptr, 1, dboost_tol, dboost_val), "Error: info is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02_numericBoost(handle, info, 1, (double*)nullptr, dboost_val), "Error: boost_tol is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02_numericBoost(handle, info, 1, dboost_tol, (T*)nullptr), "Error: boost_val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02_analysis( handle, m, nnz, descr, dval, (int*)nullptr, dcol, info, policy, dbuffer), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02_analysis( handle, m, nnz, descr, dval, dptr, (int*)nullptr, info, policy, dbuffer), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02_analysis( handle, m, nnz, descr, (T*)nullptr, dptr, dcol, info, policy, dbuffer), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02_analysis( handle, m, nnz, descr, dval, dptr, dcol, info, policy, (void*)nullptr), "Error: dbuffer is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02_analysis( handle, m, nnz, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, info, policy, dbuffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02_analysis( handle, m, nnz, descr, dval, dptr, dcol, (csrilu02Info_t) nullptr, policy, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrilu02_analysis( (hipsparseHandle_t) nullptr, m, nnz, descr, dval, dptr, dcol, info, policy, dbuffer)); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02(handle, m, nnz, descr, dval, (int*)nullptr, dcol, info, policy, dbuffer), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02(handle, m, nnz, descr, dval, dptr, (int*)nullptr, info, policy, dbuffer), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02(handle, m, nnz, descr, (T*)nullptr, dptr, dcol, info, policy, dbuffer), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02(handle, m, nnz, descr, dval, dptr, dcol, info, policy, (void*)nullptr), "Error: dbuffer is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02( handle, m, nnz, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, info, policy, dbuffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02( handle, m, nnz, descr, dval, dptr, dcol, (csrilu02Info_t) nullptr, policy, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrilu02( (hipsparseHandle_t) nullptr, m, nnz, descr, dval, dptr, dcol, info, policy, dbuffer)); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02_zeroPivot(handle, info, (int*)nullptr), "Error: position is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02_zeroPivot(handle, (csrilu02Info_t) nullptr, &position), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXcsrilu02_zeroPivot((hipsparseHandle_t) nullptr, info, &position)); #endif } template hipsparseStatus_t testing_csrilu02(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) int m = argus.M; int boost = argus.numericboost; double boost_tol = argus.boosttol; T boost_val = make_DataType(argus.boostval, argus.boostvali); hipsparseIndexBase_t idx_base = argus.baseA; hipsparseSolvePolicy_t policy = argus.solve_policy; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_csrilu02(new csrilu02_struct); csrilu02Info_t info = unique_ptr_csrilu02->info; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); if(m == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse only accepts m > 1 return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, m, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hcsr_val_orig(hcsr_val); // Allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dval1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dval2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto d_position_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; auto boost_tol_managed = hipsparse_unique_ptr{device_malloc(sizeof(double)), device_free}; auto boost_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval1 = (T*)dval1_managed.get(); T* dval2 = (T*)dval2_managed.get(); int* d_position = (int*)d_position_managed.get(); double* dboost_tol = (double*)boost_tol_managed.get(); T* dboost_val = (T*)boost_val_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval1, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval2, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); // Obtain csrilu02 buffer size int bufferSize; CHECK_HIPSPARSE_ERROR( hipsparseXcsrilu02_bufferSize(handle, m, nnz, descr, dval1, dptr, dcol, info, &bufferSize)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * bufferSize), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); if(argus.unit_check) { CHECK_HIP_ERROR(hipMemcpy(dboost_tol, &boost_tol, sizeof(double), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dboost_val, &boost_val, sizeof(T), hipMemcpyHostToDevice)); // Pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrilu02_analysis( handle, m, nnz, descr, dval1, dptr, dcol, info, policy, dbuffer)); CHECK_HIPSPARSE_ERROR( hipsparseXcsrilu02_numericBoost(handle, info, boost, &boost_tol, &boost_val)); CHECK_HIPSPARSE_ERROR( hipsparseXcsrilu02(handle, m, nnz, descr, dval1, dptr, dcol, info, policy, dbuffer)); int hposition_1; hipsparseStatus_t pivot_status_1; pivot_status_1 = hipsparseXcsrilu02_zeroPivot(handle, info, &hposition_1); // Pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrilu02_analysis( handle, m, nnz, descr, dval2, dptr, dcol, info, policy, dbuffer)); CHECK_HIPSPARSE_ERROR( hipsparseXcsrilu02_numericBoost(handle, info, boost, dboost_tol, dboost_val)); CHECK_HIPSPARSE_ERROR( hipsparseXcsrilu02(handle, m, nnz, descr, dval2, dptr, dcol, info, policy, dbuffer)); int hposition_2; hipsparseStatus_t pivot_status_2; pivot_status_2 = hipsparseXcsrilu02_zeroPivot(handle, info, d_position); CHECK_HIP_ERROR(hipMemcpy(&hposition_2, d_position, sizeof(int), hipMemcpyDeviceToHost)); // Copy output from device to CPU std::vector result1(nnz); std::vector result2(nnz); CHECK_HIP_ERROR(hipMemcpy(result1.data(), dval1, sizeof(T) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(result2.data(), dval2, sizeof(T) * nnz, hipMemcpyDeviceToHost)); // Host csrilu02 int position_gold = csrilu0(m, hcsr_row_ptr.data(), hcsr_col_ind.data(), hcsr_val.data(), idx_base, boost, boost_tol, boost_val); unit_check_general(1, 1, 1, &position_gold, &hposition_1); unit_check_general(1, 1, 1, &position_gold, &hposition_2); if(hposition_1 != -1) { verify_hipsparse_status_zero_pivot(pivot_status_1, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); return HIPSPARSE_STATUS_SUCCESS; } if(hposition_2 != -1) { verify_hipsparse_status_zero_pivot(pivot_status_2, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); return HIPSPARSE_STATUS_SUCCESS; } #if defined(__HIP_PLATFORM_AMD__) unit_check_general(1, nnz, 1, hcsr_val.data(), result1.data()); unit_check_general(1, nnz, 1, hcsr_val.data(), result2.data()); #elif defined(__HIP_PLATFORM_NVIDIA__) // do weaker check for cusparse unit_check_near(1, nnz, 1, hcsr_val.data(), result1.data()); unit_check_near(1, nnz, 1, hcsr_val.data(), result2.data()); #endif } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIP_ERROR( hipMemcpy(dval1, hcsr_val_orig.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrilu02( handle, m, nnz, descr, dval1, dptr, dcol, info, policy, dbuffer)); } double gpu_time_used = 0; // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIP_ERROR( hipMemcpy(dval1, hcsr_val_orig.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); double temp = get_time_us(); CHECK_HIPSPARSE_ERROR(hipsparseXcsrilu02( handle, m, nnz, descr, dval1, dptr, dcol, info, policy, dbuffer)); gpu_time_used += (get_time_us() - temp); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = csrilu0_gbyte_count(m, nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::nnz, nnz, display_key_t::solve_policy, hipsparse_solvepolicy2string(policy), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRILU0_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_csrilusv.hpp000066400000000000000000000502321501764003400233660ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2018-2019 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSRILUSV_HPP #define TESTING_CSRILUSV_HPP #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include #include #include using namespace hipsparse; using namespace hipsparse_test; template hipsparseStatus_t testing_csrilusv(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) hipsparseIndexBase_t idx_base = argus.baseA; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_M(new descr_struct); hipsparseMatDescr_t descr_M = unique_ptr_descr_M->descr; std::unique_ptr unique_ptr_csrilu02_info(new csrilu02_struct); csrilu02Info_t info_M = unique_ptr_csrilu02_info->info; // Initialize the matrix descriptor CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_M, idx_base)); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Initial Data on CPU int m; int n; int nnz; if(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(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); // Obtain csrilu02 buffer size int size; CHECK_HIPSPARSE_ERROR( hipsparseXcsrilu02_bufferSize(handle, m, nnz, descr_M, dval, dptr, dcol, info_M, &size)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * size), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); // csrilu02 analysis CHECK_HIPSPARSE_ERROR(hipsparseXcsrilu02_analysis(handle, m, nnz, descr_M, dval, dptr, dcol, info_M, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer)); // Compute incomplete LU factorization CHECK_HIPSPARSE_ERROR(hipsparseXcsrilu02(handle, m, nnz, descr_M, dval, dptr, dcol, info_M, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer)); // Check for zero pivot int hposition_1, hposition_2; hipsparseStatus_t pivot_status_1, pivot_status_2; // Host pointer mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); pivot_status_1 = hipsparseXcsrilu02_zeroPivot(handle, info_M, &hposition_1); // device pointer mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); pivot_status_2 = hipsparseXcsrilu02_zeroPivot(handle, info_M, d_position); // Copy output to CPU std::vector iluresult(nnz); CHECK_HIP_ERROR(hipMemcpy(iluresult.data(), dval, sizeof(T) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(&hposition_2, d_position, sizeof(int), hipMemcpyDeviceToHost)); // Compute host reference csrilu0 int position_gold = csrilu0(m, hcsr_row_ptr.data(), hcsr_col_ind.data(), hcsr_val.data(), idx_base, false, 0.0, make_DataType(0.0, 0.0)); // Check zero pivot results unit_check_general(1, 1, 1, &position_gold, &hposition_1); unit_check_general(1, 1, 1, &position_gold, &hposition_2); // If zero pivot was found, do not go further if(hposition_1 != -1) { verify_hipsparse_status_zero_pivot(pivot_status_1, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); return HIPSPARSE_STATUS_SUCCESS; } if(hposition_2 != -1) { verify_hipsparse_status_zero_pivot(pivot_status_2, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); return HIPSPARSE_STATUS_SUCCESS; } // Check csrilu0 factorization #if defined(__HIP_PLATFORM_AMD__) unit_check_general(1, nnz, 1, hcsr_val.data(), iluresult.data()); #elif defined(__HIP_PLATFORM_NVIDIA__) unit_check_near(1, nnz, 1, hcsr_val.data(), iluresult.data()); #endif // Create info structs for lower and upper part std::unique_ptr unique_ptr_csrsv2_lower(new csrsv2_struct); std::unique_ptr unique_ptr_csrsv2_upper(new csrsv2_struct); csrsv2Info_t info_L = unique_ptr_csrsv2_lower->info; csrsv2Info_t info_U = unique_ptr_csrsv2_upper->info; // Create matrix descriptors for csrsv std::unique_ptr unique_ptr_descr_L(new descr_struct); hipsparseMatDescr_t descr_L = unique_ptr_descr_L->descr; CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_L, idx_base)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatFillMode(descr_L, HIPSPARSE_FILL_MODE_LOWER)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatDiagType(descr_L, HIPSPARSE_DIAG_TYPE_UNIT)); std::unique_ptr unique_ptr_descr_U(new descr_struct); hipsparseMatDescr_t descr_U = unique_ptr_descr_U->descr; CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_U, idx_base)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatFillMode(descr_U, HIPSPARSE_FILL_MODE_UPPER)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatDiagType(descr_U, HIPSPARSE_DIAG_TYPE_NON_UNIT)); // Obtain csrsv buffer sizes int size_lower, size_upper; CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_bufferSize(handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, m, nnz, descr_L, dval, dptr, dcol, info_L, &size_lower)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_bufferSize(handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, m, nnz, descr_U, dval, dptr, dcol, info_U, &size_upper)); // Pick maximum size so that we need only one buffer size = std::max(size_lower, size_upper); // Allocate buffer on the device auto dbuffer_sv_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * size), device_free}; void* dbuffer_sv = (void*)dbuffer_sv_managed.get(); // csrsv analysis CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_analysis(handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, m, nnz, descr_L, dval, dptr, dcol, info_L, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer_sv)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_analysis(handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, m, nnz, descr_U, dval, dptr, dcol, info_U, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer_sv)); // Initialize some more structures required for Lz = x T h_alpha = static_cast(1); std::vector hx(m, static_cast(1)); std::vector hy_gold(m); std::vector hz_gold(m); // Allocate device memory auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dz_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dz_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; T* dx = (T*)dx_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* dz_1 = (T*)dz_1_managed.get(); T* dz_2 = (T*)dz_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); // Copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dx, hx.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); // Solve Lz = x // host pointer mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_solve(handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, m, nnz, &h_alpha, descr_L, dval, dptr, dcol, info_L, dx, dz_1, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer_sv)); // Check for zero pivot pivot_status_1 = hipsparseXcsrsv2_zeroPivot(handle, info_L, &hposition_1); // device pointer mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_solve(handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, m, nnz, d_alpha, descr_L, dval, dptr, dcol, info_L, dx, dz_2, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer_sv)); // Check for zero pivot pivot_status_2 = hipsparseXcsrsv2_zeroPivot(handle, info_L, d_position); // Host csrsv hipDeviceProp_t prop; 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-6.4.3/clients/include/testing_csrmm.hpp000066400000000000000000000714171501764003400226450ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2018-2019 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSRMM_HPP #define TESTING_CSRMM_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csrmm_bad_arg(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; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dC_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dB = (T*)dB_managed.get(); T* dC = (T*)dC_managed.get(); verify_hipsparse_status_invalid_size(hipsparseXcsrmm2(handle, transA, transB, -1, N, K, nnz, &alpha, descr, dval, dptr, dcol, dB, ldb, &beta, dC, ldc), "Error: M < 0"); verify_hipsparse_status_invalid_size(hipsparseXcsrmm2(handle, transA, transB, M, -1, K, nnz, &alpha, descr, dval, dptr, dcol, dB, ldb, &beta, dC, ldc), "Error: N < 0"); verify_hipsparse_status_invalid_size(hipsparseXcsrmm2(handle, transA, transB, M, N, -1, nnz, &alpha, descr, dval, dptr, dcol, dB, ldb, &beta, dC, ldc), "Error: K < 0"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &alpha, descr, dval, (int*)nullptr, dcol, dB, ldb, &beta, dC, ldc), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &alpha, descr, dval, dptr, (int*)nullptr, dB, ldb, &beta, dC, ldc), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &alpha, descr, (T*)nullptr, dptr, dcol, dB, ldb, &beta, dC, ldc), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &alpha, descr, dval, dptr, dcol, (T*)nullptr, ldb, &beta, dC, ldc), "Error: dB is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &alpha, descr, dval, dptr, dcol, dB, ldb, &beta, (T*)nullptr, ldc), "Error: dC is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, (T*)nullptr, descr, dval, dptr, dcol, dB, ldb, &beta, dC, ldc), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &alpha, descr, dval, dptr, dcol, dB, ldb, (T*)nullptr, dC, ldc), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &alpha, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, dB, ldb, &beta, dC, ldc), "Error: descr is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrmm2((hipsparseHandle_t) nullptr, transA, transB, M, N, K, nnz, &alpha, descr, dval, dptr, dcol, dB, ldb, &beta, dC, ldc)); #endif } template hipsparseStatus_t testing_csrmm(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) int M = argus.M; int N = argus.N; int K = argus.K; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseOperation_t transB = argus.transB; hipsparseIndexBase_t idx_base = argus.baseA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); srand(12345ULL); // Host structures std::vector hcsr_row_ptrA; std::vector hcsr_col_indA; std::vector hcsr_valA; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, M, K, nnz, hcsr_row_ptrA, hcsr_col_indA, hcsr_valA, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Some matrix properties int A_m = M; int B_m = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE ? K : M) : N; int B_n = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? N : (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE ? K : M); int C_m = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE ? M : K); int C_n = N; int ldb = B_m; int ldc = C_m; int nrowB = ldb; int ncolB = B_n; int nrowC = ldc; int ncolC = C_n; int Bnnz = nrowB * ncolB; int Cnnz = nrowC * ncolC; // Host structures - Dense matrix B and C std::vector hB(Bnnz); std::vector hC_1(Cnnz); std::vector hC_2(Cnnz); std::vector hC_gold(Cnnz); hipsparseInit(hB, nrowB, ncolB); hipsparseInit(hC_1, nrowC, ncolC); // copy vector is easy in STL; hC_gold = hC_1: save a copy in hy_gold which will be output of // CPU hC_gold = hC_1; hC_2 = hC_1; // allocate memory on device auto dcsr_row_ptrA_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (A_m + 1)), device_free}; auto dcsr_col_indA_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_valA_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * Bnnz), device_free}; auto dC_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * Cnnz), device_free}; auto dC_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * Cnnz), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dcsr_row_ptrA = (int*)dcsr_row_ptrA_managed.get(); int* dcsr_col_indA = (int*)dcsr_col_indA_managed.get(); T* dcsr_valA = (T*)dcsr_valA_managed.get(); T* dB = (T*)dB_managed.get(); T* dC_1 = (T*)dC_1_managed.get(); T* dC_2 = (T*)dC_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy( dcsr_row_ptrA, hcsr_row_ptrA.data(), sizeof(int) * (A_m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_indA, hcsr_col_indA.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_valA, hcsr_valA.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * Bnnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_1, hC_1.data(), sizeof(T) * Cnnz, hipMemcpyHostToDevice)); if(argus.unit_check) { CHECK_HIP_ERROR(hipMemcpy(dC_2, hC_2.data(), sizeof(T) * Cnnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &h_alpha, descr, dcsr_valA, dcsr_row_ptrA, dcsr_col_indA, dB, ldb, &h_beta, dC_1, ldc)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, d_alpha, descr, dcsr_valA, dcsr_row_ptrA, dcsr_col_indA, dB, ldb, d_beta, dC_2, ldc)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hC_1.data(), dC_1, sizeof(T) * Cnnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hC_2.data(), dC_2, sizeof(T) * Cnnz, hipMemcpyDeviceToHost)); // CPU host_csrmm(M, N, K, transA, transB, h_alpha, hcsr_row_ptrA.data(), hcsr_col_indA.data(), hcsr_valA.data(), hB.data(), ldb, HIPSPARSE_ORDER_COL, h_beta, hC_gold.data(), ldc, HIPSPARSE_ORDER_COL, idx_base, false); unit_check_near(nrowC, ncolC, ldc, hC_gold.data(), hC_1.data()); unit_check_near(nrowC, ncolC, ldc, hC_gold.data(), hC_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &h_alpha, descr, dcsr_valA, dcsr_row_ptrA, dcsr_col_indA, dB, ldb, &h_beta, dC_1, ldc)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &h_alpha, descr, dcsr_valA, dcsr_row_ptrA, dcsr_col_indA, dB, ldb, &h_beta, dC_1, ldc)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = csrmm_gflop_count(B_m, nnz, C_m * C_n, h_beta != make_DataType(0.0)); double gbyte_count = csrmm_gbyte_count( A_m, nnz, B_m * B_n, C_m * C_n, h_beta != make_DataType(0.0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, M, display_key_t::N, N, display_key_t::K, K, display_key_t::transA, hipsparse_operation2string(transA), display_key_t::transB, hipsparse_operation2string(transB), display_key_t::nnzA, nnz, display_key_t::nnzB, B_m * B_n, display_key_t::nnzC, C_m * C_n, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRMM_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_csrmv.hpp000066400000000000000000000342351501764003400226530ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2018-2019 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSRMV_HPP #define TESTING_CSRMV_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csrmv_bad_arg(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; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dx = (T*)dx_managed.get(); T* dy = (T*)dy_managed.get(); verify_hipsparse_status_invalid_pointer( hipsparseXcsrmv( handle, transA, m, n, nnz, &alpha, descr, dval, (int*)nullptr, dcol, dx, &beta, dy), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrmv( handle, transA, m, n, nnz, &alpha, descr, dval, dptr, (int*)nullptr, dx, &beta, dy), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrmv( handle, transA, m, n, nnz, &alpha, descr, (T*)nullptr, dptr, dcol, dx, &beta, dy), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrmv( handle, transA, m, n, nnz, &alpha, descr, dval, dptr, dcol, (T*)nullptr, &beta, dy), "Error: dx is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrmv( handle, transA, m, n, nnz, &alpha, descr, dval, dptr, dcol, dx, &beta, (T*)nullptr), "Error: dy is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrmv( handle, transA, m, n, nnz, (T*)nullptr, descr, dval, dptr, dcol, dx, &beta, dy), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrmv( handle, transA, m, n, nnz, &alpha, descr, dval, dptr, dcol, dx, (T*)nullptr, dy), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrmv(handle, transA, m, n, nnz, &alpha, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, dx, &beta, dy), "Error: descr is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrmv((hipsparseHandle_t) nullptr, transA, m, n, nnz, &alpha, descr, dval, dptr, dcol, dx, &beta, dy)); #endif } template hipsparseStatus_t testing_csrmv(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) int nrow = argus.M; int ncol = argus.N; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseIndexBase_t idx_base = argus.baseA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix( filename, nrow, ncol, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } int m = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? nrow : ncol; int n = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? ncol : nrow; std::vector hx(n); std::vector hy_1(m); std::vector hy_2(m); std::vector hy_gold(m); hipsparseInit(hx, 1, n); hipsparseInit(hy_1, 1, m); // copy vector is easy in STL; hy_gold = hx: save a copy in hy_gold which will be output of CPU hy_2 = hy_1; hy_gold = hy_1; // allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (nrow + 1)), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * n), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dx = (T*)dx_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsr_row_ptr.data(), sizeof(int) * (nrow + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx, hx.data(), sizeof(T) * n, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_1, hy_1.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); if(argus.unit_check) { CHECK_HIP_ERROR(hipMemcpy(dy_2, hy_2.data(), sizeof(T) * m, hipMemcpyHostToDevice)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrmv( handle, transA, nrow, ncol, nnz, &h_alpha, descr, dval, dptr, dcol, dx, &h_beta, dy_1)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrmv( handle, transA, nrow, ncol, nnz, d_alpha, descr, dval, dptr, dcol, dx, d_beta, dy_2)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hy_1.data(), dy_1, sizeof(T) * m, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_2.data(), dy_2, sizeof(T) * m, hipMemcpyDeviceToHost)); host_csrmv(transA, nrow, ncol, nnz, h_alpha, hcsr_row_ptr.data(), hcsr_col_ind.data(), hcsr_val.data(), hx.data(), h_beta, hy_gold.data(), idx_base); unit_check_near(1, m, 1, hy_gold.data(), hy_1.data()); unit_check_near(1, m, 1, hy_gold.data(), hy_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrmv(handle, transA, nrow, ncol, nnz, &h_alpha, descr, dval, dptr, dcol, dx, &h_beta, dy_1)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrmv(handle, transA, nrow, ncol, nnz, &h_alpha, descr, dval, dptr, dcol, dx, &h_beta, dy_1)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = spmv_gflop_count(nrow, nnz, h_beta != make_DataType(0.0)); double gbyte_count = csrmv_gbyte_count(nrow, ncol, nnz, h_beta != make_DataType(0.0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, nrow, display_key_t::N, ncol, display_key_t::nnz, nnz, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRMV_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_csrsm2.hpp000066400000000000000000001605421501764003400227330ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSRSM2_HPP #define TESTING_CSRSM2_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csrsm2_bad_arg(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; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_csrsm2_info(new csrsm2_struct); csrsm2Info_t info = unique_ptr_csrsm2_info->info; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dB = (T*)dB_managed.get(); void* dbuffer = (void*)dbuffer_managed.get(); size_t size; int position; verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, (T*)nullptr, descr, dval, dptr, dcol, dB, safe_size, info, policy, &size), "Error: dalpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, (int*)nullptr, dcol, dB, safe_size, info, policy, &size), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, (int*)nullptr, dB, safe_size, info, policy, &size), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, (T*)nullptr, dptr, dcol, dB, safe_size, info, policy, &size), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, info, policy, (size_t*)nullptr), "Error: size is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, dB, safe_size, info, policy, &size), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, (csrsm2Info_t) nullptr, policy, &size), "Error: info is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, (T*)nullptr, safe_size, info, policy, &size), "Error: dB is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXcsrsm2_bufferSizeExt((hipsparseHandle_t) nullptr, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, info, policy, &size)); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, (T*)nullptr, descr, dval, dptr, dcol, dB, safe_size, info, policy, dbuffer), "Error: dalpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, (int*)nullptr, dcol, dB, safe_size, info, policy, dbuffer), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, (int*)nullptr, dB, safe_size, info, policy, dbuffer), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, (T*)nullptr, dptr, dcol, dB, safe_size, info, policy, dbuffer), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, info, policy, (void*)nullptr), "Error: dbuffer is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, dB, safe_size, info, policy, dbuffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, (T*)nullptr, safe_size, info, policy, dbuffer), "Error: dB is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, (csrsm2Info_t) nullptr, policy, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrsm2_analysis((hipsparseHandle_t) nullptr, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, info, policy, dbuffer)); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, (int*)nullptr, dcol, dB, safe_size, info, policy, dbuffer), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, (int*)nullptr, dB, safe_size, info, policy, dbuffer), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, (T*)nullptr, dptr, dcol, dB, safe_size, info, policy, dbuffer), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, (T*)nullptr, safe_size, info, policy, dbuffer), "Error: dB is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, (T*)nullptr, descr, dval, dptr, dcol, dB, safe_size, info, policy, dbuffer), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, info, policy, (void*)nullptr), "Error: dbuffer is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, dB, safe_size, info, policy, dbuffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, (csrsm2Info_t) nullptr, policy, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrsm2_solve((hipsparseHandle_t) nullptr, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, info, policy, dbuffer)); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_zeroPivot(handle, info, (int*)nullptr), "Error: position is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsm2_zeroPivot(handle, (csrsm2Info_t) nullptr, &position), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXcsrsm2_zeroPivot((hipsparseHandle_t) nullptr, info, &position)); #endif } template hipsparseStatus_t testing_csrsm2(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int m = argus.M; int nrhs = argus.N; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseOperation_t transA = argus.transA; hipsparseOperation_t transB = argus.transB; hipsparseDiagType_t diag = argus.diag_type; hipsparseFillMode_t uplo = argus.fill_mode; hipsparseSolvePolicy_t policy = argus.solve_policy; T h_alpha = make_DataType(argus.alpha); std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_csrsm2_info(new csrsm2_struct); csrsm2Info_t info = unique_ptr_csrsm2_info->info; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); // Set matrix diag type CHECK_HIPSPARSE_ERROR(hipsparseSetMatDiagType(descr, diag)); // Set matrix fill mode CHECK_HIPSPARSE_ERROR(hipsparseSetMatFillMode(descr, uplo)); srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, m, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } int ldb = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : nrhs; std::vector hB_1(m * nrhs); std::vector hB_2(m * nrhs); std::vector hB_gold(m * nrhs); int h_analysis_pivot_gold; int h_analysis_pivot_1; int h_analysis_pivot_2; int h_solve_pivot_gold; int h_solve_pivot_1; int h_solve_pivot_2; hipsparseInit(hB_1, 1, m * nrhs); hB_2 = hB_1; hB_gold = hB_1; // Allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dB_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * nrhs), device_free}; auto dB_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * nrhs), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_analysis_pivot_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; auto d_solve_pivot_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dB_1 = (T*)dB_1_managed.get(); T* dB_2 = (T*)dB_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); int* d_analysis_pivot_2 = (int*)d_analysis_pivot_2_managed.get(); int* d_solve_pivot_2 = (int*)d_solve_pivot_2_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB_1, hB_1.data(), sizeof(T) * m * nrhs, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); // Obtain csrsm2 buffer size size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB_1, ldb, info, policy, &bufferSize)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * bufferSize), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); hipsparseStatus_t status_analysis_1; hipsparseStatus_t status_analysis_2; hipsparseStatus_t status_solve_1; hipsparseStatus_t status_solve_2; CHECK_HIP_ERROR(hipMemcpy(dB_2, hB_2.data(), sizeof(T) * m * nrhs, hipMemcpyHostToDevice)); // csrsm2 analysis - host mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB_1, ldb, info, policy, dbuffer)); // Get pivot status_analysis_1 = hipsparseXcsrsm2_zeroPivot(handle, info, &h_analysis_pivot_1); if(h_analysis_pivot_1 != -1) { verify_hipsparse_status_zero_pivot(status_analysis_1, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); } // csrsm2 analysis - device mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, d_alpha, descr, dval, dptr, dcol, dB_2, ldb, info, policy, dbuffer)); // Get pivot status_analysis_2 = hipsparseXcsrsm2_zeroPivot(handle, info, d_analysis_pivot_2); if(h_analysis_pivot_1 != -1) { verify_hipsparse_status_zero_pivot(status_analysis_2, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); } if(argus.unit_check) { // csrsm2 solve - host mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB_1, ldb, info, policy, dbuffer)); // Get pivot status_solve_1 = hipsparseXcsrsm2_zeroPivot(handle, info, &h_solve_pivot_1); if(h_solve_pivot_1 != -1) { verify_hipsparse_status_zero_pivot(status_solve_1, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); } // csrsm2 solve - device mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, d_alpha, descr, dval, dptr, dcol, dB_2, ldb, info, policy, dbuffer)); // Get pivot status_solve_2 = hipsparseXcsrsm2_zeroPivot(handle, info, d_solve_pivot_2); if(h_solve_pivot_1 != -1) { verify_hipsparse_status_zero_pivot(status_solve_2, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); } // Copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hB_1.data(), dB_1, sizeof(T) * m * nrhs, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hB_2.data(), dB_2, sizeof(T) * m * nrhs, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(&h_analysis_pivot_2, d_analysis_pivot_2, sizeof(int), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(&h_solve_pivot_2, d_solve_pivot_2, sizeof(int), hipMemcpyDeviceToHost)); // Host csrsm2 host_csrsm2(m, nrhs, nnz, transA, transB, h_alpha, hcsr_row_ptr, hcsr_col_ind, hcsr_val, hB_gold, ldb, HIPSPARSE_ORDER_COL, diag, uplo, idx_base, &h_analysis_pivot_gold, &h_solve_pivot_gold); // Check pivots unit_check_general(1, 1, 1, &h_analysis_pivot_gold, &h_analysis_pivot_1); unit_check_general(1, 1, 1, &h_analysis_pivot_gold, &h_analysis_pivot_2); unit_check_general(1, 1, 1, &h_solve_pivot_gold, &h_solve_pivot_1); unit_check_general(1, 1, 1, &h_solve_pivot_gold, &h_solve_pivot_2); // Check solution matrix if no pivot has been found if(h_analysis_pivot_gold == -1 && h_solve_pivot_gold == -1) { unit_check_near(1, m * nrhs, 1, hB_gold.data(), hB_1.data()); unit_check_near(1, m * nrhs, 1, hB_gold.data(), hB_2.data()); } } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB_1, ldb, info, policy, dbuffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB_1, ldb, info, policy, dbuffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = csrsv_gflop_count(m, nnz, diag) * nrhs; double gbyte_count = csrsv_gbyte_count(m, nnz) * nrhs; double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::nnz, nnz, display_key_t::nrhs, nrhs, display_key_t::alpha, h_alpha, display_key_t::transA, hipsparse_operation2string(transA), display_key_t::transB, hipsparse_operation2string(transB), display_key_t::diag_type, hipsparse_diagtype2string(diag), display_key_t::fill_mode, hipsparse_fillmode2string(uplo), display_key_t::solve_policy, hipsparse_solvepolicy2string(policy), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRSM2_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_csrsort.hpp000066400000000000000000000265501501764003400232210ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2018-2019 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSRSORT_HPP #define TESTING_CSRSORT_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; void testing_csrsort_bad_arg(void) { #if(!defined(CUDART_VERSION)) int m = 100; int n = 100; int nnz = 100; int safe_size = 100; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; size_t buffer_size = 0; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto perm_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto buffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* csr_col_ind = (int*)csr_col_ind_managed.get(); int* perm = (int*)perm_managed.get(); void* buffer = (void*)buffer_managed.get(); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsort_bufferSizeExt( handle, m, n, nnz, (int*)nullptr, csr_col_ind, &buffer_size), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsort_bufferSizeExt( handle, m, n, nnz, csr_row_ptr, (int*)nullptr, &buffer_size), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsort_bufferSizeExt( handle, m, n, nnz, csr_row_ptr, csr_col_ind, (size_t*)nullptr), "Error: buffer_size is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrsort_bufferSizeExt( (hipsparseHandle_t) nullptr, m, n, nnz, csr_row_ptr, csr_col_ind, &buffer_size)); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsort(handle, m, n, nnz, descr, (int*)nullptr, csr_col_ind, perm, buffer), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsort(handle, m, n, nnz, descr, csr_row_ptr, (int*)nullptr, perm, buffer), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsort(handle, m, n, nnz, descr, csr_row_ptr, csr_col_ind, perm, (int*)nullptr), "Error: buffer is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsort(handle, m, n, nnz, (hipsparseMatDescr_t) nullptr, csr_row_ptr, csr_col_ind, perm, buffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrsort( (hipsparseHandle_t) nullptr, m, n, nnz, descr, csr_row_ptr, csr_col_ind, perm, buffer)); #endif } hipsparseStatus_t testing_csrsort(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int m = argus.M; int n = argus.N; int permute = argus.permute; hipsparseIndexBase_t idx_base = argus.baseA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Unsort CSR columns std::vector hperm(nnz); std::vector hcsr_col_ind_unsorted(nnz); std::vector hcsr_val_unsorted(nnz); hcsr_col_ind_unsorted = hcsr_col_ind; hcsr_val_unsorted = hcsr_val; for(int i = 0; i < m; ++i) { int row_begin = hcsr_row_ptr[i] - idx_base; int row_end = hcsr_row_ptr[i + 1] - idx_base; int row_nnz = row_end - row_begin; for(int j = row_begin; j < row_end; ++j) { int rng = row_begin + rand() % row_nnz; int temp_col = hcsr_col_ind_unsorted[j]; float temp_val = hcsr_val_unsorted[j]; hcsr_col_ind_unsorted[j] = hcsr_col_ind_unsorted[rng]; hcsr_val_unsorted[j] = hcsr_val_unsorted[rng]; hcsr_col_ind_unsorted[rng] = temp_col; hcsr_val_unsorted[rng] = temp_val; } } // Allocate memory on the device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * nnz), device_free}; auto dcsr_val_sorted_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * nnz), device_free}; auto dperm_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); float* dcsr_val = (float*)dcsr_val_managed.get(); float* dcsr_val_sorted = (float*)dcsr_val_sorted_managed.get(); // Set permutation vector, if asked for int* dperm = permute ? (int*)dperm_managed.get() : nullptr; // Copy data from host to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy( dcsr_col_ind, hcsr_col_ind_unsorted.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_val, hcsr_val_unsorted.data(), sizeof(float) * nnz, hipMemcpyHostToDevice)); // Obtain buffer size size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseXcsrsort_bufferSizeExt( handle, m, n, nnz, dcsr_row_ptr, dcsr_col_ind, &bufferSize)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * bufferSize), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); if(permute) { // Initialize perm with identity permutation CHECK_HIPSPARSE_ERROR(hipsparseCreateIdentityPermutation(handle, nnz, dperm)); } if(argus.unit_check) { // Sort CSR columns CHECK_HIPSPARSE_ERROR(hipsparseXcsrsort( handle, m, n, nnz, descr, dcsr_row_ptr, dcsr_col_ind, dperm, dbuffer)); if(permute) { // Sort CSR values CHECK_HIPSPARSE_ERROR(hipsparseSgthr( handle, nnz, dcsr_val, dcsr_val_sorted, dperm, HIPSPARSE_INDEX_BASE_ZERO)); } // Copy output from device to host CHECK_HIP_ERROR(hipMemcpy( hcsr_col_ind_unsorted.data(), dcsr_col_ind, sizeof(int) * nnz, hipMemcpyDeviceToHost)); if(permute) { CHECK_HIP_ERROR(hipMemcpy(hcsr_val_unsorted.data(), dcsr_val_sorted, sizeof(float) * nnz, hipMemcpyDeviceToHost)); } // Unit check unit_check_general(1, nnz, 1, hcsr_col_ind.data(), hcsr_col_ind_unsorted.data()); if(permute) { unit_check_general(1, nnz, 1, hcsr_val.data(), hcsr_val_unsorted.data()); } } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrsort( handle, m, n, nnz, descr, dcsr_row_ptr, dcsr_col_ind, dperm, dbuffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrsort( handle, m, n, nnz, descr, dcsr_row_ptr, dcsr_col_ind, dperm, dbuffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = csrsort_gbyte_count(m, nnz, permute); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::permute, (permute ? "yes" : "no"), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRSORT_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_csrsv2.hpp000066400000000000000000001002531501764003400227350ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2018-2019 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSRSV2_HPP #define TESTING_CSRSV2_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csrsv2_bad_arg(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; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_csrsv2_info(new csrsv2_struct); csrsv2Info_t info = unique_ptr_csrsv2_info->info; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dx = (T*)dx_managed.get(); T* dy = (T*)dy_managed.get(); void* dbuffer = (void*)dbuffer_managed.get(); int size; int position; verify_hipsparse_status_invalid_pointer( hipsparseXcsrsv2_bufferSize( handle, transA, m, nnz, descr, dval, (int*)nullptr, dcol, info, &size), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsv2_bufferSize( handle, transA, m, nnz, descr, dval, dptr, (int*)nullptr, info, &size), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsv2_bufferSize( handle, transA, m, nnz, descr, (T*)nullptr, dptr, dcol, info, &size), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsv2_bufferSize( handle, transA, m, nnz, descr, dval, dptr, dcol, info, (int*)nullptr), "Error: size is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsv2_bufferSize( handle, transA, m, nnz, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, info, &size), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsv2_bufferSize( handle, transA, m, nnz, descr, dval, dptr, dcol, (csrsv2Info_t) nullptr, &size), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrsv2_bufferSize( (hipsparseHandle_t) nullptr, transA, m, nnz, descr, dval, dptr, dcol, info, &size)); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsv2_analysis( handle, transA, m, nnz, descr, dval, (int*)nullptr, dcol, info, policy, dbuffer), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsv2_analysis( handle, transA, m, nnz, descr, dval, dptr, (int*)nullptr, info, policy, dbuffer), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsv2_analysis( handle, transA, m, nnz, descr, (T*)nullptr, dptr, dcol, info, policy, dbuffer), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsv2_analysis( handle, transA, m, nnz, descr, dval, dptr, dcol, info, policy, (void*)nullptr), "Error: dbuffer is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsv2_analysis(handle, transA, m, nnz, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, info, policy, dbuffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsv2_analysis(handle, transA, m, nnz, descr, dval, dptr, dcol, (csrsv2Info_t) nullptr, policy, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrsv2_analysis((hipsparseHandle_t) nullptr, transA, m, nnz, descr, dval, dptr, dcol, info, policy, dbuffer)); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr, dval, (int*)nullptr, dcol, info, dx, dy, policy, dbuffer), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr, dval, dptr, (int*)nullptr, info, dx, dy, policy, dbuffer), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr, (T*)nullptr, dptr, dcol, info, dx, dy, policy, dbuffer), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, info, (T*)nullptr, dy, policy, dbuffer), "Error: dx is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, info, dx, (T*)nullptr, policy, dbuffer), "Error: dy is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsv2_solve(handle, transA, m, nnz, (T*)nullptr, descr, dval, dptr, dcol, info, dx, dy, policy, dbuffer), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, info, dx, dy, policy, (void*)nullptr), "Error: dbuffer is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsv2_solve(handle, transA, m, nnz, &h_alpha, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, info, dx, dy, policy, dbuffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, (csrsv2Info_t) nullptr, dx, dy, policy, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrsv2_solve((hipsparseHandle_t) nullptr, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, info, dx, dy, policy, dbuffer)); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsv2_zeroPivot(handle, info, (int*)nullptr), "Error: position is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsv2_zeroPivot(handle, (csrsv2Info_t) nullptr, &position), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXcsrsv2_zeroPivot((hipsparseHandle_t) nullptr, info, &position)); #endif } template hipsparseStatus_t testing_csrsv2(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int m = argus.M; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseOperation_t trans = argus.transA; hipsparseDiagType_t diag_type = argus.diag_type; hipsparseFillMode_t fill_mode = argus.fill_mode; hipsparseSolvePolicy_t policy = argus.solve_policy; T h_alpha = make_DataType(argus.alpha); std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_csrsv2_info(new csrsv2_struct); csrsv2Info_t info = unique_ptr_csrsv2_info->info; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); // Set matrix diag type CHECK_HIPSPARSE_ERROR(hipsparseSetMatDiagType(descr, diag_type)); // Set matrix fill mode CHECK_HIPSPARSE_ERROR(hipsparseSetMatFillMode(descr, fill_mode)); if(m == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, m, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hx(m); std::vector hy_1(m); std::vector hy_2(m); std::vector hy_gold(m); hipsparseInit(hx, 1, m); // Allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_position_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dx = (T*)dx_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); int* d_position = (int*)d_position_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx, hx.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_1, hy_1.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); // Obtain csrsv2 buffer size int bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_bufferSize( handle, trans, m, nnz, descr, dval, dptr, dcol, info, &bufferSize)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * bufferSize), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); // csrsv2 analysis CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_analysis( handle, trans, m, nnz, descr, dval, dptr, dcol, info, policy, dbuffer)); if(argus.unit_check) { CHECK_HIP_ERROR(hipMemcpy(dy_2, hy_2.data(), sizeof(T) * m, hipMemcpyHostToDevice)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_solve(handle, trans, m, nnz, &h_alpha, descr, dval, dptr, dcol, info, dx, dy_1, policy, dbuffer)); int hposition_1; hipsparseStatus_t pivot_status_1; pivot_status_1 = hipsparseXcsrsv2_zeroPivot(handle, info, &hposition_1); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_solve(handle, trans, m, nnz, d_alpha, descr, dval, dptr, dcol, info, dx, dy_2, policy, dbuffer)); hipsparseStatus_t pivot_status_2; pivot_status_2 = hipsparseXcsrsv2_zeroPivot(handle, info, d_position); // Copy output from device to CPU int hposition_2; CHECK_HIP_ERROR(hipMemcpy(hy_1.data(), dy_1, sizeof(T) * m, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_2.data(), dy_2, sizeof(T) * m, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(&hposition_2, d_position, sizeof(int), hipMemcpyDeviceToHost)); // Host csrsv2 hipDeviceProp_t prop; hipGetDeviceProperties(&prop, 0); int position_gold; if((fill_mode == HIPSPARSE_FILL_MODE_LOWER && trans == HIPSPARSE_OPERATION_NON_TRANSPOSE) || (fill_mode == HIPSPARSE_FILL_MODE_UPPER && trans == HIPSPARSE_OPERATION_TRANSPOSE)) { position_gold = csr_lsolve(trans, m, hcsr_row_ptr.data(), hcsr_col_ind.data(), hcsr_val.data(), h_alpha, hx.data(), hy_gold.data(), idx_base, diag_type, prop.warpSize); } else { position_gold = csr_usolve(trans, m, hcsr_row_ptr.data(), hcsr_col_ind.data(), hcsr_val.data(), h_alpha, hx.data(), hy_gold.data(), idx_base, diag_type, prop.warpSize); } unit_check_general(1, 1, 1, &position_gold, &hposition_1); unit_check_general(1, 1, 1, &position_gold, &hposition_2); if(hposition_1 != -1) { verify_hipsparse_status_zero_pivot(pivot_status_1, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); return HIPSPARSE_STATUS_SUCCESS; } if(hposition_2 != -1) { verify_hipsparse_status_zero_pivot(pivot_status_2, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); return HIPSPARSE_STATUS_SUCCESS; } unit_check_near(1, m, 1, hy_gold.data(), hy_1.data()); unit_check_near(1, m, 1, hy_gold.data(), hy_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_solve(handle, trans, m, nnz, &h_alpha, descr, dval, dptr, dcol, info, dx, dy_1, policy, dbuffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_solve(handle, trans, m, nnz, &h_alpha, descr, dval, dptr, dcol, info, dx, dy_1, policy, dbuffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = csrsv_gflop_count(m, nnz, diag_type); double gbyte_count = csrsv_gbyte_count(m, nnz); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::nnz, nnz, display_key_t::alpha, h_alpha, display_key_t::trans, hipsparse_operation2string(trans), display_key_t::diag_type, hipsparse_diagtype2string(diag_type), display_key_t::fill_mode, hipsparse_fillmode2string(fill_mode), display_key_t::solve_policy, hipsparse_solvepolicy2string(policy), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRSV2_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_csru2csr.hpp000066400000000000000000000402161501764003400232630ustar00rootroot00000000000000/* ************************************************************************ * 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_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include using namespace hipsparse; using namespace hipsparse_test; void testing_csru2csr_bad_arg(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) int m = 100; int n = 100; int nnz = 100; int safe_size = 100; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_csru2csr(new csru2csr_struct); csru2csrInfo_t info = unique_ptr_csru2csr->info; size_t bufferSize; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto buffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* csr_col_ind = (int*)csr_col_ind_managed.get(); float* csr_val = (float*)csr_val_managed.get(); void* buffer = (void*)buffer_managed.get(); // Testing csru2csr_bufferSizeExt for bad args #ifndef __HIP_PLATFORM_NVIDIA__ // cusparse seem to not have any error checking verify_hipsparse_status_invalid_handle(hipsparseXcsru2csr_bufferSizeExt( nullptr, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, info, &bufferSize)); verify_hipsparse_status_invalid_pointer( hipsparseXcsru2csr_bufferSizeExt( handle, m, n, nnz, (float*)nullptr, csr_row_ptr, csr_col_ind, info, &bufferSize), "Error: csr_val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsru2csr_bufferSizeExt( handle, m, n, nnz, csr_val, nullptr, csr_col_ind, info, &bufferSize), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsru2csr_bufferSizeExt( handle, m, n, nnz, csr_val, csr_row_ptr, nullptr, info, &bufferSize), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsru2csr_bufferSizeExt( handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, nullptr, &bufferSize), "Error: info is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsru2csr_bufferSizeExt( handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, info, nullptr), "Error: bufferSize is nullptr"); #endif verify_hipsparse_status_invalid_size( hipsparseXcsru2csr_bufferSizeExt( handle, -1, n, nnz, csr_val, csr_row_ptr, csr_col_ind, info, &bufferSize), "Error: m is invalid"); verify_hipsparse_status_invalid_size( hipsparseXcsru2csr_bufferSizeExt( handle, m, -1, nnz, csr_val, csr_row_ptr, csr_col_ind, info, &bufferSize), "Error: n is invalid"); verify_hipsparse_status_invalid_size( hipsparseXcsru2csr_bufferSizeExt( handle, m, n, -1, csr_val, csr_row_ptr, csr_col_ind, info, &bufferSize), "Error: nnz is invalid"); #ifndef __HIP_PLATFORM_NVIDIA__ // cusparse seem to not have any error checking for some parts verify_hipsparse_status_success( hipsparseXcsru2csr_bufferSizeExt( handle, 0, n, 0, (float*)nullptr, nullptr, nullptr, nullptr, &bufferSize), "Success"); verify_hipsparse_status_success( hipsparseXcsru2csr_bufferSizeExt( handle, m, 0, 0, (float*)nullptr, nullptr, nullptr, nullptr, &bufferSize), "Success"); verify_hipsparse_status_invalid_size( hipsparseXcsru2csr_bufferSizeExt( handle, 0, n, nnz, (float*)nullptr, nullptr, nullptr, nullptr, &bufferSize), "Error: nnz is invalid"); verify_hipsparse_status_invalid_pointer( hipsparseXcsru2csr_bufferSizeExt( handle, 0, n, 0, (float*)nullptr, nullptr, nullptr, nullptr, nullptr), "Error: bufferSize is invalid"); #endif // Testing csru2csr for bad args #ifndef __HIP_PLATFORM_NVIDIA__ // cusparse seem to not have any error checking for some parts verify_hipsparse_status_invalid_handle(hipsparseXcsru2csr( nullptr, m, n, nnz, descr, csr_val, csr_row_ptr, csr_col_ind, info, buffer)); verify_hipsparse_status_invalid_pointer( hipsparseXcsru2csr( handle, m, n, nnz, descr, csr_val, csr_row_ptr, csr_col_ind, nullptr, buffer), "Error: info is nullptr"); #endif verify_hipsparse_status_invalid_pointer( hipsparseXcsru2csr( handle, m, n, nnz, nullptr, csr_val, csr_row_ptr, csr_col_ind, info, buffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsru2csr( handle, m, n, nnz, descr, (float*)nullptr, csr_row_ptr, csr_col_ind, info, buffer), "Error: csr_val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsru2csr(handle, m, n, nnz, descr, csr_val, nullptr, csr_col_ind, info, buffer), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsru2csr(handle, m, n, nnz, descr, csr_val, csr_row_ptr, nullptr, info, buffer), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsru2csr( handle, m, n, nnz, descr, csr_val, csr_row_ptr, csr_col_ind, info, nullptr), "Error: buffer is nullptr"); verify_hipsparse_status_invalid_size( hipsparseXcsru2csr( handle, -1, n, nnz, descr, csr_val, csr_row_ptr, csr_col_ind, info, buffer), "Error: m is invalid"); verify_hipsparse_status_invalid_size( hipsparseXcsru2csr( handle, m, -1, nnz, descr, csr_val, csr_row_ptr, csr_col_ind, info, buffer), "Error: n is invalid"); verify_hipsparse_status_invalid_size( hipsparseXcsru2csr( handle, m, n, -1, descr, csr_val, csr_row_ptr, csr_col_ind, info, buffer), "Error: nnz is invalid"); #ifndef __HIP_PLATFORM_NVIDIA__ // cusparse seem to not have any error checking for some parts verify_hipsparse_status_success( hipsparseXcsru2csr( handle, 0, n, 0, nullptr, (float*)nullptr, nullptr, nullptr, nullptr, &bufferSize), "Success"); verify_hipsparse_status_success( hipsparseXcsru2csr( handle, m, 0, 0, nullptr, (float*)nullptr, nullptr, nullptr, nullptr, &bufferSize), "Success"); verify_hipsparse_status_invalid_size( hipsparseXcsru2csr( handle, 0, n, nnz, nullptr, (float*)nullptr, nullptr, nullptr, nullptr, &bufferSize), "Error: nnz is invalid"); #endif // Testing csr2csru for bad args #ifndef __HIP_PLATFORM_NVIDIA__ // cusparse seem to not have any error checking for some parts verify_hipsparse_status_invalid_handle(hipsparseXcsr2csru( nullptr, m, n, nnz, descr, csr_val, csr_row_ptr, csr_col_ind, info, buffer)); verify_hipsparse_status_invalid_pointer( hipsparseXcsr2csru( handle, m, n, nnz, descr, csr_val, csr_row_ptr, csr_col_ind, nullptr, buffer), "Error: info is nullptr"); #endif verify_hipsparse_status_invalid_pointer( hipsparseXcsr2csru( handle, m, n, nnz, nullptr, csr_val, csr_row_ptr, csr_col_ind, info, buffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsr2csru( handle, m, n, nnz, descr, (float*)nullptr, csr_row_ptr, csr_col_ind, info, buffer), "Error: csr_val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsr2csru(handle, m, n, nnz, descr, csr_val, nullptr, csr_col_ind, info, buffer), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsr2csru(handle, m, n, nnz, descr, csr_val, csr_row_ptr, nullptr, info, buffer), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsr2csru( handle, m, n, nnz, descr, csr_val, csr_row_ptr, csr_col_ind, info, nullptr), "Error: buffer is nullptr"); verify_hipsparse_status_invalid_size( hipsparseXcsr2csru( handle, -1, n, nnz, descr, csr_val, csr_row_ptr, csr_col_ind, info, buffer), "Error: m is invalid"); verify_hipsparse_status_invalid_size( hipsparseXcsr2csru( handle, m, -1, nnz, descr, csr_val, csr_row_ptr, csr_col_ind, info, buffer), "Error: n is invalid"); verify_hipsparse_status_invalid_size( hipsparseXcsr2csru( handle, m, n, -1, descr, csr_val, csr_row_ptr, csr_col_ind, info, buffer), "Error: nnz is invalid"); #ifndef __HIP_PLATFORM_NVIDIA__ // cusparse seem to not have any error checking for some parts verify_hipsparse_status_success( hipsparseXcsr2csru( handle, 0, n, 0, nullptr, (float*)nullptr, nullptr, nullptr, nullptr, &bufferSize), "Success"); verify_hipsparse_status_success( hipsparseXcsr2csru( handle, m, 0, 0, nullptr, (float*)nullptr, nullptr, nullptr, nullptr, &bufferSize), "Success"); verify_hipsparse_status_invalid_size( hipsparseXcsr2csru( handle, 0, n, nnz, nullptr, (float*)nullptr, nullptr, nullptr, nullptr, &bufferSize), "Error: nnz is invalid"); #endif #endif } template hipsparseStatus_t testing_csru2csr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) int m = argus.M; int n = argus.N; hipsparseIndexBase_t idx_base = argus.baseA; std::string filename = argus.filename; // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; hipsparseSetMatIndexBase(descr, idx_base); std::unique_ptr unique_ptr_info(new csru2csr_struct); csru2csrInfo_t info = unique_ptr_info->info; srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind_gold; std::vector hcsr_val_gold; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix( filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind_gold, hcsr_val_gold, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Unsort CSR columns std::vector hperm(nnz); std::vector hcsr_col_ind_unsorted_gold(nnz); std::vector hcsr_val_unsorted_gold(nnz); hcsr_col_ind_unsorted_gold = hcsr_col_ind_gold; hcsr_val_unsorted_gold = hcsr_val_gold; for(int i = 0; i < m; ++i) { int row_begin = hcsr_row_ptr[i] - idx_base; int row_end = hcsr_row_ptr[i + 1] - idx_base; int row_nnz = row_end - row_begin; for(int j = row_begin; j < row_end; ++j) { int rng = row_begin + rand() % row_nnz; int temp_col = hcsr_col_ind_unsorted_gold[j] - idx_base; T temp_val = hcsr_val_unsorted_gold[j]; hcsr_col_ind_unsorted_gold[j] = hcsr_col_ind_unsorted_gold[rng]; hcsr_val_unsorted_gold[j] = hcsr_val_unsorted_gold[rng]; hcsr_col_ind_unsorted_gold[rng] = temp_col + idx_base; hcsr_val_unsorted_gold[rng] = temp_val; } } // Allocate memory on the device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); // Copy data from host to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy( dcsr_col_ind, hcsr_col_ind_unsorted_gold.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_val, hcsr_val_unsorted_gold.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); // Obtain buffer size size_t buffer_size; CHECK_HIPSPARSE_ERROR(hipsparseXcsru2csr_bufferSizeExt( handle, m, n, nnz, dcsr_val, dcsr_row_ptr, dcsr_col_ind, info, &buffer_size)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * buffer_size), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); if(argus.unit_check) { // Sort CSR columns CHECK_HIPSPARSE_ERROR(hipsparseXcsru2csr( handle, m, n, nnz, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, info, dbuffer)); // Copy output from device to host std::vector hcsr_col_ind(nnz); std::vector hcsr_val(nnz); CHECK_HIP_ERROR( hipMemcpy(hcsr_col_ind.data(), dcsr_col_ind, sizeof(int) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val.data(), dcsr_val, sizeof(T) * nnz, hipMemcpyDeviceToHost)); // Unsort CSR columns back to original state CHECK_HIPSPARSE_ERROR(hipsparseXcsr2csru( handle, m, n, nnz, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, info, dbuffer)); // Copy output from device to host std::vector hcsr_col_ind_unsorted(nnz); std::vector hcsr_val_unsorted(nnz); CHECK_HIP_ERROR(hipMemcpy( hcsr_col_ind_unsorted.data(), dcsr_col_ind, sizeof(int) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val_unsorted.data(), dcsr_val, sizeof(T) * nnz, hipMemcpyDeviceToHost)); // Unit check unit_check_general(1, nnz, 1, hcsr_col_ind.data(), hcsr_col_ind_gold.data()); unit_check_general(1, nnz, 1, hcsr_val.data(), hcsr_val_gold.data()); unit_check_general( 1, nnz, 1, hcsr_col_ind_unsorted.data(), hcsr_col_ind_unsorted_gold.data()); unit_check_general(1, nnz, 1, hcsr_val_unsorted.data(), hcsr_val_unsorted_gold.data()); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRU2CSR_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_csx2dense.hpp000066400000000000000000000304021501764003400234070ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSX2DENSE_HPP #define TESTING_CSX2DENSE_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; #include template void testing_csx2dense_bad_arg(FUNC& csx2dense) { #if(!defined(CUDART_VERSION)) static constexpr int M = 1; static constexpr int N = 1; static constexpr int LD = M; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; auto m_csx_val = hipsparse_unique_ptr{device_malloc(sizeof(T) * 1), device_free}; auto m_dense_val = hipsparse_unique_ptr{device_malloc(sizeof(T) * 1), device_free}; auto m_nnzPerRowColumn = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; auto m_csx_ptr = hipsparse_unique_ptr{device_malloc(sizeof(int) * (1 + 1)), device_free}; auto m_csx_ind = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; int* d_csx_row = (HIPSPARSE_DIRECTION_ROW == DIRA) ? ((int*)m_csx_ptr.get()) : ((int*)m_csx_ind.get()); int* d_csx_col = (HIPSPARSE_DIRECTION_ROW == DIRA) ? ((int*)m_csx_ind.get()) : ((int*)m_csx_ptr.get()); T* d_dense_val = (T*)m_dense_val.get(); T* d_csx_val = (T*)m_csx_val.get(); int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(m_csx_ptr.get(), local_ptr, sizeof(int) * (1 + 1), hipMemcpyHostToDevice)); verify_hipsparse_status_invalid_handle( csx2dense(nullptr, 0, 0, nullptr, (const T*)nullptr, nullptr, nullptr, (T*)nullptr, 0)); verify_hipsparse_status_invalid_pointer( csx2dense(handle, M, N, nullptr, d_csx_val, d_csx_row, d_csx_col, d_dense_val, LD), "Error: an invalid pointer must be detected."); verify_hipsparse_status_invalid_pointer( csx2dense(handle, M, N, descr, (const T*)nullptr, d_csx_row, d_csx_col, d_dense_val, LD), "Error: an invalid pointer must be detected."); verify_hipsparse_status_invalid_pointer( csx2dense(handle, M, N, descr, d_csx_val, nullptr, d_csx_col, d_dense_val, LD), "Error: an invalid pointer must be detected."); verify_hipsparse_status_invalid_pointer( csx2dense(handle, M, N, descr, d_csx_val, d_csx_row, nullptr, d_dense_val, LD), "Error: an invalid pointer must be detected."); verify_hipsparse_status_invalid_pointer( csx2dense(handle, M, N, descr, d_csx_val, d_csx_row, d_csx_col, (T*)nullptr, LD), "Error: an invalid pointer must be detected."); verify_hipsparse_status_invalid_size( csx2dense(handle, -1, N, descr, d_csx_val, d_csx_row, d_csx_col, d_dense_val, LD), "Error: invalid size for m detected."); verify_hipsparse_status_invalid_size( csx2dense(handle, M, -1, descr, d_csx_val, d_csx_row, d_csx_col, d_dense_val, LD), "Error: invalid size for n detected."); verify_hipsparse_status_invalid_size( csx2dense(handle, M, N, descr, d_csx_val, d_csx_row, d_csx_col, d_dense_val, M - 1), "Error: invalid size for LD detected."); #endif } template hipsparseStatus_t testing_csx2dense(const Arguments& argus, FUNC1& csx2dense, FUNC2& dense2csx) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int M = argus.M; int N = argus.N; int LD = argus.lda; hipsparseIndexBase_t idx_base = argus.baseA; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); int DIMDIR = (HIPSPARSE_DIRECTION_ROW == DIRA) ? M : N; std::vector h_dense_val_ref(LD * N); std::vector h_dense_val(LD * N); std::vector h_nnzPerRowColumn(DIMDIR); // Create the dense matrix. auto m_dense_val = hipsparse_unique_ptr{device_malloc(sizeof(T) * LD * N), device_free}; auto nnzPerRowColumn_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * DIMDIR), device_free}; auto nnzTotalDevHostPtr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; T* d_dense_val = (T*)m_dense_val.get(); int* d_nnzPerRowColumn = (int*)nnzPerRowColumn_managed.get(); // Initialize the entire allocated memory. for(int i = 0; i < LD; ++i) { for(int j = 0; j < N; ++j) { h_dense_val_ref[j * LD + i] = make_DataType(-1); } } // Initialize a random dense matrix. srand(0); gen_dense_random_sparsity_pattern(M, N, h_dense_val_ref.data(), LD, HIPSPARSE_ORDER_COL, 0.2); // Transfer. CHECK_HIP_ERROR( hipMemcpy(d_dense_val, h_dense_val_ref.data(), sizeof(T) * LD * N, hipMemcpyHostToDevice)); int nnz; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseXnnz(handle, DIRA, M, N, descr, d_dense_val, LD, d_nnzPerRowColumn, &nnz)); // Transfer. CHECK_HIP_ERROR(hipMemcpy( h_nnzPerRowColumn.data(), d_nnzPerRowColumn, sizeof(int) * DIMDIR, hipMemcpyDeviceToHost)); auto m_csx_row_col_ptr = hipsparse_unique_ptr{device_malloc(sizeof(int) * (DIMDIR + 1)), device_free}; auto m_csx_val = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto m_csx_col_row_ind = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; int* d_csx_row_col_ptr = (int*)m_csx_row_col_ptr.get(); int* d_csx_col_row_ind = (int*)m_csx_col_row_ind.get(); T* d_csx_val = (T*)m_csx_val.get(); std::vector cpu_csx_row_col_ptr(DIMDIR + 1); std::vector cpu_csx_val(nnz); std::vector cpu_csx_col_row_ind(nnz); CHECK_HIPSPARSE_ERROR( dense2csx(handle, M, N, descr, d_dense_val, LD, d_nnzPerRowColumn, d_csx_val, (DIRA == HIPSPARSE_DIRECTION_ROW) ? d_csx_row_col_ptr : d_csx_col_row_ind, (DIRA == HIPSPARSE_DIRECTION_ROW) ? d_csx_col_row_ind : d_csx_row_col_ptr)); // Copy on host. CHECK_HIP_ERROR(hipMemcpy(cpu_csx_row_col_ptr.data(), d_csx_row_col_ptr, sizeof(int) * (DIMDIR + 1), hipMemcpyDeviceToHost)); if(nnz > 0) { CHECK_HIP_ERROR( hipMemcpy(cpu_csx_val.data(), d_csx_val, sizeof(T) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(cpu_csx_col_row_ind.data(), d_csx_col_row_ind, sizeof(int) * nnz, hipMemcpyDeviceToHost)); } if(argus.unit_check) { for(int i = 0; i < LD; ++i) { for(int j = 0; j < N; ++j) { h_dense_val[j * LD + i] = make_DataType(-2); } } CHECK_HIP_ERROR( hipMemcpy(d_dense_val, h_dense_val.data(), sizeof(T) * LD * N, hipMemcpyHostToDevice)); host_csx2dense(M, N, hipsparseGetMatIndexBase(descr), cpu_csx_val.data(), cpu_csx_row_col_ptr.data(), cpu_csx_col_row_ind.data(), h_dense_val.data(), LD); CHECK_HIPSPARSE_ERROR( csx2dense(handle, M, N, descr, d_csx_val, (DIRA == HIPSPARSE_DIRECTION_ROW) ? d_csx_row_col_ptr : d_csx_col_row_ind, (DIRA == HIPSPARSE_DIRECTION_ROW) ? d_csx_col_row_ind : d_csx_row_col_ptr, d_dense_val, LD)); void* buffer = malloc(sizeof(T) * LD * N); CHECK_HIP_ERROR(hipMemcpy(buffer, d_dense_val, sizeof(T) * LD * N, hipMemcpyDeviceToHost)); unit_check_general(M, N, LD, h_dense_val.data(), (T*)buffer); unit_check_general(M, N, LD, h_dense_val.data(), h_dense_val_ref.data()); free(buffer); buffer = nullptr; } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm-up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( csx2dense(handle, M, N, descr, d_csx_val, (DIRA == HIPSPARSE_DIRECTION_ROW) ? d_csx_row_col_ptr : d_csx_col_row_ind, (DIRA == HIPSPARSE_DIRECTION_ROW) ? d_csx_col_row_ind : d_csx_row_col_ptr, d_dense_val, LD)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( csx2dense(handle, M, N, descr, d_csx_val, (DIRA == HIPSPARSE_DIRECTION_ROW) ? d_csx_row_col_ptr : d_csx_col_row_ind, (DIRA == HIPSPARSE_DIRECTION_ROW) ? d_csx_col_row_ind : d_csx_row_col_ptr, d_dense_val, LD)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = csx2dense_gbyte_count(M, N, nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, M, display_key_t::N, N, display_key_t::LD, LD, display_key_t::nnz, nnz, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSX2DENSE_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_dense2csc.hpp000066400000000000000000000037721501764003400233740ustar00rootroot00000000000000/* ************************************************************************ * 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) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_COLUMN; testing_dense2csx_bad_arg(hipsparseXdense2csc); #endif } template hipsparseStatus_t testing_dense2csc(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_COLUMN; return testing_dense2csx(argus, hipsparseXdense2csc); #else return HIPSPARSE_STATUS_SUCCESS; #endif } #endif // TESTING_DENSE2CSC hipSPARSE-rocm-6.4.3/clients/include/testing_dense2csr.hpp000066400000000000000000000037641501764003400234140ustar00rootroot00000000000000/* ************************************************************************ * 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) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_ROW; testing_dense2csx_bad_arg(hipsparseXdense2csr); #endif } template hipsparseStatus_t testing_dense2csr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_ROW; return testing_dense2csx(argus, hipsparseXdense2csr); #else return HIPSPARSE_STATUS_SUCCESS; #endif } #endif // TESTING_DENSE2CSR hipSPARSE-rocm-6.4.3/clients/include/testing_dense2csx.hpp000066400000000000000000000374631501764003400234250ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_DENSE2CSX_HPP #define TESTING_DENSE2CSX_HPP #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; #include template void testing_dense2csx_bad_arg(FUNC& dense2csx) { #if(!defined(CUDART_VERSION)) static constexpr int M = 1; static constexpr int N = 1; static constexpr int LD = M; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; auto m_csx_val = hipsparse_unique_ptr{device_malloc(sizeof(T) * 1), device_free}; auto m_dense_val = hipsparse_unique_ptr{device_malloc(sizeof(T) * 1), device_free}; auto m_nnzPerRowColumn = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; auto m_csx_row_col_ptr = hipsparse_unique_ptr{device_malloc(sizeof(int) * (1 + 1)), device_free}; auto m_csx_row_col_ind = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; T* d_dense_val = (T*)m_dense_val.get(); T* d_csx_val = (T*)m_csx_val.get(); int* d_nnzPerRowColumn = (int*)m_nnzPerRowColumn.get(); int* d_csx_row_col_ptr = (int*)m_csx_row_col_ptr.get(); int* d_csx_col_row_ind = (int*)m_csx_row_col_ind.get(); int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(d_csx_row_col_ptr, local_ptr, sizeof(int) * (1 + 1), hipMemcpyHostToDevice)); verify_hipsparse_status_invalid_handle(dense2csx( nullptr, 0, 0, nullptr, (const T*)nullptr, 0, nullptr, (T*)nullptr, nullptr, nullptr)); verify_hipsparse_status_invalid_pointer(dense2csx(handle, M, N, nullptr, d_dense_val, LD, d_nnzPerRowColumn, d_csx_val, d_csx_row_col_ptr, d_csx_col_row_ind), "Error: an invalid pointer must be detected."); verify_hipsparse_status_invalid_pointer(dense2csx(handle, M, N, descr, nullptr, LD, d_nnzPerRowColumn, d_csx_val, d_csx_row_col_ptr, d_csx_col_row_ind), "Error: an invalid pointer must be detected."); verify_hipsparse_status_invalid_pointer(dense2csx(handle, M, N, descr, d_dense_val, LD, nullptr, d_csx_val, d_csx_row_col_ptr, d_csx_col_row_ind), "Error: an invalid pointer must be detected."); verify_hipsparse_status_invalid_pointer(dense2csx(handle, M, N, descr, d_dense_val, LD, d_nnzPerRowColumn, nullptr, d_csx_row_col_ptr, d_csx_col_row_ind), "Error: an invalid pointer must be detected."); verify_hipsparse_status_invalid_pointer(dense2csx(handle, M, N, descr, d_dense_val, LD, d_nnzPerRowColumn, d_csx_val, nullptr, d_csx_col_row_ind), "Error: an invalid pointer must be detected."); verify_hipsparse_status_invalid_pointer(dense2csx(handle, M, N, descr, d_dense_val, LD, d_nnzPerRowColumn, d_csx_val, d_csx_row_col_ptr, nullptr), "Error: an invalid pointer must be detected."); verify_hipsparse_status_invalid_size(dense2csx(handle, -1, N, descr, d_dense_val, LD, d_nnzPerRowColumn, d_csx_val, d_csx_row_col_ptr, d_csx_col_row_ind), "Error: An invalid size must be detected."); verify_hipsparse_status_invalid_size(dense2csx(handle, M, -1, descr, d_dense_val, LD, d_nnzPerRowColumn, d_csx_val, d_csx_row_col_ptr, d_csx_col_row_ind), "Error: An invalid size must be detected."); verify_hipsparse_status_invalid_size(dense2csx(handle, M, N, descr, d_dense_val, M - 1, d_nnzPerRowColumn, d_csx_val, d_csx_row_col_ptr, d_csx_col_row_ind), "Error: An invalid size must be detected."); #endif } template hipsparseStatus_t testing_dense2csx(const Arguments& argus, FUNC& dense2csx) { int M = argus.M; int N = argus.N; int LD = argus.lda; hipsparseIndexBase_t idx_base = argus.baseA; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); if(M == 0 || N == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ return HIPSPARSE_STATUS_SUCCESS; #endif } int DIMDIR = (HIPSPARSE_DIRECTION_ROW == DIRA) ? M : N; std::vector h_dense_val(LD * N); std::vector h_nnzPerRowColumn(DIMDIR); // Create the dense matrix. auto m_dense_val = hipsparse_unique_ptr{device_malloc(sizeof(T) * LD * N), device_free}; auto nnzPerRowColumn_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * DIMDIR), device_free}; auto nnzTotalDevHostPtr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; T* d_dense_val = (T*)m_dense_val.get(); int* d_nnzPerRowColumn = (int*)nnzPerRowColumn_managed.get(); // Initialize the entire allocated memory. for(int i = 0; i < LD; ++i) { for(int j = 0; j < N; ++j) { h_dense_val[j * LD + i] = make_DataType(-1); } } // Initialize a random dense matrix. srand(0); gen_dense_random_sparsity_pattern(M, N, h_dense_val.data(), LD, HIPSPARSE_ORDER_COL, 0.2); // Transfer. CHECK_HIP_ERROR( hipMemcpy(d_dense_val, h_dense_val.data(), sizeof(T) * LD * N, hipMemcpyHostToDevice)); int nnz; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseXnnz(handle, DIRA, M, N, descr, d_dense_val, LD, d_nnzPerRowColumn, &nnz)); // Transfer. CHECK_HIP_ERROR(hipMemcpy( h_nnzPerRowColumn.data(), d_nnzPerRowColumn, sizeof(int) * DIMDIR, hipMemcpyDeviceToHost)); auto m_csx_row_col_ptr = hipsparse_unique_ptr{device_malloc(sizeof(int) * (DIMDIR + 1)), device_free}; auto m_csx_val = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto m_csx_col_row_ind = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; int* d_csx_row_col_ptr = (int*)m_csx_row_col_ptr.get(); int* d_csx_col_row_ind = (int*)m_csx_col_row_ind.get(); T* d_csx_val = (T*)m_csx_val.get(); std::vector cpu_csx_row_col_ptr(DIMDIR + 1); std::vector cpu_csx_val(nnz); std::vector cpu_csx_col_row_ind(nnz); if(argus.unit_check) { // Compute the reference host first. host_dense2csx(M, N, hipsparseGetMatIndexBase(descr), h_dense_val.data(), LD, h_nnzPerRowColumn.data(), cpu_csx_val.data(), cpu_csx_row_col_ptr.data(), cpu_csx_col_row_ind.data()); CHECK_HIPSPARSE_ERROR( dense2csx(handle, M, N, descr, d_dense_val, LD, d_nnzPerRowColumn, d_csx_val, (DIRA == HIPSPARSE_DIRECTION_ROW) ? d_csx_row_col_ptr : d_csx_col_row_ind, (DIRA == HIPSPARSE_DIRECTION_ROW) ? d_csx_col_row_ind : d_csx_row_col_ptr)); void* buffer = malloc(std::max(sizeof(T), sizeof(int)) * std::max(DIMDIR + 1, nnz)); // Transfer and check results. CHECK_HIP_ERROR(hipMemcpy(buffer, d_csx_val, sizeof(T) * nnz, hipMemcpyDeviceToHost)); unit_check_general(1, nnz, 1, cpu_csx_val.data(), (T*)buffer); CHECK_HIP_ERROR( hipMemcpy(buffer, d_csx_col_row_ind, sizeof(int) * nnz, hipMemcpyDeviceToHost)); unit_check_general(1, nnz, 1, cpu_csx_col_row_ind.data(), (int*)buffer); CHECK_HIP_ERROR(hipMemcpy( buffer, d_csx_row_col_ptr, sizeof(int) * (DIMDIR + 1), hipMemcpyDeviceToHost)); unit_check_general(1, (DIMDIR + 1), 1, cpu_csx_row_col_ptr.data(), (int*)buffer); free(buffer); buffer = nullptr; } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm-up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(dense2csx( handle, M, N, descr, d_dense_val, LD, d_nnzPerRowColumn, d_csx_val, (DIRA == HIPSPARSE_DIRECTION_ROW) ? d_csx_row_col_ptr : d_csx_col_row_ind, (DIRA == HIPSPARSE_DIRECTION_ROW) ? d_csx_col_row_ind : d_csx_row_col_ptr)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(dense2csx( handle, M, N, descr, d_dense_val, LD, d_nnzPerRowColumn, d_csx_val, (DIRA == HIPSPARSE_DIRECTION_ROW) ? d_csx_row_col_ptr : d_csx_col_row_ind, (DIRA == HIPSPARSE_DIRECTION_ROW) ? d_csx_col_row_ind : d_csx_row_col_ptr)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = dense2csx_gbyte_count(M, N, nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); std::cout << "GBytes/s: " << gpu_gbyte << " time (ms): " << get_gpu_time_msec(gpu_time_used) << std::endl; } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_DENSE2CSX_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_dense_to_sparse_coo.hpp000066400000000000000000000306031501764003400255310ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_DENSE_TO_SPARSE_COO_HPP #define TESTING_DENSE_TO_SPARSE_COO_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse_test; void testing_dense_to_sparse_coo_bad_arg(void) { #if(!defined(CUDART_VERSION)) int64_t safe_size = 100; int32_t m = 10; int32_t n = 10; int64_t nnz = 10; int64_t ld = m; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseDenseToSparseAlg_t alg = HIPSPARSE_DENSETOSPARSE_ALG_DEFAULT; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; // Index and data type hipsparseIndexType_t iType = HIPSPARSE_INDEX_64I; hipDataType dataType = HIP_R_32F; // Create handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto ddense_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dcoo_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dcoo_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dcoo_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; float* ddense_val = (float*)ddense_val_managed.get(); int32_t* dcoo_row_ind = (int32_t*)dcoo_row_ind_managed.get(); int32_t* dcoo_col_ind = (int32_t*)dcoo_col_ind_managed.get(); float* dcoo_val = (float*)dcoo_val_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // Matrix structures hipsparseDnVecDescr_t matA; hipsparseSpMatDescr_t matB; size_t bsize; // Create matrix structures verify_hipsparse_status_success( hipsparseCreateDnMat(&matA, m, n, ld, ddense_val, dataType, order), "success"); verify_hipsparse_status_success( hipsparseCreateCoo( &matB, m, n, nnz, dcoo_row_ind, dcoo_col_ind, dcoo_val, iType, idxBase, dataType), "success"); // denseToSparse buffer size verify_hipsparse_status_invalid_handle( hipsparseDenseToSparse_bufferSize(nullptr, matA, matB, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_bufferSize(handle, nullptr, matB, alg, &bsize), "Error: matA is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_bufferSize(handle, matA, nullptr, alg, &bsize), "Error: matB is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_bufferSize(handle, matA, matB, alg, nullptr), "Error: bsize is nullptr"); // denseToSparse analysis verify_hipsparse_status_invalid_handle( hipsparseDenseToSparse_analysis(nullptr, matA, matB, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_analysis(handle, nullptr, matB, alg, &bsize), "Error: matA is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_analysis(handle, matA, nullptr, alg, &bsize), "Error: matB is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_analysis(handle, matA, matB, alg, nullptr), "Error: bsize is nullptr"); // denseToSparse_convert verify_hipsparse_status_invalid_handle( hipsparseDenseToSparse_convert(nullptr, matA, matB, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_convert(handle, nullptr, matB, alg, dbuf), "Error: matA is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_convert(handle, matA, nullptr, alg, dbuf), "Error: matB is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_convert(handle, matA, matB, alg, nullptr), "Error: dbuf is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroyDnMat(matA), "success"); verify_hipsparse_status_success(hipsparseDestroySpMat(matB), "success"); #endif } template hipsparseStatus_t testing_dense_to_sparse_coo(Arguments argus) { #if(!defined(CUDART_VERSION)) I m = argus.M; I n = argus.N; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseDenseToSparseAlg_t alg = static_cast(argus.dense2sparse_alg); hipsparseOrder_t order = argus.orderA; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; I ld = (order == HIPSPARSE_ORDER_COL) ? m : n; // Host structures I nrow = (order == HIPSPARSE_ORDER_COL) ? ld : m; I ncol = (order == HIPSPARSE_ORDER_COL) ? n : ld; std::vector hdense_val(nrow * ncol); if(order == HIPSPARSE_ORDER_COL) { for(int i = 0; i < n; ++i) { for(int j = 0; j < ld; ++j) { hdense_val[i * ld + j] = make_DataType(-1); } } } else { for(int i = 0; i < m; ++i) { for(int j = 0; j < ld; ++j) { hdense_val[i * ld + j] = make_DataType(-1); } } } srand(0); gen_dense_random_sparsity_pattern(m, n, hdense_val.data(), ld, order, 0.2); // allocate memory on device auto ddense_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nrow * ncol), device_free}; T* ddense = (T*)ddense_managed.get(); // Copy host dense matrix to device CHECK_HIP_ERROR( hipMemcpy(ddense, hdense_val.data(), sizeof(T) * nrow * ncol, hipMemcpyHostToDevice)); // Create dense matrix hipsparseDnMatDescr_t matA; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&matA, m, n, ld, ddense, typeT, order)); // Create matrices hipsparseSpMatDescr_t matB; CHECK_HIPSPARSE_ERROR( hipsparseCreateCoo(&matB, m, n, 0, nullptr, nullptr, nullptr, typeI, idx_base, typeT)); // Query DenseToSparse buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseDenseToSparse_bufferSize(handle, matA, matB, alg, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); CHECK_HIPSPARSE_ERROR(hipsparseDenseToSparse_analysis(handle, matA, matB, alg, buffer)); int64_t rows, cols, nnz; CHECK_HIPSPARSE_ERROR(hipsparseSpMatGetSize(matB, &rows, &cols, &nnz)); auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; I* drow = (I*)drow_managed.get(); I* dcol = (I*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseCooSetPointers(matB, drow, dcol, dval)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseDenseToSparse_convert(handle, matA, matB, alg, buffer)); // copy output from device to CPU std::vector hcoo_row_ind(nnz); std::vector hcoo_col_ind(nnz); std::vector hcoo_val(nnz); CHECK_HIP_ERROR( hipMemcpy(hcoo_row_ind.data(), drow, sizeof(I) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcoo_col_ind.data(), dcol, sizeof(I) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hcoo_val.data(), dval, sizeof(T) * nnz, hipMemcpyDeviceToHost)); std::vector hcoo_row_ind_cpu(nnz); std::vector hcoo_col_ind_cpu(nnz); std::vector hcoo_val_cpu(nnz); if(order == HIPSPARSE_ORDER_COL) { int index = 0; for(I i = 0; i < m; ++i) { for(I j = 0; j < n; ++j) { if(hdense_val[j * ld + i] != make_DataType(0.0)) { hcoo_row_ind_cpu[index] = i + idx_base; hcoo_col_ind_cpu[index] = j + idx_base; hcoo_val_cpu[index] = hdense_val[j * ld + i]; index++; } } } } else { int index = 0; for(I i = 0; i < m; ++i) { for(I j = 0; j < n; ++j) { if(hdense_val[i * ld + j] != make_DataType(0.0)) { hcoo_row_ind_cpu[index] = i + idx_base; hcoo_col_ind_cpu[index] = j + idx_base; hcoo_val_cpu[index] = hdense_val[i * ld + j]; index++; } } } } unit_check_general(1, nnz, 1, hcoo_row_ind_cpu.data(), hcoo_row_ind.data()); unit_check_general(1, nnz, 1, hcoo_col_ind_cpu.data(), hcoo_col_ind.data()); unit_check_general(1, nnz, 1, hcoo_val_cpu.data(), hcoo_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm-up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseDenseToSparse_convert(handle, matA, matB, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseDenseToSparse_convert(handle, matA, matB, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = dense2coo_gbyte_count(m, n, (I)nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::order, order, display_key_t::algorithm, hipsparse_densetosparsealg2string(alg), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(matA)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matB)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_DENSE_TO_SPARSE_COO_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_dense_to_sparse_csc.hpp000066400000000000000000000335721501764003400255310ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_DENSE_TO_SPARSE_CSC_HPP #define TESTING_DENSE_TO_SPARSE_CSC_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse_test; void testing_dense_to_sparse_csc_bad_arg(void) { #if(!defined(CUDART_VERSION)) int64_t safe_size = 100; int32_t m = 10; int32_t n = 10; int64_t nnz = 10; int64_t ld = m; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseDenseToSparseAlg_t alg = HIPSPARSE_DENSETOSPARSE_ALG_DEFAULT; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; // Index and data type hipsparseIndexType_t iType = HIPSPARSE_INDEX_32I; hipsparseIndexType_t jType = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; // Create handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto ddense_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dcsc_col_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dcsc_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dcsc_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; float* ddense_val = (float*)ddense_val_managed.get(); int32_t* dcsc_col_ptr = (int32_t*)dcsc_col_ptr_managed.get(); int32_t* dcsc_row_ind = (int32_t*)dcsc_row_ind_managed.get(); float* dcsc_val = (float*)dcsc_val_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // Matrix structures hipsparseDnVecDescr_t matA; hipsparseSpMatDescr_t matB; size_t bsize; // Create matrix structures verify_hipsparse_status_success( hipsparseCreateDnMat(&matA, m, n, ld, ddense_val, dataType, order), "success"); verify_hipsparse_status_success(hipsparseCreateCsc(&matB, m, n, nnz, dcsc_col_ptr, dcsc_row_ind, dcsc_val, iType, jType, idxBase, dataType), "success"); // denseToSparse buffer size verify_hipsparse_status_invalid_handle( hipsparseDenseToSparse_bufferSize(nullptr, matA, matB, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_bufferSize(handle, nullptr, matB, alg, &bsize), "Error: matA is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_bufferSize(handle, matA, nullptr, alg, &bsize), "Error: matB is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_bufferSize(handle, matA, matB, alg, nullptr), "Error: bsize is nullptr"); // denseToSparse analysis verify_hipsparse_status_invalid_handle( hipsparseDenseToSparse_analysis(nullptr, matA, matB, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_analysis(handle, nullptr, matB, alg, &bsize), "Error: matA is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_analysis(handle, matA, nullptr, alg, &bsize), "Error: matB is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_analysis(handle, matA, matB, alg, nullptr), "Error: bsize is nullptr"); // denseToSparse_convert verify_hipsparse_status_invalid_handle( hipsparseDenseToSparse_convert(nullptr, matA, matB, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_convert(handle, nullptr, matB, alg, dbuf), "Error: matA is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_convert(handle, matA, nullptr, alg, dbuf), "Error: matB is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_convert(handle, matA, matB, alg, nullptr), "Error: dbuf is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroyDnMat(matA), "success"); verify_hipsparse_status_success(hipsparseDestroySpMat(matB), "success"); #endif } template hipsparseStatus_t testing_dense_to_sparse_csc(Arguments argus) { #if(!defined(CUDART_VERSION)) J m = argus.M; J n = argus.N; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseDenseToSparseAlg_t alg = static_cast(argus.dense2sparse_alg); hipsparseOrder_t order = argus.orderA; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipsparseIndexType_t typeJ = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; I ld = (order == HIPSPARSE_ORDER_COL) ? m : n; // Host structures I nrow = (order == HIPSPARSE_ORDER_COL) ? ld : m; I ncol = (order == HIPSPARSE_ORDER_COL) ? n : ld; std::vector hdense_val(nrow * ncol); if(order == HIPSPARSE_ORDER_COL) { for(int i = 0; i < n; ++i) { for(int j = 0; j < ld; ++j) { hdense_val[i * ld + j] = make_DataType(-1); } } } else { for(int i = 0; i < m; ++i) { for(int j = 0; j < ld; ++j) { hdense_val[i * ld + j] = make_DataType(-1); } } } srand(0); gen_dense_random_sparsity_pattern(m, n, hdense_val.data(), ld, order, 0.2); // allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (n + 1)), device_free}; auto ddense_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nrow * ncol), device_free}; I* dptr = (I*)dptr_managed.get(); T* ddense = (T*)ddense_managed.get(); // Copy host dense matrix to device CHECK_HIP_ERROR( hipMemcpy(ddense, hdense_val.data(), sizeof(T) * nrow * ncol, hipMemcpyHostToDevice)); // Create dense matrix hipsparseDnMatDescr_t matA; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&matA, m, n, ld, ddense, typeT, order)); // Create matrices hipsparseSpMatDescr_t matB; CHECK_HIPSPARSE_ERROR( hipsparseCreateCsc(&matB, m, n, 0, dptr, nullptr, nullptr, typeI, typeJ, idx_base, typeT)); // Query DenseToSparse buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseDenseToSparse_bufferSize(handle, matA, matB, alg, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); CHECK_HIPSPARSE_ERROR(hipsparseDenseToSparse_analysis(handle, matA, matB, alg, buffer)); int64_t rows, cols, nnz; CHECK_HIPSPARSE_ERROR(hipsparseSpMatGetSize(matB, &rows, &cols, &nnz)); auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; J* drow = (J*)drow_managed.get(); T* dval = (T*)dval_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseCscSetPointers(matB, dptr, drow, dval)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseDenseToSparse_convert(handle, matA, matB, alg, buffer)); // copy output from device to CPU std::vector hcsc_col_ptr(n + 1); std::vector hcsc_row_ind(nnz); std::vector hcsc_val(nnz); CHECK_HIP_ERROR( hipMemcpy(hcsc_col_ptr.data(), dptr, sizeof(I) * (n + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsc_row_ind.data(), drow, sizeof(J) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hcsc_val.data(), dval, sizeof(T) * nnz, hipMemcpyDeviceToHost)); std::vector hcsc_col_ptr_cpu(n + 1); std::vector hcsc_row_ind_cpu(nnz); std::vector hcsc_val_cpu(nnz); std::vector hnnz_per_column(n, 0); if(order == HIPSPARSE_ORDER_COL) { for(J i = 0; i < m; ++i) { for(J j = 0; j < n; ++j) { if(hdense_val[j * ld + i] != make_DataType(0.0)) { hnnz_per_column[j]++; } } } } else { for(J i = 0; i < m; ++i) { for(J j = 0; j < n; ++j) { if(hdense_val[i * ld + j] != make_DataType(0.0)) { hnnz_per_column[j]++; } } } } hcsc_col_ptr_cpu[0] = idx_base; for(J i = 0; i < n; ++i) { hcsc_col_ptr_cpu[i + 1] = hnnz_per_column[i] + hcsc_col_ptr_cpu[i]; } if(order == HIPSPARSE_ORDER_COL) { int index = 0; for(J i = 0; i < n; ++i) { for(J j = 0; j < m; ++j) { if(hdense_val[i * ld + j] != make_DataType(0.0)) { hcsc_val_cpu[index] = hdense_val[i * ld + j]; hcsc_row_ind_cpu[index] = j + idx_base; index++; } } } } else { int index = 0; for(J i = 0; i < n; ++i) { for(J j = 0; j < m; ++j) { if(hdense_val[j * ld + i] != make_DataType(0.0)) { hcsc_val_cpu[index] = hdense_val[j * ld + i]; hcsc_row_ind_cpu[index] = j + idx_base; index++; } } } } unit_check_general(1, (n + 1), 1, hcsc_col_ptr_cpu.data(), hcsc_col_ptr.data()); unit_check_general(1, nnz, 1, hcsc_row_ind_cpu.data(), hcsc_row_ind.data()); unit_check_general(1, nnz, 1, hcsc_val_cpu.data(), hcsc_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm-up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseDenseToSparse_convert(handle, matA, matB, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseDenseToSparse_convert(handle, matA, matB, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = dense2csx_gbyte_count(m, n, nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::order, order, display_key_t::algorithm, hipsparse_densetosparsealg2string(alg), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(matA)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matB)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_DENSE_TO_SPARSE_CSC_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_dense_to_sparse_csr.hpp000066400000000000000000000336061501764003400255460ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_DENSE_TO_SPARSE_CSR_HPP #define TESTING_DENSE_TO_SPARSE_CSR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse_test; void testing_dense_to_sparse_csr_bad_arg(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) int64_t safe_size = 100; int32_t m = 10; int32_t n = 10; int64_t nnz = 10; int64_t ld = m; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseDenseToSparseAlg_t alg = HIPSPARSE_DENSETOSPARSE_ALG_DEFAULT; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; // Index and data type hipsparseIndexType_t iType = HIPSPARSE_INDEX_32I; hipsparseIndexType_t jType = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; // Create handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto ddense_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; float* ddense_val = (float*)ddense_val_managed.get(); int32_t* dcsr_row_ptr = (int32_t*)dcsr_row_ptr_managed.get(); int32_t* dcsr_col_ind = (int32_t*)dcsr_col_ind_managed.get(); float* dcsr_val = (float*)dcsr_val_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // Matrix structures hipsparseDnVecDescr_t matA; hipsparseSpMatDescr_t matB; size_t bsize; // Create matrix structures verify_hipsparse_status_success( hipsparseCreateDnMat(&matA, m, n, ld, ddense_val, dataType, order), "success"); verify_hipsparse_status_success(hipsparseCreateCsr(&matB, m, n, nnz, dcsr_row_ptr, dcsr_col_ind, dcsr_val, iType, jType, idxBase, dataType), "success"); // denseToSparse buffer size verify_hipsparse_status_invalid_handle( hipsparseDenseToSparse_bufferSize(nullptr, matA, matB, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_bufferSize(handle, nullptr, matB, alg, &bsize), "Error: matA is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_bufferSize(handle, matA, nullptr, alg, &bsize), "Error: matB is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_bufferSize(handle, matA, matB, alg, nullptr), "Error: bsize is nullptr"); // denseToSparse analysis verify_hipsparse_status_invalid_handle( hipsparseDenseToSparse_analysis(nullptr, matA, matB, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_analysis(handle, nullptr, matB, alg, &bsize), "Error: matA is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_analysis(handle, matA, nullptr, alg, &bsize), "Error: matB is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_analysis(handle, matA, matB, alg, nullptr), "Error: bsize is nullptr"); // denseToSparse_convert verify_hipsparse_status_invalid_handle( hipsparseDenseToSparse_convert(nullptr, matA, matB, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_convert(handle, nullptr, matB, alg, dbuf), "Error: matA is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_convert(handle, matA, nullptr, alg, dbuf), "Error: matB is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_convert(handle, matA, matB, alg, nullptr), "Error: dbuf is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroyDnMat(matA), "success"); verify_hipsparse_status_success(hipsparseDestroySpMat(matB), "success"); #endif } template hipsparseStatus_t testing_dense_to_sparse_csr(Arguments argus) { #if(!defined(CUDART_VERSION)) J m = argus.M; J n = argus.N; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseDenseToSparseAlg_t alg = static_cast(argus.dense2sparse_alg); hipsparseOrder_t order = argus.orderA; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipsparseIndexType_t typeJ = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; I ld = (order == HIPSPARSE_ORDER_COL) ? m : n; // Host structures I nrow = (order == HIPSPARSE_ORDER_COL) ? ld : m; I ncol = (order == HIPSPARSE_ORDER_COL) ? n : ld; std::vector hdense_val(nrow * ncol); if(order == HIPSPARSE_ORDER_COL) { for(int i = 0; i < n; ++i) { for(int j = 0; j < ld; ++j) { hdense_val[i * ld + j] = make_DataType(-1); } } } else { for(int i = 0; i < m; ++i) { for(int j = 0; j < ld; ++j) { hdense_val[i * ld + j] = make_DataType(-1); } } } srand(0); gen_dense_random_sparsity_pattern(m, n, hdense_val.data(), ld, order, 0.2); // allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (m + 1)), device_free}; auto ddense_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nrow * ncol), device_free}; I* dptr = (I*)dptr_managed.get(); T* ddense = (T*)ddense_managed.get(); // Copy host dense matrix to device CHECK_HIP_ERROR( hipMemcpy(ddense, hdense_val.data(), sizeof(T) * nrow * ncol, hipMemcpyHostToDevice)); // Create dense matrix hipsparseDnMatDescr_t matA; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&matA, m, n, ld, ddense, typeT, order)); // Create matrices hipsparseSpMatDescr_t matB; CHECK_HIPSPARSE_ERROR( hipsparseCreateCsr(&matB, m, n, 0, dptr, nullptr, nullptr, typeI, typeJ, idx_base, typeT)); // Query DenseToSparse buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseDenseToSparse_bufferSize(handle, matA, matB, alg, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); CHECK_HIPSPARSE_ERROR(hipsparseDenseToSparse_analysis(handle, matA, matB, alg, buffer)); int64_t rows, cols, nnz; CHECK_HIPSPARSE_ERROR(hipsparseSpMatGetSize(matB, &rows, &cols, &nnz)); auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; J* dcol = (J*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseCsrSetPointers(matB, dptr, dcol, dval)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseDenseToSparse_convert(handle, matA, matB, alg, buffer)); // copy output from device to CPU std::vector hcsr_row_ptr(m + 1); std::vector hcsr_col_ind(nnz); std::vector hcsr_val(nnz); CHECK_HIP_ERROR( hipMemcpy(hcsr_row_ptr.data(), dptr, sizeof(I) * (m + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_col_ind.data(), dcol, sizeof(J) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hcsr_val.data(), dval, sizeof(T) * nnz, hipMemcpyDeviceToHost)); std::vector hcsr_row_ptr_cpu(m + 1); std::vector hcsr_col_ind_cpu(nnz); std::vector hcsr_val_cpu(nnz); std::vector hnnz_per_row(m, 0); if(order == HIPSPARSE_ORDER_COL) { for(J i = 0; i < m; ++i) { for(J j = 0; j < n; ++j) { if(hdense_val[j * ld + i] != make_DataType(0.0)) { hnnz_per_row[i]++; } } } } else { for(J i = 0; i < m; ++i) { for(J j = 0; j < n; ++j) { if(hdense_val[i * ld + j] != make_DataType(0.0)) { hnnz_per_row[i]++; } } } } hcsr_row_ptr_cpu[0] = idx_base; for(J i = 0; i < m; ++i) { hcsr_row_ptr_cpu[i + 1] = hnnz_per_row[i] + hcsr_row_ptr_cpu[i]; } if(order == HIPSPARSE_ORDER_COL) { int index = 0; for(J i = 0; i < m; ++i) { for(J j = 0; j < n; ++j) { if(hdense_val[j * ld + i] != make_DataType(0.0)) { hcsr_val_cpu[index] = hdense_val[j * ld + i]; hcsr_col_ind_cpu[index] = j + idx_base; index++; } } } } else { int index = 0; for(J i = 0; i < m; ++i) { for(J j = 0; j < n; ++j) { if(hdense_val[i * ld + j] != make_DataType(0.0)) { hcsr_val_cpu[index] = hdense_val[i * ld + j]; hcsr_col_ind_cpu[index] = j + idx_base; index++; } } } } unit_check_general(1, (m + 1), 1, hcsr_row_ptr_cpu.data(), hcsr_row_ptr.data()); unit_check_general(1, nnz, 1, hcsr_col_ind_cpu.data(), hcsr_col_ind.data()); unit_check_general(1, nnz, 1, hcsr_val_cpu.data(), hcsr_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm-up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseDenseToSparse_convert(handle, matA, matB, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseDenseToSparse_convert(handle, matA, matB, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = dense2csx_gbyte_count(m, n, nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::order, order, display_key_t::algorithm, hipsparse_densetosparsealg2string(alg), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(matA)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matB)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_DENSE_TO_SPARSE_CSR_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_dnmat_descr.hpp000066400000000000000000000137741501764003400240110ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2023 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_DNMAT_DESCR_HPP #define TESTING_DNMAT_DESCR_HPP #include "hipsparse_test_unique_ptr.hpp" #ifdef GOOGLE_TEST #include #endif #include using namespace hipsparse_test; void testing_dnmat_descr_bad_arg(void) { #if(!defined(CUDART_VERSION)) int64_t rows = 100; int64_t cols = 100; int64_t ld = 100; hipsparseOrder_t order = HIPSPARSE_ORDER_ROW; hipDataType dataType = HIP_R_32F; // Allocate memory on device auto val_data_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * rows * cols), device_free}; float* val_data = (float*)val_data_managed.get(); hipsparseDnMatDescr_t x; // hipsparseCreateDnMat verify_hipsparse_status_invalid_pointer( hipsparseCreateDnMat(nullptr, rows, cols, ld, val_data, dataType, order), "Error: x is nullptr"); verify_hipsparse_status_invalid_size( hipsparseCreateDnMat(&x, -1, cols, ld, val_data, dataType, order), "Error: rows is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateDnMat(&x, rows, -1, ld, val_data, dataType, order), "Error: cols is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateDnMat(&x, rows, cols, -1, val_data, dataType, order), "Error: ld is < 0"); verify_hipsparse_status_invalid_pointer( hipsparseCreateDnMat(&x, rows, cols, ld, nullptr, dataType, order), "Error: val_data is nullptr"); // hipsparseDestroyDnVec verify_hipsparse_status_invalid_pointer(hipsparseDestroyDnMat(nullptr), "Error: x is nullptr"); // Create valid descriptor verify_hipsparse_status_success( hipsparseCreateDnMat(&x, rows, cols, ld, val_data, dataType, order), "Success"); // hipsparseDnMatGet void* data; verify_hipsparse_status_invalid_pointer( hipsparseDnMatGet(nullptr, &rows, &cols, &ld, &data, &dataType, &order), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDnMatGet(x, nullptr, &cols, &ld, &data, &dataType, &order), "Error: rows is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDnMatGet(x, &rows, nullptr, &ld, &data, &dataType, &order), "Error: cols is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDnMatGet(x, &rows, &cols, nullptr, &data, &dataType, &order), "Error: ld is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDnMatGet(x, &rows, &cols, &ld, nullptr, &dataType, &order), "Error: data is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDnMatGet(x, &rows, &cols, &ld, &data, nullptr, &order), "Error: dataType is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDnMatGet(x, &rows, &cols, &ld, &data, &dataType, nullptr), "Error: order is nullptr"); // hipsparseDnMatGetValues verify_hipsparse_status_invalid_pointer(hipsparseDnMatGetValues(nullptr, &data), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseDnMatGetValues(x, nullptr), "Error: val is nullptr"); // hipsparseDnVecSetValues verify_hipsparse_status_invalid_pointer(hipsparseDnMatSetValues(nullptr, data), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseDnMatSetValues(x, nullptr), "Error: val is nullptr"); int batch_count = 100; int64_t batch_stride = 100; // hipsparseDnMatSetStridedBatch verify_hipsparse_status_invalid_pointer( hipsparseDnMatSetStridedBatch(nullptr, batch_count, batch_stride), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseDnMatSetStridedBatch(x, -1, batch_stride), "Error: batch_count < 0"); verify_hipsparse_status_invalid_pointer(hipsparseDnMatSetStridedBatch(x, batch_count, -1), "Error: batch_stride < 0"); // hipsparseDnMatGetStridedBatch verify_hipsparse_status_invalid_pointer( hipsparseDnMatGetStridedBatch(nullptr, &batch_count, &batch_stride), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDnMatGetStridedBatch(x, nullptr, &batch_stride), "Error: batch_count is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseDnMatGetStridedBatch(x, &batch_count, nullptr), "Error: batch_stride is nullptr"); // Destroy valid descriptor verify_hipsparse_status_success(hipsparseDestroyDnVec(x), "Success"); #endif } #endif // TESTING_DNMAT_DESCR_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_dnvec_descr.hpp000066400000000000000000000101451501764003400237720ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_DNVEC_DESCR_HPP #define TESTING_DNVEC_DESCR_HPP #include "hipsparse_test_unique_ptr.hpp" #ifdef GOOGLE_TEST #include #endif #include using namespace hipsparse_test; void testing_dnvec_descr_bad_arg(void) { #if(!defined(CUDART_VERSION)) int64_t size = 100; hipDataType dataType = HIP_R_32F; // Allocate memory on device auto val_data_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * size), device_free}; float* val_data = (float*)val_data_managed.get(); hipsparseDnVecDescr_t x; // hipsparseCreateDnVec verify_hipsparse_status_invalid_pointer(hipsparseCreateDnVec(nullptr, size, val_data, dataType), "Error: x is nullptr"); verify_hipsparse_status_invalid_size(hipsparseCreateDnVec(&x, -1, val_data, dataType), "Error: size is < 0"); verify_hipsparse_status_invalid_pointer(hipsparseCreateDnVec(&x, size, nullptr, dataType), "Error: val_data is nullptr"); // hipsparseDestroyDnVec verify_hipsparse_status_invalid_pointer(hipsparseDestroyDnVec(nullptr), "Error: x is nullptr"); // Create valid descriptor verify_hipsparse_status_success(hipsparseCreateDnVec(&x, size, val_data, dataType), "Success"); // hipsparseDnVecGet void* data; verify_hipsparse_status_invalid_pointer(hipsparseDnVecGet(nullptr, &size, &data, &dataType), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseDnVecGet(x, nullptr, &data, &dataType), "Error: size is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseDnVecGet(x, &size, nullptr, &dataType), "Error: val_data is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseDnVecGet(x, &size, &data, nullptr), "Error: dataType is nullptr"); // hipsparseDnVecGetValues verify_hipsparse_status_invalid_pointer(hipsparseDnVecGetValues(nullptr, &data), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseDnVecGetValues(x, nullptr), "Error: val is nullptr"); // hipsparseDnVecSetValues verify_hipsparse_status_invalid_pointer(hipsparseDnVecSetValues(nullptr, data), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseDnVecSetValues(x, nullptr), "Error: val is nullptr"); // Destroy valid descriptor verify_hipsparse_status_success(hipsparseDestroyDnVec(x), "Success"); #endif } #endif // TESTING_DNVEC_DESCR_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_dotci.hpp000066400000000000000000000173551501764003400226270ustar00rootroot00000000000000/* ************************************************************************ * 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 "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include using namespace hipsparse; using namespace hipsparse_test; template void testing_dotci_bad_arg(void) { #if(!defined(CUDART_VERSION)) int nnz = 100; int safe_size = 100; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; T* dx_val = (T*)dx_val_managed.get(); int* dx_ind = (int*)dx_ind_managed.get(); T* dy = (T*)dy_managed.get(); T result; verify_hipsparse_status_invalid_pointer( hipsparseXdotci(handle, nnz, (T*)nullptr, dx_ind, dy, &result, idx_base), "Error: x_val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXdotci(handle, nnz, dx_val, (int*)nullptr, dy, &result, idx_base), "Error: x_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXdotci(handle, nnz, dx_val, dx_ind, (T*)nullptr, &result, idx_base), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXdotci(handle, nnz, dx_val, dx_ind, dy, (T*)nullptr, idx_base), "Error: result is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXdotci((hipsparseHandle_t) nullptr, nnz, dx_val, dx_ind, dy, &result, idx_base)); #endif } template hipsparseStatus_t testing_dotci(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) int N = argus.N; int nnz = argus.nnz; hipsparseIndexBase_t idx_base = argus.baseA; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Grab stream used by handle hipStream_t stream; CHECK_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // Host structures std::vector hx_ind(nnz); std::vector hx_val(nnz); std::vector hy(N); T hresult_1; T hresult_2; T hresult_gold; // Initial Data on CPU srand(12345ULL); hipsparseInitIndex(hx_ind.data(), nnz, 1, N); hipsparseInit(hx_val, 1, nnz); hipsparseInit(hy, 1, N); // allocate memory on device auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * N), device_free}; auto dresult_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dx_ind = (int*)dx_ind_managed.get(); T* dx_val = (T*)dx_val_managed.get(); T* dy = (T*)dy_managed.get(); T* dresult_2 = (T*)dresult_2_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dx_ind, hx_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx_val, hx_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy, hy.data(), sizeof(T) * N, hipMemcpyHostToDevice)); if(argus.unit_check) { // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseXdotci(handle, nnz, dx_val, dx_ind, dy, &hresult_1, idx_base)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseXdotci(handle, nnz, dx_val, dx_ind, dy, dresult_2, idx_base)); // copy output from device to CPU^ CHECK_HIP_ERROR(hipMemcpy(&hresult_2, dresult_2, sizeof(T), hipMemcpyDeviceToHost)); // CPU hresult_gold = make_DataType(0.0); for(int i = 0; i < nnz; ++i) { hresult_gold = hresult_gold + testing_mult(testing_conj(hx_val[i]), hy[hx_ind[i] - idx_base]); } // enable unit check, notice unit check is not invasive, but norm check is, // unit check and norm check can not be interchanged their order unit_check_general(1, 1, 1, &hresult_gold, &hresult_1); unit_check_general(1, 1, 1, &hresult_gold, &hresult_2); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXdotci(handle, nnz, dx_val, dx_ind, dy, &hresult_1, idx_base)); CHECK_HIP_ERROR(hipStreamSynchronize(stream)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXdotci(handle, nnz, dx_val, dx_ind, dy, &hresult_1, idx_base)); CHECK_HIP_ERROR(hipStreamSynchronize(stream)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = doti_gflop_count(nnz); double gbyte_count = doti_gbyte_count(nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); display_timing_info(display_key_t::nnz, nnz, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_DOTCI_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_doti.hpp000066400000000000000000000172711501764003400224610ustar00rootroot00000000000000/* ************************************************************************ * 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 "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include using namespace hipsparse; using namespace hipsparse_test; template void testing_doti_bad_arg(void) { #if(!defined(CUDART_VERSION)) int nnz = 100; int safe_size = 100; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; T* dx_val = (T*)dx_val_managed.get(); int* dx_ind = (int*)dx_ind_managed.get(); T* dy = (T*)dy_managed.get(); T result; verify_hipsparse_status_invalid_pointer( hipsparseXdoti(handle, nnz, (T*)nullptr, dx_ind, dy, &result, idx_base), "Error: x_val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXdoti(handle, nnz, dx_val, (int*)nullptr, dy, &result, idx_base), "Error: x_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXdoti(handle, nnz, dx_val, dx_ind, (T*)nullptr, &result, idx_base), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXdoti(handle, nnz, dx_val, dx_ind, dy, (T*)nullptr, idx_base), "Error: result is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXdoti((hipsparseHandle_t) nullptr, nnz, dx_val, dx_ind, dy, &result, idx_base)); #endif } template hipsparseStatus_t testing_doti(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) int N = argus.N; int nnz = argus.nnz; hipsparseIndexBase_t idx_base = argus.baseA; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Grab stream used by handle hipStream_t stream; CHECK_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // Host structures std::vector hx_ind(nnz); std::vector hx_val(nnz); std::vector hy(N); T hresult_1; T hresult_2; T hresult_gold; // Initial Data on CPU srand(12345ULL); hipsparseInitIndex(hx_ind.data(), nnz, 1, N); hipsparseInit(hx_val, 1, nnz); hipsparseInit(hy, 1, N); // allocate memory on device auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * N), device_free}; auto dresult_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dx_ind = (int*)dx_ind_managed.get(); T* dx_val = (T*)dx_val_managed.get(); T* dy = (T*)dy_managed.get(); T* dresult_2 = (T*)dresult_2_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dx_ind, hx_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx_val, hx_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy, hy.data(), sizeof(T) * N, hipMemcpyHostToDevice)); if(argus.unit_check) { // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseXdoti(handle, nnz, dx_val, dx_ind, dy, &hresult_1, idx_base)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXdoti(handle, nnz, dx_val, dx_ind, dy, dresult_2, idx_base)); // copy output from device to CPU^ CHECK_HIP_ERROR(hipMemcpy(&hresult_2, dresult_2, sizeof(T), hipMemcpyDeviceToHost)); // CPU hresult_gold = make_DataType(0.0); for(int i = 0; i < nnz; ++i) { hresult_gold = hresult_gold + testing_mult(hy[hx_ind[i] - idx_base], hx_val[i]); } // enable unit check, notice unit check is not invasive, but norm check is, // unit check and norm check can not be interchanged their order unit_check_general(1, 1, 1, &hresult_gold, &hresult_1); unit_check_general(1, 1, 1, &hresult_gold, &hresult_2); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXdoti(handle, nnz, dx_val, dx_ind, dy, &hresult_1, idx_base)); CHECK_HIP_ERROR(hipStreamSynchronize(stream)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXdoti(handle, nnz, dx_val, dx_ind, dy, &hresult_1, idx_base)); CHECK_HIP_ERROR(hipStreamSynchronize(stream)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = doti_gflop_count(nnz); double gbyte_count = doti_gbyte_count(nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); display_timing_info(display_key_t::nnz, nnz, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_DOTI_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_gather.hpp000066400000000000000000000153561501764003400227760ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_GATHER_HPP #define TESTING_GATHER_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include using namespace hipsparse_test; void testing_gather_bad_arg(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) int64_t size = 100; int64_t nnz = 100; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipDataType dataType = HIP_R_32F; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * nnz), device_free}; auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * size), device_free}; float* dx_val = (float*)dx_val_managed.get(); int* dx_ind = (int*)dx_ind_managed.get(); float* dy = (float*)dy_managed.get(); // Structures hipsparseSpVecDescr_t x; hipsparseDnVecDescr_t y; verify_hipsparse_status_success( hipsparseCreateSpVec(&x, size, nnz, dx_ind, dx_val, idxType, idxBase, dataType), "Success"); verify_hipsparse_status_success(hipsparseCreateDnVec(&y, size, dy, dataType), "Success"); // Gather verify_hipsparse_status_invalid_handle(hipsparseGather(nullptr, y, x)); verify_hipsparse_status_invalid_pointer(hipsparseGather(handle, nullptr, x), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseGather(handle, y, nullptr), "Error: x is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpVec(x), "Success"); verify_hipsparse_status_success(hipsparseDestroyDnVec(y), "Success"); #endif } template hipsparseStatus_t testing_gather(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) I size = argus.N; I nnz = argus.nnz; hipsparseIndexBase_t idxBase = argus.baseA; // Index and data type hipsparseIndexType_t idxType = getIndexType(); hipDataType dataType = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hx_ind(nnz); std::vector hx_val(nnz); std::vector hx_val_gold(nnz); std::vector hy(size); // Initial Data on CPU srand(12345ULL); hipsparseInitIndex(hx_ind.data(), nnz, 1, size); hipsparseInit(hy, 1, size); // Allocate memory on device auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz), device_free}; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * size), device_free}; I* dx_ind = (I*)dx_ind_managed.get(); T* dx_val = (T*)dx_val_managed.get(); T* dy = (T*)dy_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dx_ind, hx_ind.data(), sizeof(I) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy, hy.data(), sizeof(T) * size, hipMemcpyHostToDevice)); // Create structures hipsparseSpVecDescr_t x; hipsparseDnVecDescr_t y; CHECK_HIPSPARSE_ERROR( hipsparseCreateSpVec(&x, size, nnz, dx_ind, dx_val, idxType, idxBase, dataType)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&y, size, dy, dataType)); if(argus.unit_check) { // Gather CHECK_HIPSPARSE_ERROR(hipsparseGather(handle, y, x)); // Copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hx_val.data(), dx_val, sizeof(T) * nnz, hipMemcpyDeviceToHost)); // CPU for(int64_t i = 0; i < nnz; ++i) { hx_val_gold[i] = hy[hx_ind[i] - idxBase]; } // Verify results against host unit_check_general(1, nnz, 1, hx_val_gold.data(), hx_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseGather(handle, y, x)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseGather(handle, y, x)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = gthr_gbyte_count(nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::nnz, nnz, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIPSPARSE_ERROR(hipsparseDestroySpVec(x)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GATHER_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_gebsr2csr.hpp000066400000000000000000000676141501764003400234240ustar00rootroot00000000000000/* ************************************************************************ * 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 "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_gebsr2csr_bad_arg(void) { #if(!defined(CUDART_VERSION)) int m = 1; int n = 1; int safe_size = 1; int row_block_dim = 2; int col_block_dim = 2; hipsparseIndexBase_t csr_idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexBase_t bsr_idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseDirection_t dir = HIPSPARSE_DIRECTION_ROW; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_csr_descr(new descr_struct); hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; std::unique_ptr unique_ptr_bsr_descr(new descr_struct); hipsparseMatDescr_t bsr_descr = unique_ptr_bsr_descr->descr; hipsparseSetMatIndexBase(csr_descr, csr_idx_base); hipsparseSetMatIndexBase(bsr_descr, bsr_idx_base); auto bsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto bsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto bsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto csr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* bsr_row_ptr = (int*)bsr_row_ptr_managed.get(); int* bsr_col_ind = (int*)bsr_col_ind_managed.get(); T* bsr_val = (T*)bsr_val_managed.get(); int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* csr_col_ind = (int*)csr_col_ind_managed.get(); T* csr_val = (T*)csr_val_managed.get(); int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(bsr_row_ptr, local_ptr, sizeof(int) * (1 + 1), hipMemcpyHostToDevice)); verify_hipsparse_status_invalid_handle(hipsparseXgebsr2csr(nullptr, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, row_block_dim, col_block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind)); verify_hipsparse_status_invalid_pointer(hipsparseXgebsr2csr(handle, dir, m, n, nullptr, bsr_val, bsr_row_ptr, bsr_col_ind, row_block_dim, col_block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: bsr_descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgebsr2csr(handle, dir, m, n, bsr_descr, (T*)nullptr, bsr_row_ptr, bsr_col_ind, row_block_dim, col_block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: bsr_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgebsr2csr(handle, dir, m, n, bsr_descr, bsr_val, nullptr, bsr_col_ind, row_block_dim, col_block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: bsr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgebsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, nullptr, row_block_dim, col_block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: bsr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgebsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, row_block_dim, col_block_dim, nullptr, csr_val, csr_row_ptr, csr_col_ind), "Error: csr_descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgebsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, row_block_dim, col_block_dim, csr_descr, (T*)nullptr, csr_row_ptr, csr_col_ind), "Error: csr_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgebsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, row_block_dim, col_block_dim, csr_descr, csr_val, nullptr, csr_col_ind), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgebsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, row_block_dim, col_block_dim, csr_descr, csr_val, csr_row_ptr, nullptr), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_size(hipsparseXgebsr2csr(handle, dir, -1, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, row_block_dim, col_block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: m is invalid"); verify_hipsparse_status_invalid_size(hipsparseXgebsr2csr(handle, dir, m, -1, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, row_block_dim, col_block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: n is invalid"); verify_hipsparse_status_invalid_size(hipsparseXgebsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, -1, col_block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: row_block_dim is invalid"); verify_hipsparse_status_invalid_size(hipsparseXgebsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, row_block_dim, -1, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: col_block_dim is invalid"); #endif } template hipsparseStatus_t testing_gebsr2csr(Arguments argus) { int m = argus.M; int n = argus.N; int row_block_dim = argus.row_block_dimA; int col_block_dim = argus.col_block_dimA; hipsparseIndexBase_t csr_idx_base = argus.baseA; hipsparseIndexBase_t bsr_idx_base = argus.baseB; hipsparseDirection_t dir = argus.dirA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_csr_descr(new descr_struct); hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; std::unique_ptr unique_ptr_bsr_descr(new descr_struct); hipsparseMatDescr_t bsr_descr = unique_ptr_bsr_descr->descr; hipsparseSetMatIndexBase(csr_descr, csr_idx_base); hipsparseSetMatIndexBase(bsr_descr, bsr_idx_base); if(m == 0 || n == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse does not support m == 0 for csr2bsr return HIPSPARSE_STATUS_SUCCESS; #endif } int mb = m * row_block_dim; int nb = n * col_block_dim; srand(12345ULL); // Host structures std::vector bsr_row_ptr; std::vector bsr_col_ind; std::vector bsr_val; // Read or construct CSR matrix int nnzb = 0; if(!generate_csr_matrix( filename, mb, nb, nnzb, bsr_row_ptr, bsr_col_ind, bsr_val, bsr_idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } m = mb * row_block_dim; n = nb * col_block_dim; size_t nnz = nnzb * row_block_dim * col_block_dim; // Now use the csr matrix as the symbolic for the gebsr matrix. bsr_val.resize(nnz); int idx = 0; switch(dir) { case HIPSPARSE_DIRECTION_COLUMN: { for(int i = 0; i < mb; ++i) { for(int r = 0; r < row_block_dim; ++r) { for(int k = bsr_row_ptr[i] - bsr_idx_base; k < bsr_row_ptr[i + 1] - bsr_idx_base; ++k) { for(int c = 0; c < col_block_dim; ++c) { bsr_val[k * row_block_dim * col_block_dim + c * row_block_dim + r] = make_DataType(++idx); } } } } break; } case HIPSPARSE_DIRECTION_ROW: { for(int i = 0; i < mb; ++i) { for(int r = 0; r < row_block_dim; ++r) { for(int k = bsr_row_ptr[i] - bsr_idx_base; k < bsr_row_ptr[i + 1] - bsr_idx_base; ++k) { for(int c = 0; c < col_block_dim; ++c) { bsr_val[k * row_block_dim * col_block_dim + r * col_block_dim + c] = make_DataType(++idx); } } } } break; } } // Allocate memory on the device auto dbsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb + 1)), device_free}; auto dbsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnzb), device_free}; auto dbsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; int* dbsr_row_ptr = (int*)dbsr_row_ptr_managed.get(); int* dbsr_col_ind = (int*)dbsr_col_ind_managed.get(); T* dbsr_val = (T*)dbsr_val_managed.get(); int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); // Copy data from host to device CHECK_HIP_ERROR( hipMemcpy(dbsr_row_ptr, bsr_row_ptr.data(), sizeof(int) * (mb + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dbsr_col_ind, bsr_col_ind.data(), sizeof(int) * nnzb, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dbsr_val, bsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2csr(handle, dir, mb, nb, bsr_descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, row_block_dim, col_block_dim, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind)); // Host CSR matrix std::vector dh_csr_row_ptr(m + 1); std::vector dh_csr_col_ind(nnz); std::vector dh_csr_val(nnz); // Copy output from device to host CHECK_HIP_ERROR(hipMemcpy( dh_csr_row_ptr.data(), dcsr_row_ptr, sizeof(int) * (m + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( dh_csr_col_ind.data(), dcsr_col_ind, sizeof(int) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(dh_csr_val.data(), dcsr_val, sizeof(T) * nnz, hipMemcpyDeviceToHost)); // Host CSR matrix std::vector h_csr_row_ptr(m + 1); std::vector h_csr_col_ind(nnz); std::vector h_csr_val(nnz); // Host gebsr2csr host_gebsr_to_csr(dir, mb, nb, nnzb, bsr_val, bsr_row_ptr, bsr_col_ind, row_block_dim, col_block_dim, bsr_idx_base, h_csr_val, h_csr_row_ptr, h_csr_col_ind, csr_idx_base); // Unit check unit_check_general(1, m + 1, 1, dh_csr_row_ptr.data(), h_csr_row_ptr.data()); unit_check_general(1, nnz, 1, dh_csr_col_ind.data(), h_csr_col_ind.data()); unit_check_general(1, nnz, 1, dh_csr_val.data(), h_csr_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2csr(handle, dir, mb, nb, bsr_descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, row_block_dim, col_block_dim, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2csr(handle, dir, mb, nb, bsr_descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, row_block_dim, col_block_dim, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = gebsr2csr_gbyte_count(mb, row_block_dim, col_block_dim, nnzb); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::Mb, mb, display_key_t::Nb, nb, display_key_t::row_block_dim, row_block_dim, display_key_t::col_block_dim, col_block_dim, display_key_t::nnzb, nnzb, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GEBSR2CSR_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_gebsr2gebsc.hpp000066400000000000000000000756511501764003400237200ustar00rootroot00000000000000/* ************************************************************************ * 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 "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_gebsr2gebsc_bad_arg(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 = 1; auto bsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto bsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto bsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* bsr_row_ptr = (int*)bsr_row_ptr_managed.get(); int* bsr_col_ind = (int*)bsr_col_ind_managed.get(); T* bsr_val = (T*)bsr_val_managed.get(); auto bsc_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto bsc_col_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto bsc_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto buffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; void* buffer = buffer_managed.get(); int* bsc_row_ind = (int*)bsc_row_ind_managed.get(); int* bsc_col_ptr = (int*)bsc_col_ptr_managed.get(); T* bsc_val = (T*)bsc_val_managed.get(); int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(bsr_row_ptr, local_ptr, sizeof(int) * (safe_size + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(bsc_col_ptr, local_ptr, sizeof(int) * (safe_size + 1), hipMemcpyHostToDevice)); size_t buffer_size; status = hipsparseXgebsr2gebsc_bufferSize(nullptr, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, &buffer_size); verify_hipsparse_status_invalid_handle(status); status = hipsparseXgebsr2gebsc_bufferSize(handle, -1, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, &buffer_size); verify_hipsparse_status_invalid_size(status, "Error: mb is invalid"); status = hipsparseXgebsr2gebsc_bufferSize(handle, safe_size, -1, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, &buffer_size); verify_hipsparse_status_invalid_size(status, "Error: nb is invalid"); status = hipsparseXgebsr2gebsc_bufferSize(handle, safe_size, safe_size, -1, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, &buffer_size); verify_hipsparse_status_invalid_size(status, "Error: nnzb is invalid"); status = hipsparseXgebsr2gebsc_bufferSize(handle, safe_size, safe_size, safe_size, nullptr, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, &buffer_size); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_val is nullptr"); status = hipsparseXgebsr2gebsc_bufferSize(handle, safe_size, safe_size, safe_size, bsr_val, nullptr, bsr_col_ind, safe_size, safe_size, &buffer_size); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_row_ptr is nullptr"); status = hipsparseXgebsr2gebsc_bufferSize(handle, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, nullptr, safe_size, safe_size, &buffer_size); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_col_ind is nullptr"); status = hipsparseXgebsr2gebsc_bufferSize(handle, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, -1, safe_size, &buffer_size); verify_hipsparse_status_invalid_size(status, "Error: row_block_dim is invalid"); status = hipsparseXgebsr2gebsc_bufferSize(handle, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, -1, &buffer_size); verify_hipsparse_status_invalid_size(status, "Error: col_block_dim is invalid"); status = hipsparseXgebsr2gebsc_bufferSize(handle, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer_size is nullptr"); // Test hipsparseXgebsr2gebsc() status = hipsparseXgebsr2gebsc(nullptr, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, bsc_val, bsc_row_ind, bsc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, buffer); verify_hipsparse_status_invalid_handle(status); status = hipsparseXgebsr2gebsc(handle, -1, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, bsc_val, bsc_row_ind, bsc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, buffer); verify_hipsparse_status_invalid_size(status, "Error: mb is invalid"); status = hipsparseXgebsr2gebsc(handle, safe_size, -1, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, bsc_val, bsc_row_ind, bsc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, buffer); verify_hipsparse_status_invalid_size(status, "Error: nb is invalid"); status = hipsparseXgebsr2gebsc(handle, safe_size, safe_size, -1, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, bsc_val, bsc_row_ind, bsc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, buffer); verify_hipsparse_status_invalid_size(status, "Error: nnzb is invalid"); status = hipsparseXgebsr2gebsc(handle, safe_size, safe_size, safe_size, nullptr, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, bsc_val, bsc_row_ind, bsc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, buffer); verify_hipsparse_status_invalid_size(status, "Error: bsr_val is nullptr"); status = hipsparseXgebsr2gebsc(handle, safe_size, safe_size, safe_size, bsr_val, nullptr, bsr_col_ind, safe_size, safe_size, bsc_val, bsc_row_ind, bsc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_row_ptr is nullptr"); status = hipsparseXgebsr2gebsc(handle, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, nullptr, safe_size, safe_size, bsc_val, bsc_row_ind, bsc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_col_ind is nullptr"); status = hipsparseXgebsr2gebsc(handle, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, -1, safe_size, bsc_val, bsc_row_ind, bsc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, buffer); verify_hipsparse_status_invalid_size(status, "Error: row_block_dim is invalid"); status = hipsparseXgebsr2gebsc(handle, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, -1, bsc_val, bsc_row_ind, bsc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, buffer); verify_hipsparse_status_invalid_size(status, "Error: col_block_dim is invalid"); status = hipsparseXgebsr2gebsc(handle, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, nullptr, bsc_row_ind, bsc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsc_val is nullptr"); status = hipsparseXgebsr2gebsc(handle, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, bsc_val, nullptr, bsc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsc_row_ind is nullptr"); status = hipsparseXgebsr2gebsc(handle, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, bsc_val, bsc_row_ind, nullptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsc_col_ptr is nullptr"); status = hipsparseXgebsr2gebsc(handle, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, bsc_val, bsc_row_ind, bsc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer is invalid"); #endif } #define DEVICE_ALLOC(TYPE, NAME, SIZE) \ auto NAME##_managed = hipsparse_unique_ptr{device_malloc(sizeof(TYPE) * SIZE), device_free}; \ TYPE* NAME = (TYPE*)NAME##_managed.get() template hipsparseStatus_t testing_gebsr2gebsc(Arguments argus) { int m = argus.M; int n = argus.N; int row_block_dim = argus.row_block_dimA; int col_block_dim = argus.col_block_dimA; hipsparseAction_t action = argus.action; hipsparseIndexBase_t base = argus.baseA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; if(m == 0 || n == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse does not support m == 0 for csr2bsr return HIPSPARSE_STATUS_SUCCESS; #endif } int mb = m * row_block_dim; int nb = n * col_block_dim; srand(12345ULL); // Host structures std::vector hbsr_row_ptr; std::vector hbsr_col_ind; std::vector hbsr_val; // Read or construct CSR matrix int nnzb = 0; if(!generate_csr_matrix(filename, mb, nb, nnzb, hbsr_row_ptr, hbsr_col_ind, hbsr_val, base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } m = mb * row_block_dim; n = nb * col_block_dim; size_t nnz = nnzb * row_block_dim * col_block_dim; // Now use the csr matrix as the symbolic for the gebsr matrix. hbsr_val.resize(nnz); for(size_t i = 0; i < nnz; ++i) { hbsr_val[i] = random_generator(); } DEVICE_ALLOC(int, dbsr_row_ptr, (mb + 1)); DEVICE_ALLOC(int, dbsr_col_ind, nnzb); DEVICE_ALLOC(T, dbsr_val, (nnzb * row_block_dim * col_block_dim)); // Copy data from host to device CHECK_HIP_ERROR(hipMemcpy( dbsr_row_ptr, hbsr_row_ptr.data(), sizeof(int) * (mb + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dbsr_col_ind, hbsr_col_ind.data(), sizeof(int) * nnzb, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dbsr_val, hbsr_val.data(), sizeof(T) * nnzb * row_block_dim * col_block_dim, hipMemcpyHostToDevice)); // Obtain required buffer size (from host) size_t buffer_size; CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2gebsc_bufferSize(handle, mb, nb, nnzb, dbsr_val, dbsr_row_ptr, dbsr_col_ind, row_block_dim, col_block_dim, &buffer_size)); // Allocate the buffer size. auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(buffer_size), device_free}; void* dbuffer = dbuffer_managed.get(); DEVICE_ALLOC(int, dbsc_row_ind, nnzb); DEVICE_ALLOC(int, dbsc_col_ptr, (nb + 1)); DEVICE_ALLOC(T, dbsc_val, (nnzb * row_block_dim * col_block_dim)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2gebsc(handle, mb, nb, nnzb, dbsr_val, dbsr_row_ptr, dbsr_col_ind, row_block_dim, col_block_dim, dbsc_val, dbsc_row_ind, dbsc_col_ptr, action, base, dbuffer)); // Transfer to host. std::vector hbsc_from_device_row_ind(nnzb); std::vector hbsc_from_device_col_ptr(nb + 1); std::vector hbsc_from_device_val(nnzb * row_block_dim * col_block_dim); CHECK_HIP_ERROR(hipMemcpy(hbsc_from_device_col_ptr.data(), dbsc_col_ptr, sizeof(int) * (nb + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsc_from_device_row_ind.data(), dbsc_row_ind, sizeof(int) * nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsc_from_device_val.data(), dbsc_val, sizeof(T) * nnzb * row_block_dim * col_block_dim, hipMemcpyDeviceToHost)); // Allocate host bsc matrix. std::vector hbsc_row_ind(nnzb); std::vector hbsc_col_ptr(nb + 1); std::vector hbsc_val(nnzb * row_block_dim * col_block_dim); host_gebsr_to_gebsc(mb, nb, nnzb, hbsr_row_ptr, hbsr_col_ind, hbsr_val, row_block_dim, col_block_dim, hbsc_row_ind, hbsc_col_ptr, hbsc_val, action, base); unit_check_general(1, nb + 1, 1, hbsc_from_device_col_ptr.data(), hbsc_col_ptr.data()); unit_check_general(1, nnzb, 1, hbsc_from_device_row_ind.data(), hbsc_row_ind.data()); if(action == HIPSPARSE_ACTION_NUMERIC) { unit_check_general(1, nnzb * row_block_dim * col_block_dim, 1, hbsc_from_device_val.data(), hbsc_val.data()); } } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2gebsc(handle, mb, nb, nnzb, dbsr_val, dbsr_row_ptr, dbsr_col_ind, row_block_dim, col_block_dim, dbsc_val, dbsc_row_ind, dbsc_col_ptr, action, base, dbuffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2gebsc(handle, mb, nb, nnzb, dbsr_val, dbsr_row_ptr, dbsr_col_ind, row_block_dim, col_block_dim, dbsc_val, dbsc_row_ind, dbsc_col_ptr, action, base, dbuffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = gebsr2gebsc_gbyte_count(mb, nb, nnzb, row_block_dim, col_block_dim, action); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::Mb, mb, display_key_t::Nb, nb, display_key_t::nnzb, nnzb, display_key_t::row_block_dim, row_block_dim, display_key_t::col_block_dim, col_block_dim, display_key_t::action, hipsparse_action2string(action), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GEBSR2GEBSC_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_gebsr2gebsr.hpp000066400000000000000000001740011501764003400237240ustar00rootroot00000000000000/* ************************************************************************ * 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 "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" using namespace hipsparse; using namespace hipsparse_test; template void testing_gebsr2gebsr_bad_arg(void) { #if(!defined(CUDART_VERSION)) int mb = 1; int nb = 1; int nnzb = 1; int safe_size = 1; int row_block_dim_A = 2; int col_block_dim_A = 2; int row_block_dim_C = 2; int col_block_dim_C = 2; hipsparseIndexBase_t idx_base_A = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexBase_t idx_base_C = HIPSPARSE_INDEX_BASE_ZERO; hipsparseDirection_t dir = HIPSPARSE_DIRECTION_ROW; hipsparseStatus_t status; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = unique_ptr_descr_A->descr; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; hipsparseSetMatIndexBase(descr_A, idx_base_A); hipsparseSetMatIndexBase(descr_C, idx_base_C); auto bsr_row_ptr_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto bsr_col_ind_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto bsr_val_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto bsr_row_ptr_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto bsr_col_ind_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto bsr_val_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto temp_buffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* bsr_row_ptr_A = (int*)bsr_row_ptr_A_managed.get(); int* bsr_col_ind_A = (int*)bsr_col_ind_A_managed.get(); T* bsr_val_A = (T*)bsr_val_A_managed.get(); int* bsr_row_ptr_C = (int*)bsr_row_ptr_C_managed.get(); int* bsr_col_ind_C = (int*)bsr_col_ind_C_managed.get(); T* bsr_val_C = (T*)bsr_val_C_managed.get(); T* temp_buffer = (T*)temp_buffer_managed.get(); int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(bsr_row_ptr_A, local_ptr, sizeof(int) * (safe_size + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(bsr_row_ptr_C, local_ptr, sizeof(int) * (safe_size + 1), hipMemcpyHostToDevice)); // Testing hipsparseXgebsr2gebsr_bufferSize() int buffer_size; // Test invalid handle status = hipsparseXgebsr2gebsr_bufferSize(nullptr, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, row_block_dim_C, col_block_dim_C, &buffer_size); verify_hipsparse_status_invalid_handle(status); // Test invalid pointers status = hipsparseXgebsr2gebsr_bufferSize(handle, dir, mb, nb, nnzb, nullptr, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, row_block_dim_C, col_block_dim_C, &buffer_size); verify_hipsparse_status_invalid_pointer(status, "Error: descr_A is nullptr"); status = hipsparseXgebsr2gebsr_bufferSize(handle, dir, mb, nb, nnzb, descr_A, (const T*)nullptr, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, row_block_dim_C, col_block_dim_C, &buffer_size); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_val_A is nullptr"); status = hipsparseXgebsr2gebsr_bufferSize(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, nullptr, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, row_block_dim_C, col_block_dim_C, &buffer_size); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_row_ptr_A is nullptr"); status = hipsparseXgebsr2gebsr_bufferSize(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, nullptr, row_block_dim_A, col_block_dim_A, row_block_dim_C, col_block_dim_C, &buffer_size); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_col_ind_A is nullptr"); status = hipsparseXgebsr2gebsr_bufferSize(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, row_block_dim_C, col_block_dim_C, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer_size is nullptr"); // Test invalid sizes status = hipsparseXgebsr2gebsr_bufferSize(handle, dir, -1, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, row_block_dim_C, col_block_dim_C, &buffer_size); verify_hipsparse_status_invalid_size(status, "Error: mb is invalid"); status = hipsparseXgebsr2gebsr_bufferSize(handle, dir, mb, -1, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, row_block_dim_C, col_block_dim_C, &buffer_size); verify_hipsparse_status_invalid_size(status, "Error: nb is invalid"); status = hipsparseXgebsr2gebsr_bufferSize(handle, dir, mb, nb, -1, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, row_block_dim_C, col_block_dim_C, &buffer_size); verify_hipsparse_status_invalid_size(status, "Error: nnzb is invalid"); status = hipsparseXgebsr2gebsr_bufferSize(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, -1, col_block_dim_A, row_block_dim_C, col_block_dim_C, &buffer_size); verify_hipsparse_status_invalid_size(status, "Error: row_block_dim_A is invalid"); status = hipsparseXgebsr2gebsr_bufferSize(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, -1, row_block_dim_C, col_block_dim_C, &buffer_size); verify_hipsparse_status_invalid_size(status, "Error: col_block_dim_A is invalid"); status = hipsparseXgebsr2gebsr_bufferSize(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, -1, col_block_dim_C, &buffer_size); verify_hipsparse_status_invalid_size(status, "Error: row_block_dim_C is invalid"); status = hipsparseXgebsr2gebsr_bufferSize(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, row_block_dim_C, -1, &buffer_size); verify_hipsparse_status_invalid_size(status, "Error: col_block_dim_C is invalid"); // Testing hipsparseXgebsr2gebsrNnz() int nnz_total_dev_host_ptr; // Test invalid handle status = hipsparseXgebsr2gebsrNnz(nullptr, dir, mb, nb, nnzb, descr_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_row_ptr_C, row_block_dim_C, col_block_dim_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_handle(status); // Test invalid pointers status = hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, nnzb, nullptr, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_row_ptr_C, row_block_dim_C, col_block_dim_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_A is nullptr"); status = hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, nnzb, descr_A, nullptr, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_row_ptr_C, row_block_dim_C, col_block_dim_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_row_ptr_A is nullptr"); status = hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, nnzb, descr_A, bsr_row_ptr_A, nullptr, row_block_dim_A, col_block_dim_A, descr_C, bsr_row_ptr_C, row_block_dim_C, col_block_dim_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_col_ind_A is nullptr"); status = hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, nnzb, descr_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, nullptr, bsr_row_ptr_C, row_block_dim_C, col_block_dim_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_C is nullptr"); status = hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, nnzb, descr_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, nullptr, row_block_dim_C, col_block_dim_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_row_ptr_C is nullptr"); status = hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, nnzb, descr_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_row_ptr_C, row_block_dim_C, col_block_dim_C, nullptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: nnz_total_dev_host_ptr is nullptr"); // Test invalid sizes status = hipsparseXgebsr2gebsrNnz(handle, dir, -1, nb, nnzb, descr_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_row_ptr_C, row_block_dim_C, col_block_dim_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: mb is invalid"); status = hipsparseXgebsr2gebsrNnz(handle, dir, mb, -1, nnzb, descr_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_row_ptr_C, row_block_dim_C, col_block_dim_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: nb is invalid"); status = hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, -1, descr_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_row_ptr_C, row_block_dim_C, col_block_dim_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: nnzb is invalid"); status = hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, nnzb, descr_A, bsr_row_ptr_A, bsr_col_ind_A, -1, col_block_dim_A, descr_C, bsr_row_ptr_C, row_block_dim_C, col_block_dim_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: row_block_dim_A is invalid"); status = hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, nnzb, descr_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, -1, descr_C, bsr_row_ptr_C, row_block_dim_C, col_block_dim_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: col_block_dim_A is invalid"); status = hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, nnzb, descr_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_row_ptr_C, -1, col_block_dim_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: row_block_dim_C is invalid"); status = hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, nnzb, descr_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_row_ptr_C, row_block_dim_C, -1, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: col_block_dim_C is invalid"); // Test hipsparseXgebsr2gebsr() // Test invalid handle status = hipsparseXgebsr2gebsr(nullptr, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_handle(status); // Test invalid pointers status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, nullptr, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_A is nullptr"); status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, (const T*)nullptr, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_val_A is nullptr"); status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, nullptr, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_row_ptr_A is nullptr"); status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, nullptr, row_block_dim_A, col_block_dim_A, descr_C, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_col_ind_A is nullptr"); status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, nullptr, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_C is nullptr"); status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, (T*)nullptr, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_val_C is nullptr"); status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_val_C, nullptr, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_row_ptr_C is nullptr"); status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_val_C, bsr_row_ptr_C, nullptr, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_col_ind_C is nullptr"); // Test invalid sizes status = hipsparseXgebsr2gebsr(handle, dir, -1, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: mb is invalid"); status = hipsparseXgebsr2gebsr(handle, dir, mb, -1, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: nb is invalid"); status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, -1, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: nnzb is invalid"); status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, -1, col_block_dim_A, descr_C, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: row_block_dim_A is invalid"); status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, -1, descr_C, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: col_block_dim_A is invalid"); status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, -1, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: row_block_dim_C is invalid"); status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, -1, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: col_block_dim_C is invalid"); #endif } template hipsparseStatus_t testing_gebsr2gebsr(Arguments argus) { int m = argus.M; int n = argus.N; int row_block_dim_A = argus.row_block_dimA; int col_block_dim_A = argus.col_block_dimA; int row_block_dim_C = argus.row_block_dimB; int col_block_dim_C = argus.col_block_dimB; hipsparseIndexBase_t idx_base_A = argus.baseA; hipsparseIndexBase_t idx_base_C = argus.baseB; hipsparseDirection_t dir = argus.dirA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = unique_ptr_descr_A->descr; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; hipsparseSetMatIndexBase(descr_A, idx_base_A); hipsparseSetMatIndexBase(descr_C, idx_base_C); if(m == 0 || n == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse does not support m == 0 for csr2bsr return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base_A)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // mb and nb can be modified if reading from a file int mb = (m + row_block_dim_A - 1) / row_block_dim_A; int nb = (n + col_block_dim_A - 1) / col_block_dim_A; int mb_C = (mb * row_block_dim_A + row_block_dim_C - 1) / row_block_dim_C; int nb_C = (nb * col_block_dim_A + col_block_dim_C - 1) / col_block_dim_C; // allocate memory on device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dbsr_row_ptr_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb + 1)), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); int* dbsr_row_ptr_A = (int*)dbsr_row_ptr_A_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_val, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); size_t buffer_size_conversion; CHECK_HIPSPARSE_ERROR(hipsparseXcsr2gebsr_bufferSize(handle, dir, m, n, descr_A, dcsr_val, dcsr_row_ptr, dcsr_col_ind, row_block_dim_A, col_block_dim_A, &buffer_size_conversion)); auto dbuffer_conversion_managed = hipsparse_unique_ptr{device_malloc(buffer_size_conversion), device_free}; void* dbuffer_conversion = dbuffer_conversion_managed.get(); // Obtain BSR nnzb first on the host and then using the device and ensure they give the same results CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); int nnzb; CHECK_HIPSPARSE_ERROR(hipsparseXcsr2gebsrNnz(handle, dir, m, n, descr_A, dcsr_row_ptr, dcsr_col_ind, descr_A, dbsr_row_ptr_A, row_block_dim_A, col_block_dim_A, &nnzb, dbuffer_conversion)); // Allocate memory on the device auto dbsr_col_ind_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnzb), device_free}; auto dbsr_val_A_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * nnzb * row_block_dim_A * col_block_dim_A), device_free}; auto dbsr_row_ptr_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb_C + 1)), device_free}; int* dbsr_col_ind_A = (int*)dbsr_col_ind_A_managed.get(); T* dbsr_val_A = (T*)dbsr_val_A_managed.get(); int* dbsr_row_ptr_C = (int*)dbsr_row_ptr_C_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseXcsr2gebsr(handle, dir, m, n, descr_A, dcsr_val, dcsr_row_ptr, dcsr_col_ind, descr_A, dbsr_val_A, dbsr_row_ptr_A, dbsr_col_ind_A, row_block_dim_A, col_block_dim_A, dbuffer_conversion)); // Copy output from device to host std::vector hbsr_row_ptr_A(mb + 1); std::vector hbsr_col_ind_A(nnzb); std::vector hbsr_val_A(nnzb * row_block_dim_A * col_block_dim_A); CHECK_HIP_ERROR(hipMemcpy( hbsr_row_ptr_A.data(), dbsr_row_ptr_A, sizeof(int) * (mb + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hbsr_col_ind_A.data(), dbsr_col_ind_A, sizeof(int) * nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsr_val_A.data(), dbsr_val_A, sizeof(T) * nnzb * row_block_dim_A * col_block_dim_A, hipMemcpyDeviceToHost)); int buffer_size = 0; CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2gebsr_bufferSize(handle, dir, mb, nb, nnzb, descr_A, dbsr_val_A, dbsr_row_ptr_A, dbsr_col_ind_A, row_block_dim_A, col_block_dim_A, row_block_dim_C, col_block_dim_C, &buffer_size)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * buffer_size), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); // Obtain BSR nnzb first on the host and then using the device and ensure they give the same results CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); int hnnzb_C; CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, nnzb, descr_A, dbsr_row_ptr_A, dbsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, dbsr_row_ptr_C, row_block_dim_C, col_block_dim_C, &hnnzb_C, dbuffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); auto dnnzb_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dnnzb_C = (int*)dnnzb_C_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, nnzb, descr_A, dbsr_row_ptr_A, dbsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, dbsr_row_ptr_C, row_block_dim_C, col_block_dim_C, dnnzb_C, dbuffer)); int hnnzb_C_copied_from_device; CHECK_HIP_ERROR( hipMemcpy(&hnnzb_C_copied_from_device, dnnzb_C, sizeof(int), hipMemcpyDeviceToHost)); if(argus.unit_check) { // Check that using host and device pointer mode gives the same result unit_check_general(1, 1, 1, &hnnzb_C_copied_from_device, &hnnzb_C); } // Allocate memory on the device auto dbsr_col_ind_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * hnnzb_C), device_free}; auto dbsr_val_C_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * hnnzb_C * row_block_dim_C * col_block_dim_C), device_free}; int* dbsr_col_ind_C = (int*)dbsr_col_ind_C_managed.get(); T* dbsr_val_C = (T*)dbsr_val_C_managed.get(); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, dbsr_val_A, dbsr_row_ptr_A, dbsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, dbsr_val_C, dbsr_row_ptr_C, dbsr_col_ind_C, row_block_dim_C, col_block_dim_C, dbuffer)); // Copy output from device to host std::vector hbsr_row_ptr_C(mb_C + 1); std::vector hbsr_col_ind_C(hnnzb_C); std::vector hbsr_val_C(hnnzb_C * row_block_dim_C * col_block_dim_C); CHECK_HIP_ERROR(hipMemcpy(hbsr_row_ptr_C.data(), dbsr_row_ptr_C, sizeof(int) * (mb_C + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hbsr_col_ind_C.data(), dbsr_col_ind_C, sizeof(int) * hnnzb_C, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsr_val_C.data(), dbsr_val_C, sizeof(T) * hnnzb_C * row_block_dim_C * col_block_dim_C, hipMemcpyDeviceToHost)); // Host csr2bsr conversion std::vector hbsr_row_ptr_C_gold; std::vector hbsr_col_ind_C_gold; std::vector hbsr_val_C_gold; // call host gebsr2gebsr here host_gebsr_to_gebsr(dir, mb, nb, nnzb, hbsr_val_A, hbsr_row_ptr_A, hbsr_col_ind_A, row_block_dim_A, col_block_dim_A, idx_base_A, hbsr_val_C_gold, hbsr_row_ptr_C_gold, hbsr_col_ind_C_gold, row_block_dim_C, col_block_dim_C, idx_base_C); int nnzb_C_gold = hbsr_row_ptr_C_gold[mb_C] - hbsr_row_ptr_C_gold[0]; // Unit check unit_check_general(1, 1, 1, &nnzb_C_gold, &hnnzb_C); unit_check_general(1, mb_C + 1, 1, hbsr_row_ptr_C_gold.data(), hbsr_row_ptr_C.data()); unit_check_general(1, hnnzb_C, 1, hbsr_col_ind_C_gold.data(), hbsr_col_ind_C.data()); unit_check_general(1, hnnzb_C * row_block_dim_C * col_block_dim_C, 1, hbsr_val_C_gold.data(), hbsr_val_C.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, dbsr_val_A, dbsr_row_ptr_A, dbsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, dbsr_val_C, dbsr_row_ptr_C, dbsr_col_ind_C, row_block_dim_C, col_block_dim_C, dbuffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, dbsr_val_A, dbsr_row_ptr_A, dbsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, dbsr_val_C, dbsr_row_ptr_C, dbsr_col_ind_C, row_block_dim_C, col_block_dim_C, dbuffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = gebsr2gebsr_gbyte_count(mb, mb_C, row_block_dim_A, col_block_dim_A, row_block_dim_C, col_block_dim_C, nnzb, hnnzb_C); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::MbA, mb, display_key_t::NbA, nb, display_key_t::MbC, mb_C, display_key_t::NbC, nb_C, display_key_t::row_block_dimA, row_block_dim_A, display_key_t::col_block_dimA, col_block_dim_A, display_key_t::row_block_dimC, row_block_dim_C, display_key_t::col_block_dimC, col_block_dim_C, display_key_t::nnzbA, nnzb, display_key_t::nnzbC, hnnzb_C, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GEBSR2GEBSR_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_gemmi.hpp000066400000000000000000000651661501764003400226260ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_GEMMI_HPP #define TESTING_GEMMI_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_gemmi_bad_arg(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(); verify_hipsparse_status_invalid_handle(hipsparseXgemmi(nullptr, safe_size, safe_size, safe_size, safe_size, &alpha, dA, safe_size, dval, dptr, drow, &beta, dC, safe_size)); verify_hipsparse_status_invalid_pointer(hipsparseXgemmi(handle, safe_size, safe_size, safe_size, safe_size, nullptr, dA, safe_size, dval, dptr, drow, &beta, dC, safe_size), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgemmi(handle, safe_size, safe_size, safe_size, safe_size, &alpha, nullptr, safe_size, dval, dptr, drow, &beta, dC, safe_size), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgemmi(handle, safe_size, safe_size, safe_size, safe_size, &alpha, dA, safe_size, nullptr, dptr, drow, &beta, dC, safe_size), "Error: cscValB is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgemmi(handle, safe_size, safe_size, safe_size, safe_size, &alpha, dA, safe_size, dval, nullptr, drow, &beta, dC, safe_size), "Error: cscColPtrB is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgemmi(handle, safe_size, safe_size, safe_size, safe_size, &alpha, dA, safe_size, dval, dptr, nullptr, &beta, dC, safe_size), "Error: cscRowIndB is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgemmi(handle, safe_size, safe_size, safe_size, safe_size, &alpha, dA, safe_size, dval, dptr, drow, nullptr, dC, safe_size), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgemmi(handle, safe_size, safe_size, safe_size, safe_size, &alpha, dA, safe_size, dval, dptr, drow, &beta, nullptr, safe_size), "Error: C is nullptr"); verify_hipsparse_status_invalid_size(hipsparseXgemmi(handle, -1, safe_size, safe_size, safe_size, &alpha, dA, safe_size, dval, dptr, drow, &beta, dC, safe_size), "Error: m is invalid"); verify_hipsparse_status_invalid_size(hipsparseXgemmi(handle, safe_size, -1, safe_size, safe_size, &alpha, dA, safe_size, dval, dptr, drow, &beta, dC, safe_size), "Error: n is invalid"); verify_hipsparse_status_invalid_size(hipsparseXgemmi(handle, safe_size, safe_size, -1, safe_size, &alpha, dA, safe_size, dval, dptr, drow, &beta, dC, safe_size), "Error: k is invalid"); verify_hipsparse_status_invalid_size(hipsparseXgemmi(handle, safe_size, safe_size, safe_size, -1, &alpha, dA, safe_size, dval, dptr, drow, &beta, dC, safe_size), "Error: nnz is invalid"); verify_hipsparse_status_invalid_size(hipsparseXgemmi(handle, safe_size, safe_size, safe_size, safe_size, &alpha, dA, -1, dval, dptr, drow, &beta, dC, safe_size), "Error: lda is invalid"); verify_hipsparse_status_invalid_size(hipsparseXgemmi(handle, safe_size, safe_size, safe_size, safe_size, &alpha, dA, safe_size, dval, dptr, drow, &beta, dC, -1), "Error: ldc is invalid"); #endif } template hipsparseStatus_t testing_gemmi(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int M = argus.M; int N = argus.N; int K = argus.K; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; if(M == 0 || N == 0 || K == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcsc_col_ptrB; std::vector hcsc_row_indB; std::vector hcsc_valB; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix( filename, N, K, nnz, hcsc_col_ptrB, hcsc_row_indB, hcsc_valB, HIPSPARSE_INDEX_BASE_ZERO)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } int lda = std::max(1, M); int ldc = std::max(1, M); int Annz = lda * K; int Cnnz = ldc * N; // Host structures - Dense matrix B and C std::vector hA(Annz); std::vector hC_1(Cnnz); std::vector hC_2(Cnnz); std::vector hC_gold(Cnnz); hipsparseInit(hA, M, K); hipsparseInit(hC_gold, M, N); // allocate memory on device auto dcsc_col_ptrB_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (N + 1)), device_free}; auto dcsc_row_indB_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsc_valB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dA_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * Annz), device_free}; auto dC_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * Cnnz), device_free}; auto dC_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * Cnnz), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dcsc_col_ptrB = (int*)dcsc_col_ptrB_managed.get(); int* dcsc_row_indB = (int*)dcsc_row_indB_managed.get(); T* dcsc_valB = (T*)dcsc_valB_managed.get(); T* dA = (T*)dA_managed.get(); T* dC_1 = (T*)dC_1_managed.get(); T* dC_2 = (T*)dC_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy( dcsc_col_ptrB, hcsc_col_ptrB.data(), sizeof(int) * (N + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsc_row_indB, hcsc_row_indB.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsc_valB, hcsc_valB.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dA, hA.data(), sizeof(T) * Annz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_1, hC_gold.data(), sizeof(T) * Cnnz, hipMemcpyHostToDevice)); if(argus.unit_check) { CHECK_HIP_ERROR(hipMemcpy(dC_2, dC_1, sizeof(T) * Cnnz, hipMemcpyDeviceToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXgemmi(handle, M, N, K, nnz, &h_alpha, dA, lda, dcsc_valB, dcsc_col_ptrB, dcsc_row_indB, &h_beta, dC_1, ldc)); // pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXgemmi(handle, M, N, K, nnz, d_alpha, dA, lda, dcsc_valB, dcsc_col_ptrB, dcsc_row_indB, d_beta, dC_2, ldc)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hC_1.data(), dC_1, sizeof(T) * Cnnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hC_2.data(), dC_2, sizeof(T) * Cnnz, hipMemcpyDeviceToHost)); // CPU for(int i = 0; i < M; ++i) { for(int j = 0; j < N; ++j) { T sum = make_DataType(0); int col_begin = hcsc_col_ptrB[j]; int col_end = hcsc_col_ptrB[j + 1]; for(int k = col_begin; k < col_end; ++k) { int row_B = hcsc_row_indB[k]; T val_B = hcsc_valB[k]; T val_A = hA[row_B * lda + i]; sum = testing_fma(val_A, val_B, sum); } hC_gold[j * ldc + i] = testing_fma(h_beta, hC_gold[j * ldc + i], testing_mult(h_alpha, sum)); } } unit_check_near(M, N, ldc, hC_gold.data(), hC_1.data()); unit_check_near(M, N, ldc, hC_gold.data(), hC_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgemmi(handle, M, N, K, nnz, &h_alpha, dA, lda, dcsc_valB, dcsc_col_ptrB, dcsc_row_indB, &h_beta, dC_1, ldc)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgemmi(handle, M, N, K, nnz, &h_alpha, dA, lda, dcsc_valB, dcsc_col_ptrB, dcsc_row_indB, &h_beta, dC_1, ldc)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = gemmi_gflop_count(M, nnz, M * N, h_beta != make_DataType(0.0)); double gbyte_count = gemmi_gbyte_count(N, nnz, M * K, M * N, h_beta != make_DataType(0.0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, M, display_key_t::N, N, display_key_t::K, K, display_key_t::nnzA, M * K, display_key_t::nnzB, nnz, display_key_t::nnzC, M * N, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GEMMI_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_gemvi.hpp000066400000000000000000000300301501764003400226150ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_GEMVI_HPP #define TESTING_GEMVI_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include using namespace hipsparse; using namespace hipsparse_test; void testing_gemvi_bad_arg(void) { #if(!defined(CUDART_VERSION)) int m = 100; int n = 100; int nnz = 100; int lda = 100; static constexpr hipsparseOperation_t opType = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; 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(); // 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_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(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int m = argus.M; int n = argus.N; int nnz = argus.nnz; T alpha = make_DataType(argus.alpha); T beta = make_DataType(argus.beta); hipsparseOperation_t trans = argus.transA; hipsparseIndexBase_t idxBase = argus.baseA; std::string filename = argus.filename; int lda = m; // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hA(m * n); std::vector hx_val(nnz); std::vector hx_ind(nnz); std::vector hy(m); std::vector hy_gold(m); // Initial Data on CPU srand(12345ULL); hipsparseInitIndex(hx_ind.data(), nnz, 1, n); hipsparseInit(hx_val, 1, nnz); hipsparseInit(hy, 1, m); hy_gold = hy; for(int i = 0; i < m * n; ++i) { hA[i] = random_generator(); } // Allocate memory on device auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dA_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * n), device_free}; int* dx_ind = (int*)dx_ind_managed.get(); T* dx_val = (T*)dx_val_managed.get(); T* dy = (T*)dy_managed.get(); T* dA = (T*)dA_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dx_ind, hx_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx_val, hx_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy, hy.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dA, hA.data(), sizeof(T) * m * n, hipMemcpyHostToDevice)); // gemvi bufferSize int bufferSize; void* externalBuffer; CHECK_HIPSPARSE_ERROR(hipsparseXgemvi_bufferSize(handle, trans, m, n, nnz, &bufferSize)); CHECK_HIP_ERROR(hipMalloc(&externalBuffer, bufferSize)); if(argus.unit_check) { // gemvi CHECK_HIPSPARSE_ERROR(hipsparseXgemvi(handle, trans, m, n, &alpha, dA, lda, nnz, dx_val, dx_ind, &beta, dy, idxBase, externalBuffer)); // CPU for(int i = 0; i < m; ++i) { T sum = make_DataType(0); for(int j = 0; j < nnz; ++j) { sum = testing_fma(hx_val[j], hA[(hx_ind[j] - idxBase) * lda + i], sum); } hy_gold[i] = testing_fma(alpha, sum, testing_mult(beta, hy_gold[i])); } // Verify results against host CHECK_HIP_ERROR(hipMemcpy(hy.data(), dy, sizeof(T) * m, hipMemcpyDeviceToHost)); unit_check_near(m, 1, 1, hy_gold.data(), hy.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgemvi(handle, trans, m, n, &alpha, dA, lda, nnz, dx_val, dx_ind, &beta, dy, idxBase, externalBuffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgemvi(handle, trans, m, n, &alpha, dA, lda, nnz, dx_val, dx_ind, &beta, dy, idxBase, externalBuffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = gemvi_gflop_count(m, nnz); double gbyte_count = gemvi_gbyte_count((trans == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : n, nnz, beta != make_DataType(0.0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::trans, hipsparse_operation2string(trans), display_key_t::alpha, alpha, display_key_t::beta, beta, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(externalBuffer)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GEMVI_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_gpsv_interleaved_batch.hpp000066400000000000000000000274621501764003400262270ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_GPSV_INTERLEAVED_BATCH_HPP #define TESTING_GPSV_INTERLEAVED_BATCH_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_gpsv_interleaved_batch_bad_arg(void) { // Dont do bad argument checking for cuda #if(!defined(CUDART_VERSION)) int safe_size = 100; int algo = 0; int m = 10; int batch_count = 10; // Create handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dds_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto ddl_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dd_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto ddu_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto ddw_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; T* dds = (T*)dds_managed.get(); T* ddl = (T*)ddl_managed.get(); T* dd = (T*)dd_managed.get(); T* ddu = (T*)ddu_managed.get(); T* ddw = (T*)ddw_managed.get(); T* dx = (T*)dx_managed.get(); void* dbuf = (void*)dbuf_managed.get(); size_t bsize; // gpsvInterleavedBatch_bufferSizeExt verify_hipsparse_status_invalid_handle(hipsparseXgpsvInterleavedBatch_bufferSizeExt( nullptr, algo, m, dds, ddl, dd, ddu, ddw, dx, batch_count, &bsize)); verify_hipsparse_status_invalid_value( hipsparseXgpsvInterleavedBatch_bufferSizeExt( handle, algo, -1, dds, ddl, dd, ddu, ddw, dx, batch_count, &bsize), "Error: m is invalid"); verify_hipsparse_status_invalid_value( hipsparseXgpsvInterleavedBatch_bufferSizeExt( handle, algo, m, dds, ddl, dd, ddu, ddw, dx, -1, &bsize), "Error: batch_count is invalid"); verify_hipsparse_status_invalid_pointer( hipsparseXgpsvInterleavedBatch_bufferSizeExt( handle, algo, m, dds, ddl, dd, ddu, ddw, dx, batch_count, nullptr), "Error: bsize is nullptr"); // gpsvInterleavedBatch verify_hipsparse_status_invalid_handle(hipsparseXgpsvInterleavedBatch( nullptr, algo, m, dds, ddl, dd, ddu, ddw, dx, batch_count, dbuf)); verify_hipsparse_status_invalid_value( hipsparseXgpsvInterleavedBatch( handle, algo, -1, dds, ddl, dd, ddu, ddw, dx, batch_count, dbuf), "Error: m is invalid"); verify_hipsparse_status_invalid_value( hipsparseXgpsvInterleavedBatch(handle, algo, m, dds, ddl, dd, ddu, ddw, dx, -1, dbuf), "Error: batch_count is invalid"); verify_hipsparse_status_invalid_pointer( hipsparseXgpsvInterleavedBatch( handle, algo, m, (T*)nullptr, ddl, dd, ddu, ddw, dx, batch_count, dbuf), "Error: dds is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgpsvInterleavedBatch( handle, algo, m, dds, (T*)nullptr, dd, ddu, ddw, dx, batch_count, dbuf), "Error: ddl is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgpsvInterleavedBatch( handle, algo, m, dds, ddl, (T*)nullptr, ddu, ddw, dx, batch_count, dbuf), "Error: dd is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgpsvInterleavedBatch( handle, algo, m, dds, ddl, dd, (T*)nullptr, ddw, dx, batch_count, dbuf), "Error: ddu is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgpsvInterleavedBatch( handle, algo, m, dds, ddl, dd, ddu, (T*)nullptr, dx, batch_count, dbuf), "Error: ddw is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgpsvInterleavedBatch( handle, algo, m, dds, ddl, dd, ddu, ddw, (T*)nullptr, batch_count, dbuf), "Error: dx is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgpsvInterleavedBatch( handle, algo, m, dds, ddl, dd, ddu, ddw, dx, batch_count, nullptr), "Error: bsize is nullptr"); #endif } template hipsparseStatus_t testing_gpsv_interleaved_batch(Arguments argus) { int m = argus.M; int batch_count = argus.batch_count; int algo = argus.gpsv_alg; // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hds(m * batch_count, make_DataType(1)); std::vector hdl(m * batch_count, make_DataType(1)); std::vector hd(m * batch_count, make_DataType(2)); std::vector hdu(m * batch_count, make_DataType(1)); std::vector hdw(m * batch_count, make_DataType(1)); std::vector hx(m * batch_count, make_DataType(3)); for(int i = 0; i < batch_count; i++) { hds[i] = make_DataType(0); hds[batch_count + i] = make_DataType(0); hdl[i] = make_DataType(0); hdu[batch_count * (m - 1) + i] = make_DataType(0); hdw[batch_count * (m - 1) + i] = make_DataType(0); hdw[batch_count * (m - 2) + i] = make_DataType(0); } std::vector hx_original = hx; // allocate memory on device auto dds_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * batch_count), device_free}; auto ddl_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * batch_count), device_free}; auto dd_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * batch_count), device_free}; auto ddu_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * batch_count), device_free}; auto ddw_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * batch_count), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * batch_count), device_free}; T* dds = (T*)dds_managed.get(); T* ddl = (T*)ddl_managed.get(); T* dd = (T*)dd_managed.get(); T* ddu = (T*)ddu_managed.get(); T* ddw = (T*)ddw_managed.get(); T* dx = (T*)dx_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dds, hds.data(), sizeof(T) * m * batch_count, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(ddl, hdl.data(), sizeof(T) * m * batch_count, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dd, hd.data(), sizeof(T) * m * batch_count, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(ddu, hdu.data(), sizeof(T) * m * batch_count, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(ddw, hdw.data(), sizeof(T) * m * batch_count, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx, hx.data(), sizeof(T) * m * batch_count, hipMemcpyHostToDevice)); // Query SparseToDense buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseXgpsvInterleavedBatch_bufferSizeExt( handle, algo, m, dds, ddl, dd, ddu, ddw, dx, batch_count, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseXgpsvInterleavedBatch( handle, algo, m, dds, ddl, dd, ddu, ddw, dx, batch_count, buffer)); // copy output from device to CPU CHECK_HIP_ERROR( hipMemcpy(hx.data(), dx, sizeof(T) * m * batch_count, hipMemcpyDeviceToHost)); // Check std::vector hresult(m * batch_count, make_DataType(3)); for(int b = 0; b < batch_count; b++) { for(int i = 0; i < m; ++i) { T sum = testing_mult(hd[batch_count * i + b], hx[batch_count * i + b]); sum = sum + ((i - 2 >= 0) ? testing_mult(hds[batch_count * i + b], hx[batch_count * (i - 2) + b]) : make_DataType(0)); sum = sum + ((i - 1 >= 0) ? testing_mult(hdl[batch_count * i + b], hx[batch_count * (i - 1) + b]) : make_DataType(0)); sum = sum + ((i + 1 < m) ? testing_mult(hdu[batch_count * i + b], hx[batch_count * (i + 1) + b]) : make_DataType(0)); sum = sum + ((i + 2 < m) ? testing_mult(hdw[batch_count * i + b], hx[batch_count * (i + 2) + b]) : make_DataType(0)); hresult[batch_count * i + b] = sum; } } unit_check_near(1, m * batch_count, 1, hx_original.data(), hresult.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgpsvInterleavedBatch( handle, algo, m, dds, ddl, dd, ddu, ddw, dx, batch_count, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgpsvInterleavedBatch( handle, algo, m, dds, ddl, dd, ddu, ddw, dx, batch_count, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = gpsv_interleaved_batch_gbyte_count(m, batch_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::batch_count, batch_count, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GPSV_INTERLEAVED_BATCH_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_gthr.hpp000066400000000000000000000143571501764003400224700ustar00rootroot00000000000000/* ************************************************************************ * 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 "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include using namespace hipsparse; using namespace hipsparse_test; template void testing_gthr_bad_arg(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(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_pointer( hipsparseXgthr(handle, nnz, dy, dx_val, (int*)nullptr, idx_base), "Error: x_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgthr(handle, nnz, dy, (T*)nullptr, dx_ind, idx_base), "Error: x_val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgthr(handle, nnz, (T*)nullptr, dx_val, dx_ind, idx_base), "Error: y is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXgthr((hipsparseHandle_t) nullptr, nnz, dy, dx_val, dx_ind, idx_base)); #endif } template hipsparseStatus_t testing_gthr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int N = argus.N; int nnz = argus.nnz; hipsparseIndexBase_t idx_base = argus.baseA; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hx_ind(nnz); std::vector hx_val(nnz); std::vector hx_val_gold(nnz); std::vector hy(N); // Initial Data on CPU srand(12345ULL); hipsparseInitIndex(hx_ind.data(), nnz, 1, N); hipsparseInit(hy, 1, N); // allocate memory on device auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * N), device_free}; int* dx_ind = (int*)dx_ind_managed.get(); T* dx_val = (T*)dx_val_managed.get(); T* dy = (T*)dy_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dx_ind, hx_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy, hy.data(), sizeof(T) * N, hipMemcpyHostToDevice)); if(argus.unit_check) { // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXgthr(handle, nnz, dy, dx_val, dx_ind, idx_base)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hx_val.data(), dx_val, sizeof(T) * nnz, hipMemcpyDeviceToHost)); // CPU for(int i = 0; i < nnz; ++i) { hx_val_gold[i] = hy[hx_ind[i] - idx_base]; } // enable unit check, notice unit check is not invasive, but norm check is, // unit check and norm check can not be interchanged their order unit_check_general(1, nnz, 1, hx_val_gold.data(), hx_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgthr(handle, nnz, dy, dx_val, dx_ind, idx_base)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgthr(handle, nnz, dy, dx_val, dx_ind, idx_base)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = gthr_gbyte_count(nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::nnz, nnz, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GTHR_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_gthrz.hpp000066400000000000000000000150401501764003400226500ustar00rootroot00000000000000/* ************************************************************************ * 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 "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include using namespace hipsparse; using namespace hipsparse_test; template void testing_gthrz_bad_arg(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(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_pointer( hipsparseXgthrz(handle, nnz, dy, dx_val, (int*)nullptr, idx_base), "Error: x_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgthrz(handle, nnz, dy, (T*)nullptr, dx_ind, idx_base), "Error: x_val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgthrz(handle, nnz, (T*)nullptr, dx_val, dx_ind, idx_base), "Error: y is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXgthrz((hipsparseHandle_t) nullptr, nnz, dy, dx_val, dx_ind, idx_base)); #endif } template hipsparseStatus_t testing_gthrz(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int N = argus.N; int nnz = argus.nnz; hipsparseIndexBase_t idx_base = argus.baseA; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hx_ind(nnz); std::vector hx_val(nnz); std::vector hx_val_gold(nnz); std::vector hy(N); std::vector hy_gold(N); // Initial Data on CPU srand(12345ULL); hipsparseInitIndex(hx_ind.data(), nnz, 1, N); hipsparseInit(hy, 1, N); hy_gold = hy; // allocate memory on device auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * N), device_free}; int* dx_ind = (int*)dx_ind_managed.get(); T* dx_val = (T*)dx_val_managed.get(); T* dy = (T*)dy_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dx_ind, hx_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy, hy.data(), sizeof(T) * N, hipMemcpyHostToDevice)); if(argus.unit_check) { // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXgthrz(handle, nnz, dy, dx_val, dx_ind, idx_base)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hx_val.data(), dx_val, sizeof(T) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy.data(), dy, sizeof(T) * N, hipMemcpyDeviceToHost)); // CPU for(int i = 0; i < nnz; ++i) { hx_val_gold[i] = hy_gold[hx_ind[i] - idx_base]; hy_gold[hx_ind[i] - idx_base] = make_DataType(0.0); } // enable unit check, notice unit check is not invasive, but norm check is, // unit check and norm check can not be interchanged their order unit_check_general(1, nnz, 1, hx_val_gold.data(), hx_val.data()); unit_check_general(1, N, 1, hy_gold.data(), hy.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgthrz(handle, nnz, dy, dx_val, dx_ind, idx_base)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgthrz(handle, nnz, dy, dx_val, dx_ind, idx_base)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = gthrz_gbyte_count(nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::nnz, nnz, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GTHRZ_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_gtsv.hpp000066400000000000000000000216001501764003400224740ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_GTSV2_HPP #define TESTING_GTSV2_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_gtsv2_bad_arg(void) { // Dont do bad argument checking for cuda #if(!defined(CUDART_VERSION)) int safe_size = 100; int m = 10; int n = 10; int ldb = m; // Create handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto ddl_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dd_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto ddu_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; T* ddl = (T*)ddl_managed.get(); T* dd = (T*)dd_managed.get(); T* ddu = (T*)ddu_managed.get(); T* dB = (T*)dB_managed.get(); void* dbuf = (void*)dbuf_managed.get(); size_t bsize; // gtsv buffer size verify_hipsparse_status_invalid_handle( hipsparseXgtsv2_bufferSizeExt(nullptr, m, n, ddl, dd, ddu, dB, ldb, &bsize)); verify_hipsparse_status_invalid_value( hipsparseXgtsv2_bufferSizeExt(handle, -1, n, ddl, dd, ddu, dB, ldb, &bsize), "Error: m is invalid"); verify_hipsparse_status_invalid_value( hipsparseXgtsv2_bufferSizeExt(handle, m, -1, ddl, dd, ddu, dB, ldb, &bsize), "Error: n is invalid"); verify_hipsparse_status_invalid_value( hipsparseXgtsv2_bufferSizeExt(handle, m, n, ddl, dd, ddu, dB, -1, &bsize), "Error: ldb is invalid"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsv2_bufferSizeExt(handle, m, n, ddl, dd, ddu, dB, ldb, nullptr), "Error: bsize is nullptr"); // gtsv verify_hipsparse_status_invalid_handle( hipsparseXgtsv2(nullptr, m, n, ddl, dd, ddu, dB, ldb, dbuf)); verify_hipsparse_status_invalid_value( hipsparseXgtsv2(handle, -1, n, ddl, dd, ddu, dB, ldb, dbuf), "Error: m is invalid"); verify_hipsparse_status_invalid_value( hipsparseXgtsv2(handle, m, -1, ddl, dd, ddu, dB, ldb, dbuf), "Error: n is invalid"); verify_hipsparse_status_invalid_value(hipsparseXgtsv2(handle, m, n, ddl, dd, ddu, dB, -1, dbuf), "Error: ldb is invalid"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsv2(handle, m, n, (const T*)nullptr, dd, ddu, dB, ldb, dbuf), "Error: ddl is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsv2(handle, m, n, ddl, (const T*)nullptr, ddu, dB, ldb, dbuf), "Error: dd is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsv2(handle, m, n, ddl, dd, (const T*)nullptr, dB, ldb, dbuf), "Error: ddu is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsv2(handle, m, n, ddl, dd, ddu, (T*)nullptr, ldb, dbuf), "Error: dB is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsv2(handle, m, n, ddl, dd, ddu, dB, ldb, nullptr), "Error: bsize is nullptr"); #endif } template hipsparseStatus_t testing_gtsv2(Arguments argus) { int m = argus.M; int n = argus.N; // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; int ldb = 2 * m; // Host structures std::vector hdl(m, make_DataType(1)); std::vector hd(m, make_DataType(2)); std::vector hdu(m, make_DataType(1)); std::vector hB(ldb * n, make_DataType(3)); hdl[0] = make_DataType(0); hdu[m - 1] = make_DataType(0); std::vector hB_original = hB; // allocate memory on device auto ddl_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dd_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto ddu_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * ldb * n), device_free}; T* ddl = (T*)ddl_managed.get(); T* dd = (T*)dd_managed.get(); T* ddu = (T*)ddu_managed.get(); T* dB = (T*)dB_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(ddl, hdl.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dd, hd.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(ddu, hdu.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * ldb * n, hipMemcpyHostToDevice)); // Query SparseToDense buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR( hipsparseXgtsv2_bufferSizeExt(handle, m, n, ddl, dd, ddu, dB, ldb, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseXgtsv2(handle, m, n, ddl, dd, ddu, dB, ldb, buffer)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hB.data(), dB, sizeof(T) * ldb * n, hipMemcpyDeviceToHost)); // Check std::vector hresult = hB_original; for(int j = 0; j < n; j++) { hresult[ldb * j] = testing_mult(hd[0], hB[ldb * j]) + testing_mult(hdu[0], hB[ldb * j + 1]); hresult[ldb * j + m - 1] = testing_mult(hdl[m - 1], hB[ldb * j + m - 2]) + testing_mult(hd[m - 1], hB[ldb * j + m - 1]); for(int i = 1; i < m - 1; i++) { hresult[ldb * j + i] = testing_mult(hdl[i], hB[ldb * j + i - 1]) + testing_mult(hd[i], hB[ldb * j + i]) + testing_mult(hdu[i], hB[ldb * j + i + 1]); } } unit_check_near(m, n, ldb, hB_original.data(), hresult.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgtsv2(handle, m, n, ddl, dd, ddu, dB, ldb, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgtsv2(handle, m, n, ddl, dd, ddu, dB, ldb, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = gtsv_gbyte_count(m, n); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GTSV2_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_gtsv2_nopivot.hpp000066400000000000000000000217011501764003400243360ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_GTSV2_NOPIVOT_HPP #define TESTING_GTSV2_NOPIVOT_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_gtsv2_nopivot_bad_arg(void) { // Dont do bad argument checking for cuda #if(!defined(CUDART_VERSION)) int safe_size = 100; int m = 10; int n = 10; int ldb = m; // Create handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto ddl_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dd_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto ddu_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; T* ddl = (T*)ddl_managed.get(); T* dd = (T*)dd_managed.get(); T* ddu = (T*)ddu_managed.get(); T* dB = (T*)dB_managed.get(); void* dbuf = (void*)dbuf_managed.get(); size_t bsize; // gtsv_nopivot buffer size verify_hipsparse_status_invalid_handle( hipsparseXgtsv2_nopivot_bufferSizeExt(nullptr, m, n, ddl, dd, ddu, dB, ldb, &bsize)); verify_hipsparse_status_invalid_value( hipsparseXgtsv2_nopivot_bufferSizeExt(handle, -1, n, ddl, dd, ddu, dB, ldb, &bsize), "Error: m is invalid"); verify_hipsparse_status_invalid_value( hipsparseXgtsv2_nopivot_bufferSizeExt(handle, m, -1, ddl, dd, ddu, dB, ldb, &bsize), "Error: n is invalid"); verify_hipsparse_status_invalid_value( hipsparseXgtsv2_nopivot_bufferSizeExt(handle, m, n, ddl, dd, ddu, dB, -1, &bsize), "Error: ldb is invalid"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsv2_nopivot_bufferSizeExt(handle, m, n, ddl, dd, ddu, dB, ldb, nullptr), "Error: bsize is nullptr"); // gtsv_nopivot verify_hipsparse_status_invalid_handle( hipsparseXgtsv2_nopivot(nullptr, m, n, ddl, dd, ddu, dB, ldb, dbuf)); verify_hipsparse_status_invalid_value( hipsparseXgtsv2_nopivot(handle, -1, n, ddl, dd, ddu, dB, ldb, dbuf), "Error: m is invalid"); verify_hipsparse_status_invalid_value( hipsparseXgtsv2_nopivot(handle, m, -1, ddl, dd, ddu, dB, ldb, dbuf), "Error: n is invalid"); verify_hipsparse_status_invalid_value( hipsparseXgtsv2_nopivot(handle, m, n, ddl, dd, ddu, dB, -1, dbuf), "Error: ldb is invalid"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsv2_nopivot(handle, m, n, (const T*)nullptr, dd, ddu, dB, ldb, dbuf), "Error: ddl is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsv2_nopivot(handle, m, n, ddl, (const T*)nullptr, ddu, dB, ldb, dbuf), "Error: dd is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsv2_nopivot(handle, m, n, ddl, dd, (const T*)nullptr, dB, ldb, dbuf), "Error: ddu is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsv2_nopivot(handle, m, n, ddl, dd, ddu, (T*)nullptr, ldb, dbuf), "Error: dB is nullptr"); #endif } template hipsparseStatus_t testing_gtsv2_nopivot(Arguments argus) { int m = argus.M; int n = argus.N; // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; int ldb = 2 * m; // Host structures std::vector hdl(m, make_DataType(1)); std::vector hd(m, make_DataType(2)); std::vector hdu(m, make_DataType(1)); std::vector hB(ldb * n, make_DataType(3)); hdl[0] = make_DataType(0); hdu[m - 1] = make_DataType(0); std::vector hB_original = hB; // allocate memory on device auto ddl_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dd_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto ddu_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * ldb * n), device_free}; T* ddl = (T*)ddl_managed.get(); T* dd = (T*)dd_managed.get(); T* ddu = (T*)ddu_managed.get(); T* dB = (T*)dB_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(ddl, hdl.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dd, hd.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(ddu, hdu.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * ldb * n, hipMemcpyHostToDevice)); // Query SparseToDense buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR( hipsparseXgtsv2_nopivot_bufferSizeExt(handle, m, n, ddl, dd, ddu, dB, ldb, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseXgtsv2_nopivot(handle, m, n, ddl, dd, ddu, dB, ldb, buffer)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hB.data(), dB, sizeof(T) * ldb * n, hipMemcpyDeviceToHost)); // Check std::vector hresult(ldb * n, make_DataType(3)); for(int j = 0; j < n; j++) { hresult[ldb * j] = testing_mult(hd[0], hB[ldb * j]) + testing_mult(hdu[0], hB[ldb * j + 1]); hresult[ldb * j + m - 1] = testing_mult(hdl[m - 1], hB[ldb * j + m - 2]) + testing_mult(hd[m - 1], hB[ldb * j + m - 1]); for(int i = 1; i < m - 1; i++) { hresult[ldb * j + i] = testing_mult(hdl[i], hB[ldb * j + i - 1]) + testing_mult(hd[i], hB[ldb * j + i]) + testing_mult(hdu[i], hB[ldb * j + i + 1]); } } unit_check_near(m, n, ldb, hB_original.data(), hresult.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXgtsv2_nopivot(handle, m, n, ddl, dd, ddu, dB, ldb, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXgtsv2_nopivot(handle, m, n, ddl, dd, ddu, dB, ldb, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = gtsv_gbyte_count(m, n); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GTSV2_NOPIVOT_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_gtsv2_strided_batch.hpp000066400000000000000000000250051501764003400254400ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_GTSV2_NOPIVOT_STRIDED_BATCH_HPP #define TESTING_GTSV2_NOPIVOT_STRIDED_BATCH_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_gtsv2_strided_batch_bad_arg(void) { // Dont do bad argument checking for cuda #if(!defined(CUDART_VERSION)) int safe_size = 100; int m = 10; int batch_count = 10; int batch_stride = m; // Create handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto ddl_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dd_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto ddu_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; T* ddl = (T*)ddl_managed.get(); T* dd = (T*)dd_managed.get(); T* ddu = (T*)ddu_managed.get(); T* dx = (T*)dx_managed.get(); void* dbuf = (void*)dbuf_managed.get(); size_t bsize; // gtsv2StridedBatch_bufferSize verify_hipsparse_status_invalid_handle(hipsparseXgtsv2StridedBatch_bufferSizeExt( nullptr, m, ddl, dd, ddu, dx, batch_count, batch_stride, &bsize)); verify_hipsparse_status_invalid_value( hipsparseXgtsv2StridedBatch_bufferSizeExt( handle, -1, ddl, dd, ddu, dx, batch_count, batch_stride, &bsize), "Error: m is invalid"); verify_hipsparse_status_invalid_value( hipsparseXgtsv2StridedBatch_bufferSizeExt( handle, m, ddl, dd, ddu, dx, -1, batch_stride, &bsize), "Error: batch_count is invalid"); verify_hipsparse_status_invalid_value(hipsparseXgtsv2StridedBatch_bufferSizeExt( handle, m, ddl, dd, ddu, dx, batch_count, -1, &bsize), "Error: batch_stride is invalid"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsv2StridedBatch_bufferSizeExt( handle, m, ddl, dd, ddu, dx, batch_count, batch_stride, nullptr), "Error: bsize is nullptr"); // gtsv2StridedBatch verify_hipsparse_status_invalid_handle( hipsparseXgtsv2StridedBatch(nullptr, m, ddl, dd, ddu, dx, batch_count, batch_stride, dbuf)); verify_hipsparse_status_invalid_value( hipsparseXgtsv2StridedBatch(handle, -1, ddl, dd, ddu, dx, batch_count, batch_stride, dbuf), "Error: m is invalid"); verify_hipsparse_status_invalid_value( hipsparseXgtsv2StridedBatch(handle, m, ddl, dd, ddu, dx, -1, batch_stride, dbuf), "Error: batch_count is invalid"); verify_hipsparse_status_invalid_value( hipsparseXgtsv2StridedBatch(handle, m, ddl, dd, ddu, dx, batch_count, -1, dbuf), "Error: batch_stride is invalid"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsv2StridedBatch( handle, m, (const T*)nullptr, dd, ddu, dx, batch_count, batch_stride, dbuf), "Error: ddl is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsv2StridedBatch( handle, m, ddl, (const T*)nullptr, ddu, dx, batch_count, batch_stride, dbuf), "Error: dd is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsv2StridedBatch( handle, m, ddl, dd, (const T*)nullptr, dx, batch_count, batch_stride, dbuf), "Error: ddu is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsv2StridedBatch( handle, m, ddl, dd, ddu, (T*)nullptr, batch_count, batch_stride, dbuf), "Error: dx is nullptr"); #endif } template hipsparseStatus_t testing_gtsv2_strided_batch(Arguments argus) { int m = argus.M; int batch_count = argus.batch_count; // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; int batch_stride = 2 * m; // Host structures std::vector hdl(batch_stride * batch_count, make_DataType(1)); std::vector hd(batch_stride * batch_count, make_DataType(2)); std::vector hdu(batch_stride * batch_count, make_DataType(1)); std::vector hx(batch_stride * batch_count, make_DataType(3)); for(int i = 0; i < batch_count; i++) { hdl[batch_stride * i + 0] = make_DataType(0); hdu[batch_stride * i + m - 1] = make_DataType(0); } std::vector hx_original = hx; // allocate memory on device auto ddl_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * batch_stride * batch_count), device_free}; auto dd_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * batch_stride * batch_count), device_free}; auto ddu_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * batch_stride * batch_count), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * batch_stride * batch_count), device_free}; T* ddl = (T*)ddl_managed.get(); T* dd = (T*)dd_managed.get(); T* ddu = (T*)ddu_managed.get(); T* dx = (T*)dx_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(ddl, hdl.data(), sizeof(T) * batch_stride * batch_count, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dd, hd.data(), sizeof(T) * batch_stride * batch_count, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(ddu, hdu.data(), sizeof(T) * batch_stride * batch_count, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dx, hx.data(), sizeof(T) * batch_stride * batch_count, hipMemcpyHostToDevice)); // Query SparseToDense buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseXgtsv2StridedBatch_bufferSizeExt( handle, m, ddl, dd, ddu, dx, batch_count, batch_stride, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseXgtsv2StridedBatch( handle, m, ddl, dd, ddu, dx, batch_count, batch_stride, buffer)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy( hx.data(), dx, sizeof(T) * batch_stride * batch_count, hipMemcpyDeviceToHost)); // Check std::vector hresult(batch_stride * batch_count, make_DataType(3)); for(int j = 0; j < batch_count; j++) { hresult[batch_stride * j] = testing_mult(hd[batch_stride * j + 0], hx[batch_stride * j]) + testing_mult(hdu[batch_stride * j + 0], hx[batch_stride * j + 1]); hresult[batch_stride * j + m - 1] = testing_mult(hdl[batch_stride * j + m - 1], hx[batch_stride * j + m - 2]) + testing_mult(hd[batch_stride * j + m - 1], hx[batch_stride * j + m - 1]); for(int i = 1; i < m - 1; i++) { hresult[batch_stride * j + i] = testing_mult(hdl[batch_stride * j + i], hx[batch_stride * j + i - 1]) + testing_mult(hd[batch_stride * j + i], hx[batch_stride * j + i]) + testing_mult(hdu[batch_stride * j + i], hx[batch_stride * j + i + 1]); } } unit_check_near(1, batch_stride * batch_count, 1, hx_original.data(), hresult.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgtsv2StridedBatch( handle, m, ddl, dd, ddu, dx, batch_count, batch_stride, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgtsv2StridedBatch( handle, m, ddl, dd, ddu, dx, batch_count, batch_stride, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = gtsv_strided_batch_gbyte_count(m, batch_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::batch_count, batch_count, display_key_t::batch_stride, batch_stride, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GTSV2_NOPIVOT_STRIDED_BATCH_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_gtsv_interleaved_batch.hpp000066400000000000000000000234751501764003400262330ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_GTSV_INTERLEAVED_BATCH_HPP #define TESTING_GTSV_INTERLEAVED_BATCH_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_gtsv_interleaved_batch_bad_arg(void) { // Dont do bad argument checking for cuda #if(!defined(CUDART_VERSION)) int safe_size = 100; int algo = 0; int m = 10; int batch_count = 10; // Create handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto ddl_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dd_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto ddu_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; T* ddl = (T*)ddl_managed.get(); T* dd = (T*)dd_managed.get(); T* ddu = (T*)ddu_managed.get(); T* dx = (T*)dx_managed.get(); void* dbuf = (void*)dbuf_managed.get(); size_t bsize; // gtsvInterleavedBatch_bufferSizeExt verify_hipsparse_status_invalid_handle(hipsparseXgtsvInterleavedBatch_bufferSizeExt( nullptr, algo, m, ddl, dd, ddu, dx, batch_count, &bsize)); verify_hipsparse_status_invalid_value( hipsparseXgtsvInterleavedBatch_bufferSizeExt( handle, algo, -1, ddl, dd, ddu, dx, batch_count, &bsize), "Error: m is invalid"); verify_hipsparse_status_invalid_value( hipsparseXgtsvInterleavedBatch_bufferSizeExt(handle, algo, m, ddl, dd, ddu, dx, -1, &bsize), "Error: batch_count is invalid"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsvInterleavedBatch_bufferSizeExt( handle, algo, m, ddl, dd, ddu, dx, batch_count, nullptr), "Error: bsize is nullptr"); // gtsvInterleavedBatch verify_hipsparse_status_invalid_handle( hipsparseXgtsvInterleavedBatch(nullptr, algo, m, ddl, dd, ddu, dx, batch_count, dbuf)); verify_hipsparse_status_invalid_value( hipsparseXgtsvInterleavedBatch(handle, algo, -1, ddl, dd, ddu, dx, batch_count, dbuf), "Error: m is invalid"); verify_hipsparse_status_invalid_value( hipsparseXgtsvInterleavedBatch(handle, algo, m, ddl, dd, ddu, dx, -1, dbuf), "Error: batch_count is invalid"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsvInterleavedBatch( handle, algo, m, (T*)nullptr, dd, ddu, dx, batch_count, dbuf), "Error: ddl is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsvInterleavedBatch( handle, algo, m, ddl, (T*)nullptr, ddu, dx, batch_count, dbuf), "Error: dd is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsvInterleavedBatch( handle, algo, m, ddl, dd, (T*)nullptr, dx, batch_count, dbuf), "Error: ddu is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsvInterleavedBatch( handle, algo, m, ddl, dd, ddu, (T*)nullptr, batch_count, dbuf), "Error: dx is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsvInterleavedBatch(handle, algo, m, ddl, dd, ddu, dx, batch_count, nullptr), "Error: bsize is nullptr"); #endif } template hipsparseStatus_t testing_gtsv_interleaved_batch(Arguments argus) { int m = argus.M; int batch_count = argus.batch_count; int algo = argus.gtsv_alg; // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hdl(m * batch_count, make_DataType(1)); std::vector hd(m * batch_count, make_DataType(2)); std::vector hdu(m * batch_count, make_DataType(1)); std::vector hx(m * batch_count, make_DataType(3)); for(int i = 0; i < batch_count; i++) { hdl[i] = make_DataType(0); hdu[batch_count * (m - 1) + i] = make_DataType(0); } std::vector hx_original = hx; // allocate memory on device auto ddl_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * batch_count), device_free}; auto dd_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * batch_count), device_free}; auto ddu_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * batch_count), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * batch_count), device_free}; T* ddl = (T*)ddl_managed.get(); T* dd = (T*)dd_managed.get(); T* ddu = (T*)ddu_managed.get(); T* dx = (T*)dx_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(ddl, hdl.data(), sizeof(T) * m * batch_count, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dd, hd.data(), sizeof(T) * m * batch_count, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(ddu, hdu.data(), sizeof(T) * m * batch_count, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx, hx.data(), sizeof(T) * m * batch_count, hipMemcpyHostToDevice)); // Query SparseToDense buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseXgtsvInterleavedBatch_bufferSizeExt( handle, algo, m, ddl, dd, ddu, dx, batch_count, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR( hipsparseXgtsvInterleavedBatch(handle, algo, m, ddl, dd, ddu, dx, batch_count, buffer)); // copy output from device to CPU CHECK_HIP_ERROR( hipMemcpy(hx.data(), dx, sizeof(T) * m * batch_count, hipMemcpyDeviceToHost)); // Check std::vector hresult(m * batch_count, make_DataType(3)); for(int j = 0; j < batch_count; j++) { hresult[j] = testing_mult(hd[j], hx[j]) + testing_mult(hdu[j], hx[batch_count + j]); hresult[batch_count * (m - 1) + j] = testing_mult(hdl[batch_count * (m - 1) + j], hx[batch_count * (m - 2) + j]) + testing_mult(hd[batch_count * (m - 1) + j], hx[batch_count * (m - 1) + j]); } for(int i = 1; i < m - 1; i++) { for(int j = 0; j < batch_count; j++) { hresult[batch_count * i + j] = testing_mult(hdl[batch_count * i + j], hx[batch_count * (i - 1) + j]) + testing_mult(hd[batch_count * i + j], hx[batch_count * i + j]) + testing_mult(hdu[batch_count * i + j], hx[batch_count * (i + 1) + j]); } } unit_check_near(1, m * batch_count, 1, hx_original.data(), hresult.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgtsvInterleavedBatch( handle, algo, m, ddl, dd, ddu, dx, batch_count, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgtsvInterleavedBatch( handle, algo, m, ddl, dd, ddu, dx, batch_count, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = gtsv_interleaved_batch_gbyte_count(m, batch_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::batch_count, batch_count, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GTSV_INTERLEAVED_BATCH_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_hyb2csr.hpp000066400000000000000000000222251501764003400230710ustar00rootroot00000000000000/* ************************************************************************ * 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 "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_hyb2csr_bad_arg(void) { #if(!defined(CUDART_VERSION)) int safe_size = 100; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_hyb(new hyb_struct); hipsparseHybMat_t hyb = unique_ptr_hyb->hyb; testhyb* dhyb = (testhyb*)hyb; dhyb->m = safe_size; dhyb->n = safe_size; dhyb->ell_nnz = safe_size; dhyb->coo_nnz = safe_size; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* csr_col_ind = (int*)csr_col_ind_managed.get(); T* csr_val = (T*)csr_val_managed.get(); verify_hipsparse_status_invalid_pointer( hipsparseXhyb2csr(handle, descr, hyb, csr_val, (int*)nullptr, csr_col_ind), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXhyb2csr(handle, descr, hyb, csr_val, csr_row_ptr, (int*)nullptr), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXhyb2csr(handle, descr, hyb, (T*)nullptr, csr_row_ptr, csr_col_ind), "Error: csr_val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXhyb2csr( handle, (hipsparseMatDescr_t) nullptr, hyb, csr_val, csr_row_ptr, csr_col_ind), "Error: csr_val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXhyb2csr( handle, descr, (hipsparseHybMat_t) nullptr, csr_val, csr_row_ptr, csr_col_ind), "Error: csr_val is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXhyb2csr( (hipsparseHandle_t) nullptr, descr, hyb, csr_val, csr_row_ptr, csr_col_ind)); #endif } template hipsparseStatus_t testing_hyb2csr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) int m = argus.M; int n = argus.N; hipsparseIndexBase_t idx_base = argus.baseA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_hyb(new hyb_struct); hipsparseHybMat_t hyb = unique_ptr_hyb->hyb; CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); srand(12345ULL); // Host structures std::vector hcsr_row_ptr_gold; std::vector hcsr_col_ind_gold; std::vector hcsr_val_gold; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix( filename, m, n, nnz, hcsr_row_ptr_gold, hcsr_col_ind_gold, hcsr_val_gold, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Allocate memory on the device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); // Copy data from host to device CHECK_HIP_ERROR(hipMemcpy( dcsr_row_ptr, hcsr_row_ptr_gold.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy( dcsr_col_ind, hcsr_col_ind_gold.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_val, hcsr_val_gold.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); // Convert CSR to HYB CHECK_HIPSPARSE_ERROR(hipsparseXcsr2hyb(handle, m, n, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, hyb, 0, HIPSPARSE_HYB_PARTITION_AUTO)); // Set all CSR arrays to zero CHECK_HIP_ERROR(hipMemset(dcsr_row_ptr, 0, sizeof(int) * (m + 1))); CHECK_HIP_ERROR(hipMemset(dcsr_col_ind, 0, sizeof(int) * nnz)); CHECK_HIP_ERROR(hipMemset(dcsr_val, 0, sizeof(T) * nnz)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR( hipsparseXhyb2csr(handle, descr, hyb, dcsr_val, dcsr_row_ptr, dcsr_col_ind)); // Copy output from device to host std::vector hcsr_row_ptr(m + 1); std::vector hcsr_col_ind(nnz); std::vector hcsr_val(nnz); CHECK_HIP_ERROR(hipMemcpy( hcsr_row_ptr.data(), dcsr_row_ptr, sizeof(int) * (m + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_col_ind.data(), dcsr_col_ind, sizeof(int) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val.data(), dcsr_val, sizeof(T) * nnz, hipMemcpyDeviceToHost)); // Unit check unit_check_general(1, m + 1, 1, hcsr_row_ptr_gold.data(), hcsr_row_ptr.data()); unit_check_general(1, nnz, 1, hcsr_col_ind_gold.data(), hcsr_col_ind.data()); unit_check_general(1, nnz, 1, hcsr_val_gold.data(), hcsr_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXhyb2csr(handle, descr, hyb, dcsr_val, dcsr_row_ptr, dcsr_col_ind)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXhyb2csr(handle, descr, hyb, dcsr_val, dcsr_row_ptr, dcsr_col_ind)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; testhyb* dhyb = (testhyb*)hyb; double gbyte_count = hyb2csr_gbyte_count(m, nnz, dhyb->ell_nnz, dhyb->coo_nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_HYB2CSR_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_hybmv.hpp000066400000000000000000000340241501764003400226420ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2018-2019 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_HYBMV_HPP #define TESTING_HYBMV_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include using namespace hipsparse; using namespace hipsparse_test; #define ELL_IND_ROW(i, el, m, width) (el) * (m) + (i) #define ELL_IND_EL(i, el, m, width) (el) + (width) * (i) #define ELL_IND(i, el, m, width) ELL_IND_ROW(i, el, m, width) template void testing_hybmv_bad_arg(void) { #if(!defined(CUDART_VERSION)) int safe_size = 100; T alpha = 0.6; T beta = 0.2; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_hyb(new hyb_struct); hipsparseHybMat_t hyb = unique_ptr_hyb->hyb; testhyb* dhyb = (testhyb*)hyb; dhyb->m = safe_size; dhyb->n = safe_size; dhyb->ell_nnz = safe_size; dhyb->coo_nnz = safe_size; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; T* dx = (T*)dx_managed.get(); T* dy = (T*)dy_managed.get(); verify_hipsparse_status_invalid_pointer( hipsparseXhybmv(handle, transA, &alpha, descr, hyb, (T*)nullptr, &beta, dy), "Error: dx is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXhybmv(handle, transA, &alpha, descr, hyb, dx, &beta, (T*)nullptr), "Error: dy is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXhybmv(handle, transA, (T*)nullptr, descr, hyb, dx, &beta, dy), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXhybmv(handle, transA, &alpha, descr, hyb, dx, (T*)nullptr, dy), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXhybmv(handle, transA, &alpha, descr, (hipsparseHybMat_t) nullptr, dx, &beta, dy), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXhybmv(handle, transA, &alpha, (hipsparseMatDescr_t) nullptr, hyb, dx, &beta, dy), "Error: descr is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXhybmv((hipsparseHandle_t) nullptr, transA, &alpha, descr, hyb, dx, &beta, dy)); #endif } template hipsparseStatus_t testing_hybmv(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) int m = argus.M; int n = argus.N; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseHybPartition_t part = argus.part; int user_ell_width = argus.ell_width; std::string filename = argus.filename; T zero = make_DataType(0.0); T one = make_DataType(1.0); std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); std::unique_ptr unique_ptr_hyb(new hyb_struct); hipsparseHybMat_t hyb = unique_ptr_hyb->hyb; srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcol_ind; std::vector hval; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcol_ind, hval, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hx(n); std::vector hy_1(m); std::vector hy_2(m); std::vector hy_gold(m); hipsparseInit(hx, 1, n); hipsparseInit(hy_1, 1, m); // copy vector is easy in STL; hy_gold = hx: save a copy in hy_gold which will be output of CPU hy_2 = hy_1; hy_gold = hy_1; // allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * n), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dx = (T*)dx_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcol_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hval.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx, hx.data(), sizeof(T) * n, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_1, hy_1.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // ELL width limit int width_limit = (m > 0) ? ((2 * nnz - 1) / m + 1) : 0; // Limit ELL user width if(part == HIPSPARSE_HYB_PARTITION_USER) { user_ell_width = (m > 0) ? (user_ell_width * nnz / m) : 0; user_ell_width = std::min(width_limit, user_ell_width); } // Convert CSR to HYB hipsparseStatus_t status = hipsparseXcsr2hyb(handle, m, n, descr, dval, dptr, dcol, hyb, user_ell_width, part); if(part == HIPSPARSE_HYB_PARTITION_MAX) { // Compute max ELL width int ell_max_width = 0; for(int i = 0; i < m; ++i) { ell_max_width = std::max(hcsr_row_ptr[i + 1] - hcsr_row_ptr[i], ell_max_width); } if(ell_max_width > width_limit) { verify_hipsparse_status_invalid_value(status, "ell_max_width > width_limit"); return HIPSPARSE_STATUS_SUCCESS; } } if(argus.unit_check) { // Copy HYB structure to CPU testhyb* dhyb = (testhyb*)hyb; int ell_nnz = dhyb->ell_nnz; int coo_nnz = dhyb->coo_nnz; std::vector hell_col(ell_nnz); std::vector hell_val(ell_nnz); std::vector hcoo_row(coo_nnz); std::vector hcoo_col(coo_nnz); std::vector hcoo_val(coo_nnz); if(ell_nnz > 0) { CHECK_HIP_ERROR(hipMemcpy( hell_col.data(), dhyb->ell_col_ind, sizeof(int) * ell_nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hell_val.data(), dhyb->ell_val, sizeof(T) * ell_nnz, hipMemcpyDeviceToHost)); } if(coo_nnz > 0) { CHECK_HIP_ERROR(hipMemcpy( hcoo_row.data(), dhyb->coo_row_ind, sizeof(int) * coo_nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcoo_col.data(), dhyb->coo_col_ind, sizeof(int) * coo_nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcoo_val.data(), dhyb->coo_val, sizeof(T) * coo_nnz, hipMemcpyDeviceToHost)); } CHECK_HIP_ERROR(hipMemcpy(dy_2, hy_2.data(), sizeof(T) * m, hipMemcpyHostToDevice)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseXhybmv(handle, transA, &h_alpha, descr, hyb, dx, &h_beta, dy_1)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseXhybmv(handle, transA, d_alpha, descr, hyb, dx, d_beta, dy_2)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hy_1.data(), dy_1, sizeof(T) * m, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_2.data(), dy_2, sizeof(T) * m, hipMemcpyDeviceToHost)); // CPU // ELL part if(ell_nnz > 0) { for(int i = 0; i < m; ++i) { T sum = zero; for(int p = 0; p < dhyb->ell_width; ++p) { int idx = ELL_IND(i, p, m, dhyb->ell_width); int col = hell_col[idx] - idx_base; if(col >= 0 && col < n) { sum = sum + testing_mult(hell_val[idx], hx[col]); } else { break; } } if(h_beta != zero) { hy_gold[i] = testing_mult(h_beta, hy_gold[i]) + testing_mult(h_alpha, sum); } else { hy_gold[i] = testing_mult(h_alpha, sum); } } } // COO part if(coo_nnz >= 0) { T coo_beta = (ell_nnz > 0) ? one : h_beta; for(int i = 0; i < m; ++i) { hy_gold[i] = testing_mult(hy_gold[i], coo_beta); } for(int i = 0; i < coo_nnz; ++i) { int row = hcoo_row[i] - idx_base; int col = hcoo_col[i] - idx_base; hy_gold[row] = hy_gold[row] + testing_mult(h_alpha, testing_mult(hcoo_val[i], hx[col])); } } unit_check_near(1, m, 1, hy_gold.data(), hy_1.data()); unit_check_near(1, m, 1, hy_gold.data(), hy_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXhybmv(handle, transA, &h_alpha, descr, hyb, dx, &h_beta, dy_1)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXhybmv(handle, transA, &h_alpha, descr, hyb, dx, &h_beta, dy_1)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = spmv_gflop_count(m, nnz, h_beta != make_DataType(0.0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::partition, hipsparse_partition2string(part), display_key_t::ell_width, user_ell_width, display_key_t::gflops, gpu_gflops, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_HYBMV_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_identity.hpp000066400000000000000000000105151501764003400233450ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2018-2019 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_IDENTITY_HPP #define TESTING_IDENTITY_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include using namespace hipsparse; using namespace hipsparse_test; void testing_identity_bad_arg(void) { #if(!defined(CUDART_VERSION)) int n = 100; int safe_size = 100; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto p_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; int* p = (int*)p_managed.get(); verify_hipsparse_status_invalid_pointer( hipsparseCreateIdentityPermutation(handle, n, (int*)nullptr), "Error: p is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseCreateIdentityPermutation(nullptr, n, p)); #endif } hipsparseStatus_t testing_identity(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) int n = argus.N; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hp(n); std::vector hp_gold(n); // create_identity_permutation on host for(int i = 0; i < n; ++i) { hp_gold[i] = i; } // Allocate memory on the device auto dp_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * n), device_free}; int* dp = (int*)dp_managed.get(); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseCreateIdentityPermutation(handle, n, dp)); // Copy output from device to host CHECK_HIP_ERROR(hipMemcpy(hp.data(), dp, sizeof(int) * n, hipMemcpyDeviceToHost)); // Unit check unit_check_general(1, n, 1, hp_gold.data(), hp.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseCreateIdentityPermutation(handle, n, dp)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseCreateIdentityPermutation(handle, n, dp)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = identity_gbyte_count(n); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::N, n, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_IDENTITY_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_nnz.hpp000066400000000000000000000321031501764003400223160ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_NNZ_HPP #define TESTING_NNZ_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_nnz_bad_arg(void) { static constexpr size_t safe_size = 100; static constexpr int M = 10; static constexpr int N = 10; static constexpr int lda = M; static constexpr hipsparseDirection_t dirA = HIPSPARSE_DIRECTION_ROW; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descrA = unique_ptr_descr->descr; auto A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto nnzPerRowColumn_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto nnzTotalDevHostPtr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; T* d_A = (T*)A_managed.get(); int* d_nnzPerRowColumn = (int*)nnzPerRowColumn_managed.get(); int* d_nnzTotalDevHostPtr = (int*)nnzTotalDevHostPtr_managed.get(); #if(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_handle(hipsparseXnnz( nullptr, dirA, M, N, descrA, (const T*)d_A, lda, d_nnzPerRowColumn, d_nnzTotalDevHostPtr)); verify_hipsparse_status_invalid_pointer(hipsparseXnnz(handle, dirA, M, N, nullptr, (const T*)d_A, lda, d_nnzPerRowColumn, d_nnzTotalDevHostPtr), "Error: descrA as invalid pointer must be detected."); verify_hipsparse_status_invalid_pointer(hipsparseXnnz(handle, dirA, M, N, descrA, (const T*)nullptr, lda, d_nnzPerRowColumn, d_nnzTotalDevHostPtr), "Error: A as invalid pointer must be detected."); verify_hipsparse_status_invalid_pointer( hipsparseXnnz( handle, dirA, M, N, descrA, (const T*)d_A, lda, nullptr, d_nnzTotalDevHostPtr), "Error: nnzPerRowColumn as invalid pointer must be detected."); verify_hipsparse_status_invalid_pointer( hipsparseXnnz(handle, dirA, M, N, descrA, (const T*)d_A, lda, d_nnzPerRowColumn, nullptr), "Error: nnzTotalDevHostPtr as invalid pointer must be detected."); #endif // Testing invalid direction try { hipsparseXnnz(handle, (hipsparseDirection_t)77, -1, -1, descrA, (const T*)nullptr, -1, nullptr, nullptr); // An exception should be thrown. verify_hipsparse_status_internal_error( HIPSPARSE_STATUS_SUCCESS, "Error: an exception must be thrown from the conversion of the hipsparseDirection_t."); } catch(...) { } verify_hipsparse_status_invalid_size(hipsparseXnnz(handle, dirA, -1, N, descrA, (const T*)d_A, lda, d_nnzPerRowColumn, d_nnzTotalDevHostPtr), "Error: M < 0 must be detected."); verify_hipsparse_status_invalid_size(hipsparseXnnz(handle, dirA, M, -1, descrA, (const T*)d_A, lda, d_nnzPerRowColumn, d_nnzTotalDevHostPtr), "Error: N < 0 must be detected."); verify_hipsparse_status_invalid_size(hipsparseXnnz(handle, dirA, M, N, descrA, (const T*)d_A, M - 1, d_nnzPerRowColumn, d_nnzTotalDevHostPtr), "Error: lda < M must be detected."); } template hipsparseStatus_t testing_nnz(Arguments argus) { int M = argus.M; int N = argus.N; int lda = argus.lda; hipsparseDirection_t dirA = argus.dirA; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descrA = unique_ptr_descr->descr; if(M == 0 || N == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ return HIPSPARSE_STATUS_SUCCESS; #endif } // Create the dense matrix. int MN = (dirA == HIPSPARSE_DIRECTION_ROW) ? M : N; auto A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * lda * N), device_free}; auto nnzPerRowColumn_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * MN), device_free}; auto nnzTotalDevHostPtr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; T* d_A = (T*)A_managed.get(); int* d_nnzPerRowColumn = (int*)nnzPerRowColumn_managed.get(); int* d_nnzTotalDevHostPtr = (int*)nnzTotalDevHostPtr_managed.get(); std::vector h_A(lda * N); std::vector h_nnzPerRowColumn(MN); std::vector hd_nnzPerRowColumn(MN); std::vector h_nnzTotalDevHostPtr(1); std::vector hd_nnzTotalDevHostPtr(1); // Initialize the entire allocated memory. for(int i = 0; i < lda; ++i) { for(int j = 0; j < N; ++j) { h_A[j * lda + i] = make_DataType(-1); } } // Initialize a random dense matrix. srand(0); gen_dense_random_sparsity_pattern(M, N, h_A.data(), lda, HIPSPARSE_ORDER_COL, 0.2); // Transfer. CHECK_HIP_ERROR(hipMemcpy(d_A, h_A.data(), sizeof(T) * lda * N, hipMemcpyHostToDevice)); if(argus.unit_check) { // Compute the reference host first. host_nnz(dirA, M, N, descrA, h_A.data(), lda, h_nnzPerRowColumn.data(), h_nnzTotalDevHostPtr.data()); // Pointer mode device for nnz and call. CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXnnz(handle, dirA, M, N, descrA, (const T*)d_A, lda, d_nnzPerRowColumn, d_nnzTotalDevHostPtr)); // Transfer. CHECK_HIP_ERROR(hipMemcpy( hd_nnzPerRowColumn.data(), d_nnzPerRowColumn, sizeof(int) * MN, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hd_nnzTotalDevHostPtr.data(), d_nnzTotalDevHostPtr, sizeof(int) * 1, hipMemcpyDeviceToHost)); // Check results. unit_check_general(1, MN, 1, hd_nnzPerRowColumn.data(), h_nnzPerRowColumn.data()); unit_check_general(1, 1, 1, hd_nnzTotalDevHostPtr.data(), h_nnzTotalDevHostPtr.data()); // Pointer mode host for nnz and call. int dh_nnz; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXnnz( handle, dirA, M, N, descrA, (const T*)d_A, lda, d_nnzPerRowColumn, &dh_nnz)); // Transfer. CHECK_HIP_ERROR(hipMemcpy( hd_nnzPerRowColumn.data(), d_nnzPerRowColumn, sizeof(int) * MN, hipMemcpyDeviceToHost)); // Check results. unit_check_general(1, MN, 1, hd_nnzPerRowColumn.data(), h_nnzPerRowColumn.data()); unit_check_general(1, 1, 1, &dh_nnz, h_nnzTotalDevHostPtr.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm-up int h_nnz; for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXnnz( handle, dirA, M, N, descrA, (const T*)d_A, lda, d_nnzPerRowColumn, &h_nnz)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXnnz( handle, dirA, M, N, descrA, (const T*)d_A, lda, d_nnzPerRowColumn, &h_nnz)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = nnz_gbyte_count(M, N, dirA); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, M, display_key_t::N, N, display_key_t::LD, lda, display_key_t::nnz, h_nnz, display_key_t::direction, hipsparse_direction2string(dirA), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_NNZ_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_prune_csr2csr.hpp000066400000000000000000001116251501764003400243120ustar00rootroot00000000000000/* ************************************************************************ * 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 "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_prune_csr2csr_bad_arg(void) { #if(!defined(CUDART_VERSION)) size_t safe_size = 1; int M = 1; int N = 1; int nnz_A = 1; T threshold = static_cast(1); int nnz_total_dev_host_ptr = 1; size_t buffer_size = 1; hipsparseStatus_t status; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = unique_ptr_descr_A->descr; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; auto csr_row_ptr_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto csr_col_ind_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto csr_row_ptr_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto csr_col_ind_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto temp_buffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* csr_row_ptr_A = (int*)csr_row_ptr_A_managed.get(); int* csr_col_ind_A = (int*)csr_col_ind_A_managed.get(); T* csr_val_A = (T*)csr_val_A_managed.get(); int* csr_row_ptr_C = (int*)csr_row_ptr_C_managed.get(); int* csr_col_ind_C = (int*)csr_col_ind_C_managed.get(); T* csr_val_C = (T*)csr_val_C_managed.get(); T* temp_buffer = (T*)temp_buffer_managed.get(); int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(csr_row_ptr_C, local_ptr, sizeof(int) * (safe_size + 1), hipMemcpyHostToDevice)); // Test hipsparseXpruneCsr2csr_bufferSize status = hipsparseXpruneCsr2csr_bufferSize(nullptr, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, &buffer_size); verify_hipsparse_status_invalid_handle(status); status = hipsparseXpruneCsr2csr_bufferSize(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer size is nullptr"); // Test hipsparseXpruneCsr2csrNnz status = hipsparseXpruneCsr2csrNnz(nullptr, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_handle(status); status = hipsparseXpruneCsr2csrNnz(handle, -1, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: M is invalid"); status = hipsparseXpruneCsr2csrNnz(handle, M, -1, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: N is invalid"); status = hipsparseXpruneCsr2csrNnz(handle, M, N, -1, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: nnz_A is invalid"); status = hipsparseXpruneCsr2csrNnz(handle, M, N, nnz_A, nullptr, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_A is nullptr"); status = hipsparseXpruneCsr2csrNnz(handle, M, N, nnz_A, descr_A, (const T*)nullptr, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_val_A is nullptr"); status = hipsparseXpruneCsr2csrNnz(handle, M, N, nnz_A, descr_A, csr_val_A, nullptr, csr_col_ind_A, &threshold, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr_A is nullptr"); status = hipsparseXpruneCsr2csrNnz(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, nullptr, &threshold, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind is nullptr"); status = hipsparseXpruneCsr2csrNnz(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, (const T*)nullptr, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: threshold is nullptr"); status = hipsparseXpruneCsr2csrNnz(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, nullptr, csr_row_ptr_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_C is nullptr"); status = hipsparseXpruneCsr2csrNnz(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, nullptr, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr_C is nullptr"); status = hipsparseXpruneCsr2csrNnz(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_row_ptr_C, nullptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: nnz_total_dev_host_ptr is nullptr"); // Test hipsparseXpruneCsr2csr status = hipsparseXpruneCsr2csr(nullptr, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, temp_buffer); verify_hipsparse_status_invalid_handle(status); status = hipsparseXpruneCsr2csr(handle, -1, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: M is invalid"); status = hipsparseXpruneCsr2csr(handle, M, -1, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: N is invalid"); status = hipsparseXpruneCsr2csr(handle, M, N, -1, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: nnz_A is invalid"); status = hipsparseXpruneCsr2csr(handle, M, N, nnz_A, nullptr, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_A is nullptr"); status = hipsparseXpruneCsr2csr(handle, M, N, nnz_A, descr_A, (const T*)nullptr, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_val_A is nullptr"); status = hipsparseXpruneCsr2csr(handle, M, N, nnz_A, descr_A, csr_val_A, nullptr, csr_col_ind_A, &threshold, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr_A is nullptr"); status = hipsparseXpruneCsr2csr(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, nullptr, &threshold, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind_A is nullptr"); status = hipsparseXpruneCsr2csr(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, (const T*)nullptr, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: threshold is nullptr"); status = hipsparseXpruneCsr2csr(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, nullptr, csr_val_C, csr_row_ptr_C, csr_col_ind_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_C is nullptr"); status = hipsparseXpruneCsr2csr(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, (T*)nullptr, csr_row_ptr_C, csr_col_ind_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_val_C is nullptr"); status = hipsparseXpruneCsr2csr(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_val_C, nullptr, csr_col_ind_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr_C is nullptr"); status = hipsparseXpruneCsr2csr(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_val_C, csr_row_ptr_C, nullptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind_C is nullptr"); #endif } template hipsparseStatus_t testing_prune_csr2csr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) int M = argus.M; int N = argus.N; T threshold = make_DataType(argus.threshold); hipsparseIndexBase_t csr_idx_base_A = argus.baseA; hipsparseIndexBase_t csr_idx_base_C = argus.baseB; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = unique_ptr_descr_A->descr; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_A, csr_idx_base_A)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_C, csr_idx_base_C)); if(M == 0 || N == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector h_csr_row_ptr_A; std::vector h_csr_col_ind_A; std::vector h_csr_val_A; // Read or construct CSR matrix int nnz_A = 0; if(!generate_csr_matrix( filename, M, N, nnz_A, h_csr_row_ptr_A, h_csr_col_ind_A, h_csr_val_A, csr_idx_base_A)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Allocate device memory auto d_nnz_total_dev_host_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; auto d_csr_row_ptr_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; auto d_csr_row_ptr_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; auto d_csr_col_ind_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz_A), device_free}; auto d_csr_val_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_A), device_free}; int* d_nnz_total_dev_host_ptr = (int*)d_nnz_total_dev_host_ptr_managed.get(); int* d_csr_row_ptr_C = (int*)d_csr_row_ptr_C_managed.get(); int* d_csr_row_ptr_A = (int*)d_csr_row_ptr_A_managed.get(); int* d_csr_col_ind_A = (int*)d_csr_col_ind_A_managed.get(); T* d_csr_val_A = (T*)d_csr_val_A_managed.get(); // Transfer. CHECK_HIP_ERROR(hipMemcpy( d_csr_row_ptr_A, h_csr_row_ptr_A.data(), sizeof(int) * (M + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy( d_csr_col_ind_A, h_csr_col_ind_A.data(), sizeof(int) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(d_csr_val_A, h_csr_val_A.data(), sizeof(T) * nnz_A, hipMemcpyHostToDevice)); size_t buffer_size = 4; CHECK_HIPSPARSE_ERROR(hipsparseXpruneCsr2csr_bufferSize(handle, M, N, nnz_A, descr_A, d_csr_val_A, d_csr_row_ptr_A, d_csr_col_ind_A, &threshold, descr_C, (const T*)nullptr, d_csr_row_ptr_C, (const int*)nullptr, &buffer_size)); auto d_temp_buffer_managed = hipsparse_unique_ptr{device_malloc(buffer_size), device_free}; T* d_temp_buffer = (T*)d_temp_buffer_managed.get(); auto d_threshold_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; T* d_threshold = (T*)d_threshold_managed.get(); CHECK_HIP_ERROR(hipMemcpy(d_threshold, &threshold, sizeof(T), hipMemcpyHostToDevice)); std::vector h_nnz_total_dev_host_ptr(1); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXpruneCsr2csrNnz(handle, M, N, nnz_A, descr_A, d_csr_val_A, d_csr_row_ptr_A, d_csr_col_ind_A, &threshold, descr_C, d_csr_row_ptr_C, &h_nnz_total_dev_host_ptr[0], d_temp_buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXpruneCsr2csrNnz(handle, M, N, nnz_A, descr_A, d_csr_val_A, d_csr_row_ptr_A, d_csr_col_ind_A, d_threshold, descr_C, d_csr_row_ptr_C, d_nnz_total_dev_host_ptr, d_temp_buffer)); std::vector h_nnz_total_copied_from_device(1); CHECK_HIP_ERROR(hipMemcpy(h_nnz_total_copied_from_device.data(), d_nnz_total_dev_host_ptr, sizeof(int), hipMemcpyDeviceToHost)); if(argus.unit_check) { unit_check_general( 1, 1, 1, h_nnz_total_dev_host_ptr.data(), h_nnz_total_copied_from_device.data()); } auto d_csr_col_ind_C_managed = hipsparse_unique_ptr{ device_malloc(sizeof(int) * h_nnz_total_dev_host_ptr[0]), device_free}; auto d_csr_val_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * h_nnz_total_dev_host_ptr[0]), device_free}; int* d_csr_col_ind_C = (int*)d_csr_col_ind_C_managed.get(); T* d_csr_val_C = (T*)d_csr_val_C_managed.get(); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXpruneCsr2csr(handle, M, N, nnz_A, descr_A, d_csr_val_A, d_csr_row_ptr_A, d_csr_col_ind_A, &threshold, descr_C, d_csr_val_C, d_csr_row_ptr_C, d_csr_col_ind_C, d_temp_buffer)); std::vector h_csr_row_ptr_C(M + 1); std::vector h_csr_col_ind_C(h_nnz_total_dev_host_ptr[0]); std::vector h_csr_val_C(h_nnz_total_dev_host_ptr[0]); CHECK_HIP_ERROR(hipMemcpy( h_csr_row_ptr_C.data(), d_csr_row_ptr_C, sizeof(int) * (M + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(h_csr_col_ind_C.data(), d_csr_col_ind_C, sizeof(int) * h_nnz_total_dev_host_ptr[0], hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(h_csr_val_C.data(), d_csr_val_C, sizeof(T) * h_nnz_total_dev_host_ptr[0], hipMemcpyDeviceToHost)); // call host and check results std::vector h_nnz_C_cpu(1); std::vector h_csr_row_ptr_cpu; std::vector h_csr_col_ind_cpu; std::vector h_csr_val_cpu; host_prune_csr_to_csr(M, N, nnz_A, h_csr_row_ptr_A, h_csr_col_ind_A, h_csr_val_A, h_nnz_C_cpu[0], h_csr_row_ptr_cpu, h_csr_col_ind_cpu, h_csr_val_cpu, csr_idx_base_A, csr_idx_base_C, threshold); unit_check_general(1, 1, 1, h_nnz_C_cpu.data(), h_nnz_total_dev_host_ptr.data()); unit_check_general(1, (M + 1), 1, h_csr_row_ptr_cpu.data(), h_csr_row_ptr_C.data()); unit_check_general( 1, h_nnz_total_dev_host_ptr[0], 1, h_csr_col_ind_cpu.data(), h_csr_col_ind_C.data()); unit_check_general( 1, h_nnz_total_dev_host_ptr[0], 1, h_csr_val_cpu.data(), h_csr_val_C.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXpruneCsr2csr(handle, M, N, nnz_A, descr_A, d_csr_val_A, d_csr_row_ptr_A, d_csr_col_ind_A, &threshold, descr_C, d_csr_val_C, d_csr_row_ptr_C, d_csr_col_ind_C, d_temp_buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXpruneCsr2csr(handle, M, N, nnz_A, descr_A, d_csr_val_A, d_csr_row_ptr_A, d_csr_col_ind_A, &threshold, descr_C, d_csr_val_C, d_csr_row_ptr_C, d_csr_col_ind_C, d_temp_buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = prune_csr2csr_gbyte_count(M, nnz_A, h_nnz_total_dev_host_ptr[0]); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, M, display_key_t::N, N, display_key_t::nnzA, nnz_A, display_key_t::nnzC, h_nnz_total_dev_host_ptr[0], display_key_t::threshold, threshold, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_PRUNE_CSR2CSR_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_prune_csr2csr_by_percentage.hpp000066400000000000000000001401441501764003400271770ustar00rootroot00000000000000/* ************************************************************************ * 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 "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_prune_csr2csr_by_percentage_bad_arg(void) { #if(!defined(CUDART_VERSION)) size_t safe_size = 1; int M = 1; int N = 1; int nnz_A = 1; T percentage = static_cast(0); int nnz_total_dev_host_ptr = 1; size_t buffer_size = 1; hipsparseStatus_t status; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = unique_ptr_descr_A->descr; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; std::unique_ptr unique_ptr_info(new prune_struct); pruneInfo_t info = unique_ptr_info->info; auto csr_row_ptr_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto csr_col_ind_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto csr_row_ptr_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto csr_col_ind_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto temp_buffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* csr_row_ptr_A = (int*)csr_row_ptr_A_managed.get(); int* csr_col_ind_A = (int*)csr_col_ind_A_managed.get(); T* csr_val_A = (T*)csr_val_A_managed.get(); int* csr_row_ptr_C = (int*)csr_row_ptr_C_managed.get(); int* csr_col_ind_C = (int*)csr_col_ind_C_managed.get(); T* csr_val_C = (T*)csr_val_C_managed.get(); T* temp_buffer = (T*)temp_buffer_managed.get(); int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(csr_row_ptr_C, local_ptr, sizeof(int) * (safe_size + 1), hipMemcpyHostToDevice)); // Test hipsparseXpruneCsr2csrByPercentage_bufferSize status = hipsparseXpruneCsr2csrByPercentage_bufferSize(nullptr, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, &buffer_size); verify_hipsparse_status_invalid_handle(status); status = hipsparseXpruneCsr2csrByPercentage_bufferSize(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer size is nullptr"); // Test hipsparseXpruneCsr2csrNnzByPercentage status = hipsparseXpruneCsr2csrNnzByPercentage(nullptr, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_handle(status); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, -1, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: M is invalid"); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, M, -1, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: N is invalid"); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, -1, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: nnz_A is invalid"); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, (T)-1, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: percentage is less than 0"); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, (T)101, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: percentage is greater than 100"); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, nnz_A, nullptr, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_A is nullptr"); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, nnz_A, descr_A, (const T*)nullptr, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_val_A is nullptr"); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, nullptr, csr_col_ind_A, percentage, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr_A is nullptr"); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, nullptr, percentage, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind is nullptr"); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, nullptr, csr_row_ptr_C, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_C is nullptr"); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, nullptr, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr_C is nullptr"); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_row_ptr_C, nullptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: nnz_total_dev_host_ptr is nullptr"); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, info, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer is nullptr"); // Test hipsparseXpruneCsr2csrByPercentage status = hipsparseXpruneCsr2csrByPercentage(nullptr, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_handle(status); status = hipsparseXpruneCsr2csrByPercentage(handle, -1, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: M is invalid"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, -1, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: N is invalid"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, -1, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: nnz_A is invalid"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, (T)-1, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: percentage is less than 0"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, (T)101, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: percentage is greater than 100"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, nullptr, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_A is nullptr"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, (const T*)nullptr, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_val_A is nullptr"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, nullptr, csr_col_ind_A, percentage, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr_A is nullptr"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, nullptr, percentage, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind_A is nullptr"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, nullptr, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_C is nullptr"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, (T*)nullptr, csr_row_ptr_C, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_val_C is nullptr"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_val_C, nullptr, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr_C is nullptr"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_val_C, csr_row_ptr_C, nullptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind_C is nullptr"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer is nullptr"); #endif } template hipsparseStatus_t testing_prune_csr2csr_by_percentage(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) int M = argus.M; int N = argus.N; T percentage = make_DataType(argus.percentage); hipsparseIndexBase_t csr_idx_base_A = argus.baseA; hipsparseIndexBase_t csr_idx_base_C = argus.baseB; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = unique_ptr_descr_A->descr; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; std::unique_ptr unique_ptr_info(new prune_struct); pruneInfo_t info = unique_ptr_info->info; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_A, csr_idx_base_A)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_C, csr_idx_base_C)); if(M == 0 || N == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector h_csr_row_ptr_A; std::vector h_csr_col_ind_A; std::vector h_csr_val_A; // Read or construct CSR matrix int nnz_A = 0; if(!generate_csr_matrix( filename, M, N, nnz_A, h_csr_row_ptr_A, h_csr_col_ind_A, h_csr_val_A, csr_idx_base_A)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Allocate device memory auto d_nnz_total_dev_host_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; auto d_csr_row_ptr_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; auto d_csr_row_ptr_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; auto d_csr_col_ind_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz_A), device_free}; auto d_csr_val_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_A), device_free}; int* d_nnz_total_dev_host_ptr = (int*)d_nnz_total_dev_host_ptr_managed.get(); int* d_csr_row_ptr_C = (int*)d_csr_row_ptr_C_managed.get(); int* d_csr_row_ptr_A = (int*)d_csr_row_ptr_A_managed.get(); int* d_csr_col_ind_A = (int*)d_csr_col_ind_A_managed.get(); T* d_csr_val_A = (T*)d_csr_val_A_managed.get(); // Transfer. CHECK_HIP_ERROR(hipMemcpy( d_csr_row_ptr_A, h_csr_row_ptr_A.data(), sizeof(int) * (M + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy( d_csr_col_ind_A, h_csr_col_ind_A.data(), sizeof(int) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(d_csr_val_A, h_csr_val_A.data(), sizeof(T) * nnz_A, hipMemcpyHostToDevice)); size_t buffer_size; CHECK_HIPSPARSE_ERROR(hipsparseXpruneCsr2csrByPercentage_bufferSize(handle, M, N, nnz_A, descr_A, d_csr_val_A, d_csr_row_ptr_A, d_csr_col_ind_A, percentage, descr_C, (const T*)nullptr, d_csr_row_ptr_C, (const int*)nullptr, info, &buffer_size)); auto d_temp_buffer_managed = hipsparse_unique_ptr{device_malloc(buffer_size), device_free}; T* d_temp_buffer = (T*)d_temp_buffer_managed.get(); std::vector h_nnz_total_dev_host_ptr(1); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, nnz_A, descr_A, d_csr_val_A, d_csr_row_ptr_A, d_csr_col_ind_A, percentage, descr_C, d_csr_row_ptr_C, &h_nnz_total_dev_host_ptr[0], info, d_temp_buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, nnz_A, descr_A, d_csr_val_A, d_csr_row_ptr_A, d_csr_col_ind_A, percentage, descr_C, d_csr_row_ptr_C, d_nnz_total_dev_host_ptr, info, d_temp_buffer)); std::vector h_nnz_total_copied_from_device(1); CHECK_HIP_ERROR(hipMemcpy(h_nnz_total_copied_from_device.data(), d_nnz_total_dev_host_ptr, sizeof(int), hipMemcpyDeviceToHost)); if(argus.unit_check) { unit_check_general( 1, 1, 1, h_nnz_total_dev_host_ptr.data(), h_nnz_total_copied_from_device.data()); } auto d_csr_col_ind_C_managed = hipsparse_unique_ptr{ device_malloc(sizeof(int) * h_nnz_total_dev_host_ptr[0]), device_free}; auto d_csr_val_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * h_nnz_total_dev_host_ptr[0]), device_free}; int* d_csr_col_ind_C = (int*)d_csr_col_ind_C_managed.get(); T* d_csr_val_C = (T*)d_csr_val_C_managed.get(); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, d_csr_val_A, d_csr_row_ptr_A, d_csr_col_ind_A, percentage, descr_C, d_csr_val_C, d_csr_row_ptr_C, d_csr_col_ind_C, info, d_temp_buffer)); std::vector h_csr_row_ptr_C(M + 1); std::vector h_csr_col_ind_C(h_nnz_total_dev_host_ptr[0]); std::vector h_csr_val_C(h_nnz_total_dev_host_ptr[0]); CHECK_HIP_ERROR(hipMemcpy( h_csr_row_ptr_C.data(), d_csr_row_ptr_C, sizeof(int) * (M + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(h_csr_col_ind_C.data(), d_csr_col_ind_C, sizeof(int) * h_nnz_total_dev_host_ptr[0], hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(h_csr_val_C.data(), d_csr_val_C, sizeof(T) * h_nnz_total_dev_host_ptr[0], hipMemcpyDeviceToHost)); // call host and check results std::vector h_nnz_C_cpu(1); std::vector h_csr_row_ptr_cpu; std::vector h_csr_col_ind_cpu; std::vector h_csr_val_cpu; host_prune_csr_to_csr_by_percentage(M, N, nnz_A, h_csr_row_ptr_A, h_csr_col_ind_A, h_csr_val_A, h_nnz_C_cpu[0], h_csr_row_ptr_cpu, h_csr_col_ind_cpu, h_csr_val_cpu, csr_idx_base_A, csr_idx_base_C, percentage); unit_check_general(1, 1, 1, h_nnz_C_cpu.data(), h_nnz_total_dev_host_ptr.data()); unit_check_general(1, (M + 1), 1, h_csr_row_ptr_cpu.data(), h_csr_row_ptr_C.data()); unit_check_general( 1, h_nnz_total_dev_host_ptr[0], 1, h_csr_col_ind_cpu.data(), h_csr_col_ind_C.data()); unit_check_general( 1, h_nnz_total_dev_host_ptr[0], 1, h_csr_val_cpu.data(), h_csr_val_C.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, d_csr_val_A, d_csr_row_ptr_A, d_csr_col_ind_A, percentage, descr_C, d_csr_val_C, d_csr_row_ptr_C, d_csr_col_ind_C, info, d_temp_buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, d_csr_val_A, d_csr_row_ptr_A, d_csr_col_ind_A, percentage, descr_C, d_csr_val_C, d_csr_row_ptr_C, d_csr_col_ind_C, info, d_temp_buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = prune_csr2csr_by_percentage_gbyte_count(M, nnz_A, h_nnz_total_dev_host_ptr[0]); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, M, display_key_t::N, N, display_key_t::nnzA, nnz_A, display_key_t::nnzC, h_nnz_total_dev_host_ptr[0], display_key_t::percentage, percentage, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_PRUNE_CSR2CSR_BY_PERCENTAGE_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_prune_dense2csr.hpp000066400000000000000000000540531501764003400246220ustar00rootroot00000000000000/* ************************************************************************ * 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 "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_prune_dense2csr_bad_arg(void) { #if(!defined(CUDART_VERSION)) size_t safe_size = 100; int M = 1; int N = 1; int LDA = M; T threshold = static_cast(1); int nnz_total_dev_host_ptr = 100; size_t buffer_size = 100; hipsparseStatus_t status; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto csr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto temp_buffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* csr_col_ind = (int*)csr_col_ind_managed.get(); T* csr_val = (T*)csr_val_managed.get(); T* A = (T*)A_managed.get(); T* temp_buffer = (T*)temp_buffer_managed.get(); int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(csr_row_ptr, local_ptr, sizeof(int) * (1 + 1), hipMemcpyHostToDevice)); // Test hipsparseXpruneDense2csr_bufferSize status = hipsparseXpruneDense2csr_bufferSize( nullptr, M, N, A, LDA, &threshold, descr, csr_val, csr_row_ptr, csr_col_ind, &buffer_size); verify_hipsparse_status_invalid_handle(status); status = hipsparseXpruneDense2csr_bufferSize( handle, M, N, A, LDA, &threshold, descr, csr_val, csr_row_ptr, csr_col_ind, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer size is nullptr"); // Test hipsparseXpruneDense2csrNnz status = hipsparseXpruneDense2csrNnz(nullptr, M, N, A, LDA, &threshold, descr, csr_row_ptr, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_handle(status); status = hipsparseXpruneDense2csrNnz(handle, -1, N, A, LDA, &threshold, descr, csr_row_ptr, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: M is invalid"); status = hipsparseXpruneDense2csrNnz(handle, M, -1, A, LDA, &threshold, descr, csr_row_ptr, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: N is invalid"); status = hipsparseXpruneDense2csrNnz( handle, M, N, A, -1, &threshold, descr, csr_row_ptr, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: LDA is invalid"); status = hipsparseXpruneDense2csrNnz(handle, M, N, (const T*)nullptr, LDA, &threshold, descr, csr_row_ptr, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: A is nullptr"); status = hipsparseXpruneDense2csrNnz(handle, M, N, A, LDA, (const T*)nullptr, descr, csr_row_ptr, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: threshold is nullptr"); status = hipsparseXpruneDense2csrNnz(handle, M, N, A, LDA, &threshold, nullptr, csr_row_ptr, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); status = hipsparseXpruneDense2csrNnz( handle, M, N, A, LDA, &threshold, descr, nullptr, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr is nullptr"); status = hipsparseXpruneDense2csrNnz( handle, M, N, A, LDA, &threshold, descr, csr_row_ptr, nullptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: nnz_total_dev_host_ptr is nullptr"); // Test hipsparseXpruneDense2csr status = hipsparseXpruneDense2csr( nullptr, M, N, A, LDA, &threshold, descr, csr_val, csr_row_ptr, csr_col_ind, temp_buffer); verify_hipsparse_status_invalid_handle(status); status = hipsparseXpruneDense2csr( handle, -1, N, A, LDA, &threshold, descr, csr_val, csr_row_ptr, csr_col_ind, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: M is invalid"); status = hipsparseXpruneDense2csr( handle, M, -1, A, LDA, &threshold, descr, csr_val, csr_row_ptr, csr_col_ind, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: N is invalid"); status = hipsparseXpruneDense2csr( handle, M, N, A, -1, &threshold, descr, csr_val, csr_row_ptr, csr_col_ind, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: LDA is invalid"); status = hipsparseXpruneDense2csr(handle, M, N, (const T*)nullptr, LDA, &threshold, descr, csr_val, csr_row_ptr, csr_col_ind, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: A is nullptr"); status = hipsparseXpruneDense2csr(handle, M, N, A, LDA, (const T*)nullptr, descr, csr_val, csr_row_ptr, csr_col_ind, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: threshold is nullptr"); status = hipsparseXpruneDense2csr( handle, M, N, A, LDA, &threshold, nullptr, csr_val, csr_row_ptr, csr_col_ind, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); status = hipsparseXpruneDense2csr(handle, M, N, A, LDA, &threshold, descr, (T*)nullptr, csr_row_ptr, csr_col_ind, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_val is nullptr"); status = hipsparseXpruneDense2csr( handle, M, N, A, LDA, &threshold, descr, csr_val, nullptr, csr_col_ind, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr is nullptr"); status = hipsparseXpruneDense2csr( handle, M, N, A, LDA, &threshold, descr, csr_val, csr_row_ptr, nullptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind is nullptr"); #endif } template hipsparseStatus_t testing_prune_dense2csr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) int M = argus.M; int N = argus.N; int LDA = argus.lda; T threshold = make_DataType(argus.threshold); hipsparseIndexBase_t idx_base = argus.baseA; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); if(M == 0 || N == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ return HIPSPARSE_STATUS_SUCCESS; #endif } // Allocate host memory std::vector h_A(LDA * N); std::vector h_nnz_total_dev_host_ptr(1); // Allocate device memory auto d_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * LDA * N), device_free}; auto d_nnz_total_dev_host_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; auto d_csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; T* d_A = (T*)d_A_managed.get(); int* d_nnz_total_dev_host_ptr = (int*)d_nnz_total_dev_host_ptr_managed.get(); int* d_csr_row_ptr = (int*)d_csr_row_ptr_managed.get(); // Initialize the entire allocated memory. for(int i = 0; i < LDA; ++i) { for(int j = 0; j < N; ++j) { h_A[j * LDA + i] = make_DataType(-1); } } // Initialize a random dense matrix. srand(0); gen_dense_random_sparsity_pattern(M, N, h_A.data(), LDA, HIPSPARSE_ORDER_COL, 0.2); // Transfer. CHECK_HIP_ERROR(hipMemcpy(d_A, h_A.data(), sizeof(T) * LDA * N, hipMemcpyHostToDevice)); size_t buffer_size = 512; CHECK_HIPSPARSE_ERROR(hipsparseXpruneDense2csr_bufferSize(handle, M, N, d_A, LDA, &threshold, descr, (const T*)nullptr, d_csr_row_ptr, (const int*)nullptr, &buffer_size)); auto d_temp_buffer_managed = hipsparse_unique_ptr{device_malloc(buffer_size), device_free}; T* d_temp_buffer = (T*)d_temp_buffer_managed.get(); auto d_threshold_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; T* d_threshold = (T*)d_threshold_managed.get(); CHECK_HIP_ERROR(hipMemcpy(d_threshold, &threshold, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXpruneDense2csrNnz(handle, M, N, d_A, LDA, &threshold, descr, d_csr_row_ptr, &h_nnz_total_dev_host_ptr[0], d_temp_buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXpruneDense2csrNnz(handle, M, N, d_A, LDA, d_threshold, descr, d_csr_row_ptr, d_nnz_total_dev_host_ptr, d_temp_buffer)); std::vector h_nnz_total_copied_from_device(1); CHECK_HIP_ERROR(hipMemcpy(h_nnz_total_copied_from_device.data(), d_nnz_total_dev_host_ptr, sizeof(int), hipMemcpyDeviceToHost)); if(argus.unit_check) { unit_check_general( 1, 1, 1, h_nnz_total_dev_host_ptr.data(), h_nnz_total_copied_from_device.data()); } auto d_csr_col_ind_managed = hipsparse_unique_ptr{ device_malloc(sizeof(int) * h_nnz_total_dev_host_ptr[0]), device_free}; auto d_csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * h_nnz_total_dev_host_ptr[0]), device_free}; int* d_csr_col_ind = (int*)d_csr_col_ind_managed.get(); T* d_csr_val = (T*)d_csr_val_managed.get(); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXpruneDense2csr(handle, M, N, d_A, LDA, &threshold, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, d_temp_buffer)); std::vector h_csr_row_ptr(M + 1); std::vector h_csr_col_ind(h_nnz_total_dev_host_ptr[0]); std::vector h_csr_val(h_nnz_total_dev_host_ptr[0]); CHECK_HIP_ERROR(hipMemcpy( h_csr_row_ptr.data(), d_csr_row_ptr, sizeof(int) * (M + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(h_csr_col_ind.data(), d_csr_col_ind, sizeof(int) * h_nnz_total_dev_host_ptr[0], hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(h_csr_val.data(), d_csr_val, sizeof(T) * h_nnz_total_dev_host_ptr[0], hipMemcpyDeviceToHost)); // call host and check results std::vector h_nnz_cpu(1); std::vector h_csr_row_ptr_cpu; std::vector h_csr_col_ind_cpu; std::vector h_csr_val_cpu; host_prune_dense2csr(M, N, h_A, LDA, idx_base, threshold, h_nnz_cpu[0], h_csr_val_cpu, h_csr_row_ptr_cpu, h_csr_col_ind_cpu); unit_check_general(1, 1, 1, h_nnz_cpu.data(), h_nnz_total_dev_host_ptr.data()); unit_check_general(1, (M + 1), 1, h_csr_row_ptr_cpu.data(), h_csr_row_ptr.data()); unit_check_general( 1, h_nnz_total_dev_host_ptr[0], 1, h_csr_col_ind_cpu.data(), h_csr_col_ind.data()); unit_check_general( 1, h_nnz_total_dev_host_ptr[0], 1, h_csr_val_cpu.data(), h_csr_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXpruneDense2csr(handle, M, N, d_A, LDA, &threshold, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, d_temp_buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXpruneDense2csr(handle, M, N, d_A, LDA, &threshold, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, d_temp_buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = prune_dense2csr_gbyte_count(M, N, h_nnz_total_dev_host_ptr[0]); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, M, display_key_t::N, N, display_key_t::LD, LDA, display_key_t::nnz, h_nnz_total_dev_host_ptr[0], display_key_t::threshold, threshold, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_PRUNE_DENSE2CSR_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_prune_dense2csr_by_percentage.hpp000066400000000000000000000770171501764003400275160ustar00rootroot00000000000000/* ************************************************************************ * 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 "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_prune_dense2csr_by_percentage_bad_arg(void) { #if(!defined(CUDART_VERSION)) size_t safe_size = 1; int M = 1; int N = 1; int LDA = M; T percentage = static_cast(1); int nnz_total_dev_host_ptr = 1; size_t buffer_size = 1; hipsparseStatus_t status; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_info(new prune_struct); pruneInfo_t info = unique_ptr_info->info; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto csr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto temp_buffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* csr_col_ind = (int*)csr_col_ind_managed.get(); T* csr_val = (T*)csr_val_managed.get(); T* A = (T*)A_managed.get(); T* temp_buffer = (T*)temp_buffer_managed.get(); int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(csr_row_ptr, local_ptr, sizeof(int) * (1 + 1), hipMemcpyHostToDevice)); // Test hipsparseXpruneDense2csrByPercentage_bufferSize status = hipsparseXpruneDense2csrByPercentage_bufferSize(nullptr, M, N, A, LDA, percentage, descr, csr_val, csr_row_ptr, csr_col_ind, info, &buffer_size); verify_hipsparse_status_invalid_handle(status); status = hipsparseXpruneDense2csrByPercentage_bufferSize( handle, M, N, A, LDA, percentage, descr, csr_val, csr_row_ptr, csr_col_ind, info, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer size is nullptr"); // Test hipsparseXpruneDense2csrNnzByPercentage status = hipsparseXpruneDense2csrNnzByPercentage(nullptr, M, N, A, LDA, percentage, descr, csr_row_ptr, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_handle(status); status = hipsparseXpruneDense2csrNnzByPercentage(handle, -1, N, A, LDA, percentage, descr, csr_row_ptr, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: M is invalid"); status = hipsparseXpruneDense2csrNnzByPercentage(handle, M, -1, A, LDA, percentage, descr, csr_row_ptr, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: N is invalid"); status = hipsparseXpruneDense2csrNnzByPercentage(handle, M, N, A, -1, percentage, descr, csr_row_ptr, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: LDA is invalid"); status = hipsparseXpruneDense2csrNnzByPercentage(handle, M, N, A, LDA, (T)-1.0, descr, csr_row_ptr, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: percentage is less than 0"); status = hipsparseXpruneDense2csrNnzByPercentage(handle, M, N, A, LDA, (T)101.0, descr, csr_row_ptr, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: percentage is more than 100"); status = hipsparseXpruneDense2csrNnzByPercentage(handle, M, N, (const T*)nullptr, LDA, percentage, descr, csr_row_ptr, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: A is nullptr"); status = hipsparseXpruneDense2csrNnzByPercentage(handle, M, N, A, LDA, percentage, nullptr, csr_row_ptr, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); status = hipsparseXpruneDense2csrNnzByPercentage(handle, M, N, A, LDA, percentage, descr, nullptr, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr is nullptr"); status = hipsparseXpruneDense2csrNnzByPercentage( handle, M, N, A, LDA, percentage, descr, csr_row_ptr, nullptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: nnz_total_dev_host_ptr is nullptr"); status = hipsparseXpruneDense2csrNnzByPercentage(handle, M, N, A, LDA, percentage, descr, csr_row_ptr, &nnz_total_dev_host_ptr, info, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer size is nullptr"); // Test hipsparseXpruneDense2csrByPercentage status = hipsparseXpruneDense2csrByPercentage(nullptr, M, N, A, LDA, percentage, descr, csr_val, csr_row_ptr, csr_col_ind, info, temp_buffer); verify_hipsparse_status_invalid_handle(status); status = hipsparseXpruneDense2csrByPercentage(handle, -1, N, A, LDA, percentage, descr, csr_val, csr_row_ptr, csr_col_ind, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: M is invalid"); status = hipsparseXpruneDense2csrByPercentage(handle, M, -1, A, LDA, percentage, descr, csr_val, csr_row_ptr, csr_col_ind, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: N is invalid"); status = hipsparseXpruneDense2csrByPercentage(handle, M, N, A, -1, percentage, descr, csr_val, csr_row_ptr, csr_col_ind, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: LDA is invalid"); status = hipsparseXpruneDense2csrByPercentage( handle, M, N, A, LDA, (T)-1.0, descr, csr_val, csr_row_ptr, csr_col_ind, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: percentage is less than 0"); status = hipsparseXpruneDense2csrByPercentage(handle, M, N, A, LDA, (T)101.0, descr, csr_val, csr_row_ptr, csr_col_ind, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: percentage is more than 100"); status = hipsparseXpruneDense2csrByPercentage(handle, M, N, (const T*)nullptr, LDA, percentage, descr, csr_val, csr_row_ptr, csr_col_ind, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: A is nullptr"); status = hipsparseXpruneDense2csrByPercentage(handle, M, N, A, LDA, percentage, nullptr, csr_val, csr_row_ptr, csr_col_ind, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); status = hipsparseXpruneDense2csrByPercentage(handle, M, N, A, LDA, percentage, descr, (T*)nullptr, csr_row_ptr, csr_col_ind, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_val is nullptr"); status = hipsparseXpruneDense2csrByPercentage( handle, M, N, A, LDA, percentage, descr, csr_val, nullptr, csr_col_ind, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr is nullptr"); status = hipsparseXpruneDense2csrByPercentage( handle, M, N, A, LDA, percentage, descr, csr_val, csr_row_ptr, nullptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind is nullptr"); status = hipsparseXpruneDense2csrByPercentage( handle, M, N, A, LDA, percentage, descr, csr_val, csr_row_ptr, csr_col_ind, info, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer is nullptr"); #endif } template hipsparseStatus_t testing_prune_dense2csr_by_percentage(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) int M = argus.M; int N = argus.N; int LDA = argus.lda; T percentage = argus.get_percentage(); hipsparseIndexBase_t idx_base = argus.baseA; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_info(new prune_struct); pruneInfo_t info = unique_ptr_info->info; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); if(M == 0 || N == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ return HIPSPARSE_STATUS_SUCCESS; #endif } // Allocate host memory std::vector h_A(LDA * N); std::vector h_nnz_total_dev_host_ptr(1); // Allocate device memory auto d_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * LDA * N), device_free}; auto d_nnz_total_dev_host_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; auto d_csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; T* d_A = (T*)d_A_managed.get(); int* d_nnz_total_dev_host_ptr = (int*)d_nnz_total_dev_host_ptr_managed.get(); int* d_csr_row_ptr = (int*)d_csr_row_ptr_managed.get(); // Initialize the entire allocated memory. for(int i = 0; i < LDA; ++i) { for(int j = 0; j < N; ++j) { h_A[j * LDA + i] = make_DataType(-1); } } // Initialize a random dense matrix. srand(0); gen_dense_random_sparsity_pattern(M, N, h_A.data(), LDA, HIPSPARSE_ORDER_COL, 0.2); // Transfer. CHECK_HIP_ERROR(hipMemcpy(d_A, h_A.data(), sizeof(T) * LDA * N, hipMemcpyHostToDevice)); size_t buffer_size = 512; CHECK_HIPSPARSE_ERROR(hipsparseXpruneDense2csrByPercentage_bufferSize(handle, M, N, d_A, LDA, percentage, descr, (const T*)nullptr, d_csr_row_ptr, (const int*)nullptr, info, &buffer_size)); auto d_temp_buffer_managed = hipsparse_unique_ptr{device_malloc(buffer_size), device_free}; T* d_temp_buffer = (T*)d_temp_buffer_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXpruneDense2csrNnzByPercentage(handle, M, N, d_A, LDA, percentage, descr, d_csr_row_ptr, &h_nnz_total_dev_host_ptr[0], info, d_temp_buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXpruneDense2csrNnzByPercentage(handle, M, N, d_A, LDA, percentage, descr, d_csr_row_ptr, d_nnz_total_dev_host_ptr, info, d_temp_buffer)); std::vector h_nnz_total_copied_from_device(1); CHECK_HIP_ERROR(hipMemcpy(h_nnz_total_copied_from_device.data(), d_nnz_total_dev_host_ptr, sizeof(int), hipMemcpyDeviceToHost)); if(argus.unit_check) { unit_check_general( 1, 1, 1, h_nnz_total_dev_host_ptr.data(), h_nnz_total_copied_from_device.data()); } auto d_csr_col_ind_managed = hipsparse_unique_ptr{ device_malloc(sizeof(int) * h_nnz_total_dev_host_ptr[0]), device_free}; auto d_csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * h_nnz_total_dev_host_ptr[0]), device_free}; int* d_csr_col_ind = (int*)d_csr_col_ind_managed.get(); T* d_csr_val = (T*)d_csr_val_managed.get(); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXpruneDense2csrByPercentage(handle, M, N, d_A, LDA, percentage, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, info, d_temp_buffer)); std::vector h_csr_row_ptr(M + 1); std::vector h_csr_col_ind(h_nnz_total_dev_host_ptr[0]); std::vector h_csr_val(h_nnz_total_dev_host_ptr[0]); CHECK_HIP_ERROR(hipMemcpy( h_csr_row_ptr.data(), d_csr_row_ptr, sizeof(int) * (M + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(h_csr_col_ind.data(), d_csr_col_ind, sizeof(int) * h_nnz_total_dev_host_ptr[0], hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(h_csr_val.data(), d_csr_val, sizeof(T) * h_nnz_total_dev_host_ptr[0], hipMemcpyDeviceToHost)); // call host and check results std::vector h_nnz_cpu(1); std::vector h_csr_row_ptr_cpu; std::vector h_csr_col_ind_cpu; std::vector h_csr_val_cpu; host_prune_dense2csr_by_percentage(M, N, h_A, LDA, idx_base, percentage, h_nnz_cpu[0], h_csr_val_cpu, h_csr_row_ptr_cpu, h_csr_col_ind_cpu); unit_check_general(1, 1, 1, h_nnz_cpu.data(), h_nnz_total_dev_host_ptr.data()); unit_check_general(1, (M + 1), 1, h_csr_row_ptr_cpu.data(), h_csr_row_ptr.data()); unit_check_general( 1, h_nnz_total_dev_host_ptr[0], 1, h_csr_col_ind_cpu.data(), h_csr_col_ind.data()); unit_check_general( 1, h_nnz_total_dev_host_ptr[0], 1, h_csr_val_cpu.data(), h_csr_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXpruneDense2csrByPercentage(handle, M, N, d_A, LDA, percentage, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, info, d_temp_buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXpruneDense2csrByPercentage(handle, M, N, d_A, LDA, percentage, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, info, d_temp_buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = prune_dense2csr_by_percentage_gbyte_count(M, N, h_nnz_total_dev_host_ptr[0]); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, M, display_key_t::M, N, display_key_t::nnz, h_nnz_total_dev_host_ptr[0], display_key_t::percentage, percentage, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_PRUNE_DENSE2CSR_BY_PERCENTAGE_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_rot.hpp000066400000000000000000000243751501764003400223310ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_ROT_HPP #define TESTING_ROT_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include using namespace hipsparse_test; void testing_rot_bad_arg(void) { #if(!defined(CUDART_VERSION) || (CUDART_VERSION >= 11000 && CUDART_VERSION < 13000)) int64_t size = 100; int64_t nnz = 100; float c_coeff = 3.7; float s_coeff = 1.2; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipDataType dataType = HIP_R_32F; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * nnz), device_free}; auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * size), device_free}; float* dx_val = (float*)dx_val_managed.get(); int* dx_ind = (int*)dx_ind_managed.get(); float* dy = (float*)dy_managed.get(); // Structures hipsparseSpVecDescr_t x; hipsparseDnVecDescr_t y; verify_hipsparse_status_success( hipsparseCreateSpVec(&x, size, nnz, dx_ind, dx_val, idxType, idxBase, dataType), "Success"); verify_hipsparse_status_success(hipsparseCreateDnVec(&y, size, dy, dataType), "Success"); // Rot verify_hipsparse_status_invalid_handle(hipsparseRot(nullptr, &c_coeff, &s_coeff, x, y)); verify_hipsparse_status_invalid_pointer(hipsparseRot(handle, nullptr, &s_coeff, x, y), "Error: c_coeff is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseRot(handle, &c_coeff, nullptr, x, y), "Error: s_coeff is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseRot(handle, &c_coeff, &s_coeff, nullptr, y), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseRot(handle, &c_coeff, &s_coeff, x, nullptr), "Error: y is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpVec(x), "Success"); verify_hipsparse_status_success(hipsparseDestroyDnVec(y), "Success"); #endif } template hipsparseStatus_t testing_rot(Arguments argus) { #if(!defined(CUDART_VERSION) || (CUDART_VERSION >= 11000 && CUDART_VERSION < 13000)) I size = argus.N; I nnz = argus.nnz; T hc_coeff = make_DataType(argus.alpha); T hs_coeff = make_DataType(argus.beta); hipsparseIndexBase_t idxBase = argus.baseA; // Index and data type hipsparseIndexType_t idxType = getIndexType(); hipDataType dataType = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hx_ind(nnz); std::vector hx_val_1(nnz); std::vector hx_val_2(nnz); std::vector hx_val_gold(nnz); std::vector hy_1(size); std::vector hy_2(size); std::vector hy_gold(size); // Initial Data on CPU srand(12345ULL); hipsparseInitIndex(hx_ind.data(), nnz, 1, size); hipsparseInit(hx_val_1, 1, nnz); hipsparseInit(hy_1, 1, size); hx_val_2 = hx_val_1; hx_val_gold = hx_val_1; hy_2 = hy_1; hy_gold = hy_1; // Allocate memory on device auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz), device_free}; auto dx_val_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dx_val_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * size), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * size), device_free}; auto dc_coeff_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto ds_coeff_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* dx_ind = (I*)dx_ind_managed.get(); T* dx_val_1 = (T*)dx_val_1_managed.get(); T* dx_val_2 = (T*)dx_val_2_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* dc_coeff = (T*)dc_coeff_managed.get(); T* ds_coeff = (T*)ds_coeff_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dx_ind, hx_ind.data(), sizeof(I) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx_val_1, hx_val_1.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx_val_2, hx_val_2.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_1, hy_1.data(), sizeof(T) * size, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_2, hy_2.data(), sizeof(T) * size, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dc_coeff, &hc_coeff, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(ds_coeff, &hs_coeff, sizeof(T), hipMemcpyHostToDevice)); // Create structures hipsparseSpVecDescr_t x1, x2; hipsparseDnVecDescr_t y1, y2; CHECK_HIPSPARSE_ERROR( hipsparseCreateSpVec(&x1, size, nnz, dx_ind, dx_val_1, idxType, idxBase, dataType)); CHECK_HIPSPARSE_ERROR( hipsparseCreateSpVec(&x2, size, nnz, dx_ind, dx_val_2, idxType, idxBase, dataType)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&y1, size, dy_1, dataType)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&y2, size, dy_2, dataType)); if(argus.unit_check) { // hipSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseRot(handle, &hc_coeff, &hs_coeff, x1, y1)); // hipSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseRot(handle, dc_coeff, ds_coeff, x2, y2)); // Copy output from device to CPU CHECK_HIP_ERROR( hipMemcpy(hx_val_1.data(), dx_val_1, sizeof(T) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hx_val_2.data(), dx_val_2, sizeof(T) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_1.data(), dy_1, sizeof(T) * size, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_2.data(), dy_2, sizeof(T) * size, hipMemcpyDeviceToHost)); // CPU for(int64_t i = 0; i < nnz; ++i) { I idx = hx_ind[i] - idxBase; T x = hx_val_gold[i]; T y = hy_gold[idx]; hx_val_gold[i] = testing_mult(hc_coeff, x) + testing_mult(hs_coeff, y); hy_gold[idx] = testing_mult(hc_coeff, y) - testing_mult(hs_coeff, x); } // Verify results against host unit_check_general(1, nnz, 1, hx_val_gold.data(), hx_val_1.data()); unit_check_general(1, nnz, 1, hx_val_gold.data(), hx_val_2.data()); unit_check_general(1, size, 1, hy_gold.data(), hy_1.data()); unit_check_general(1, size, 1, hy_gold.data(), hy_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseRot(handle, &hc_coeff, &hs_coeff, x1, y1)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseRot(handle, &hc_coeff, &hs_coeff, x1, y1)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = roti_gflop_count(nnz); double gbyte_count = roti_gbyte_count(nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); display_timing_info(display_key_t::nnz, nnz, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIPSPARSE_ERROR(hipsparseDestroySpVec(x1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpVec(x2)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y2)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_ROT_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_roti.hpp000066400000000000000000000225741501764003400225010ustar00rootroot00000000000000/* ************************************************************************ * 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 "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include using namespace hipsparse; using namespace hipsparse_test; template void testing_roti_bad_arg(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(); verify_hipsparse_status_invalid_value( hipsparseXroti(handle, -1, dx_val, dx_ind, dy, &c, &s, idx_base), "Error: nnz is invalid"); // cusparse returns success when passed nullptrs #if(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_pointer( hipsparseXroti(handle, nnz, dx_val, (int*)nullptr, dy, &c, &s, idx_base), "Error: x_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXroti(handle, nnz, (T*)nullptr, dx_ind, dy, &c, &s, idx_base), "Error: x_val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXroti(handle, nnz, dx_val, dx_ind, (T*)nullptr, &c, &s, idx_base), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXroti(handle, nnz, dx_val, dx_ind, dy, (T*)nullptr, &s, idx_base), "Error: c is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXroti(handle, nnz, dx_val, dx_ind, dy, &c, (T*)nullptr, idx_base), "Error: s is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXroti(nullptr, nnz, dx_val, dx_ind, dy, &c, &s, idx_base)); #endif } template hipsparseStatus_t testing_roti(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int N = argus.N; int nnz = argus.nnz; T c = argus.get_alpha(); T s = argus.get_beta(); hipsparseIndexBase_t idx_base = argus.baseA; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hx_ind(nnz); std::vector hx_val_1(nnz); std::vector hx_val_2(nnz); std::vector hx_val_gold(nnz); std::vector hy_1(N); std::vector hy_2(N); std::vector hy_gold(N); // Initial Data on CPU srand(12345ULL); hipsparseInitIndex(hx_ind.data(), nnz, 1, N); hipsparseInit(hx_val_1, 1, nnz); hipsparseInit(hy_1, 1, N); hx_val_2 = hx_val_1; hx_val_gold = hx_val_1; hy_2 = hy_1; hy_gold = hy_1; // allocate memory on device auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dx_val_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dx_val_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * N), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * N), device_free}; auto dc_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto ds_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dx_ind = (int*)dx_ind_managed.get(); T* dx_val_1 = (T*)dx_val_1_managed.get(); T* dx_val_2 = (T*)dx_val_2_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* dc = (T*)dc_managed.get(); T* ds = (T*)ds_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dx_ind, hx_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx_val_1, hx_val_1.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_1, hy_1.data(), sizeof(T) * N, hipMemcpyHostToDevice)); if(argus.unit_check) { CHECK_HIP_ERROR( hipMemcpy(dx_val_2, hx_val_2.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_2, hy_2.data(), sizeof(T) * N, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dc, &c, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(ds, &s, sizeof(T), hipMemcpyHostToDevice)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseXroti(handle, nnz, dx_val_1, dx_ind, dy_1, &c, &s, idx_base)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseXroti(handle, nnz, dx_val_2, dx_ind, dy_2, dc, ds, idx_base)); // copy output from device to CPU CHECK_HIP_ERROR( hipMemcpy(hx_val_1.data(), dx_val_1, sizeof(T) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hx_val_2.data(), dx_val_2, sizeof(T) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_1.data(), dy_1, sizeof(T) * N, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_2.data(), dy_2, sizeof(T) * N, hipMemcpyDeviceToHost)); // CPU for(int i = 0; i < nnz; ++i) { int idx = hx_ind[i] - idx_base; T x = hx_val_gold[i]; T y = hy_gold[idx]; hx_val_gold[i] = c * x + s * y; hy_gold[idx] = c * y - s * x; } // enable unit check, notice unit check is not invasive, but norm check is, // unit check and norm check can not be interchanged their order unit_check_general(1, nnz, 1, hx_val_gold.data(), hx_val_1.data()); unit_check_general(1, nnz, 1, hx_val_gold.data(), hx_val_2.data()); unit_check_general(1, N, 1, hy_gold.data(), hy_1.data()); unit_check_general(1, N, 1, hy_gold.data(), hy_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXroti(handle, nnz, dx_val_1, dx_ind, dy_1, &c, &s, idx_base)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXroti(handle, nnz, dx_val_1, dx_ind, dy_1, &c, &s, idx_base)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = roti_gflop_count(nnz); double gbyte_count = roti_gbyte_count(nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); display_timing_info(display_key_t::nnz, nnz, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_ROTI_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_scatter.hpp000066400000000000000000000155271501764003400231710ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SCATTER_HPP #define TESTING_SCATTER_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include using namespace hipsparse_test; void testing_scatter_bad_arg(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) int64_t size = 100; int64_t nnz = 100; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipDataType dataType = HIP_R_32F; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * nnz), device_free}; auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * size), device_free}; float* dx_val = (float*)dx_val_managed.get(); int* dx_ind = (int*)dx_ind_managed.get(); float* dy = (float*)dy_managed.get(); // Structures hipsparseSpVecDescr_t x; hipsparseDnVecDescr_t y; verify_hipsparse_status_success( hipsparseCreateSpVec(&x, size, nnz, dx_ind, dx_val, idxType, idxBase, dataType), "Success"); verify_hipsparse_status_success(hipsparseCreateDnVec(&y, size, dy, dataType), "Success"); // Scatter verify_hipsparse_status_invalid_handle(hipsparseScatter(nullptr, x, y)); verify_hipsparse_status_invalid_pointer(hipsparseScatter(handle, nullptr, y), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseScatter(handle, x, nullptr), "Error: y is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpVec(x), "Success"); verify_hipsparse_status_success(hipsparseDestroyDnVec(y), "Success"); #endif } template hipsparseStatus_t testing_scatter(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) I size = argus.N; I nnz = argus.nnz; hipsparseIndexBase_t idxBase = argus.baseA; // Index and data type hipsparseIndexType_t idxType = getIndexType(); hipDataType dataType = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hx_ind(nnz); std::vector hx_val(nnz); std::vector hy(size); std::vector hy_gold(size); // Initial Data on CPU srand(12345ULL); hipsparseInitIndex(hx_ind.data(), nnz, 1, size); hipsparseInit(hx_val, 1, nnz); hipsparseInit(hy, 1, size); hy_gold = hy; // Allocate memory on device auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz), device_free}; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * size), device_free}; I* dx_ind = (I*)dx_ind_managed.get(); T* dx_val = (T*)dx_val_managed.get(); T* dy = (T*)dy_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dx_ind, hx_ind.data(), sizeof(I) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx_val, hx_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy, hy.data(), sizeof(T) * size, hipMemcpyHostToDevice)); // Create structures hipsparseSpVecDescr_t x; hipsparseDnVecDescr_t y; CHECK_HIPSPARSE_ERROR( hipsparseCreateSpVec(&x, size, nnz, dx_ind, dx_val, idxType, idxBase, dataType)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&y, size, dy, dataType)); if(argus.unit_check) { // Scatter CHECK_HIPSPARSE_ERROR(hipsparseScatter(handle, x, y)); // Copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hy.data(), dy, sizeof(T) * size, hipMemcpyDeviceToHost)); // CPU for(int64_t i = 0; i < nnz; ++i) { hy_gold[hx_ind[i] - idxBase] = hx_val[i]; } // Verify results against host unit_check_general(1, size, 1, hy_gold.data(), hy.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseScatter(handle, x, y)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseScatter(handle, x, y)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = sctr_gbyte_count(nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::nnz, nnz, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIPSPARSE_ERROR(hipsparseDestroySpVec(x)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SCATTER_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_sctr.hpp000066400000000000000000000150531501764003400224710ustar00rootroot00000000000000/* ************************************************************************ * 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 "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include using namespace hipsparse; using namespace hipsparse_test; template void testing_sctr_bad_arg(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(); verify_hipsparse_status_invalid_value(hipsparseXsctr(handle, -1, dx_val, dx_ind, dy, idx_base), "Error: nnz is invalid"); // cusparse returns success for these #if(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_pointer( hipsparseXsctr(handle, nnz, dx_val, (int*)nullptr, dy, idx_base), "Error: x_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXsctr(handle, nnz, (T*)nullptr, dx_ind, dy, idx_base), "Error: x_val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXsctr(handle, nnz, dx_val, dx_ind, (T*)nullptr, idx_base), "Error: y is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXsctr(nullptr, nnz, dx_val, dx_ind, dy, idx_base)); #endif } template hipsparseStatus_t testing_sctr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int N = argus.N; int nnz = argus.nnz; hipsparseIndexBase_t idx_base = argus.baseA; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hx_ind(nnz); std::vector hx_val(nnz); std::vector hy(N); std::vector hy_gold(N); // Initial Data on CPU srand(12345ULL); hipsparseInitIndex(hx_ind.data(), nnz, 1, N); hipsparseInit(hx_val, 1, nnz); hipsparseInit(hy, 1, N); hy_gold = hy; // allocate memory on device auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * N), device_free}; int* dx_ind = (int*)dx_ind_managed.get(); T* dx_val = (T*)dx_val_managed.get(); T* dy = (T*)dy_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dx_ind, hx_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx_val, hx_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy, hy.data(), sizeof(T) * N, hipMemcpyHostToDevice)); if(argus.unit_check) { // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXsctr(handle, nnz, dx_val, dx_ind, dy, idx_base)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hy.data(), dy, sizeof(T) * N, hipMemcpyDeviceToHost)); // CPU for(int i = 0; i < nnz; ++i) { hy_gold[hx_ind[i] - idx_base] = hx_val[i]; } // enable unit check, notice unit check is not invasive, but norm check is, // unit check and norm check can not be interchanged their order unit_check_general(1, N, 1, hy_gold.data(), hy.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXsctr(handle, nnz, dx_val, dx_ind, dy, idx_base)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXsctr(handle, nnz, dx_val, dx_ind, dy, idx_base)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = sctr_gbyte_count(nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::nnz, nnz, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SCTR_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_sddmm_coo.hpp000066400000000000000000000475451501764003400234750ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SDDMM_COO_HPP #define TESTING_SDDMM_COO_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; void testing_sddmm_coo_bad_arg(void) { #if(!defined(CUDART_VERSION)) int32_t n = 100; int32_t m = 100; int32_t k = 100; int64_t nnz = 100; int32_t safe_size = 100; float alpha = 0.6; float beta = 0.2; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOrder_t orderA = HIPSPARSE_ORDER_COL; hipsparseOrder_t orderB = HIPSPARSE_ORDER_COL; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxTypeI = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; hipsparseSDDMMAlg_t alg = HIPSPARSE_SDDMM_ALG_DEFAULT; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dA_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int32_t* drow = (int32_t*)drow_managed.get(); int32_t* dcol = (int32_t*)dcol_managed.get(); float* dval = (float*)dval_managed.get(); float* dB = (float*)dB_managed.get(); float* dA = (float*)dA_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SDDMM structures hipsparseDnMatDescr_t A, B; hipsparseSpMatDescr_t C; size_t bsize; // Create SDDMM structures verify_hipsparse_status_success(hipsparseCreateDnMat(&A, m, k, m, dA, dataType, orderA), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&B, k, n, k, dB, dataType, orderB), "success"); verify_hipsparse_status_success( hipsparseCreateCoo(&C, m, n, nnz, drow, dcol, dval, idxTypeI, idxBase, dataType), "success"); // SDDMM buffer verify_hipsparse_status_invalid_handle(hipsparseSDDMM_bufferSize( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, &bsize), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, &bsize), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, &bsize), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, &bsize), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, &bsize), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, nullptr), "Error: bsize is nullptr"); // SDDMM verify_hipsparse_status_invalid_handle(hipsparseSDDMM_preprocess( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // SDDMM verify_hipsparse_status_invalid_handle( hipsparseSDDMM(nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroyDnMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(B), "success"); verify_hipsparse_status_success(hipsparseDestroySpMat(C), "success"); #endif } template hipsparseStatus_t testing_sddmm_coo(Arguments argus) { #if(!defined(CUDART_VERSION)) I m = argus.M; I n = argus.N; I k = argus.K; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseOperation_t transB = argus.transB; hipsparseOrder_t orderA = argus.orderA; hipsparseOrder_t orderB = argus.orderB; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseSDDMMAlg_t alg = static_cast(argus.sddmm_alg); std::string filename = argus.filename; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Initial Data on CPU srand(12345ULL); // Read or construct CSR matrix I nnz = 0; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hrow_ind(nnz); // Convert to COO for(I i = 0; i < m; ++i) { for(I j = hcsr_row_ptr[i]; j < hcsr_row_ptr[i + 1]; ++j) { hrow_ind[j - idx_base] = i + idx_base; } } // Some matrix properties I A_m = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k; I A_n = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : m; I B_m = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : n; I B_n = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? n : k; I C_m = m; I C_n = n; int ld_multiplier_A = 1; int ld_multiplier_B = 1; int64_t lda = (orderA == HIPSPARSE_ORDER_COL) ? ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_A) * m) : (int64_t(ld_multiplier_A) * k)) : ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_A) * k) : (int64_t(ld_multiplier_A) * m)); int64_t ldb = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * k) : (int64_t(ld_multiplier_B) * n)) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * n) : (int64_t(ld_multiplier_B) * k)); lda = std::max(int64_t(1), lda); ldb = std::max(int64_t(1), ldb); int64_t nrowA = (orderA == HIPSPARSE_ORDER_COL) ? lda : A_m; int64_t ncolA = (orderA == HIPSPARSE_ORDER_COL) ? A_n : lda; int64_t nrowB = (orderB == HIPSPARSE_ORDER_COL) ? ldb : B_m; int64_t ncolB = (orderB == HIPSPARSE_ORDER_COL) ? B_n : ldb; int64_t nnz_A = nrowA * ncolA; int64_t nnz_B = nrowB * ncolB; std::vector hA(nnz_A); std::vector hB(nnz_B); hipsparseInit(hA, nnz_A, 1); hipsparseInit(hB, nnz_B, 1); // allocate memory on device auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz), device_free}; auto dval1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dval2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dA_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_A), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_B), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* drow = (I*)drow_managed.get(); I* dcol = (I*)dcol_managed.get(); T* dval1 = (T*)dval1_managed.get(); T* dval2 = (T*)dval2_managed.get(); T* dA = (T*)dA_managed.get(); T* dB = (T*)dB_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(drow, hrow_ind.data(), sizeof(I) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcsr_col_ind.data(), sizeof(I) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval1, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval2, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dA, hA.data(), sizeof(T) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t C1, C2; CHECK_HIPSPARSE_ERROR( hipsparseCreateCoo(&C1, C_m, C_n, nnz, drow, dcol, dval1, typeI, idx_base, typeT)); CHECK_HIPSPARSE_ERROR( hipsparseCreateCoo(&C2, C_m, C_n, nnz, drow, dcol, dval2, typeI, idx_base, typeT)); // Create dense matrices hipsparseDnMatDescr_t A, B; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&A, A_m, A_n, lda, dA, typeT, orderA)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&B, B_m, B_n, ldb, dB, typeT, orderB)); // Query SDDMM buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSDDMM_bufferSize( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSDDMM_preprocess( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSDDMM_preprocess( handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSDDMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSDDMM(handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); // copy output from device to CPU. std::vector hval1(nnz); std::vector hval2(nnz); CHECK_HIP_ERROR(hipMemcpy(hval1.data(), dval1, sizeof(T) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hval2.data(), dval2, sizeof(T) * nnz, hipMemcpyDeviceToHost)); const int64_t incA = (orderA == HIPSPARSE_ORDER_COL) ? ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? lda : 1) : ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? 1 : lda); const int64_t incB = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? 1 : ldb) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? ldb : 1); for(I i = 0; i < nnz; ++i) { const I r = hrow_ind[i] - idx_base; const I c = hcsr_col_ind[i] - idx_base; const T* Aptr = (orderA == HIPSPARSE_ORDER_COL) ? ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? &hA[r] : &hA[lda * r]) : ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? &hA[lda * r] : &hA[r]); const T* Bptr = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? &hB[ldb * c] : &hB[c]) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? &hB[c] : &hB[ldb * c]); T sum = static_cast(0); for(I j = 0; j < k; ++j) { sum = testing_fma(Aptr[incA * j], Bptr[incB * j], sum); } hcsr_val[i] = testing_mult(hcsr_val[i], h_beta) + testing_mult(h_alpha, sum); } unit_check_near(1, nnz, 1, hval1.data(), hcsr_val.data()); unit_check_near(1, nnz, 1, hval2.data(), hcsr_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSDDMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSDDMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = sddmm_gflop_count(k, nnz, h_beta != make_DataType(0)); double gbyte_count = sddmm_coo_gbyte_count(m, n, k, nnz, h_beta != make_DataType(0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::format, hipsparse_format2string(HIPSPARSE_FORMAT_COO), display_key_t::transA, hipsparse_operation2string(transA), display_key_t::transB, hipsparse_operation2string(transB), display_key_t::M, m, display_key_t::N, n, display_key_t::K, k, display_key_t::nnz, nnz, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::algorithm, hipsparse_sddmmalg2string(alg), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } // free. CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(C1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(C2)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(B)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SDDMM_COO_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_sddmm_coo_aos.hpp000066400000000000000000000472751501764003400243370ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SDDMM_COO_AOS_HPP #define TESTING_SDDMM_COO_AOS_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; void testing_sddmm_coo_aos_bad_arg(void) { #if(!defined(CUDART_VERSION)) int32_t n = 100; int32_t m = 100; int32_t k = 100; int64_t nnz = 100; int32_t safe_size = 100; float alpha = 0.6; float beta = 0.2; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOrder_t orderA = HIPSPARSE_ORDER_COL; hipsparseOrder_t orderB = HIPSPARSE_ORDER_COL; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxTypeI = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; hipsparseSDDMMAlg_t alg = HIPSPARSE_SDDMM_ALG_DEFAULT; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto drowcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dA_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int32_t* drowcol = (int32_t*)drowcol_managed.get(); float* dval = (float*)dval_managed.get(); float* dB = (float*)dB_managed.get(); float* dA = (float*)dA_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SDDMM structures hipsparseDnMatDescr_t A, B; hipsparseSpMatDescr_t C; size_t bsize; // Create SDDMM structures verify_hipsparse_status_success(hipsparseCreateDnMat(&A, m, k, m, dA, dataType, orderA), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&B, k, n, k, dB, dataType, orderB), "success"); verify_hipsparse_status_success( hipsparseCreateCooAoS(&C, m, n, nnz, drowcol, dval, idxTypeI, idxBase, dataType), "success"); // SDDMM buffer verify_hipsparse_status_invalid_handle(hipsparseSDDMM_bufferSize( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, &bsize), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, &bsize), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, &bsize), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, &bsize), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, &bsize), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, nullptr), "Error: bsize is nullptr"); // SDDMM verify_hipsparse_status_invalid_handle(hipsparseSDDMM_preprocess( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // SDDMM verify_hipsparse_status_invalid_handle( hipsparseSDDMM(nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroyDnMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(B), "success"); verify_hipsparse_status_success(hipsparseDestroySpMat(C), "success"); #endif } template hipsparseStatus_t testing_sddmm_coo_aos(Arguments argus) { #if(!defined(CUDART_VERSION)) I m = argus.M; I n = argus.N; I k = argus.K; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseOperation_t transB = argus.transB; hipsparseOrder_t orderA = argus.orderA; hipsparseOrder_t orderB = argus.orderB; hipsparseIndexBase_t idx_base = argus.baseC; hipsparseSDDMMAlg_t alg = static_cast(argus.sddmm_alg); std::string filename = argus.filename; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Initial Data on CPU srand(12345ULL); // Read or construct CSR matrix I nnz = 0; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hrowcol_ind(nnz * 2); // Convert to COO_AOS for(I i = 0; i < m; ++i) { for(I j = hcsr_row_ptr[i]; j < hcsr_row_ptr[i + 1]; ++j) { hrowcol_ind[2 * (j - idx_base) + 0] = i + idx_base; hrowcol_ind[2 * (j - idx_base) + 1] = hcsr_col_ind[j - idx_base]; } } // Some matrix properties I A_m = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k; I A_n = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : m; I B_m = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : n; I B_n = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? n : k; I C_m = m; I C_n = n; int ld_multiplier_A = 1; int ld_multiplier_B = 1; int64_t lda = (orderA == HIPSPARSE_ORDER_COL) ? ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_A) * m) : (int64_t(ld_multiplier_A) * k)) : ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_A) * k) : (int64_t(ld_multiplier_A) * m)); int64_t ldb = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * k) : (int64_t(ld_multiplier_B) * n)) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * n) : (int64_t(ld_multiplier_B) * k)); lda = std::max(int64_t(1), lda); ldb = std::max(int64_t(1), ldb); int64_t nrowA = (orderA == HIPSPARSE_ORDER_COL) ? lda : A_m; int64_t ncolA = (orderA == HIPSPARSE_ORDER_COL) ? A_n : lda; int64_t nrowB = (orderB == HIPSPARSE_ORDER_COL) ? ldb : B_m; int64_t ncolB = (orderB == HIPSPARSE_ORDER_COL) ? B_n : ldb; int64_t nnz_A = nrowA * ncolA; int64_t nnz_B = nrowB * ncolB; std::vector hA(A_m * A_n); std::vector hB(B_m * B_n); hipsparseInit(hA, nnz_A, 1); hipsparseInit(hB, nnz_B, 1); // allocate memory on device auto drowcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz * 2), device_free}; auto dval1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dval2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dA_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_A), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_B), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* drowcol = (I*)drowcol_managed.get(); T* dval1 = (T*)dval1_managed.get(); T* dval2 = (T*)dval2_managed.get(); T* dA = (T*)dA_managed.get(); T* dB = (T*)dB_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(drowcol, hrowcol_ind.data(), sizeof(I) * nnz * 2, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval1, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval2, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dA, hA.data(), sizeof(T) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t C1, C2; CHECK_HIPSPARSE_ERROR( hipsparseCreateCooAoS(&C1, C_m, C_n, nnz, drowcol, dval1, typeI, idx_base, typeT)); CHECK_HIPSPARSE_ERROR( hipsparseCreateCooAoS(&C2, C_m, C_n, nnz, drowcol, dval2, typeI, idx_base, typeT)); // Create dense matrices hipsparseDnMatDescr_t A, B; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&A, A_m, A_n, lda, dA, typeT, orderA)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&B, B_m, B_n, ldb, dB, typeT, orderB)); // Query SDDMM buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSDDMM_bufferSize( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSDDMM_preprocess( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSDDMM_preprocess( handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSDDMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSDDMM(handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); // copy output from device to CPU. std::vector hval1(nnz); std::vector hval2(nnz); CHECK_HIP_ERROR(hipMemcpy(hval1.data(), dval1, sizeof(T) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hval2.data(), dval2, sizeof(T) * nnz, hipMemcpyDeviceToHost)); const int64_t incA = (orderA == HIPSPARSE_ORDER_COL) ? ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? lda : 1) : ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? 1 : lda); const int64_t incB = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? 1 : ldb) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? ldb : 1); for(I i = 0; i < nnz; ++i) { const I r = hrowcol_ind[2 * i] - idx_base; const I c = hrowcol_ind[2 * i + 1] - idx_base; const T* Aptr = (orderA == HIPSPARSE_ORDER_COL) ? ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? &hA[r] : &hA[lda * r]) : ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? &hA[lda * r] : &hA[r]); const T* Bptr = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? &hB[ldb * c] : &hB[c]) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? &hB[c] : &hB[ldb * c]); T sum = static_cast(0); for(I j = 0; j < k; ++j) { sum = testing_fma(Aptr[incA * j], Bptr[incB * j], sum); } hcsr_val[i] = testing_mult(hcsr_val[i], h_beta) + testing_mult(h_alpha, sum); } unit_check_near(1, nnz, 1, hval1.data(), hcsr_val.data()); unit_check_near(1, nnz, 1, hval2.data(), hcsr_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSDDMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSDDMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = sddmm_gflop_count(k, nnz, h_beta != make_DataType(0)); double gbyte_count = sddmm_coo_aos_gbyte_count(m, n, k, nnz, h_beta != make_DataType(0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::format, hipsparse_format2string(HIPSPARSE_FORMAT_COO_AOS), display_key_t::transA, hipsparse_operation2string(transA), display_key_t::transB, hipsparse_operation2string(transB), display_key_t::M, m, display_key_t::N, n, display_key_t::K, k, display_key_t::nnz, nnz, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::algorithm, hipsparse_sddmmalg2string(alg), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } // free. CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(C1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(C2)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(B)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SDDMM_COO_AOS_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_sddmm_csc.hpp000066400000000000000000000500261501764003400234510ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SDDMM_CSC_HPP #define TESTING_SDDMM_CSC_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; void testing_sddmm_csc_bad_arg(void) { #if(!defined(CUDART_VERSION)) int32_t n = 100; int32_t m = 100; int32_t k = 100; int64_t nnz = 100; int32_t safe_size = 100; float alpha = 0.6; float beta = 0.2; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOrder_t orderA = HIPSPARSE_ORDER_COL; hipsparseOrder_t orderB = HIPSPARSE_ORDER_COL; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxTypeI = HIPSPARSE_INDEX_64I; hipsparseIndexType_t idxTypeJ = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; hipsparseSDDMMAlg_t alg = HIPSPARSE_SDDMM_ALG_DEFAULT; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int64_t) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dA_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int64_t* dptr = (int64_t*)dptr_managed.get(); int32_t* dcol = (int32_t*)dcol_managed.get(); float* dval = (float*)dval_managed.get(); float* dB = (float*)dB_managed.get(); float* dA = (float*)dA_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SDDMM structures hipsparseDnMatDescr_t A, B; hipsparseSpMatDescr_t C; size_t bsize; // Create SDDMM structures verify_hipsparse_status_success(hipsparseCreateDnMat(&A, m, k, m, dA, dataType, orderA), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&B, k, n, k, dB, dataType, orderB), "success"); verify_hipsparse_status_success( hipsparseCreateCsc(&C, m, n, nnz, dptr, dcol, dval, idxTypeI, idxTypeJ, idxBase, dataType), "success"); // SDDMM buffer verify_hipsparse_status_invalid_handle(hipsparseSDDMM_bufferSize( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, &bsize), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, &bsize), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, &bsize), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, &bsize), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, &bsize), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, nullptr), "Error: bsize is nullptr"); // SDDMM verify_hipsparse_status_invalid_handle(hipsparseSDDMM_preprocess( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // SDDMM verify_hipsparse_status_invalid_handle( hipsparseSDDMM(nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroyDnMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(B), "success"); verify_hipsparse_status_success(hipsparseDestroySpMat(C), "success"); #endif } template hipsparseStatus_t testing_sddmm_csc(Arguments argus) { // only csr format supported when using cusparse backend #if(!defined(CUDART_VERSION)) J m = argus.M; J n = argus.N; J k = argus.K; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseOperation_t transB = argus.transB; hipsparseOrder_t orderA = argus.orderA; hipsparseOrder_t orderB = argus.orderB; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseSDDMMAlg_t alg = static_cast(argus.sddmm_alg); std::string filename = argus.filename; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipsparseIndexType_t typeJ = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hcsc_col_ptr; std::vector hcsc_row_ind; std::vector hcsc_val; // Initial Data on CPU srand(12345ULL); // Read or construct CSR matrix I nnz = 0; if(!generate_csr_matrix(filename, n, m, nnz, hcsc_col_ptr, hcsc_row_ind, hcsc_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Some matrix properties J A_m = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k; J A_n = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : m; J B_m = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : n; J B_n = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? n : k; J C_m = m; J C_n = n; int ld_multiplier_A = 1; int ld_multiplier_B = 1; int64_t lda = (orderA == HIPSPARSE_ORDER_COL) ? ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_A) * m) : (int64_t(ld_multiplier_A) * k)) : ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_A) * k) : (int64_t(ld_multiplier_A) * m)); int64_t ldb = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * k) : (int64_t(ld_multiplier_B) * n)) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * n) : (int64_t(ld_multiplier_B) * k)); lda = std::max(int64_t(1), lda); ldb = std::max(int64_t(1), ldb); int64_t nrowA = (orderA == HIPSPARSE_ORDER_COL) ? lda : A_m; int64_t ncolA = (orderA == HIPSPARSE_ORDER_COL) ? A_n : lda; int64_t nrowB = (orderB == HIPSPARSE_ORDER_COL) ? ldb : B_m; int64_t ncolB = (orderB == HIPSPARSE_ORDER_COL) ? B_n : ldb; int64_t nnz_A = nrowA * ncolA; int64_t nnz_B = nrowB * ncolB; std::vector hA(nnz_A); std::vector hB(nnz_B); hipsparseInit(hA, nnz_A, 1); hipsparseInit(hB, nnz_B, 1); // allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (C_n + 1)), device_free}; auto dind_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz), device_free}; auto dval1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dval2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dA_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_A), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_B), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* dptr = (I*)dptr_managed.get(); J* dind = (J*)dind_managed.get(); T* dval1 = (T*)dval1_managed.get(); T* dval2 = (T*)dval2_managed.get(); T* dA = (T*)dA_managed.get(); T* dB = (T*)dB_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsc_col_ptr.data(), sizeof(I) * (C_n + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dind, hcsc_row_ind.data(), sizeof(J) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval1, hcsc_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval2, hcsc_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dA, hA.data(), sizeof(T) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t C1, C2; CHECK_HIPSPARSE_ERROR( hipsparseCreateCsc(&C1, C_m, C_n, nnz, dptr, dind, dval1, typeI, typeJ, idx_base, typeT)); CHECK_HIPSPARSE_ERROR( hipsparseCreateCsc(&C2, C_m, C_n, nnz, dptr, dind, dval2, typeI, typeJ, idx_base, typeT)); // Create dense matrices hipsparseDnMatDescr_t A, B; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&A, A_m, A_n, lda, dA, typeT, orderA)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&B, B_m, B_n, ldb, dB, typeT, orderB)); // Query SDDMM buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSDDMM_bufferSize( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSDDMM_preprocess( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSDDMM_preprocess( handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSDDMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSDDMM(handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); // copy output from device to CPU. std::vector hval1(nnz); std::vector hval2(nnz); CHECK_HIP_ERROR(hipMemcpy(hval1.data(), dval1, sizeof(T) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hval2.data(), dval2, sizeof(T) * nnz, hipMemcpyDeviceToHost)); const int64_t incA = (orderA == HIPSPARSE_ORDER_COL) ? ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? lda : 1) : ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? 1 : lda); const int64_t incB = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? 1 : ldb) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? ldb : 1); for(J c = 0; c < C_n; c++) { I start = hcsc_col_ptr[c] - idx_base; I end = hcsc_col_ptr[c + 1] - idx_base; for(I j = start; j < end; j++) { J r = hcsc_row_ind[j] - idx_base; const T* Aptr = (orderA == HIPSPARSE_ORDER_COL) ? ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? &hA[r] : &hA[lda * r]) : ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? &hA[lda * r] : &hA[r]); const T* Bptr = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? &hB[ldb * c] : &hB[c]) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? &hB[c] : &hB[ldb * c]); T sum = static_cast(0); for(I s = 0; s < k; ++s) { sum = testing_fma(Aptr[incA * s], Bptr[incB * s], sum); } hcsc_val[j] = testing_mult(hcsc_val[j], h_beta) + testing_mult(h_alpha, sum); } } unit_check_near(1, nnz, 1, hval1.data(), hcsc_val.data()); unit_check_near(1, nnz, 1, hval2.data(), hcsc_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSDDMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSDDMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = sddmm_gflop_count(k, nnz, h_beta != make_DataType(0)); double gbyte_count = sddmm_csc_gbyte_count(m, n, k, nnz, h_beta != make_DataType(0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::format, hipsparse_format2string(HIPSPARSE_FORMAT_CSC), display_key_t::transA, hipsparse_operation2string(transA), display_key_t::transB, hipsparse_operation2string(transB), display_key_t::M, m, display_key_t::N, n, display_key_t::K, k, display_key_t::nnz, nnz, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::algorithm, hipsparse_sddmmalg2string(alg), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } // free. CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(C1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(C2)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(B)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SDDMM_CSC_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_sddmm_csr.hpp000066400000000000000000000477351501764003400235050ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SDDMM_CSR_HPP #define TESTING_SDDMM_CSR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; void testing_sddmm_csr_bad_arg(void) { #if(!defined(CUDART_VERSION)) int32_t n = 100; int32_t m = 100; int32_t k = 100; int64_t nnz = 100; int32_t safe_size = 100; float alpha = 0.6; float beta = 0.2; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOrder_t orderA = HIPSPARSE_ORDER_COL; hipsparseOrder_t orderB = HIPSPARSE_ORDER_COL; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxTypeI = HIPSPARSE_INDEX_64I; hipsparseIndexType_t idxTypeJ = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; hipsparseSDDMMAlg_t alg = HIPSPARSE_SDDMM_ALG_DEFAULT; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int64_t) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dA_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int64_t* dptr = (int64_t*)dptr_managed.get(); int32_t* dcol = (int32_t*)dcol_managed.get(); float* dval = (float*)dval_managed.get(); float* dB = (float*)dB_managed.get(); float* dA = (float*)dA_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SDDMM structures hipsparseDnMatDescr_t A, B; hipsparseSpMatDescr_t C; size_t bsize; // Create SDDMM structures verify_hipsparse_status_success(hipsparseCreateDnMat(&A, m, k, m, dA, dataType, orderA), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&B, k, n, k, dB, dataType, orderB), "success"); verify_hipsparse_status_success( hipsparseCreateCsr(&C, m, n, nnz, dptr, dcol, dval, idxTypeI, idxTypeJ, idxBase, dataType), "success"); // SDDMM buffer verify_hipsparse_status_invalid_handle(hipsparseSDDMM_bufferSize( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, &bsize), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, &bsize), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, &bsize), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, &bsize), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, &bsize), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, nullptr), "Error: bsize is nullptr"); // SDDMM verify_hipsparse_status_invalid_handle(hipsparseSDDMM_preprocess( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // SDDMM verify_hipsparse_status_invalid_handle( hipsparseSDDMM(nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroyDnMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(B), "success"); verify_hipsparse_status_success(hipsparseDestroySpMat(C), "success"); #endif } template hipsparseStatus_t testing_sddmm_csr(Arguments argus) { #if(!defined(CUDART_VERSION)) J m = argus.M; J n = argus.N; J k = argus.K; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseOperation_t transB = argus.transB; hipsparseOrder_t orderA = argus.orderA; hipsparseOrder_t orderB = argus.orderB; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseSDDMMAlg_t alg = static_cast(argus.sddmm_alg); std::string filename = argus.filename; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipsparseIndexType_t typeJ = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Initial Data on CPU srand(12345ULL); // Read or construct CSR matrix I nnz = 0; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Some matrix properties J A_m = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k; J A_n = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : m; J B_m = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : n; J B_n = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? n : k; J C_m = m; J C_n = n; int ld_multiplier_A = 1; int ld_multiplier_B = 1; int64_t lda = (orderA == HIPSPARSE_ORDER_COL) ? ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_A) * m) : (int64_t(ld_multiplier_A) * k)) : ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_A) * k) : (int64_t(ld_multiplier_A) * m)); int64_t ldb = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * k) : (int64_t(ld_multiplier_B) * n)) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * n) : (int64_t(ld_multiplier_B) * k)); lda = std::max(int64_t(1), lda); ldb = std::max(int64_t(1), ldb); int64_t nrowA = (orderA == HIPSPARSE_ORDER_COL) ? lda : A_m; int64_t ncolA = (orderA == HIPSPARSE_ORDER_COL) ? A_n : lda; int64_t nrowB = (orderB == HIPSPARSE_ORDER_COL) ? ldb : B_m; int64_t ncolB = (orderB == HIPSPARSE_ORDER_COL) ? B_n : ldb; int64_t nnz_A = nrowA * ncolA; int64_t nnz_B = nrowB * ncolB; std::vector hA(nnz_A); std::vector hB(nnz_B); hipsparseInit(hA, nnz_A, 1); hipsparseInit(hB, nnz_B, 1); // allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (C_m + 1)), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz), device_free}; auto dval1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dval2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dA_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_A), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_B), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* dptr = (I*)dptr_managed.get(); J* dcol = (J*)dcol_managed.get(); T* dval1 = (T*)dval1_managed.get(); T* dval2 = (T*)dval2_managed.get(); T* dA = (T*)dA_managed.get(); T* dB = (T*)dB_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsr_row_ptr.data(), sizeof(I) * (C_m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcsr_col_ind.data(), sizeof(J) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval1, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval2, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dA, hA.data(), sizeof(T) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t C1, C2; CHECK_HIPSPARSE_ERROR( hipsparseCreateCsr(&C1, C_m, C_n, nnz, dptr, dcol, dval1, typeI, typeJ, idx_base, typeT)); CHECK_HIPSPARSE_ERROR( hipsparseCreateCsr(&C2, C_m, C_n, nnz, dptr, dcol, dval2, typeI, typeJ, idx_base, typeT)); // Create dense matrices hipsparseDnMatDescr_t A, B; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&A, A_m, A_n, lda, dA, typeT, orderA)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&B, B_m, B_n, ldb, dB, typeT, orderB)); // Query SDDMM buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSDDMM_bufferSize( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSDDMM_preprocess( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSDDMM_preprocess( handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSDDMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSDDMM(handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); // copy output from device to CPU. std::vector hval1(nnz); std::vector hval2(nnz); CHECK_HIP_ERROR(hipMemcpy(hval1.data(), dval1, sizeof(T) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hval2.data(), dval2, sizeof(T) * nnz, hipMemcpyDeviceToHost)); const int64_t incA = (orderA == HIPSPARSE_ORDER_COL) ? ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? lda : 1) : ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? 1 : lda); const int64_t incB = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? 1 : ldb) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? ldb : 1); for(J r = 0; r < C_m; r++) { I start = hcsr_row_ptr[r] - idx_base; I end = hcsr_row_ptr[r + 1] - idx_base; for(I j = start; j < end; j++) { J c = hcsr_col_ind[j] - idx_base; const T* Aptr = (orderA == HIPSPARSE_ORDER_COL) ? ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? &hA[r] : &hA[lda * r]) : ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? &hA[lda * r] : &hA[r]); const T* Bptr = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? &hB[ldb * c] : &hB[c]) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? &hB[c] : &hB[ldb * c]); T sum = static_cast(0); for(I s = 0; s < k; ++s) { sum = testing_fma(Aptr[incA * s], Bptr[incB * s], sum); } hcsr_val[j] = testing_mult(hcsr_val[j], h_beta) + testing_mult(h_alpha, sum); } } unit_check_near(1, nnz, 1, hval1.data(), hcsr_val.data()); unit_check_near(1, nnz, 1, hval2.data(), hcsr_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSDDMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSDDMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = sddmm_gflop_count(k, nnz, h_beta != make_DataType(0)); double gbyte_count = sddmm_csr_gbyte_count(m, n, k, nnz, h_beta != make_DataType(0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::format, hipsparse_format2string(HIPSPARSE_FORMAT_CSR), display_key_t::transA, hipsparse_operation2string(transA), display_key_t::transB, hipsparse_operation2string(transB), display_key_t::M, m, display_key_t::N, n, display_key_t::K, k, display_key_t::nnz, nnz, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::algorithm, hipsparse_sddmmalg2string(alg), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } // free. CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(C1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(C2)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(B)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SDDMM_CSR_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_sparse_to_dense_coo.hpp000066400000000000000000000265241501764003400255400ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPARSE_TO_DENSE_COO_HPP #define TESTING_SPARSE_TO_DENSE_COO_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse_test; void testing_sparse_to_dense_coo_bad_arg(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) int64_t safe_size = 100; int32_t m = 10; int32_t n = 10; int64_t nnz = 10; int64_t ld = m; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseSparseToDenseAlg_t alg = HIPSPARSE_SPARSETODENSE_ALG_DEFAULT; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; // Index and data type hipsparseIndexType_t iType = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; // Create handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto ddense_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dcoo_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dcoo_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dcoo_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; float* ddense_val = (float*)ddense_val_managed.get(); int32_t* dcoo_row_ind = (int32_t*)dcoo_row_ind_managed.get(); int32_t* dcoo_col_ind = (int32_t*)dcoo_col_ind_managed.get(); float* dcoo_val = (float*)dcoo_val_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // Matrix structures hipsparseSpMatDescr_t matA; hipsparseDnVecDescr_t matB; size_t bsize; // Create matrix structures verify_hipsparse_status_success( hipsparseCreateCoo( &matA, m, n, nnz, dcoo_row_ind, dcoo_col_ind, dcoo_val, iType, idxBase, dataType), "success"); verify_hipsparse_status_success( hipsparseCreateDnMat(&matB, m, n, ld, ddense_val, dataType, order), "success"); // SparseToDense buffer size verify_hipsparse_status_invalid_handle( hipsparseSparseToDense_bufferSize(nullptr, matA, matB, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSparseToDense_bufferSize(handle, nullptr, matB, alg, &bsize), "Error: matA is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSparseToDense_bufferSize(handle, matA, nullptr, alg, &bsize), "Error: matB is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSparseToDense_bufferSize(handle, matA, matB, alg, nullptr), "Error: bsize is nullptr"); // SparseToDense verify_hipsparse_status_invalid_handle(hipsparseSparseToDense(nullptr, matA, matB, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSparseToDense(handle, nullptr, matB, alg, dbuf), "Error: matA is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSparseToDense(handle, matA, nullptr, alg, dbuf), "Error: matB is nullptr"); // cuda returns success here #if(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_pointer( hipsparseSparseToDense(handle, matA, matB, alg, nullptr), "Error: dbuf is nullptr"); #endif // Destruct verify_hipsparse_status_success(hipsparseDestroySpMat(matA), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(matB), "success"); #endif } template hipsparseStatus_t testing_sparse_to_dense_coo(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) I m = argus.M; I n = argus.N; hipsparseOrder_t order = argus.orderA; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseSparseToDenseAlg_t alg = static_cast(argus.sparse2dense_alg); std::string filename = argus.filename; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Initial Data on CPU srand(12345ULL); I nnz; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } I ld = (order == HIPSPARSE_ORDER_COL) ? m : n; I nrows = (order == HIPSPARSE_ORDER_COL) ? ld : m; I ncols = (order == HIPSPARSE_ORDER_COL) ? n : ld; // Fill host COO arrays std::vector hcoo_row_ind(nnz); std::vector hcoo_col_ind = hcsr_col_ind; std::vector hcoo_val = hcsr_val; for(I i = 0; i < m; i++) { I start = hcsr_row_ptr[i] - idx_base; I end = hcsr_row_ptr[i + 1] - idx_base; for(I j = start; j < end; j++) { hcoo_row_ind[j] = i + idx_base; } } // allocate memory on device auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto ddense_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nrows * ncols), device_free}; I* drow = (I*)drow_managed.get(); I* dcol = (I*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* ddense = (T*)ddense_managed.get(); // Dense matrix std::vector hdense(nrows * ncols); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(drow, hcoo_row_ind.data(), sizeof(I) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcoo_col_ind.data(), sizeof(I) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hcoo_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t matA; CHECK_HIPSPARSE_ERROR( hipsparseCreateCoo(&matA, m, n, nnz, drow, dcol, dval, typeI, idx_base, typeT)); // Create dense matrix hipsparseDnMatDescr_t matB; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&matB, m, n, ld, ddense, typeT, order)); // Query SparseToDense buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSparseToDense_bufferSize(handle, matA, matB, alg, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSparseToDense(handle, matA, matB, alg, buffer)); // copy output from device to CPU CHECK_HIP_ERROR( hipMemcpy(hdense.data(), ddense, sizeof(T) * nrows * ncols, hipMemcpyDeviceToHost)); std::vector hdense_cpu(nrows * ncols); if(order == HIPSPARSE_ORDER_COL) { for(I col = 0; col < n; ++col) { for(I row = 0; row < m; ++row) { hdense_cpu[row + ld * col] = make_DataType(0.0); } } for(I i = 0; i < nnz; i++) { I row = hcoo_row_ind[i] - idx_base; I col = hcoo_col_ind[i] - idx_base; hdense_cpu[ld * col + row] = hcoo_val[i]; } } else { for(I row = 0; row < m; ++row) { for(I col = 0; col < n; ++col) { hdense_cpu[ld * row + col] = make_DataType(0.0); } } for(I i = 0; i < nnz; i++) { I row = hcoo_row_ind[i] - idx_base; I col = hcoo_col_ind[i] - idx_base; hdense_cpu[col + ld * row] = hcoo_val[i]; } } unit_check_general(1, nrows * ncols, 1, hdense_cpu.data(), hdense.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm-up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSparseToDense(handle, matA, matB, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSparseToDense(handle, matA, matB, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = coo2dense_gbyte_count(m, n, (I)nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::order, order, display_key_t::algorithm, hipsparse_sparsetodensealg2string(alg), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matA)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(matB)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPARSE_TO_DENSE_COO_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_sparse_to_dense_csc.hpp000066400000000000000000000314421501764003400255230ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPARSE_TO_DENSE_CSC_HPP #define TESTING_SPARSE_TO_DENSE_CSC_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse_test; void testing_sparse_to_dense_csc_bad_arg(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) int64_t safe_size = 100; int32_t m = 10; int32_t n = 10; int64_t nnz = 10; int64_t ld = m; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseSparseToDenseAlg_t alg = HIPSPARSE_SPARSETODENSE_ALG_DEFAULT; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; // Index and data type hipsparseIndexType_t iType = HIPSPARSE_INDEX_32I; hipsparseIndexType_t jType = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; // Create handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto ddense_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dcsc_col_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dcsc_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dcsc_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; float* ddense_val = (float*)ddense_val_managed.get(); int32_t* dcsc_col_ptr = (int32_t*)dcsc_col_ptr_managed.get(); int32_t* dcsc_row_ind = (int32_t*)dcsc_row_ind_managed.get(); float* dcsc_val = (float*)dcsc_val_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // Matrix structures hipsparseSpMatDescr_t matA; hipsparseDnVecDescr_t matB; size_t bsize; // Create matrix structures verify_hipsparse_status_success(hipsparseCreateCsr(&matA, m, n, nnz, dcsc_col_ptr, dcsc_row_ind, dcsc_val, iType, jType, idxBase, dataType), "success"); verify_hipsparse_status_success( hipsparseCreateDnMat(&matB, m, n, ld, ddense_val, dataType, order), "success"); // SparseToDense buffer size verify_hipsparse_status_invalid_handle( hipsparseSparseToDense_bufferSize(nullptr, matA, matB, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSparseToDense_bufferSize(handle, nullptr, matB, alg, &bsize), "Error: matA is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSparseToDense_bufferSize(handle, matA, nullptr, alg, &bsize), "Error: matB is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSparseToDense_bufferSize(handle, matA, matB, alg, nullptr), "Error: bsize is nullptr"); // SparseToDense verify_hipsparse_status_invalid_handle(hipsparseSparseToDense(nullptr, matA, matB, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSparseToDense(handle, nullptr, matB, alg, dbuf), "Error: matA is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSparseToDense(handle, matA, nullptr, alg, dbuf), "Error: matB is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSparseToDense(handle, matA, matB, alg, nullptr), "Error: dbuf is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpMat(matA), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(matB), "success"); #endif } template hipsparseStatus_t testing_sparse_to_dense_csc(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) J m = argus.M; J n = argus.N; hipsparseOrder_t order = argus.orderA; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseSparseToDenseAlg_t alg = static_cast(argus.sparse2dense_alg); std::string filename = argus.filename; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipsparseIndexType_t typeJ = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures for CSR matrix std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Initial Data on CPU srand(12345ULL); I nnz; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } I ld = (order == HIPSPARSE_ORDER_COL) ? m : n; I nrows = (order == HIPSPARSE_ORDER_COL) ? ld : m; I ncols = (order == HIPSPARSE_ORDER_COL) ? n : ld; // Convert CSR matrix to CSC std::vector hcsc_col_ptr(n + 1); std::vector hcsc_row_ind(nnz); std::vector hcsc_val(nnz); // Determine nnz per column for(I i = 0; i < nnz; ++i) { ++hcsc_col_ptr[hcsr_col_ind[i] + 1 - idx_base]; } // Scan for(J i = 0; i < n; ++i) { hcsc_col_ptr[i + 1] += hcsc_col_ptr[i]; } // Fill row indices and values for(J i = 0; i < m; ++i) { for(I j = hcsr_row_ptr[i]; j < hcsr_row_ptr[i + 1]; ++j) { J col = hcsr_col_ind[j - idx_base] - idx_base; I idx = hcsc_col_ptr[col]; hcsc_row_ind[idx] = i + idx_base; hcsc_val[idx] = hcsr_val[j - idx_base]; ++hcsc_col_ptr[col]; } } // Shift column pointer array for(J i = n; i > 0; --i) { hcsc_col_ptr[i] = hcsc_col_ptr[i - 1] + idx_base; } hcsc_col_ptr[0] = idx_base; // allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (n + 1)), device_free}; auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto ddense_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nrows * ncols), device_free}; I* dptr = (I*)dptr_managed.get(); J* drow = (J*)drow_managed.get(); T* dval = (T*)dval_managed.get(); T* ddense = (T*)ddense_managed.get(); // Dense matrix std::vector hdense(nrows * ncols); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsc_col_ptr.data(), sizeof(I) * (n + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(drow, hcsc_row_ind.data(), sizeof(J) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hcsc_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t matA; CHECK_HIPSPARSE_ERROR( hipsparseCreateCsc(&matA, m, n, nnz, dptr, drow, dval, typeI, typeJ, idx_base, typeT)); // Create dense matrix hipsparseDnMatDescr_t matB; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&matB, m, n, ld, ddense, typeT, order)); // Query SparseToDense buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSparseToDense_bufferSize(handle, matA, matB, alg, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSparseToDense(handle, matA, matB, alg, buffer)); // copy output from device to CPU CHECK_HIP_ERROR( hipMemcpy(hdense.data(), ddense, sizeof(T) * nrows * ncols, hipMemcpyDeviceToHost)); std::vector hdense_cpu(nrows * ncols); if(order == HIPSPARSE_ORDER_COL) { for(J col = 0; col < n; ++col) { for(J row = 0; row < m; ++row) { hdense_cpu[row + ld * col] = make_DataType(0.0); } } for(J col = 0; col < n; ++col) { I start = hcsc_col_ptr[col] - idx_base; I end = hcsc_col_ptr[col + 1] - idx_base; for(I at = start; at < end; ++at) { hdense_cpu[(hcsc_row_ind[at] - idx_base) + ld * col] = hcsc_val[at]; } } } else { for(I row = 0; row < m; ++row) { for(I col = 0; col < n; ++col) { hdense_cpu[ld * row + col] = make_DataType(0.0); } } for(J col = 0; col < n; ++col) { I start = hcsc_col_ptr[col] - idx_base; I end = hcsc_col_ptr[col + 1] - idx_base; for(I at = start; at < end; ++at) { hdense_cpu[ld * (hcsc_row_ind[at] - idx_base) + col] = hcsc_val[at]; } } } unit_check_general(1, nrows * ncols, 1, hdense_cpu.data(), hdense.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm-up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSparseToDense(handle, matA, matB, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSparseToDense(handle, matA, matB, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = csx2dense_gbyte_count(m, n, nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::order, order, display_key_t::algorithm, hipsparse_sparsetodensealg2string(alg), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matA)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(matB)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPARSE_TO_DENSE_CSC_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_sparse_to_dense_csr.hpp000066400000000000000000000276501501764003400255500ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPARSE_TO_DENSE_CSR_HPP #define TESTING_SPARSE_TO_DENSE_CSR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse_test; void testing_sparse_to_dense_csr_bad_arg(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) int64_t safe_size = 100; int32_t m = 10; int32_t n = 10; int64_t nnz = 10; int64_t ld = m; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseSparseToDenseAlg_t alg = HIPSPARSE_SPARSETODENSE_ALG_DEFAULT; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; // Index and data type hipsparseIndexType_t iType = HIPSPARSE_INDEX_32I; hipsparseIndexType_t jType = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; // Create handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto ddense_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; float* ddense_val = (float*)ddense_val_managed.get(); int32_t* dcsr_row_ptr = (int32_t*)dcsr_row_ptr_managed.get(); int32_t* dcsr_col_ind = (int32_t*)dcsr_col_ind_managed.get(); float* dcsr_val = (float*)dcsr_val_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // Matrix structures hipsparseSpMatDescr_t matA; hipsparseDnVecDescr_t matB; size_t bsize; // Create matrix structures verify_hipsparse_status_success(hipsparseCreateCsr(&matA, m, n, nnz, dcsr_row_ptr, dcsr_col_ind, dcsr_val, iType, jType, idxBase, dataType), "success"); verify_hipsparse_status_success( hipsparseCreateDnMat(&matB, m, n, ld, ddense_val, dataType, order), "success"); // SparseToDense buffer size verify_hipsparse_status_invalid_handle( hipsparseSparseToDense_bufferSize(nullptr, matA, matB, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSparseToDense_bufferSize(handle, nullptr, matB, alg, &bsize), "Error: matA is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSparseToDense_bufferSize(handle, matA, nullptr, alg, &bsize), "Error: matB is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSparseToDense_bufferSize(handle, matA, matB, alg, nullptr), "Error: bsize is nullptr"); // SparseToDense verify_hipsparse_status_invalid_handle(hipsparseSparseToDense(nullptr, matA, matB, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSparseToDense(handle, nullptr, matB, alg, dbuf), "Error: matA is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSparseToDense(handle, matA, nullptr, alg, dbuf), "Error: matB is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSparseToDense(handle, matA, matB, alg, nullptr), "Error: dbuf is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpMat(matA), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(matB), "success"); #endif } template hipsparseStatus_t testing_sparse_to_dense_csr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) J m = argus.M; J n = argus.N; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseSparseToDenseAlg_t alg = static_cast(argus.sparse2dense_alg); hipsparseOrder_t order = argus.orderA; std::string filename = argus.filename; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipsparseIndexType_t typeJ = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Initial Data on CPU srand(12345ULL); I nnz; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } I ld = (order == HIPSPARSE_ORDER_COL) ? m : n; I nrows = (order == HIPSPARSE_ORDER_COL) ? ld : m; I ncols = (order == HIPSPARSE_ORDER_COL) ? n : ld; // allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (m + 1)), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto ddense_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nrows * ncols), device_free}; I* dptr = (I*)dptr_managed.get(); J* dcol = (J*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* ddense = (T*)ddense_managed.get(); // Dense matrix std::vector hdense(nrows * ncols); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsr_row_ptr.data(), sizeof(I) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcsr_col_ind.data(), sizeof(J) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t matA; CHECK_HIPSPARSE_ERROR( hipsparseCreateCsr(&matA, m, n, nnz, dptr, dcol, dval, typeI, typeJ, idx_base, typeT)); // Create dense matrix hipsparseDnMatDescr_t matB; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&matB, m, n, ld, ddense, typeT, order)); // Query SparseToDense buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSparseToDense_bufferSize(handle, matA, matB, alg, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSparseToDense(handle, matA, matB, alg, buffer)); // copy output from device to CPU CHECK_HIP_ERROR( hipMemcpy(hdense.data(), ddense, sizeof(T) * nrows * ncols, hipMemcpyDeviceToHost)); std::vector hdense_cpu(nrows * ncols); if(order == HIPSPARSE_ORDER_COL) { for(I col = 0; col < n; ++col) { for(I row = 0; row < m; ++row) { hdense_cpu[row + ld * col] = make_DataType(0.0); } } for(J row = 0; row < m; ++row) { I start = hcsr_row_ptr[row] - idx_base; I end = hcsr_row_ptr[row + 1] - idx_base; for(I at = start; at < end; ++at) { hdense_cpu[ld * (hcsr_col_ind[at] - idx_base) + row] = hcsr_val[at]; } } unit_check_general(m, n, ld, hdense_cpu.data(), hdense.data()); } else { for(I row = 0; row < m; ++row) { for(I col = 0; col < n; ++col) { hdense_cpu[ld * row + col] = make_DataType(0.0); } } for(J row = 0; row < m; ++row) { I start = hcsr_row_ptr[row] - idx_base; I end = hcsr_row_ptr[row + 1] - idx_base; for(I at = start; at < end; ++at) { hdense_cpu[(hcsr_col_ind[at] - idx_base) + ld * row] = hcsr_val[at]; } } } unit_check_general(1, nrows * ncols, 1, hdense_cpu.data(), hdense.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm-up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSparseToDense(handle, matA, matB, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSparseToDense(handle, matA, matB, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = csx2dense_gbyte_count(m, n, nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::order, order, display_key_t::algorithm, hipsparse_sparsetodensealg2string(alg), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matA)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(matB)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPARSE_TO_DENSE_CSR_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_spgemm_csr.hpp000066400000000000000000001175461501764003400236670ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPGEMM_CSR_HPP #define TESTING_SPGEMM_CSR_HPP #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse_test; void testing_spgemm_csr_bad_arg(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) int64_t m = 100; int64_t n = 100; int64_t k = 100; int64_t nnz_A = 100; int64_t nnz_B = 100; int64_t nnz_C = 100; int64_t safe_size = 100; float alpha = 0.6; float beta = 0.2; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseIndexBase_t idxBaseA = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexBase_t idxBaseB = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexBase_t idxBaseC = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; hipsparseSpGEMMAlg_t alg = HIPSPARSE_SPGEMM_DEFAULT; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new spgemm_struct); hipsparseSpGEMMDescr_t descr = unique_ptr_descr->descr; auto dcsr_row_ptr_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcsr_col_ind_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcsr_val_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dcsr_row_ptr_B_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcsr_col_ind_B_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcsr_val_B_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dcsr_row_ptr_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcsr_col_ind_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcsr_val_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* dcsr_row_ptr_A = (int*)dcsr_row_ptr_A_managed.get(); int* dcsr_col_ind_A = (int*)dcsr_col_ind_A_managed.get(); float* dcsr_val_A = (float*)dcsr_val_A_managed.get(); int* dcsr_row_ptr_B = (int*)dcsr_row_ptr_B_managed.get(); int* dcsr_col_ind_B = (int*)dcsr_col_ind_B_managed.get(); float* dcsr_val_B = (float*)dcsr_val_B_managed.get(); int* dcsr_row_ptr_C = (int*)dcsr_row_ptr_C_managed.get(); int* dcsr_col_ind_C = (int*)dcsr_col_ind_C_managed.get(); float* dcsr_val_C = (float*)dcsr_val_C_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SpGEMM structures hipsparseSpMatDescr_t A, B, C; size_t bufferSize; // Create SpGEMM structures verify_hipsparse_status_success(hipsparseCreateCsr(&A, m, k, nnz_A, dcsr_row_ptr_A, dcsr_col_ind_A, dcsr_val_A, idxType, idxType, idxBaseA, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateCsr(&B, k, n, nnz_B, dcsr_row_ptr_B, dcsr_col_ind_B, dcsr_val_B, idxType, idxType, idxBaseB, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateCsr(&C, m, n, nnz_C, dcsr_row_ptr_C, dcsr_col_ind_C, dcsr_val_C, idxType, idxType, idxBaseC, dataType), "success"); // SpGEMM work estimation verify_hipsparse_status_invalid_handle(hipsparseSpGEMM_workEstimation(nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, descr, &bufferSize, nullptr)); verify_hipsparse_status_invalid_pointer(hipsparseSpGEMM_workEstimation(handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, descr, &bufferSize, nullptr), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpGEMM_workEstimation(handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, descr, &bufferSize, nullptr), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpGEMM_workEstimation(handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, descr, &bufferSize, nullptr), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpGEMM_workEstimation(handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, descr, &bufferSize, nullptr), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpGEMM_workEstimation(handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, descr, &bufferSize, nullptr), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMM_workEstimation( handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, descr, nullptr, nullptr), "Error: bufferSize is nullptr"); // SpGEMM compute verify_hipsparse_status_invalid_handle(hipsparseSpGEMM_compute( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, descr, &bufferSize, dbuf)); verify_hipsparse_status_invalid_pointer(hipsparseSpGEMM_compute(handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, descr, &bufferSize, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpGEMM_compute(handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, descr, &bufferSize, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpGEMM_compute(handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, descr, &bufferSize, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpGEMM_compute(handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, descr, &bufferSize, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpGEMM_compute(handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, descr, &bufferSize, dbuf), "Error: C is nullptr"); // SpGEMM copy verify_hipsparse_status_invalid_handle(hipsparseSpGEMM_copy( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, descr)); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMM_copy(handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, descr), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMM_copy( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, descr), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMM_copy( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, descr), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMM_copy( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, descr), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMM_copy( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, descr), "Error: C is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroySpMat(B), "success"); verify_hipsparse_status_success(hipsparseDestroySpMat(C), "success"); #endif } template hipsparseStatus_t testing_spgemm_csr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) J m = argus.M; J k = argus.K; T h_alpha = make_DataType(argus.alpha); hipsparseIndexBase_t idxBaseA = argus.baseA; hipsparseIndexBase_t idxBaseB = argus.baseB; hipsparseIndexBase_t idxBaseC = argus.baseC; hipsparseSpGEMMAlg_t alg = static_cast(argus.spgemm_alg); std::string filename = argus.filename; T h_beta = make_DataType(0); hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipsparseIndexType_t typeJ = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handles std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new spgemm_struct); hipsparseSpGEMMDescr_t descr = unique_ptr_descr->descr; // Host structures std::vector hcsr_row_ptr_A; std::vector hcsr_col_ind_A; std::vector hcsr_val_A; // Initial Data on CPU srand(12345ULL); I nnz_A; if(!generate_csr_matrix( filename, m, k, nnz_A, hcsr_row_ptr_A, hcsr_col_ind_A, hcsr_val_A, idxBaseA)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // For sparse matrix B, use the transpose of A J n = m; I nnz_B = nnz_A; std::vector hcsr_row_ptr_B(k + 1); std::vector hcsr_col_ind_B(nnz_B); std::vector hcsr_val_B(nnz_B); transpose_csr(m, k, nnz_A, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), hcsr_val_A.data(), hcsr_row_ptr_B.data(), hcsr_col_ind_B.data(), hcsr_val_B.data(), idxBaseA, idxBaseB); // allocate memory on device auto dcsr_row_ptr_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (m + 1)), device_free}; auto dcsr_col_ind_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz_A), device_free}; auto dcsr_val_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_A), device_free}; auto dcsr_row_ptr_B_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (k + 1)), device_free}; auto dcsr_col_ind_B_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz_B), device_free}; auto dcsr_val_B_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_B), device_free}; auto dcsr_row_ptr_C_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (m + 1)), device_free}; auto dcsr_row_ptr_C_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (n + 1)), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* dcsr_row_ptr_A = (I*)dcsr_row_ptr_A_managed.get(); J* dcsr_col_ind_A = (J*)dcsr_col_ind_A_managed.get(); T* dcsr_val_A = (T*)dcsr_val_A_managed.get(); I* dcsr_row_ptr_B = (I*)dcsr_row_ptr_B_managed.get(); J* dcsr_col_ind_B = (J*)dcsr_col_ind_B_managed.get(); T* dcsr_val_B = (T*)dcsr_val_B_managed.get(); I* dcsr_row_ptr_C_1 = (I*)dcsr_row_ptr_C_1_managed.get(); I* dcsr_row_ptr_C_2 = (I*)dcsr_row_ptr_C_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy( dcsr_row_ptr_A, hcsr_row_ptr_A.data(), sizeof(I) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind_A, hcsr_col_ind_A.data(), sizeof(J) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_val_A, hcsr_val_A.data(), sizeof(T) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy( dcsr_row_ptr_B, hcsr_row_ptr_B.data(), sizeof(I) * (k + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind_B, hcsr_col_ind_B.data(), sizeof(J) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_val_B, hcsr_val_B.data(), sizeof(T) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t A, B, C1, C2; CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&A, m, k, nnz_A, dcsr_row_ptr_A, dcsr_col_ind_A, dcsr_val_A, typeI, typeJ, idxBaseA, typeT)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&B, k, n, nnz_B, dcsr_row_ptr_B, dcsr_col_ind_B, dcsr_val_B, typeI, typeJ, idxBaseB, typeT)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr( &C1, m, n, 0, dcsr_row_ptr_C_1, nullptr, nullptr, typeI, typeJ, idxBaseC, typeT)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr( &C2, m, n, 0, dcsr_row_ptr_C_2, nullptr, nullptr, typeI, typeJ, idxBaseC, typeT)); // Query SpGEMM work estimation buffer size_t bufferSize1; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSpGEMM_workEstimation(handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, descr, &bufferSize1, nullptr)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSpGEMM_workEstimation(handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, descr, &bufferSize1, nullptr)); void* externalBuffer1; CHECK_HIP_ERROR(hipMalloc(&externalBuffer1, bufferSize1)); // SpGEMM work estimation CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSpGEMM_workEstimation(handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, descr, &bufferSize1, externalBuffer1)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSpGEMM_workEstimation(handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, descr, &bufferSize1, externalBuffer1)); // Query SpGEMM compute buffer size_t bufferSize2; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSpGEMM_compute(handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, descr, &bufferSize2, nullptr)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSpGEMM_compute(handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, descr, &bufferSize2, nullptr)); void* externalBuffer2; CHECK_HIP_ERROR(hipMalloc(&externalBuffer2, bufferSize2)); // SpGEMM compute CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSpGEMM_compute(handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, descr, &bufferSize2, externalBuffer2)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSpGEMM_compute(handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, descr, &bufferSize2, externalBuffer2)); // Get nnz of C int64_t rows_C, cols_C, nnz_C_1, nnz_C_2; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSpMatGetSize(C1, &rows_C, &cols_C, &nnz_C_1)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSpMatGetSize(C2, &rows_C, &cols_C, &nnz_C_2)); // Allocate C auto dcsr_col_ind_C_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz_C_1), device_free}; auto dcsr_val_C_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_C_1), device_free}; auto dcsr_col_ind_C_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz_C_2), device_free}; auto dcsr_val_C_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_C_2), device_free}; J* dcsr_col_ind_C_1 = (J*)dcsr_col_ind_C_1_managed.get(); T* dcsr_val_C_1 = (T*)dcsr_val_C_1_managed.get(); J* dcsr_col_ind_C_2 = (J*)dcsr_col_ind_C_2_managed.get(); T* dcsr_val_C_2 = (T*)dcsr_val_C_2_managed.get(); CHECK_HIP_ERROR(hipMemset(dcsr_val_C_1, 0, sizeof(T) * nnz_C_1)); CHECK_HIP_ERROR(hipMemset(dcsr_val_C_2, 0, sizeof(T) * nnz_C_2)); // Set C pointers CHECK_HIPSPARSE_ERROR( hipsparseCsrSetPointers(C1, dcsr_row_ptr_C_1, dcsr_col_ind_C_1, dcsr_val_C_1)); CHECK_HIPSPARSE_ERROR( hipsparseCsrSetPointers(C2, dcsr_row_ptr_C_2, dcsr_col_ind_C_2, dcsr_val_C_2)); // SpGEMM copy CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSpGEMM_copy( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, descr)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSpGEMM_copy(handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, descr)); // Copy output from device to CPU std::vector hcsr_row_ptr_C_1(m + 1); std::vector hcsr_row_ptr_C_2(m + 1); std::vector hcsr_col_ind_C_1(nnz_C_1); std::vector hcsr_col_ind_C_2(nnz_C_2); std::vector hcsr_val_C_1(nnz_C_1); std::vector hcsr_val_C_2(nnz_C_2); CHECK_HIP_ERROR(hipMemcpy( hcsr_row_ptr_C_1.data(), dcsr_row_ptr_C_1, sizeof(I) * (m + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcsr_row_ptr_C_2.data(), dcsr_row_ptr_C_2, sizeof(I) * (m + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcsr_col_ind_C_1.data(), dcsr_col_ind_C_1, sizeof(J) * nnz_C_1, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcsr_col_ind_C_2.data(), dcsr_col_ind_C_2, sizeof(J) * nnz_C_2, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val_C_1.data(), dcsr_val_C_1, sizeof(T) * nnz_C_1, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val_C_2.data(), dcsr_val_C_2, sizeof(T) * nnz_C_2, hipMemcpyDeviceToHost)); // Compute SpGEMM nnz of C on host std::vector hcsr_row_ptr_C_gold(m + 1); int64_t nnz_C_gold = host_csrgemm2_nnz(m, n, k, &h_alpha, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), hcsr_row_ptr_B.data(), hcsr_col_ind_B.data(), (const T*)nullptr, (const I*)nullptr, (const J*)nullptr, hcsr_row_ptr_C_gold.data(), idxBaseA, idxBaseB, idxBaseC, HIPSPARSE_INDEX_BASE_ZERO); // Verify nnz and row pointer array unit_check_general(1, 1, 1, &nnz_C_gold, &nnz_C_1); unit_check_general(1, 1, 1, &nnz_C_gold, &nnz_C_2); unit_check_general(1, m + 1, 1, hcsr_row_ptr_C_gold.data(), hcsr_row_ptr_C_1.data()); unit_check_general(1, m + 1, 1, hcsr_row_ptr_C_gold.data(), hcsr_row_ptr_C_2.data()); // Compute SpGEMM on host std::vector hcsr_col_ind_C_gold(nnz_C_gold); std::vector hcsr_val_C_gold(nnz_C_gold); host_csrgemm2(m, n, k, &h_alpha, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), hcsr_val_A.data(), hcsr_row_ptr_B.data(), hcsr_col_ind_B.data(), hcsr_val_B.data(), (const T*)nullptr, (const I*)nullptr, (const J*)nullptr, (const T*)nullptr, hcsr_row_ptr_C_gold.data(), hcsr_col_ind_C_gold.data(), hcsr_val_C_gold.data(), idxBaseA, idxBaseB, idxBaseC, HIPSPARSE_INDEX_BASE_ZERO); // Verify column and value array unit_check_general(1, nnz_C_gold, 1, hcsr_col_ind_C_gold.data(), hcsr_col_ind_C_1.data()); unit_check_general(1, nnz_C_gold, 1, hcsr_col_ind_C_gold.data(), hcsr_col_ind_C_2.data()); unit_check_general(1, nnz_C_gold, 1, hcsr_val_C_gold.data(), hcsr_val_C_1.data()); unit_check_general(1, nnz_C_gold, 1, hcsr_val_C_gold.data(), hcsr_val_C_2.data()); // Free buffers CHECK_HIP_ERROR(hipFree(externalBuffer1)); CHECK_HIP_ERROR(hipFree(externalBuffer2)); // Clean up CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(B)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(C1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(C2)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPGEMM_CSR_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_spgemmreuse_csr.hpp000066400000000000000000000571571501764003400247340ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPGEMMREUSE_CSR_HPP #define TESTING_SPGEMMREUSE_CSR_HPP #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse_test; void testing_spgemmreuse_csr_bad_arg(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11031) int64_t m = 100; int64_t n = 100; int64_t k = 100; int64_t nnz_A = 100; int64_t nnz_B = 100; int64_t nnz_C = 100; int64_t safe_size = 100; float alpha = 0.6; float beta = 0.2; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseIndexBase_t idxBaseA = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexBase_t idxBaseB = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexBase_t idxBaseC = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; hipsparseSpGEMMAlg_t alg = HIPSPARSE_SPGEMM_DEFAULT; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new spgemm_struct); hipsparseSpGEMMDescr_t descr = unique_ptr_descr->descr; auto dcsr_row_ptr_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcsr_col_ind_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcsr_val_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dcsr_row_ptr_B_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcsr_col_ind_B_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcsr_val_B_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dcsr_row_ptr_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcsr_col_ind_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcsr_val_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; int* dcsr_row_ptr_A = (int*)dcsr_row_ptr_A_managed.get(); int* dcsr_col_ind_A = (int*)dcsr_col_ind_A_managed.get(); float* dcsr_val_A = (float*)dcsr_val_A_managed.get(); int* dcsr_row_ptr_B = (int*)dcsr_row_ptr_B_managed.get(); int* dcsr_col_ind_B = (int*)dcsr_col_ind_B_managed.get(); float* dcsr_val_B = (float*)dcsr_val_B_managed.get(); int* dcsr_row_ptr_C = (int*)dcsr_row_ptr_C_managed.get(); int* dcsr_col_ind_C = (int*)dcsr_col_ind_C_managed.get(); float* dcsr_val_C = (float*)dcsr_val_C_managed.get(); // SpGEMM structures hipsparseSpMatDescr_t A, B, C; size_t bufferSize; // Create SpGEMM structures verify_hipsparse_status_success(hipsparseCreateCsr(&A, m, k, nnz_A, dcsr_row_ptr_A, dcsr_col_ind_A, dcsr_val_A, idxType, idxType, idxBaseA, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateCsr(&B, k, n, nnz_B, dcsr_row_ptr_B, dcsr_col_ind_B, dcsr_val_B, idxType, idxType, idxBaseB, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateCsr(&C, m, n, nnz_C, dcsr_row_ptr_C, dcsr_col_ind_C, dcsr_val_C, idxType, idxType, idxBaseC, dataType), "success"); // SpGEMM work estimation verify_hipsparse_status_invalid_handle(hipsparseSpGEMMreuse_workEstimation( nullptr, transA, transB, A, B, C, alg, descr, &bufferSize, nullptr)); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMMreuse_workEstimation( handle, transA, transB, nullptr, B, C, alg, descr, &bufferSize, nullptr), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMMreuse_workEstimation( handle, transA, transB, A, nullptr, C, alg, descr, &bufferSize, nullptr), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMMreuse_workEstimation( handle, transA, transB, A, B, nullptr, alg, descr, &bufferSize, nullptr), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMMreuse_workEstimation( handle, transA, transB, A, B, C, alg, descr, nullptr, nullptr), "Error: bufferSize is nullptr"); // SpGEMM compute verify_hipsparse_status_invalid_handle(hipsparseSpGEMMreuse_compute( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, descr)); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMMreuse_compute( handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, descr), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMMreuse_compute( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, descr), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMMreuse_compute( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, descr), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMMreuse_compute( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, descr), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMMreuse_compute( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, descr), "Error: C is nullptr"); // SpGEMMreuse copy verify_hipsparse_status_invalid_pointer( hipsparseSpGEMMreuse_copy( handle, transA, transB, nullptr, B, C, alg, descr, &bufferSize, nullptr), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMMreuse_copy( handle, transA, transB, A, nullptr, C, alg, descr, &bufferSize, nullptr), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMMreuse_copy( handle, transA, transB, A, B, nullptr, alg, descr, &bufferSize, nullptr), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMMreuse_copy(handle, transA, transB, A, B, C, alg, descr, nullptr, nullptr), "Error: bufferSize is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroySpMat(B), "success"); verify_hipsparse_status_success(hipsparseDestroySpMat(C), "success"); #endif } template hipsparseStatus_t testing_spgemmreuse_csr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11031) J m = argus.M; J k = argus.K; T h_alpha = make_DataType(argus.alpha); hipsparseIndexBase_t idxBaseA = argus.baseA; hipsparseIndexBase_t idxBaseB = argus.baseB; hipsparseIndexBase_t idxBaseC = argus.baseC; hipsparseSpGEMMAlg_t alg = static_cast(argus.spgemm_alg); std::string filename = argus.filename; T h_beta = make_DataType(0); hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipsparseIndexType_t typeJ = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handles std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new spgemm_struct); hipsparseSpGEMMDescr_t descr = unique_ptr_descr->descr; // Host structures std::vector hcsr_row_ptr_A; std::vector hcsr_col_ind_A; std::vector hcsr_val_A; // Initial Data on CPU srand(12345ULL); I nnz_A; if(!generate_csr_matrix( filename, m, k, nnz_A, hcsr_row_ptr_A, hcsr_col_ind_A, hcsr_val_A, idxBaseA)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Sparse matrix B as the transpose of A J n = m; I nnz_B = nnz_A; std::vector hcsr_row_ptr_B(k + 1); std::vector hcsr_col_ind_B(nnz_B); std::vector hcsr_val_B(nnz_B); transpose_csr(m, k, nnz_A, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), hcsr_val_A.data(), hcsr_row_ptr_B.data(), hcsr_col_ind_B.data(), hcsr_val_B.data(), idxBaseA, idxBaseB); // allocate memory on device auto dcsr_row_ptr_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (m + 1)), device_free}; auto dcsr_col_ind_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz_A), device_free}; auto dcsr_val_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_A), device_free}; auto dcsr_row_ptr_B_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (k + 1)), device_free}; auto dcsr_col_ind_B_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz_B), device_free}; auto dcsr_val_B_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_B), device_free}; auto dcsr_row_ptr_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (m + 1)), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* dcsr_row_ptr_A = (I*)dcsr_row_ptr_A_managed.get(); J* dcsr_col_ind_A = (J*)dcsr_col_ind_A_managed.get(); T* dcsr_val_A = (T*)dcsr_val_A_managed.get(); I* dcsr_row_ptr_B = (I*)dcsr_row_ptr_B_managed.get(); J* dcsr_col_ind_B = (J*)dcsr_col_ind_B_managed.get(); T* dcsr_val_B = (T*)dcsr_val_B_managed.get(); I* dcsr_row_ptr_C = (I*)dcsr_row_ptr_C_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy( dcsr_row_ptr_A, hcsr_row_ptr_A.data(), sizeof(I) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind_A, hcsr_col_ind_A.data(), sizeof(J) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_val_A, hcsr_val_A.data(), sizeof(T) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy( dcsr_row_ptr_B, hcsr_row_ptr_B.data(), sizeof(I) * (k + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind_B, hcsr_col_ind_B.data(), sizeof(J) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_val_B, hcsr_val_B.data(), sizeof(T) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t A, B, C; CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&A, m, k, nnz_A, dcsr_row_ptr_A, dcsr_col_ind_A, dcsr_val_A, typeI, typeJ, idxBaseA, typeT)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&B, k, n, nnz_B, dcsr_row_ptr_B, dcsr_col_ind_B, dcsr_val_B, typeI, typeJ, idxBaseB, typeT)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr( &C, m, n, 0, dcsr_row_ptr_C, nullptr, nullptr, typeI, typeJ, idxBaseC, typeT)); // Query SpGEMM work estimation buffer size_t bufferSize1; CHECK_HIPSPARSE_ERROR(hipsparseSpGEMMreuse_workEstimation( handle, transA, transB, A, B, C, alg, descr, &bufferSize1, nullptr)); auto externalBuffer1_managed = hipsparse_unique_ptr{device_malloc(bufferSize1), device_free}; void* externalBuffer1 = (void*)externalBuffer1_managed.get(); // SpGEMMreuse work estimation CHECK_HIPSPARSE_ERROR(hipsparseSpGEMMreuse_workEstimation( handle, transA, transB, A, B, C, alg, descr, &bufferSize1, externalBuffer1)); size_t bufferSize2, bufferSize3, bufferSize4, bufferSize5; void * externalBuffer2 = nullptr, *externalBuffer3 = nullptr, *externalBuffer4 = nullptr, *externalBuffer5 = nullptr; // Query SpGEMM_nnz CHECK_HIPSPARSE_ERROR(hipsparseSpGEMMreuse_nnz(handle, transA, transB, A, B, C, alg, descr, &bufferSize2, externalBuffer2, &bufferSize3, externalBuffer3, &bufferSize4, externalBuffer4)); auto externalBuffer2_managed = hipsparse_unique_ptr{device_malloc(bufferSize2), device_free}; externalBuffer2 = (void*)externalBuffer2_managed.get(); auto externalBuffer3_managed = hipsparse_unique_ptr{device_malloc(bufferSize3), device_free}; externalBuffer3 = (void*)externalBuffer3_managed.get(); auto externalBuffer4_managed = hipsparse_unique_ptr{device_malloc(bufferSize4), device_free}; externalBuffer4 = (void*)externalBuffer4_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseSpGEMMreuse_nnz(handle, transA, transB, A, B, C, alg, descr, &bufferSize2, externalBuffer2, &bufferSize3, externalBuffer3, &bufferSize4, externalBuffer4)); // We can already free buffer1 externalBuffer1_managed.reset(nullptr); externalBuffer1 = nullptr; externalBuffer2_managed.reset(nullptr); externalBuffer2 = nullptr; // Get nnz of C int64_t rows_C, cols_C, nnz_C; CHECK_HIPSPARSE_ERROR(hipsparseSpMatGetSize(C, &rows_C, &cols_C, &nnz_C)); // Allocate C auto dcsr_col_ind_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz_C), device_free}; auto dcsr_val_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_C), device_free}; J* dcsr_col_ind_C = (J*)dcsr_col_ind_C_managed.get(); T* dcsr_val_C = (T*)dcsr_val_C_managed.get(); CHECK_HIP_ERROR(hipMemset(dcsr_val_C, 0, sizeof(T) * nnz_C)); // Set C pointers CHECK_HIPSPARSE_ERROR(hipsparseCsrSetPointers(C, dcsr_row_ptr_C, dcsr_col_ind_C, dcsr_val_C)); CHECK_HIPSPARSE_ERROR(hipsparseSpGEMMreuse_copy( handle, transA, transB, A, B, C, alg, descr, &bufferSize5, externalBuffer5)); auto externalBuffer5_managed = hipsparse_unique_ptr{device_malloc(bufferSize5), device_free}; externalBuffer5 = (void*)externalBuffer5_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseSpGEMMreuse_copy( handle, transA, transB, A, B, C, alg, descr, &bufferSize5, externalBuffer5)); externalBuffer3_managed.reset(nullptr); externalBuffer3 = nullptr; // Query SpGEMM compute buffer CHECK_HIPSPARSE_ERROR(hipsparseSpGEMMreuse_compute( handle, transA, transB, &h_alpha, A, B, &h_beta, C, typeT, alg, descr)); CHECK_HIPSPARSE_ERROR(hipsparseSpGEMMreuse_compute( handle, transA, transB, &h_alpha, A, B, &h_beta, C, typeT, alg, descr)); externalBuffer4_managed.reset(nullptr); externalBuffer4 = nullptr; externalBuffer5_managed.reset(nullptr); externalBuffer5 = nullptr; // Copy output from device to CPU std::vector hcsr_row_ptr_C(m + 1); std::vector hcsr_col_ind_C(nnz_C); std::vector hcsr_val_C(nnz_C); CHECK_HIP_ERROR(hipMemcpy( hcsr_row_ptr_C.data(), dcsr_row_ptr_C, sizeof(I) * (m + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_col_ind_C.data(), dcsr_col_ind_C, sizeof(J) * nnz_C, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val_C.data(), dcsr_val_C, sizeof(T) * nnz_C, hipMemcpyDeviceToHost)); // Compute SpGEMM nnz of C on host std::vector hcsr_row_ptr_C_gold(m + 1); int64_t nnz_C_gold = host_csrgemm2_nnz(m, n, k, &h_alpha, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), hcsr_row_ptr_B.data(), hcsr_col_ind_B.data(), (const T*)nullptr, (const I*)nullptr, (const J*)nullptr, hcsr_row_ptr_C_gold.data(), idxBaseA, idxBaseB, idxBaseC, HIPSPARSE_INDEX_BASE_ZERO); // Verify nnz and row pointer array unit_check_general(1, 1, 1, &nnz_C_gold, &nnz_C); unit_check_general(1, m + 1, 1, hcsr_row_ptr_C_gold.data(), hcsr_row_ptr_C.data()); // Compute SpGEMM on host std::vector hcsr_col_ind_C_gold(nnz_C_gold); std::vector hcsr_val_C_gold(nnz_C_gold); host_csrgemm2(m, n, k, &h_alpha, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), hcsr_val_A.data(), hcsr_row_ptr_B.data(), hcsr_col_ind_B.data(), hcsr_val_B.data(), (const T*)nullptr, (const I*)nullptr, (const J*)nullptr, (const T*)nullptr, hcsr_row_ptr_C_gold.data(), hcsr_col_ind_C_gold.data(), hcsr_val_C_gold.data(), idxBaseA, idxBaseB, idxBaseC, HIPSPARSE_INDEX_BASE_ZERO); // Verify column and value array unit_check_general(1, nnz_C_gold, 1, hcsr_col_ind_C_gold.data(), hcsr_col_ind_C.data()); unit_check_general(1, nnz_C_gold, 1, hcsr_val_C_gold.data(), hcsr_val_C.data()); // Clean up CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(B)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(C)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPGEMM_CSR_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_spmat_descr.hpp000066400000000000000000001723431501764003400240300ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPMAT_DESCR_HPP #define TESTING_SPMAT_DESCR_HPP #include "hipsparse_test_unique_ptr.hpp" #ifdef GOOGLE_TEST #include #endif #include #include "hipsparse_arguments.hpp" #include "utility.hpp" #include using namespace hipsparse_test; void testing_spmat_descr_bad_arg(void) { #if(!defined(CUDART_VERSION)) int64_t rows = 100; int64_t cols = 100; int64_t nnz = 100; int64_t ell_cols = 10; int64_t ell_blocksize = 2; hipsparseIndexType_t rowType = HIPSPARSE_INDEX_32I; hipsparseIndexType_t colType = HIPSPARSE_INDEX_32I; hipsparseIndexType_t cooType = HIPSPARSE_INDEX_32I; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipDataType dataType = HIP_R_32F; hipsparseFormat_t format = HIPSPARSE_FORMAT_CSR; // Allocate memory on device auto row_data_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto col_data_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto ind_data_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * 2 * nnz), device_free}; auto val_data_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * nnz), device_free}; int* row_data = (int*)row_data_managed.get(); int* col_data = (int*)col_data_managed.get(); int* ind_data = (int*)ind_data_managed.get(); float* val_data = (float*)val_data_managed.get(); hipsparseSpMatDescr_t A; // hipsparseCreateCoo verify_hipsparse_status_invalid_pointer( hipsparseCreateCoo( nullptr, rows, cols, nnz, row_data, col_data, val_data, rowType, idxBase, dataType), "Error: A is nullptr"); verify_hipsparse_status_invalid_size( hipsparseCreateCoo( &A, -1, cols, nnz, row_data, col_data, val_data, rowType, idxBase, dataType), "Error: rows is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateCoo( &A, rows, -1, nnz, row_data, col_data, val_data, rowType, idxBase, dataType), "Error: cols is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateCoo( &A, rows, cols, -1, row_data, col_data, val_data, rowType, idxBase, dataType), "Error: nnz is < 0"); verify_hipsparse_status_invalid_pointer( hipsparseCreateCoo( &A, rows, cols, nnz, nullptr, col_data, val_data, rowType, idxBase, dataType), "Error: row_data is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCreateCoo( &A, rows, cols, nnz, row_data, nullptr, val_data, rowType, idxBase, dataType), "Error: col_data is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCreateCoo( &A, rows, cols, nnz, row_data, col_data, nullptr, rowType, idxBase, dataType), "Error: val_data is nullptr"); // hipsparseCreateCooAoS verify_hipsparse_status_invalid_pointer( hipsparseCreateCooAoS( nullptr, rows, cols, nnz, ind_data, val_data, cooType, idxBase, dataType), "Error: A is nullptr"); verify_hipsparse_status_invalid_size( hipsparseCreateCooAoS(&A, -1, cols, nnz, ind_data, val_data, cooType, idxBase, dataType), "Error: rows is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateCooAoS(&A, rows, -1, nnz, ind_data, val_data, cooType, idxBase, dataType), "Error: cols is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateCooAoS(&A, rows, cols, -1, ind_data, val_data, cooType, idxBase, dataType), "Error: nnz is < 0"); verify_hipsparse_status_invalid_pointer( hipsparseCreateCooAoS(&A, rows, cols, nnz, nullptr, val_data, cooType, idxBase, dataType), "Error: ind_data is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCreateCooAoS(&A, rows, cols, nnz, ind_data, nullptr, cooType, idxBase, dataType), "Error: val_data is nullptr"); // hipsparseCreateCsr verify_hipsparse_status_invalid_pointer(hipsparseCreateCsr(nullptr, rows, cols, nnz, row_data, col_data, val_data, rowType, colType, idxBase, dataType), "Error: A is nullptr"); verify_hipsparse_status_invalid_size( hipsparseCreateCsr( &A, -1, cols, nnz, row_data, col_data, val_data, rowType, colType, idxBase, dataType), "Error: rows is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateCsr( &A, rows, -1, nnz, row_data, col_data, val_data, rowType, colType, idxBase, dataType), "Error: cols is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateCsr( &A, rows, cols, -1, row_data, col_data, val_data, rowType, colType, idxBase, dataType), "Error: nnz is < 0"); verify_hipsparse_status_invalid_pointer( hipsparseCreateCsr( &A, rows, cols, nnz, nullptr, col_data, val_data, rowType, colType, idxBase, dataType), "Error: row_data is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCreateCsr( &A, rows, cols, nnz, row_data, nullptr, val_data, rowType, colType, idxBase, dataType), "Error: col_data is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCreateCsr( &A, rows, cols, nnz, row_data, col_data, nullptr, rowType, colType, idxBase, dataType), "Error: val_data is nullptr"); // hipsparseCreateBlockedEll verify_hipsparse_status_invalid_pointer(hipsparseCreateBlockedEll(nullptr, rows, cols, ell_blocksize, ell_cols, col_data, val_data, colType, idxBase, dataType), "Error: A is nullptr"); verify_hipsparse_status_invalid_size( hipsparseCreateBlockedEll( &A, -1, cols, ell_blocksize, ell_cols, col_data, val_data, colType, idxBase, dataType), "Error: rows is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateBlockedEll( &A, rows, -1, ell_blocksize, ell_cols, col_data, val_data, colType, idxBase, dataType), "Error: cols is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateBlockedEll( &A, rows, cols, -1, ell_cols, col_data, val_data, colType, idxBase, dataType), "Error: ell_blocksize is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateBlockedEll( &A, rows, cols, ell_blocksize, -1, col_data, val_data, colType, idxBase, dataType), "Error: ell_cols is < 0"); verify_hipsparse_status_invalid_pointer( hipsparseCreateBlockedEll( &A, rows, cols, ell_blocksize, ell_cols, nullptr, val_data, colType, idxBase, dataType), "Error: ellColInd is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCreateBlockedEll( &A, rows, cols, ell_blocksize, ell_cols, col_data, nullptr, colType, idxBase, dataType), "Error: ellValue is nullptr"); // hipsparseDestroySpMat verify_hipsparse_status_invalid_pointer(hipsparseDestroySpMat(nullptr), "Error: A is nullptr"); // Create valid descriptors hipsparseSpMatDescr_t coo; hipsparseSpMatDescr_t coo_aos; hipsparseSpMatDescr_t csr; hipsparseSpMatDescr_t csc; hipsparseSpMatDescr_t bell; verify_hipsparse_status_success(hipsparseCreateBlockedEll(&bell, rows, cols, ell_blocksize, ell_cols, col_data, val_data, colType, idxBase, dataType), "Success"); verify_hipsparse_status_success( hipsparseCreateCoo( &coo, rows, cols, nnz, row_data, col_data, val_data, rowType, idxBase, dataType), "Success"); verify_hipsparse_status_success( hipsparseCreateCooAoS( &coo_aos, rows, cols, nnz, ind_data, val_data, cooType, idxBase, dataType), "Success"); verify_hipsparse_status_success(hipsparseCreateCsr(&csr, rows, cols, nnz, row_data, col_data, val_data, rowType, colType, idxBase, dataType), "Success"); verify_hipsparse_status_success(hipsparseCreateCsc(&csc, rows, cols, nnz, col_data, row_data, val_data, colType, rowType, idxBase, dataType), "Success"); void* row_ptr; void* col_ptr; void* ind_ptr; void* val_ptr; // hipsparseCooGet verify_hipsparse_status_invalid_pointer(hipsparseCooGet(nullptr, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &idxBase, &dataType), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCooGet( coo, nullptr, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &idxBase, &dataType), "Error: rows is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCooGet( coo, &rows, nullptr, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &idxBase, &dataType), "Error: cols is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCooGet(coo, &rows, &cols, nullptr, &row_ptr, &col_ptr, &val_ptr, &rowType, &idxBase, &dataType), "Error: nnz is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCooGet( coo, &rows, &cols, &nnz, nullptr, &col_ptr, &val_ptr, &rowType, &idxBase, &dataType), "Error: row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCooGet( coo, &rows, &cols, &nnz, &row_ptr, nullptr, &val_ptr, &rowType, &idxBase, &dataType), "Error: col_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCooGet( coo, &rows, &cols, &nnz, &row_ptr, &col_ptr, nullptr, &rowType, &idxBase, &dataType), "Error: val_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCooGet( coo, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, nullptr, &idxBase, &dataType), "Error: rowType is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCooGet( coo, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, nullptr, &dataType), "Error: idxBase is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCooGet( coo, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &idxBase, nullptr), "Error: dataType is nullptr"); // hipsparseCooAoSGet verify_hipsparse_status_invalid_pointer( hipsparseCooAoSGet( nullptr, &rows, &cols, &nnz, &ind_ptr, &val_ptr, &cooType, &idxBase, &dataType), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCooAoSGet( coo_aos, nullptr, &cols, &nnz, &ind_ptr, &val_ptr, &cooType, &idxBase, &dataType), "Error: rows is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCooAoSGet( coo_aos, &rows, nullptr, &nnz, &ind_ptr, &val_ptr, &cooType, &idxBase, &dataType), "Error: cols is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCooAoSGet( coo_aos, &rows, &cols, nullptr, &ind_ptr, &val_ptr, &cooType, &idxBase, &dataType), "Error: nnz is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCooAoSGet( coo_aos, &rows, &cols, &nnz, nullptr, &val_ptr, &cooType, &idxBase, &dataType), "Error: ind_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCooAoSGet( coo_aos, &rows, &cols, &nnz, &ind_ptr, nullptr, &cooType, &idxBase, &dataType), "Error: val_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCooAoSGet( coo_aos, &rows, &cols, &nnz, &ind_ptr, &val_ptr, nullptr, &idxBase, &dataType), "Error: cooType is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCooAoSGet( coo_aos, &rows, &cols, &nnz, &ind_ptr, &val_ptr, &cooType, nullptr, &dataType), "Error: idxBase is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCooAoSGet( coo_aos, &rows, &cols, &nnz, &ind_ptr, &val_ptr, &cooType, &idxBase, nullptr), "Error: dataType is nullptr"); // hipsparseCsrGet verify_hipsparse_status_invalid_pointer(hipsparseCsrGet(nullptr, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &colType, &idxBase, &dataType), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsrGet(csr, nullptr, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &colType, &idxBase, &dataType), "Error: rows is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsrGet(csr, &rows, nullptr, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &colType, &idxBase, &dataType), "Error: cols is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsrGet(csr, &rows, &cols, nullptr, &row_ptr, &col_ptr, &val_ptr, &rowType, &colType, &idxBase, &dataType), "Error: nnz is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsrGet(csr, &rows, &cols, &nnz, nullptr, &col_ptr, &val_ptr, &rowType, &colType, &idxBase, &dataType), "Error: row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsrGet(csr, &rows, &cols, &nnz, &row_ptr, nullptr, &val_ptr, &rowType, &colType, &idxBase, &dataType), "Error: col_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsrGet(csr, &rows, &cols, &nnz, &row_ptr, &col_ptr, nullptr, &rowType, &colType, &idxBase, &dataType), "Error: val_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsrGet(csr, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, nullptr, &colType, &idxBase, &dataType), "Error: rowType is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsrGet(csr, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, nullptr, &idxBase, &dataType), "Error: colType is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsrGet(csr, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &colType, nullptr, &dataType), "Error: idxBase is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsrGet(csr, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &colType, &idxBase, nullptr), "Error: dataType is nullptr"); // hipsparseCscGet verify_hipsparse_status_invalid_pointer(hipsparseCscGet(nullptr, &rows, &cols, &nnz, &col_ptr, &row_ptr, &val_ptr, &colType, &rowType, &idxBase, &dataType), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCscGet(csc, nullptr, &cols, &nnz, &col_ptr, &row_ptr, &val_ptr, &colType, &rowType, &idxBase, &dataType), "Error: rows is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCscGet(csc, &rows, nullptr, &nnz, &col_ptr, &row_ptr, &val_ptr, &colType, &rowType, &idxBase, &dataType), "Error: cols is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCscGet(csc, &rows, &cols, nullptr, &col_ptr, &row_ptr, &val_ptr, &colType, &rowType, &idxBase, &dataType), "Error: nnz is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCscGet(csc, &rows, &cols, &nnz, nullptr, &row_ptr, &val_ptr, &colType, &rowType, &idxBase, &dataType), "Error: col_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCscGet(csc, &rows, &cols, &nnz, &col_ptr, nullptr, &val_ptr, &colType, &rowType, &idxBase, &dataType), "Error: row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCscGet(csc, &rows, &cols, &nnz, &col_ptr, &row_ptr, nullptr, &colType, &rowType, &idxBase, &dataType), "Error: val_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCscGet(csc, &rows, &cols, &nnz, &col_ptr, &row_ptr, &val_ptr, nullptr, &rowType, &idxBase, &dataType), "Error: colType is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCscGet(csc, &rows, &cols, &nnz, &col_ptr, &row_ptr, &val_ptr, &colType, nullptr, &idxBase, &dataType), "Error: rowType is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCscGet(csc, &rows, &cols, &nnz, &col_ptr, &row_ptr, &val_ptr, &colType, &rowType, nullptr, &dataType), "Error: idxBase is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCscGet(csc, &rows, &cols, &nnz, &col_ptr, &row_ptr, &val_ptr, &colType, &rowType, &idxBase, nullptr), "Error: dataType is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseBlockedEllGet(nullptr, &rows, &cols, &ell_blocksize, &ell_cols, &col_ptr, &val_ptr, &colType, &idxBase, &dataType), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseBlockedEllGet(bell, nullptr, &cols, &ell_blocksize, &ell_cols, &col_ptr, &val_ptr, &colType, &idxBase, &dataType), "Error: rows is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseBlockedEllGet(bell, &rows, nullptr, &ell_blocksize, &ell_cols, &col_ptr, &val_ptr, &colType, &idxBase, &dataType), "Error: cols is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseBlockedEllGet(bell, &rows, &cols, nullptr, &ell_cols, &col_ptr, &val_ptr, &colType, &idxBase, &dataType), "Error: ell_blocksize is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseBlockedEllGet(bell, &rows, &cols, &ell_blocksize, nullptr, &col_ptr, &val_ptr, &colType, &idxBase, &dataType), "Error: ell_cols is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseBlockedEllGet(bell, &rows, &cols, &ell_blocksize, &ell_cols, nullptr, &val_ptr, &colType, &idxBase, &dataType), "Error: ellColInd"); verify_hipsparse_status_invalid_pointer(hipsparseBlockedEllGet(bell, &rows, &cols, &ell_blocksize, &ell_cols, &col_ptr, nullptr, &colType, &idxBase, &dataType), "Error: ellValue is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseBlockedEllGet(bell, &rows, &cols, &ell_blocksize, &ell_cols, &col_ptr, &val_ptr, nullptr, &idxBase, &dataType), "Error: ellIdxType is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseBlockedEllGet(bell, &rows, &cols, &ell_blocksize, &ell_cols, &col_ptr, &val_ptr, &colType, nullptr, &dataType), "Error: idxBase is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseBlockedEllGet(bell, &rows, &cols, &ell_blocksize, &ell_cols, &col_ptr, &val_ptr, &colType, &idxBase, nullptr), "Error: valueType is nullptr"); // hipsparseCsrSetPointers verify_hipsparse_status_invalid_pointer( hipsparseCsrSetPointers(nullptr, row_data, col_data, val_data), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCsrSetPointers(csr, nullptr, col_data, val_data), "Error: row_data is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCsrSetPointers(csr, row_data, nullptr, val_data), "Error: col_data is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCsrSetPointers(csr, row_data, col_data, nullptr), "Error: val_data is nullptr"); // hipsparseSpMatGetSize verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetSize(nullptr, &rows, &cols, &nnz), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetSize(coo, nullptr, &cols, &nnz), "Error: rows is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetSize(coo, &rows, nullptr, &nnz), "Error: cols is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetSize(coo, &rows, &cols, nullptr), "Error: nnz is nullptr"); // hipsparseSpMatGetFormat verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetFormat(nullptr, &format), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetFormat(coo, nullptr), "Error: format is nullptr"); // hipsparseSpMatGetIndexBase verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetIndexBase(nullptr, &idxBase), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetIndexBase(coo, nullptr), "Error: idxBase is nullptr"); // hipsparseSpMatGetValues verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetValues(nullptr, &val_ptr), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetValues(coo, nullptr), "Error: val_ptr is nullptr"); // hipsparseSpMatSetValues verify_hipsparse_status_invalid_pointer(hipsparseSpMatSetValues(nullptr, val_ptr), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpMatSetValues(coo, nullptr), "Error: val_ptr is nullptr"); int batch_count = 100; int64_t batch_stride = 100; int64_t offsets_batch_stride = 100; int64_t columns_values_batch_stride = 100; // hipsparseSpMatGetStridedBatch verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetStridedBatch(nullptr, &batch_count), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetStridedBatch(coo, nullptr), "Error: batch count is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetStridedBatch(csr, nullptr), "Error: batch count is nullptr"); // hipsparseSpMatSetStridedBatch verify_hipsparse_status_invalid_pointer(hipsparseSpMatSetStridedBatch(nullptr, batch_count), "Error: A is nullptr"); verify_hipsparse_status_invalid_size(hipsparseSpMatSetStridedBatch(coo, -1), "Error: batch count is invalid"); verify_hipsparse_status_invalid_size(hipsparseSpMatSetStridedBatch(csr, -1), "Error: batch count is invalid"); // hipsparseCooSetStridedBatch verify_hipsparse_status_invalid_pointer( hipsparseCooSetStridedBatch(nullptr, batch_count, batch_stride), "Error: A is nullptr"); verify_hipsparse_status_invalid_size(hipsparseCooSetStridedBatch(coo, -1, batch_stride), "Error: batch count is invalid"); verify_hipsparse_status_invalid_size(hipsparseCooSetStridedBatch(coo, batch_count, -1), "Error: batch stride is invalid"); verify_hipsparse_status_invalid_size(hipsparseCooSetStridedBatch(coo, -1, -1), "Error: batch count and batch stride is invalid"); // hipsparseCsrSetStridedBatch verify_hipsparse_status_invalid_pointer( hipsparseCsrSetStridedBatch( nullptr, batch_count, offsets_batch_stride, columns_values_batch_stride), "Error: A is nullptr"); verify_hipsparse_status_invalid_size( hipsparseCsrSetStridedBatch(csr, -1, offsets_batch_stride, columns_values_batch_stride), "Error: batch count is invalid"); verify_hipsparse_status_invalid_size( hipsparseCsrSetStridedBatch(csr, batch_count, -1, columns_values_batch_stride), "Error: batch stride is invalid"); verify_hipsparse_status_invalid_size( hipsparseCsrSetStridedBatch(csr, batch_count, offsets_batch_stride, -1), "Error: batch stride is invalid"); verify_hipsparse_status_invalid_size( hipsparseCsrSetStridedBatch(csr, -1, -1, columns_values_batch_stride), "Error: batch count and batch stride is invalid"); verify_hipsparse_status_invalid_size(hipsparseCsrSetStridedBatch(csr, batch_count, -1, -1), "Error: batch count and batch stride is invalid"); verify_hipsparse_status_invalid_size( hipsparseCsrSetStridedBatch(csr, -1, offsets_batch_stride, -1), "Error: batch count and batch stride is invalid"); verify_hipsparse_status_invalid_size(hipsparseCsrSetStridedBatch(csr, -1, -1, -1), "Error: batch count and batch stride is invalid"); // Destroy valid descriptors verify_hipsparse_status_success(hipsparseDestroySpMat(coo), "Success"); verify_hipsparse_status_success(hipsparseDestroySpMat(coo_aos), "Success"); verify_hipsparse_status_success(hipsparseDestroySpMat(csr), "Success"); verify_hipsparse_status_success(hipsparseDestroySpMat(csc), "Success"); verify_hipsparse_status_success(hipsparseDestroySpMat(bell), "Success"); #endif } hipsparseStatus_t testing_spmat_descr(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) int m = 2; int n = 2; int nnzC = 4; // C std::vector hcsr_row_ptrC = {0, 2, 4}; std::vector hcsr_col_indC = {0, 2, 0, 1}; std::vector hcsr_valC = {5.0f, 6.0f, 7.0f, 8.0f, 1.0f, 2.0f}; int* dcsr_row_ptrC = NULL; int* dcsr_col_indC = NULL; float* dcsr_valC = NULL; CHECK_HIP_ERROR(hipMalloc((void**)&dcsr_row_ptrC, (m + 1) * sizeof(int))); CHECK_HIP_ERROR(hipMalloc((void**)&dcsr_col_indC, nnzC * sizeof(int))); CHECK_HIP_ERROR(hipMalloc((void**)&dcsr_valC, nnzC * sizeof(float))); CHECK_HIP_ERROR(hipMemcpy( dcsr_row_ptrC, hcsr_row_ptrC.data(), (m + 1) * sizeof(int), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_indC, hcsr_col_indC.data(), nnzC * sizeof(int), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_valC, hcsr_valC.data(), nnzC * sizeof(float), hipMemcpyHostToDevice)); hipsparseHandle_t handle = NULL; hipsparseSpMatDescr_t matA, matB, matC, matD, matE, matF, matG, matH, matI, matJ, matK, matL, matM, matN, matO; CHECK_HIPSPARSE_ERROR(hipsparseCreate(&handle)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&matA, 0, 0, 0, NULL, NULL, NULL, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&matB, m, n, 0, NULL, NULL, NULL, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&matC, 0, 0, 0, dcsr_row_ptrC, NULL, NULL, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&matD, m, n, 0, dcsr_row_ptrC, NULL, NULL, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&matE, m, n, nnzC, dcsr_row_ptrC, dcsr_col_indC, dcsr_valC, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&matF, m, n, 0, NULL, dcsr_col_indC, dcsr_valC, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&matG, 0, 0, 0, NULL, dcsr_col_indC, dcsr_valC, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&matH, m, n, 0, NULL, NULL, dcsr_valC, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&matI, 0, 0, 0, NULL, NULL, dcsr_valC, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&matJ, m, n, 0, NULL, dcsr_col_indC, NULL, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&matK, 0, 0, 0, NULL, dcsr_col_indC, NULL, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&matL, m, n, 0, dcsr_row_ptrC, dcsr_col_indC, NULL, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&matM, 0, 0, 0, dcsr_row_ptrC, dcsr_col_indC, NULL, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&matN, m, n, 0, dcsr_row_ptrC, NULL, dcsr_valC, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&matO, 0, 0, 0, dcsr_row_ptrC, NULL, dcsr_valC, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); // destroy matrix/vector descriptors CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matA)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matB)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matC)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matD)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matE)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matF)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matG)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matH)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matI)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matJ)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matK)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matL)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matM)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matN)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matO)); CHECK_HIPSPARSE_ERROR(hipsparseDestroy(handle)); CHECK_HIP_ERROR(hipFree(dcsr_row_ptrC)); CHECK_HIP_ERROR(hipFree(dcsr_col_indC)); CHECK_HIP_ERROR(hipFree(dcsr_valC)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPMAT_DESCR_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_spmm_batched_coo.hpp000066400000000000000000000520241501764003400250030ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2022 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPMM_BATCHED_COO_HPP #define TESTING_SPMM_BATCHED_COO_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; void testing_spmm_batched_coo_bad_arg(void) { #if(!defined(CUDART_VERSION)) int32_t m = 100; int32_t n = 100; int32_t k = 100; int64_t nnz = 100; float alpha = 0.6; float beta = 0.2; size_t safe_size = 100; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxTypeI = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; #if(CUDART_VERSION >= 11003) hipsparseSpMMAlg_t alg = HIPSPARSE_SPMM_COO_ALG1; #else hipsparseSpMMAlg_t alg = HIPSPARSE_COOMM_ALG1; #endif std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dC_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int32_t* drow = (int32_t*)drow_managed.get(); int32_t* dcol = (int32_t*)dcol_managed.get(); float* dval = (float*)dval_managed.get(); float* dB = (float*)dB_managed.get(); float* dC = (float*)dC_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SpMM structures hipsparseSpMatDescr_t A; hipsparseDnMatDescr_t B, C; // Create SpMM structures verify_hipsparse_status_success( hipsparseCreateCoo(&A, m, k, nnz, drow, dcol, dval, idxTypeI, idxBase, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&B, k, n, k, dB, dataType, order), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&C, m, n, m, dC, dataType, order), "success"); int batch_count_A; int batch_count_B; int batch_count_C; int64_t batch_stride_A; int64_t batch_stride_B; int64_t batch_stride_C; // C_i = A * B_i batch_count_A = 1; batch_count_B = 10; batch_count_C = 5; batch_stride_A = 0; batch_stride_B = k * n; batch_stride_C = m * n; verify_hipsparse_status_success(hipsparseCooSetStridedBatch(A, batch_count_A, batch_stride_A), "success"); verify_hipsparse_status_success(hipsparseDnMatSetStridedBatch(B, batch_count_B, batch_stride_B), "success"); verify_hipsparse_status_success(hipsparseDnMatSetStridedBatch(C, batch_count_C, batch_stride_C), "success"); verify_hipsparse_status_invalid_value( hipsparseSpMM(handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf), "Error: Combination of strided batch parameters is invald"); // C_i = A_i * B batch_count_A = 10; batch_count_B = 1; batch_count_C = 5; batch_stride_A = nnz; batch_stride_B = 0; batch_stride_C = m * n; verify_hipsparse_status_success(hipsparseCooSetStridedBatch(A, batch_count_A, batch_stride_A), "success"); verify_hipsparse_status_success(hipsparseDnMatSetStridedBatch(B, batch_count_B, batch_stride_B), "success"); verify_hipsparse_status_success(hipsparseDnMatSetStridedBatch(C, batch_count_C, batch_stride_C), "success"); verify_hipsparse_status_invalid_value( hipsparseSpMM(handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf), "Error: Combination of strided batch parameters is invald"); // C_i = A_i * B_i batch_count_A = 10; batch_count_B = 10; batch_count_C = 5; batch_stride_A = nnz; batch_stride_B = k * n; batch_stride_C = m * n; verify_hipsparse_status_success(hipsparseCooSetStridedBatch(A, batch_count_A, batch_stride_A), "success"); verify_hipsparse_status_success(hipsparseDnMatSetStridedBatch(B, batch_count_B, batch_stride_B), "success"); verify_hipsparse_status_success(hipsparseDnMatSetStridedBatch(C, batch_count_C, batch_stride_C), "success"); verify_hipsparse_status_invalid_value( hipsparseSpMM(handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf), "Error: Combination of strided batch parameters is invald"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(B), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(C), "success"); #endif } template hipsparseStatus_t testing_spmm_batched_coo(Arguments argus) { #if(!defined(CUDART_VERSION)) I m = argus.M; I n = argus.N; I k = argus.K; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseOperation_t transB = argus.transB; hipsparseOrder_t orderB = argus.orderB; hipsparseOrder_t orderC = argus.orderC; hipsparseIndexBase_t idx_base = argus.baseA; I batch_count_A = 1; I batch_count_B = 10; I batch_count_C = 10; #if(CUDART_VERSION >= 11003) hipsparseSpMMAlg_t alg = HIPSPARSE_SPMM_COO_ALG1; #else hipsparseSpMMAlg_t alg = HIPSPARSE_COOMM_ALG1; #endif std::string filename = argus.filename; #if(defined(CUDART_VERSION)) if(orderB != orderC || orderB != HIPSPARSE_ORDER_COL) { return HIPSPARSE_STATUS_SUCCESS; } #endif // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hrow_ptr; std::vector hcol_ind; std::vector hval; // Initial Data on CPU srand(12345ULL); I nnz_A; if(!generate_csr_matrix(filename, (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k, (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : m, nnz_A, hrow_ptr, hcol_ind, hval, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hrow_ind(nnz_A); // Convert to COO I mk = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k; for(I i = 0; i < mk; ++i) { for(I j = hrow_ptr[i]; j < hrow_ptr[i + 1]; ++j) { hrow_ind[j - idx_base] = i + idx_base; } } // Some matrix properties I A_m = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k; I A_n = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : m; I B_m = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : n; I B_n = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? n : k; I C_m = m; I C_n = n; int ld_multiplier_B = 1; int ld_multiplier_C = 1; int64_t ldb = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * k) : (int64_t(ld_multiplier_B) * n)) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * n) : (int64_t(ld_multiplier_B) * k)); int64_t ldc = (orderC == HIPSPARSE_ORDER_COL) ? (int64_t(ld_multiplier_C) * m) : (int64_t(ld_multiplier_C) * n); ldb = std::max(int64_t(1), ldb); ldc = std::max(int64_t(1), ldc); int64_t nrowB = (orderB == HIPSPARSE_ORDER_COL) ? ldb : B_m; int64_t ncolB = (orderB == HIPSPARSE_ORDER_COL) ? B_n : ldb; int64_t nrowC = (orderC == HIPSPARSE_ORDER_COL) ? ldc : C_m; int64_t ncolC = (orderC == HIPSPARSE_ORDER_COL) ? C_n : ldc; int64_t nnz_B = nrowB * ncolB; int64_t nnz_C = nrowC * ncolC; int64_t batch_stride_A = (batch_count_A > 1) ? nnz_A : 0; int64_t batch_stride_B = (batch_count_B > 1) ? nnz_B : 0; int64_t batch_stride_C = (batch_count_C > 1) ? nnz_C : 0; // Allocate host memory for all batches of A matrix std::vector hcoo_row_ind(batch_count_A * nnz_A); std::vector hcoo_col_ind(batch_count_A * nnz_A); std::vector hcoo_val(batch_count_A * nnz_A); for(I i = 0; i < batch_count_A; i++) { for(int64_t j = 0; j < nnz_A; j++) { hcoo_row_ind[nnz_A * i + j] = hrow_ind[j]; hcoo_col_ind[nnz_A * i + j] = hcol_ind[j]; hcoo_val[nnz_A * i + j] = hval[j]; } } std::vector hB(batch_count_B * nnz_B); std::vector hC_1(batch_count_C * nnz_C); std::vector hC_2(batch_count_C * nnz_C); std::vector hC_gold(batch_count_C * nnz_C); hipsparseInit(hB, batch_count_B * nnz_B, 1); hipsparseInit(hC_1, batch_count_C * nnz_C, 1); // copy vector is easy in STL; hC_gold = hC: save a copy in hy_gold which will be output of CPU hC_2 = hC_1; hC_gold = hC_1; // allocate memory on device auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * batch_count_A * nnz_A), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * batch_count_A * nnz_A), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * batch_count_A * nnz_A), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * batch_count_B * nnz_B), device_free}; auto dC_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * batch_count_C * nnz_C), device_free}; auto dC_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * batch_count_C * nnz_C), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* dcoo_row_ind = (I*)drow_managed.get(); I* dcoo_col_ind = (I*)dcol_managed.get(); T* dcoo_val = (T*)dval_managed.get(); T* dB = (T*)dB_managed.get(); T* dC_1 = (T*)dC_1_managed.get(); T* dC_2 = (T*)dC_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dcoo_row_ind, hcoo_row_ind.data(), sizeof(I) * batch_count_A * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcoo_col_ind, hcoo_col_ind.data(), sizeof(I) * batch_count_A * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy( dcoo_val, hcoo_val.data(), sizeof(T) * batch_count_A * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dB, hB.data(), sizeof(T) * batch_count_B * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dC_1, hC_1.data(), sizeof(T) * batch_count_C * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dC_2, hC_2.data(), sizeof(T) * batch_count_C * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t A; CHECK_HIPSPARSE_ERROR(hipsparseCreateCoo( &A, A_m, A_n, nnz_A, dcoo_row_ind, dcoo_col_ind, dcoo_val, typeI, idx_base, typeT)); // Create dense matrices hipsparseDnMatDescr_t B, C1, C2; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&B, B_m, B_n, ldb, dB, typeT, orderB)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C1, C_m, C_n, ldc, dC_1, typeT, orderC)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C2, C_m, C_n, ldc, dC_2, typeT, orderC)); CHECK_HIPSPARSE_ERROR(hipsparseCooSetStridedBatch(A, batch_count_A, batch_stride_A)); CHECK_HIPSPARSE_ERROR(hipsparseDnMatSetStridedBatch(B, batch_count_B, batch_stride_B)); CHECK_HIPSPARSE_ERROR(hipsparseDnMatSetStridedBatch(C1, batch_count_C, batch_stride_C)); CHECK_HIPSPARSE_ERROR(hipsparseDnMatSetStridedBatch(C2, batch_count_C, batch_stride_C)); // Query SpMM buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSpMM_bufferSize( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, &bufferSize)); #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) //When using cusparse backend, cant pass nullptr for buffer to preprocess if(bufferSize == 0) { bufferSize = 4; } #endif void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); // HIPSPARSE pointer mode host #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSpMM_preprocess( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); #endif // HIPSPARSE pointer mode device #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSpMM_preprocess( handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); #endif if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseSpMM(handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSpMM(handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); // copy output from device to CPU CHECK_HIP_ERROR( hipMemcpy(hC_1.data(), dC_1, sizeof(T) * batch_count_C * nnz_C, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hC_2.data(), dC_2, sizeof(T) * batch_count_C * nnz_C, hipMemcpyDeviceToHost)); // CPU host_coomm_batched(A_m, n, A_n, nnz_A, batch_count_A, (I)batch_stride_A, transA, transB, h_alpha, hrow_ind.data(), hcol_ind.data(), hval.data(), hB.data(), (I)ldb, batch_count_B, (I)batch_stride_B, orderB, h_beta, hC_gold.data(), (I)ldc, batch_count_C, (I)batch_stride_C, orderC, idx_base); unit_check_near(1, batch_count_C * nnz_C, 1, hC_gold.data(), hC_1.data()); unit_check_near(1, batch_count_C * nnz_C, 1, hC_gold.data(), hC_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSpMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSpMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = batch_count_C * spmm_gflop_count(n, nnz_A, (I)C_m * (I)C_n, h_beta != make_DataType(0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gbyte_count = coomm_batched_gbyte_count(A_m, nnz_A, (I)B_m * (I)B_n, (I)C_m * (I)C_n, batch_count_A, batch_count_B, batch_count_C, h_beta != make_DataType(0)); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::K, k, display_key_t::nnzA, nnz_A, display_key_t::batch_countA, batch_count_A, display_key_t::batch_countB, batch_count_B, display_key_t::batch_countC, batch_count_C, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::algorithm, hipsparse_spmmalg2string(alg), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(B)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C2)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPMM_BATCHED_COO_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_spmm_batched_csc.hpp000066400000000000000000000525471501764003400250050ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2022 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPMM_BATCHED_CSC_HPP #define TESTING_SPMM_BATCHED_CSC_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; void testing_spmm_batched_csc_bad_arg(void) { #if(!defined(CUDART_VERSION)) int32_t m = 100; int32_t n = 100; int32_t k = 100; int64_t nnz = 100; float alpha = 0.6; float beta = 0.2; size_t safe_size = 100; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxTypeI = HIPSPARSE_INDEX_64I; hipsparseIndexType_t idxTypeJ = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; #if(CUDART_VERSION >= 11003) hipsparseSpMMAlg_t alg = HIPSPARSE_SPMM_CSR_ALG1; #else hipsparseSpMMAlg_t alg = HIPSPARSE_MM_ALG_DEFAULT; #endif std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int64_t) * safe_size), device_free}; auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dC_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int64_t* dptr = (int64_t*)dptr_managed.get(); int32_t* drow = (int32_t*)drow_managed.get(); float* dval = (float*)dval_managed.get(); float* dB = (float*)dB_managed.get(); float* dC = (float*)dC_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SpMM structures hipsparseSpMatDescr_t A; hipsparseDnMatDescr_t B, C; // Create SpMM structures verify_hipsparse_status_success( hipsparseCreateCsc(&A, m, k, nnz, dptr, drow, dval, idxTypeI, idxTypeJ, idxBase, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&B, k, n, k, dB, dataType, order), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&C, m, n, m, dC, dataType, order), "success"); int batch_count_A; int batch_count_B; int batch_count_C; int64_t offsets_batch_stride_A; int64_t rows_values_batch_stride_A; int64_t batch_stride_B; int64_t batch_stride_C; // C_i = A * B_i batch_count_A = 1; batch_count_B = 10; batch_count_C = 5; offsets_batch_stride_A = 0; rows_values_batch_stride_A = 0; batch_stride_B = k * n; batch_stride_C = m * n; verify_hipsparse_status_success( hipsparseCsrSetStridedBatch( A, batch_count_A, offsets_batch_stride_A, rows_values_batch_stride_A), "success"); verify_hipsparse_status_success(hipsparseDnMatSetStridedBatch(B, batch_count_B, batch_stride_B), "success"); verify_hipsparse_status_success(hipsparseDnMatSetStridedBatch(C, batch_count_C, batch_stride_C), "success"); verify_hipsparse_status_invalid_value( hipsparseSpMM(handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf), "Error: Combination of strided batch parameters is invald"); // C_i = A_i * B batch_count_A = 10; batch_count_B = 1; batch_count_C = 5; offsets_batch_stride_A = (k + 1); rows_values_batch_stride_A = nnz; batch_stride_B = 0; batch_stride_C = m * n; verify_hipsparse_status_success( hipsparseCsrSetStridedBatch( A, batch_count_A, offsets_batch_stride_A, rows_values_batch_stride_A), "success"); verify_hipsparse_status_success(hipsparseDnMatSetStridedBatch(B, batch_count_B, batch_stride_B), "success"); verify_hipsparse_status_success(hipsparseDnMatSetStridedBatch(C, batch_count_C, batch_stride_C), "success"); verify_hipsparse_status_invalid_value( hipsparseSpMM(handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf), "Error: Combination of strided batch parameters is invald"); // C_i = A_i * B_i batch_count_A = 10; batch_count_B = 10; batch_count_C = 5; offsets_batch_stride_A = (k + 1); rows_values_batch_stride_A = nnz; batch_stride_B = k * n; batch_stride_C = m * n; verify_hipsparse_status_success( hipsparseCsrSetStridedBatch( A, batch_count_A, offsets_batch_stride_A, rows_values_batch_stride_A), "success"); verify_hipsparse_status_success(hipsparseDnMatSetStridedBatch(B, batch_count_B, batch_stride_B), "success"); verify_hipsparse_status_success(hipsparseDnMatSetStridedBatch(C, batch_count_C, batch_stride_C), "success"); verify_hipsparse_status_invalid_value( hipsparseSpMM(handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf), "Error: Combination of strided batch parameters is invald"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(B), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(C), "success"); #endif } template hipsparseStatus_t testing_spmm_batched_csc(Arguments argus) { #if(!defined(CUDART_VERSION)) J m = argus.M; J n = argus.N; J k = argus.K; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseOperation_t transB = argus.transB; hipsparseOrder_t orderB = argus.orderB; hipsparseOrder_t orderC = argus.orderC; hipsparseIndexBase_t idx_base = argus.baseA; J batch_count_A = 1; J batch_count_B = 3; J batch_count_C = 3; #if(CUDART_VERSION >= 11003) hipsparseSpMMAlg_t alg = HIPSPARSE_SPMM_CSR_ALG1; #else hipsparseSpMMAlg_t alg = HIPSPARSE_MM_ALG_DEFAULT; #endif std::string filename = argus.filename; #if(defined(CUDART_VERSION)) if(orderB != orderC || orderB != HIPSPARSE_ORDER_COL) { return HIPSPARSE_STATUS_SUCCESS; } #endif // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipsparseIndexType_t typeJ = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hcsc_col_ptr_temp; std::vector hcsc_row_ind_temp; std::vector hcsc_val_temp; // Initial Data on CPU srand(12345ULL); I nnz_A; if(!generate_csr_matrix(filename, (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : m, (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k, nnz_A, hcsc_col_ptr_temp, hcsc_row_ind_temp, hcsc_val_temp, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Some matrix properties J A_m = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k; J A_n = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : m; J B_m = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : n; J B_n = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? n : k; J C_m = m; J C_n = n; int ld_multiplier_B = 1; int ld_multiplier_C = 1; int64_t ldb = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * k) : (int64_t(ld_multiplier_B) * n)) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * n) : (int64_t(ld_multiplier_B) * k)); int64_t ldc = (orderC == HIPSPARSE_ORDER_COL) ? (int64_t(ld_multiplier_C) * m) : (int64_t(ld_multiplier_C) * n); ldb = std::max(int64_t(1), ldb); ldc = std::max(int64_t(1), ldc); int64_t nrowB = (orderB == HIPSPARSE_ORDER_COL) ? ldb : B_m; int64_t ncolB = (orderB == HIPSPARSE_ORDER_COL) ? B_n : ldb; int64_t nrowC = (orderC == HIPSPARSE_ORDER_COL) ? ldc : C_m; int64_t ncolC = (orderC == HIPSPARSE_ORDER_COL) ? C_n : ldc; int64_t nnz_B = nrowB * ncolB; int64_t nnz_C = nrowC * ncolC; int64_t offsets_batch_stride_A = (batch_count_A > 1) ? (A_n + 1) : 0; int64_t rows_values_batch_stride_A = (batch_count_A > 1) ? nnz_A : 0; int64_t batch_stride_B = (batch_count_B > 1) ? nnz_B : 0; int64_t batch_stride_C = (batch_count_C > 1) ? nnz_C : 0; // Allocate host memory for all batches of A matrix std::vector hcsc_col_ptr(batch_count_A * (A_n + 1)); std::vector hcsc_row_ind(batch_count_A * nnz_A); std::vector hcsc_val(batch_count_A * nnz_A); for(J i = 0; i < batch_count_A; i++) { for(J j = 0; j < (A_n + 1); j++) { hcsc_col_ptr[(A_n + 1) * i + j] = hcsc_col_ptr_temp[j]; } for(I j = 0; j < nnz_A; j++) { hcsc_row_ind[nnz_A * i + j] = hcsc_row_ind_temp[j]; hcsc_val[nnz_A * i + j] = hcsc_val_temp[j]; } } // Allocate host memory for vectors std::vector hB(batch_count_B * nnz_B); std::vector hC_1(batch_count_C * nnz_C); std::vector hC_2(batch_count_C * nnz_C); std::vector hC_gold(batch_count_C * nnz_C); hipsparseInit(hB, batch_count_B * nnz_B, 1); hipsparseInit(hC_1, batch_count_C * nnz_C, 1); // copy vector is easy in STL; hC_gold = hC: save a copy in hy_gold which will be output of CPU hC_2 = hC_1; hC_gold = hC_1; // allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (A_n + 1)), device_free}; auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz_A), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_A), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * batch_count_B * nnz_B), device_free}; auto dC_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * batch_count_C * nnz_C), device_free}; auto dC_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * batch_count_C * nnz_C), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* dptr = (I*)dptr_managed.get(); J* drow = (J*)drow_managed.get(); T* dval = (T*)dval_managed.get(); T* dB = (T*)dB_managed.get(); T* dC_1 = (T*)dC_1_managed.get(); T* dC_2 = (T*)dC_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsc_col_ptr.data(), sizeof(I) * (A_n + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(drow, hcsc_row_ind.data(), sizeof(J) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hcsc_val.data(), sizeof(T) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dB, hB.data(), sizeof(T) * batch_count_B * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dC_1, hC_1.data(), sizeof(T) * batch_count_C * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dC_2, hC_2.data(), sizeof(T) * batch_count_C * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t A; CHECK_HIPSPARSE_ERROR( hipsparseCreateCsc(&A, A_m, A_n, nnz_A, dptr, drow, dval, typeI, typeJ, idx_base, typeT)); // Create dense matrices hipsparseDnMatDescr_t B, C1, C2; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&B, B_m, B_n, ldb, dB, typeT, orderB)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C1, C_m, C_n, ldc, dC_1, typeT, orderC)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C2, C_m, C_n, ldc, dC_2, typeT, orderC)); CHECK_HIPSPARSE_ERROR(hipsparseCsrSetStridedBatch( A, batch_count_A, offsets_batch_stride_A, rows_values_batch_stride_A)); CHECK_HIPSPARSE_ERROR(hipsparseDnMatSetStridedBatch(B, batch_count_B, batch_stride_B)); CHECK_HIPSPARSE_ERROR(hipsparseDnMatSetStridedBatch(C1, batch_count_C, batch_stride_C)); CHECK_HIPSPARSE_ERROR(hipsparseDnMatSetStridedBatch(C2, batch_count_C, batch_stride_C)); // Query SpMM buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSpMM_bufferSize( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, &bufferSize)); #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) //When using cusparse backend, cant pass nullptr for buffer to preprocess if(bufferSize == 0) { bufferSize = 4; } #endif void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); // HIPSPARSE pointer mode host #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSpMM_preprocess( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); #endif // HIPSPARSE pointer mode device #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSpMM_preprocess( handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); #endif if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseSpMM(handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSpMM(handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); // copy output from device to CPU CHECK_HIP_ERROR( hipMemcpy(hC_1.data(), dC_1, sizeof(T) * batch_count_C * nnz_C, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hC_2.data(), dC_2, sizeof(T) * batch_count_C * nnz_C, hipMemcpyDeviceToHost)); // CPU host_cscmm_batched(A_m, n, A_n, batch_count_A, (I)offsets_batch_stride_A, (I)rows_values_batch_stride_A, transA, transB, h_alpha, hcsc_col_ptr.data(), hcsc_row_ind.data(), hcsc_val.data(), hB.data(), (J)ldb, batch_count_B, (I)batch_stride_B, orderB, h_beta, hC_gold.data(), (J)ldc, batch_count_C, (I)batch_stride_C, orderC, idx_base); unit_check_near(1, batch_count_C * nnz_C, 1, hC_gold.data(), hC_1.data()); unit_check_near(1, batch_count_C * nnz_C, 1, hC_gold.data(), hC_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSpMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSpMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = batch_count_C * spmm_gflop_count(n, nnz_A, (I)C_m * (I)C_n, h_beta != make_DataType(0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gbyte_count = cscmm_batched_gbyte_count(A_n, nnz_A, (I)B_m * (I)B_n, (I)C_m * (I)C_n, batch_count_A, batch_count_B, batch_count_C, h_beta != make_DataType(0)); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::K, k, display_key_t::nnzA, nnz_A, display_key_t::batch_countA, batch_count_A, display_key_t::batch_countB, batch_count_B, display_key_t::batch_countC, batch_count_C, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::algorithm, hipsparse_spmmalg2string(alg), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(B)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C2)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPMM_BATCHED_CSC_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_spmm_batched_csr.hpp000066400000000000000000000526761501764003400250270ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2022 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPMM_BATCHED_CSR_HPP #define TESTING_SPMM_BATCHED_CSR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; void testing_spmm_batched_csr_bad_arg(void) { #if(!defined(CUDART_VERSION)) int32_t m = 100; int32_t n = 100; int32_t k = 100; int64_t nnz = 100; float alpha = 0.6; float beta = 0.2; size_t safe_size = 100; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxTypeI = HIPSPARSE_INDEX_64I; hipsparseIndexType_t idxTypeJ = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; #if(CUDART_VERSION >= 11003) hipsparseSpMMAlg_t alg = HIPSPARSE_SPMM_CSR_ALG1; #else hipsparseSpMMAlg_t alg = HIPSPARSE_MM_ALG_DEFAULT; #endif std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int64_t) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dC_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int64_t* dptr = (int64_t*)dptr_managed.get(); int32_t* dcol = (int32_t*)dcol_managed.get(); float* dval = (float*)dval_managed.get(); float* dB = (float*)dB_managed.get(); float* dC = (float*)dC_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SpMM structures hipsparseSpMatDescr_t A; hipsparseDnMatDescr_t B, C; // Create SpMM structures verify_hipsparse_status_success( hipsparseCreateCsr(&A, m, k, nnz, dptr, dcol, dval, idxTypeI, idxTypeJ, idxBase, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&B, k, n, k, dB, dataType, order), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&C, m, n, m, dC, dataType, order), "success"); int batch_count_A; int batch_count_B; int batch_count_C; int64_t offsets_batch_stride_A; int64_t columns_values_batch_stride_A; int64_t batch_stride_B; int64_t batch_stride_C; // C_i = A * B_i batch_count_A = 1; batch_count_B = 10; batch_count_C = 5; offsets_batch_stride_A = 0; columns_values_batch_stride_A = 0; batch_stride_B = k * n; batch_stride_C = m * n; verify_hipsparse_status_success( hipsparseCsrSetStridedBatch( A, batch_count_A, offsets_batch_stride_A, columns_values_batch_stride_A), "success"); verify_hipsparse_status_success(hipsparseDnMatSetStridedBatch(B, batch_count_B, batch_stride_B), "success"); verify_hipsparse_status_success(hipsparseDnMatSetStridedBatch(C, batch_count_C, batch_stride_C), "success"); verify_hipsparse_status_invalid_value( hipsparseSpMM(handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf), "Error: Combination of strided batch parameters is invald"); // C_i = A_i * B batch_count_A = 10; batch_count_B = 1; batch_count_C = 5; offsets_batch_stride_A = (m + 1); columns_values_batch_stride_A = nnz; batch_stride_B = 0; batch_stride_C = m * n; verify_hipsparse_status_success( hipsparseCsrSetStridedBatch( A, batch_count_A, offsets_batch_stride_A, columns_values_batch_stride_A), "success"); verify_hipsparse_status_success(hipsparseDnMatSetStridedBatch(B, batch_count_B, batch_stride_B), "success"); verify_hipsparse_status_success(hipsparseDnMatSetStridedBatch(C, batch_count_C, batch_stride_C), "success"); verify_hipsparse_status_invalid_value( hipsparseSpMM(handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf), "Error: Combination of strided batch parameters is invald"); // C_i = A_i * B_i batch_count_A = 10; batch_count_B = 10; batch_count_C = 5; offsets_batch_stride_A = (m + 1); columns_values_batch_stride_A = nnz; batch_stride_B = k * n; batch_stride_C = m * n; verify_hipsparse_status_success( hipsparseCsrSetStridedBatch( A, batch_count_A, offsets_batch_stride_A, columns_values_batch_stride_A), "success"); verify_hipsparse_status_success(hipsparseDnMatSetStridedBatch(B, batch_count_B, batch_stride_B), "success"); verify_hipsparse_status_success(hipsparseDnMatSetStridedBatch(C, batch_count_C, batch_stride_C), "success"); verify_hipsparse_status_invalid_value( hipsparseSpMM(handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf), "Error: Combination of strided batch parameters is invald"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(B), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(C), "success"); #endif } template hipsparseStatus_t testing_spmm_batched_csr(Arguments argus) { #if(!defined(CUDART_VERSION)) J m = argus.M; J n = argus.N; J k = argus.K; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseOperation_t transB = argus.transB; hipsparseOrder_t orderB = argus.orderB; hipsparseOrder_t orderC = argus.orderC; hipsparseIndexBase_t idx_base = argus.baseA; J batch_count_A = 1; J batch_count_B = 3; J batch_count_C = 3; #if(CUDART_VERSION >= 11003) hipsparseSpMMAlg_t alg = HIPSPARSE_SPMM_CSR_ALG1; #else hipsparseSpMMAlg_t alg = HIPSPARSE_MM_ALG_DEFAULT; #endif std::string filename = argus.filename; #if(defined(CUDART_VERSION)) if(orderB != orderC || orderB != HIPSPARSE_ORDER_COL) { return HIPSPARSE_STATUS_SUCCESS; } #endif // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipsparseIndexType_t typeJ = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hcsr_row_ptr_temp; std::vector hcsr_col_ind_temp; std::vector hcsr_val_temp; // Initial Data on CPU srand(12345ULL); I nnz_A; if(!generate_csr_matrix(filename, (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k, (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : m, nnz_A, hcsr_row_ptr_temp, hcsr_col_ind_temp, hcsr_val_temp, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Some matrix properties J A_m = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k; J A_n = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : m; J B_m = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : n; J B_n = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? n : k; J C_m = m; J C_n = n; int ld_multiplier_B = 1; int ld_multiplier_C = 1; int64_t ldb = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * k) : (int64_t(ld_multiplier_B) * n)) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * n) : (int64_t(ld_multiplier_B) * k)); int64_t ldc = (orderC == HIPSPARSE_ORDER_COL) ? (int64_t(ld_multiplier_C) * m) : (int64_t(ld_multiplier_C) * n); ldb = std::max(int64_t(1), ldb); ldc = std::max(int64_t(1), ldc); int64_t nrowB = (orderB == HIPSPARSE_ORDER_COL) ? ldb : B_m; int64_t ncolB = (orderB == HIPSPARSE_ORDER_COL) ? B_n : ldb; int64_t nrowC = (orderC == HIPSPARSE_ORDER_COL) ? ldc : C_m; int64_t ncolC = (orderC == HIPSPARSE_ORDER_COL) ? C_n : ldc; int64_t nnz_B = nrowB * ncolB; int64_t nnz_C = nrowC * ncolC; int64_t offsets_batch_stride_A = (batch_count_A > 1) ? (A_m + 1) : 0; int64_t columns_values_batch_stride_A = (batch_count_A > 1) ? nnz_A : 0; int64_t batch_stride_B = (batch_count_B > 1) ? nnz_B : 0; int64_t batch_stride_C = (batch_count_C > 1) ? nnz_C : 0; // Allocate host memory for all batches of A matrix std::vector hcsr_row_ptr(batch_count_A * (A_m + 1)); std::vector hcsr_col_ind(batch_count_A * nnz_A); std::vector hcsr_val(batch_count_A * nnz_A); for(J i = 0; i < batch_count_A; i++) { for(J j = 0; j < (A_m + 1); j++) { hcsr_row_ptr[(A_m + 1) * i + j] = hcsr_row_ptr_temp[j]; } for(I j = 0; j < nnz_A; j++) { hcsr_col_ind[nnz_A * i + j] = hcsr_col_ind_temp[j]; hcsr_val[nnz_A * i + j] = hcsr_val_temp[j]; } } std::vector hB(batch_count_B * nnz_B); std::vector hC_1(batch_count_C * nnz_C); std::vector hC_2(batch_count_C * nnz_C); std::vector hC_gold(batch_count_C * nnz_C); hipsparseInit(hB, batch_count_B * nnz_B, 1); hipsparseInit(hC_1, batch_count_C * nnz_C, 1); // copy vector is easy in STL; hC_gold = hC: save a copy in hy_gold which will be output of CPU hC_2 = hC_1; hC_gold = hC_1; // allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (A_m + 1)), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz_A), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_A), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * batch_count_B * nnz_B), device_free}; auto dC_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * batch_count_C * nnz_C), device_free}; auto dC_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * batch_count_C * nnz_C), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* dptr = (I*)dptr_managed.get(); J* dcol = (J*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dB = (T*)dB_managed.get(); T* dC_1 = (T*)dC_1_managed.get(); T* dC_2 = (T*)dC_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsr_row_ptr.data(), sizeof(I) * (A_m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcsr_col_ind.data(), sizeof(J) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hcsr_val.data(), sizeof(T) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dB, hB.data(), sizeof(T) * batch_count_B * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dC_1, hC_1.data(), sizeof(T) * batch_count_C * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dC_2, hC_2.data(), sizeof(T) * batch_count_C * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t A; CHECK_HIPSPARSE_ERROR( hipsparseCreateCsr(&A, A_m, A_n, nnz_A, dptr, dcol, dval, typeI, typeJ, idx_base, typeT)); // Create dense matrices hipsparseDnMatDescr_t B, C1, C2; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&B, B_m, B_n, ldb, dB, typeT, orderB)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C1, C_m, C_n, ldc, dC_1, typeT, orderC)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C2, C_m, C_n, ldc, dC_2, typeT, orderC)); CHECK_HIPSPARSE_ERROR(hipsparseCsrSetStridedBatch( A, batch_count_A, offsets_batch_stride_A, columns_values_batch_stride_A)); CHECK_HIPSPARSE_ERROR(hipsparseDnMatSetStridedBatch(B, batch_count_B, batch_stride_B)); CHECK_HIPSPARSE_ERROR(hipsparseDnMatSetStridedBatch(C1, batch_count_C, batch_stride_C)); CHECK_HIPSPARSE_ERROR(hipsparseDnMatSetStridedBatch(C2, batch_count_C, batch_stride_C)); // Query SpMM buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSpMM_bufferSize( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, &bufferSize)); #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) //When using cusparse backend, cant pass nullptr for buffer to preprocess if(bufferSize == 0) { bufferSize = 4; } #endif void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); // HIPSPARSE pointer mode host #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSpMM_preprocess( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); #endif // HIPSPARSE pointer mode device #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSpMM_preprocess( handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); #endif if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseSpMM(handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSpMM(handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); // copy output from device to CPU CHECK_HIP_ERROR( hipMemcpy(hC_1.data(), dC_1, sizeof(T) * batch_count_C * nnz_C, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hC_2.data(), dC_2, sizeof(T) * batch_count_C * nnz_C, hipMemcpyDeviceToHost)); // CPU host_csrmm_batched(A_m, n, A_n, batch_count_A, (I)offsets_batch_stride_A, (I)columns_values_batch_stride_A, transA, transB, h_alpha, hcsr_row_ptr.data(), hcsr_col_ind.data(), hcsr_val.data(), hB.data(), (J)ldb, batch_count_B, (I)batch_stride_B, orderB, h_beta, hC_gold.data(), (J)ldc, batch_count_C, (I)batch_stride_C, orderC, idx_base, false); unit_check_near(1, batch_count_C * nnz_C, 1, hC_gold.data(), hC_1.data()); unit_check_near(1, batch_count_C * nnz_C, 1, hC_gold.data(), hC_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSpMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSpMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = batch_count_C * spmm_gflop_count(n, nnz_A, (I)C_m * (I)C_n, h_beta != make_DataType(0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gbyte_count = csrmm_batched_gbyte_count(A_m, nnz_A, (I)B_m * (I)B_n, (I)C_m * (I)C_n, batch_count_A, batch_count_B, batch_count_C, h_beta != make_DataType(0)); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::K, k, display_key_t::nnzA, nnz_A, display_key_t::batch_countA, batch_count_A, display_key_t::batch_countB, batch_count_B, display_key_t::batch_countC, batch_count_C, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::algorithm, hipsparse_spmmalg2string(alg), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(B)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C2)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPMM_BATCHED_CSR_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_spmm_bell.hpp000066400000000000000000000434561501764003400235000ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPMM_BELL_HPP #define TESTING_SPMM_BELL_HPP #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; void testing_spmm_bell_bad_arg(void) { #if(!defined(CUDART_VERSION)) int32_t n = 100; int32_t m = 100; int32_t k = 100; int32_t ell_blocksize = 2; int32_t ell_cols = 10; int32_t safe_size = 100; float alpha = 0.6; float beta = 0.2; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; hipsparseSpMMAlg_t alg = HIPSPARSE_SPMM_BLOCKED_ELL_ALG1; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dC_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int32_t* dind = (int32_t*)dind_managed.get(); float* dval = (float*)dval_managed.get(); float* dB = (float*)dB_managed.get(); float* dC = (float*)dC_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SpMM structures hipsparseSpMatDescr_t A; hipsparseDnMatDescr_t B, C; size_t bsize; // Create SpMM structures verify_hipsparse_status_success( hipsparseCreateBlockedEll( &A, m, k, ell_blocksize, ell_cols, dind, dval, idxType, idxBase, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&B, k, n, k, dB, dataType, order), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&C, m, n, m, dC, dataType, order), "success"); // SpMM buffer verify_hipsparse_status_invalid_handle(hipsparseSpMM_bufferSize( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, &bsize), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, &bsize), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, &bsize), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, &bsize), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, &bsize), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, nullptr), "Error: bsize is nullptr"); // SpMM_preprocess verify_hipsparse_status_invalid_handle(hipsparseSpMM_preprocess( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // SpMM verify_hipsparse_status_invalid_handle( hipsparseSpMM(nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(B), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(C), "success"); #endif } template hipsparseStatus_t testing_spmm_bell() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) std::vector hval = {make_DataType(1.0), make_DataType(2.0), make_DataType(3.0), make_DataType(4.0), make_DataType(5.0), make_DataType(6.0), make_DataType(7.0), make_DataType(8.0), make_DataType(9.0), make_DataType(10.0), make_DataType(11.0), make_DataType(12.0), make_DataType(13.0), make_DataType(14.0), make_DataType(15.0), make_DataType(16.0)}; std::vector hcol_ind = {1, 2, 1, 2, 1, 2, 3, 4, 1, 2, 3, 4, 5, 6, 5, 6}; std::vector hrow_ptr = {1, 3, 5, 9, 13, 15, 17}; std::vector hbell_val = {make_DataType(1.0), make_DataType(2.0), make_DataType(3.0), make_DataType(4.0), make_DataType(-7.0), make_DataType(-7.0), make_DataType(-7.0), make_DataType(-7.0), make_DataType(5.0), make_DataType(6.0), make_DataType(7.0), make_DataType(8.0), make_DataType(9.0), make_DataType(10.0), make_DataType(11.0), make_DataType(12.0), make_DataType(13.0), make_DataType(14.0), make_DataType(15.0), make_DataType(16.0), make_DataType(-7.0), make_DataType(-7.0), make_DataType(-7.0), make_DataType(-7.0)}; std::vector hbell_ind = {1, 0, 1, 2, 3, 0}; I ell_cols = 4; I ell_blocksize = 2; I m = 6; I k = 6; I nnz = 16; I n = 2; I ldb = k; I ldc = m; T h_alpha = make_DataType(2.0); T h_beta = make_DataType(1.0); hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ONE; hipsparseSpMMAlg_t alg = HIPSPARSE_SPMM_BLOCKED_ELL_ALG1; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::vector hB = {make_DataType(1.0), make_DataType(1.0), make_DataType(-1.0), make_DataType(2.0), make_DataType(1.0), make_DataType(3.0), make_DataType(-1.0), make_DataType(4.0), make_DataType(1.0), make_DataType(5.0), make_DataType(-1.0), make_DataType(6.0)}; std::vector hC_1 = {make_DataType(1.0), make_DataType(1.0), make_DataType(-1.0), make_DataType(2.0), make_DataType(1.0), make_DataType(3.0), make_DataType(-1.0), make_DataType(4.0), make_DataType(1.0), make_DataType(5.0), make_DataType(-1.0), make_DataType(6.0)}; std::vector hC_gold = {make_DataType(35.0), make_DataType(41.0), make_DataType(115.0), make_DataType(126.0), make_DataType(25.0), make_DataType(31.0), make_DataType(149.0), make_DataType(172.0), make_DataType(155.0), make_DataType(169.0), make_DataType(45.0), make_DataType(58.0)}; std::vector hC_2(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(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(drow_ptr, hrow_ptr.data(), sizeof(I) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol_ind, hcol_ind.data(), sizeof(I) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hval.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * k * n, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_1, hC_1.data(), sizeof(T) * m * n, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_2, hC_2.data(), sizeof(T) * m * n, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dbell_ind, hbell_ind.data(), sizeof(I) * (ell_cols / ell_blocksize) * (m / ell_blocksize), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dbell_val, hbell_val.data(), sizeof(T) * ell_cols * m, hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t A_bell; CHECK_HIPSPARSE_ERROR(hipsparseCreateBlockedEll( &A_bell, m, k, ell_blocksize, ell_cols, dbell_ind, dbell_val, typeI, idx_base, typeT)); hipsparseSpMatDescr_t A_csr; CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr( &A_csr, m, k, nnz, drow_ptr, dcol_ind, dval, typeI, typeI, idx_base, typeT)); // Create dense matrices hipsparseDnMatDescr_t B, C1, C2; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&B, k, n, ldb, dB, typeT, order)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C1, m, n, ldc, dC_1, typeT, order)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C2, m, n, ldc, dC_2, typeT, order)); // Query SpMM buffer size_t bufferSize_bell; CHECK_HIPSPARSE_ERROR(hipsparseSpMM_bufferSize( handle, transA, transB, &h_alpha, A_bell, B, &h_beta, C1, typeT, alg, &bufferSize_bell)); void* buffer_bell; CHECK_HIP_ERROR(hipMalloc(&buffer_bell, bufferSize_bell)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) CHECK_HIPSPARSE_ERROR(hipsparseSpMM_preprocess( handle, transA, transB, &h_alpha, A_bell, B, &h_beta, C1, typeT, alg, buffer_bell)); #endif CHECK_HIPSPARSE_ERROR(hipsparseSpMM( handle, transA, transB, &h_alpha, A_bell, B, &h_beta, C1, typeT, alg, buffer_bell)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) CHECK_HIPSPARSE_ERROR(hipsparseSpMM_preprocess( handle, transA, transB, d_alpha, A_bell, B, d_beta, C2, typeT, alg, buffer_bell)); #endif CHECK_HIPSPARSE_ERROR(hipsparseSpMM( handle, transA, transB, d_alpha, A_bell, B, d_beta, C2, typeT, alg, buffer_bell)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hC_1.data(), dC_1, sizeof(T) * m * n, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hC_2.data(), dC_2, sizeof(T) * m * n, hipMemcpyDeviceToHost)); unit_check_near(1, m * n, 1, hC_gold.data(), hC_1.data()); unit_check_near(1, m * n, 1, hC_gold.data(), hC_2.data()); CHECK_HIP_ERROR(hipFree(buffer_bell)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A_csr)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A_bell)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(B)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C2)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPMM_BELL_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_spmm_coo.hpp000066400000000000000000000465671501764003400233500ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPMM_COO_HPP #define TESTING_SPMM_COO_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; void testing_spmm_coo_bad_arg(void) { #if(!defined(CUDART_VERSION)) int32_t n = 100; int32_t m = 100; int32_t k = 100; int32_t nnz = 100; int32_t safe_size = 100; float alpha = 0.6; float beta = 0.2; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; // // ! // #if(CUDART_VERSION >= 11003) hipsparseSpMMAlg_t alg = HIPSPARSE_SPMM_COO_ALG1; #else hipsparseSpMMAlg_t alg = HIPSPARSE_MM_ALG_DEFAULT; #endif std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dC_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int32_t* drow = (int32_t*)drow_managed.get(); int32_t* dcol = (int32_t*)dcol_managed.get(); float* dval = (float*)dval_managed.get(); float* dB = (float*)dB_managed.get(); float* dC = (float*)dC_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SpMM structures hipsparseSpMatDescr_t A; hipsparseDnMatDescr_t B, C; size_t bsize; // Create SpMM structures verify_hipsparse_status_success( hipsparseCreateCoo(&A, m, k, nnz, drow, dcol, dval, idxType, idxBase, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&B, k, n, k, dB, dataType, order), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&C, m, n, m, dC, dataType, order), "success"); // SpMM buffer verify_hipsparse_status_invalid_handle(hipsparseSpMM_bufferSize( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, &bsize), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, &bsize), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, &bsize), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, &bsize), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, &bsize), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, nullptr), "Error: bsize is nullptr"); #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) // SpMM_preprocess verify_hipsparse_status_invalid_handle(hipsparseSpMM_preprocess( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); #endif // SpMM verify_hipsparse_status_invalid_handle( hipsparseSpMM(nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(B), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(C), "success"); #endif } template hipsparseStatus_t testing_spmm_coo(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) I m = argus.M; I n = argus.N; I k = argus.K; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseOperation_t transB = argus.transB; hipsparseOrder_t orderB = argus.orderB; hipsparseOrder_t orderC = argus.orderC; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseSpMMAlg_t alg = static_cast(argus.spmm_alg); std::string filename = argus.filename; #if(defined(CUDART_VERSION)) if(orderB != orderC || orderB != HIPSPARSE_ORDER_COL) { return HIPSPARSE_STATUS_SUCCESS; } #endif // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hrow_ptr; std::vector hcol_ind; std::vector hval; // Initial Data on CPU srand(12345ULL); I nnz_A; if(!generate_csr_matrix(filename, (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k, (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : m, nnz_A, hrow_ptr, hcol_ind, hval, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hrow_ind(nnz_A); // Convert to COO I mk = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k; for(I i = 0; i < mk; ++i) { for(I j = hrow_ptr[i]; j < hrow_ptr[i + 1]; ++j) { hrow_ind[j - idx_base] = i + idx_base; } } // Some matrix properties I A_m = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k; I A_n = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : m; I B_m = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : n; I B_n = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? n : k; I C_m = m; I C_n = n; int ld_multiplier_B = 1; int ld_multiplier_C = 1; int64_t ldb = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * k) : (int64_t(ld_multiplier_B) * n)) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * n) : (int64_t(ld_multiplier_B) * k)); int64_t ldc = (orderC == HIPSPARSE_ORDER_COL) ? (int64_t(ld_multiplier_C) * m) : (int64_t(ld_multiplier_C) * n); ldb = std::max(int64_t(1), ldb); ldc = std::max(int64_t(1), ldc); int64_t nrowB = (orderB == HIPSPARSE_ORDER_COL) ? ldb : B_m; int64_t ncolB = (orderB == HIPSPARSE_ORDER_COL) ? B_n : ldb; int64_t nrowC = (orderC == HIPSPARSE_ORDER_COL) ? ldc : C_m; int64_t ncolC = (orderC == HIPSPARSE_ORDER_COL) ? C_n : ldc; int64_t nnz_B = nrowB * ncolB; int64_t nnz_C = nrowC * ncolC; std::vector hB(nnz_B); std::vector hC_1(nnz_C); std::vector hC_2(nnz_C); std::vector hC_gold(nnz_C); hipsparseInit(hB, nnz_B, 1); hipsparseInit(hC_1, nnz_C, 1); // copy vector is easy in STL; hC_gold = hB: save a copy in hy_gold which will be output of CPU hC_2 = hC_1; hC_gold = hC_1; // allocate memory on device auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz_A), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz_A), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_A), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_B), device_free}; auto dC_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_C), device_free}; auto dC_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_C), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* drow = (I*)drow_managed.get(); I* dcol = (I*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dB = (T*)dB_managed.get(); T* dC_1 = (T*)dC_1_managed.get(); T* dC_2 = (T*)dC_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(drow, hrow_ind.data(), sizeof(I) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcol_ind.data(), sizeof(I) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hval.data(), sizeof(T) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_1, hC_1.data(), sizeof(T) * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_2, hC_2.data(), sizeof(T) * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t A; CHECK_HIPSPARSE_ERROR( hipsparseCreateCoo(&A, A_m, A_n, nnz_A, drow, dcol, dval, typeI, idx_base, typeT)); // Create dense matrices hipsparseDnMatDescr_t B, C1, C2; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&B, B_m, B_n, ldb, dB, typeT, orderB)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C1, C_m, C_n, ldc, dC_1, typeT, orderC)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C2, C_m, C_n, ldc, dC_2, typeT, orderC)); // Query SpMM buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSpMM_bufferSize( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, &bufferSize)); #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) //When using cusparse backend, cant pass nullptr for buffer to preprocess if(bufferSize == 0) { bufferSize = 4; } #endif void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); // HIPSPARSE pointer mode host #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSpMM_preprocess( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); #endif // HIPSPARSE pointer mode device #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSpMM_preprocess( handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); #endif if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseSpMM(handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSpMM(handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hC_1.data(), dC_1, sizeof(T) * nnz_C, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hC_2.data(), dC_2, sizeof(T) * nnz_C, hipMemcpyDeviceToHost)); // CPU host_coomm(A_m, n, A_n, nnz_A, transA, transB, h_alpha, hrow_ind.data(), hcol_ind.data(), hval.data(), hB.data(), (I)ldb, orderB, h_beta, hC_gold.data(), (I)ldc, orderC, idx_base); unit_check_near(1, nnz_C, 1, hC_gold.data(), hC_1.data()); unit_check_near(1, nnz_C, 1, hC_gold.data(), hC_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSpMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSpMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = spmm_gflop_count(n, nnz_A, (I)C_m * (I)C_n, h_beta != make_DataType(0)); double gbyte_count = coomm_gbyte_count( nnz_A, (I)B_m * (I)B_n, (I)C_m * (I)C_n, h_beta != make_DataType(0)); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::K, k, display_key_t::nnzA, nnz_A, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::algorithm, hipsparse_spmmalg2string(alg), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(B)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C2)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPMM_COO_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_spmm_csc.hpp000066400000000000000000000464321501764003400233270ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPMM_CSC_HPP #define TESTING_SPMM_CSC_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; void testing_spmm_csc_bad_arg(void) { #if(!defined(CUDART_VERSION)) int32_t m = 100; int32_t n = 100; int32_t k = 100; int64_t nnz = 100; int32_t safe_size = 100; float alpha = 0.6; float beta = 0.2; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxTypeI = HIPSPARSE_INDEX_64I; hipsparseIndexType_t idxTypeJ = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; #if(CUDART_VERSION >= 11003) hipsparseSpMMAlg_t alg = HIPSPARSE_SPMM_CSR_ALG1; #else hipsparseSpMMAlg_t alg = HIPSPARSE_MM_ALG_DEFAULT; #endif std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int64_t) * safe_size), device_free}; auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dC_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int64_t* dptr = (int64_t*)dptr_managed.get(); int32_t* drow = (int32_t*)drow_managed.get(); float* dval = (float*)dval_managed.get(); float* dB = (float*)dB_managed.get(); float* dC = (float*)dC_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SpMM structures hipsparseSpMatDescr_t A; hipsparseDnMatDescr_t B, C; size_t bsize; // Create SpMM structures verify_hipsparse_status_success( hipsparseCreateCsc(&A, m, k, nnz, dptr, drow, dval, idxTypeI, idxTypeJ, idxBase, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&B, k, n, k, dB, dataType, order), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&C, m, n, m, dC, dataType, order), "success"); // SpMM buffer verify_hipsparse_status_invalid_handle(hipsparseSpMM_bufferSize( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, &bsize), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, &bsize), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, &bsize), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, &bsize), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, &bsize), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, nullptr), "Error: bsize is nullptr"); #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) // SpMM_preprocess verify_hipsparse_status_invalid_handle(hipsparseSpMM_preprocess( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); #endif // SpMM verify_hipsparse_status_invalid_handle( hipsparseSpMM(nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(B), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(C), "success"); #endif } template hipsparseStatus_t testing_spmm_csc(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11061) J m = argus.M; J n = argus.N; J k = argus.K; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseOperation_t transB = argus.transB; hipsparseOrder_t orderB = argus.orderB; hipsparseOrder_t orderC = argus.orderC; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseSpMMAlg_t alg = static_cast(argus.spmm_alg); std::string filename = argus.filename; #if(defined(CUDART_VERSION)) if(orderB != orderC || orderB != HIPSPARSE_ORDER_COL) { return HIPSPARSE_STATUS_SUCCESS; } #endif // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipsparseIndexType_t typeJ = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hcsc_col_ptr; std::vector hcsc_row_ind; std::vector hcsc_val; // Initial Data on CPU srand(12345ULL); I nnz_A; if(!generate_csr_matrix(filename, (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : m, (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k, nnz_A, hcsc_col_ptr, hcsc_row_ind, hcsc_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Some matrix properties J A_m = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k; J A_n = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : m; J B_m = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : n; J B_n = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? n : k; J C_m = m; J C_n = n; int ld_multiplier_B = 1; int ld_multiplier_C = 1; int64_t ldb = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * k) : (int64_t(ld_multiplier_B) * n)) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * n) : (int64_t(ld_multiplier_B) * k)); int64_t ldc = (orderC == HIPSPARSE_ORDER_COL) ? (int64_t(ld_multiplier_C) * m) : (int64_t(ld_multiplier_C) * n); ldb = std::max(int64_t(1), ldb); ldc = std::max(int64_t(1), ldc); int64_t nrowB = (orderB == HIPSPARSE_ORDER_COL) ? ldb : B_m; int64_t ncolB = (orderB == HIPSPARSE_ORDER_COL) ? B_n : ldb; int64_t nrowC = (orderC == HIPSPARSE_ORDER_COL) ? ldc : C_m; int64_t ncolC = (orderC == HIPSPARSE_ORDER_COL) ? C_n : ldc; int64_t nnz_B = nrowB * ncolB; int64_t nnz_C = nrowC * ncolC; // Allocate host memory for vectors std::vector hB(nnz_B); std::vector hC_1(nnz_C); std::vector hC_2(nnz_C); std::vector hC_gold(nnz_C); hipsparseInit(hB, nnz_B, 1); hipsparseInit(hC_1, nnz_C, 1); // copy vector is easy in STL; hC_gold = hB: save a copy in hy_gold which will be output of CPU hC_2 = hC_1; hC_gold = hC_1; // allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (A_n + 1)), device_free}; auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz_A), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_A), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_B), device_free}; auto dC_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_C), device_free}; auto dC_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_C), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* dptr = (I*)dptr_managed.get(); J* drow = (J*)drow_managed.get(); T* dval = (T*)dval_managed.get(); T* dB = (T*)dB_managed.get(); T* dC_1 = (T*)dC_1_managed.get(); T* dC_2 = (T*)dC_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsc_col_ptr.data(), sizeof(I) * (A_n + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(drow, hcsc_row_ind.data(), sizeof(J) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hcsc_val.data(), sizeof(T) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_1, hC_1.data(), sizeof(T) * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_2, hC_2.data(), sizeof(T) * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t A; CHECK_HIPSPARSE_ERROR( hipsparseCreateCsc(&A, A_m, A_n, nnz_A, dptr, drow, dval, typeI, typeJ, idx_base, typeT)); // Create dense matrices hipsparseDnMatDescr_t B, C1, C2; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&B, B_m, B_n, ldb, dB, typeT, orderB)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C1, C_m, C_n, ldc, dC_1, typeT, orderC)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C2, C_m, C_n, ldc, dC_2, typeT, orderC)); // Query SpMM buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSpMM_bufferSize( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, &bufferSize)); #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) //When using cusparse backend, cant pass nullptr for buffer to preprocess if(bufferSize == 0) { bufferSize = 4; } #endif void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); // HIPSPARSE pointer mode host #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSpMM_preprocess( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); #endif // HIPSPARSE pointer mode device #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSpMM_preprocess( handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); #endif if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseSpMM(handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSpMM(handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hC_1.data(), dC_1, sizeof(T) * nnz_C, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hC_2.data(), dC_2, sizeof(T) * nnz_C, hipMemcpyDeviceToHost)); // CPU host_cscmm(A_m, n, A_n, transA, transB, h_alpha, hcsc_col_ptr.data(), hcsc_row_ind.data(), hcsc_val.data(), hB.data(), (J)ldb, orderB, h_beta, hC_gold.data(), (J)ldc, orderC, idx_base); unit_check_near(1, nnz_C, 1, hC_gold.data(), hC_1.data()); unit_check_near(1, nnz_C, 1, hC_gold.data(), hC_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSpMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSpMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = spmm_gflop_count(n, nnz_A, (I)C_m * (I)C_n, h_beta != make_DataType(0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gbyte_count = cscmm_gbyte_count( A_n, nnz_A, (I)B_m * (I)B_n, (I)C_m * (I)C_n, h_beta != make_DataType(0)); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::K, k, display_key_t::nnzA, nnz_A, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::algorithm, hipsparse_spmmalg2string(alg), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(B)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C2)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPMM_CSC_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_spmm_csr.hpp000066400000000000000000000463461501764003400233520ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPMM_CSR_HPP #define TESTING_SPMM_CSR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; void testing_spmm_csr_bad_arg(void) { #if(!defined(CUDART_VERSION)) int32_t m = 100; int32_t n = 100; int32_t k = 100; int64_t nnz = 100; int32_t safe_size = 100; float alpha = 0.6; float beta = 0.2; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxTypeI = HIPSPARSE_INDEX_64I; hipsparseIndexType_t idxTypeJ = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; // // ! // #if(CUDART_VERSION >= 11003) hipsparseSpMMAlg_t alg = HIPSPARSE_SPMM_CSR_ALG1; #else hipsparseSpMMAlg_t alg = HIPSPARSE_MM_ALG_DEFAULT; #endif std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int64_t) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dC_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int64_t* dptr = (int64_t*)dptr_managed.get(); int32_t* dcol = (int32_t*)dcol_managed.get(); float* dval = (float*)dval_managed.get(); float* dB = (float*)dB_managed.get(); float* dC = (float*)dC_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SpMM structures hipsparseSpMatDescr_t A; hipsparseDnMatDescr_t B, C; size_t bsize; // Create SpMM structures verify_hipsparse_status_success( hipsparseCreateCsr(&A, m, k, nnz, dptr, dcol, dval, idxTypeI, idxTypeJ, idxBase, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&B, k, n, k, dB, dataType, order), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&C, m, n, m, dC, dataType, order), "success"); // SpMM buffer verify_hipsparse_status_invalid_handle(hipsparseSpMM_bufferSize( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, &bsize), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, &bsize), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, &bsize), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, &bsize), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, &bsize), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, nullptr), "Error: bsize is nullptr"); #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) // SpMM_preprocess verify_hipsparse_status_invalid_handle(hipsparseSpMM_preprocess( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); #endif // SpMM verify_hipsparse_status_invalid_handle( hipsparseSpMM(nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(B), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(C), "success"); #endif } template hipsparseStatus_t testing_spmm_csr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) J m = argus.M; J n = argus.N; J k = argus.K; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseOperation_t transB = argus.transB; hipsparseOrder_t orderB = argus.orderB; hipsparseOrder_t orderC = argus.orderC; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseSpMMAlg_t alg = static_cast(argus.spmm_alg); std::string filename = argus.filename; #if(defined(CUDART_VERSION)) if(orderB != orderC || orderB != HIPSPARSE_ORDER_COL) { return HIPSPARSE_STATUS_SUCCESS; } #endif // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipsparseIndexType_t typeJ = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Initial Data on CPU srand(12345ULL); I nnz_A; if(!generate_csr_matrix(filename, (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k, (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : m, nnz_A, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Some matrix properties J A_m = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k; J A_n = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : m; J B_m = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : n; J B_n = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? n : k; J C_m = m; J C_n = n; int ld_multiplier_B = 1; int ld_multiplier_C = 1; int64_t ldb = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * k) : (int64_t(ld_multiplier_B) * n)) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * n) : (int64_t(ld_multiplier_B) * k)); int64_t ldc = (orderC == HIPSPARSE_ORDER_COL) ? (int64_t(ld_multiplier_C) * m) : (int64_t(ld_multiplier_C) * n); ldb = std::max(int64_t(1), ldb); ldc = std::max(int64_t(1), ldc); int64_t nrowB = (orderB == HIPSPARSE_ORDER_COL) ? ldb : B_m; int64_t ncolB = (orderB == HIPSPARSE_ORDER_COL) ? B_n : ldb; int64_t nrowC = (orderC == HIPSPARSE_ORDER_COL) ? ldc : C_m; int64_t ncolC = (orderC == HIPSPARSE_ORDER_COL) ? C_n : ldc; int64_t nnz_B = nrowB * ncolB; int64_t nnz_C = nrowC * ncolC; // Allocate host memory for vectors std::vector hB(nnz_B); std::vector hC_1(nnz_C); std::vector hC_2(nnz_C); std::vector hC_gold(nnz_C); hipsparseInit(hB, nnz_B, 1); hipsparseInit(hC_1, nnz_C, 1); hC_2 = hC_1; hC_gold = hC_1; // allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (A_m + 1)), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz_A), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_A), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_B), device_free}; auto dC_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_C), device_free}; auto dC_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_C), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* dptr = (I*)dptr_managed.get(); J* dcol = (J*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dB = (T*)dB_managed.get(); T* dC_1 = (T*)dC_1_managed.get(); T* dC_2 = (T*)dC_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // Copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsr_row_ptr.data(), sizeof(I) * (A_m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcsr_col_ind.data(), sizeof(J) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hcsr_val.data(), sizeof(T) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_1, hC_1.data(), sizeof(T) * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_2, hC_2.data(), sizeof(T) * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t A; CHECK_HIPSPARSE_ERROR( hipsparseCreateCsr(&A, A_m, A_n, nnz_A, dptr, dcol, dval, typeI, typeJ, idx_base, typeT)); // Create dense matrices hipsparseDnMatDescr_t B, C1, C2; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&B, B_m, B_n, ldb, dB, typeT, orderB)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C1, C_m, C_n, ldc, dC_1, typeT, orderC)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C2, C_m, C_n, ldc, dC_2, typeT, orderC)); // Query SpMM buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSpMM_bufferSize( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, &bufferSize)); #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) //When using cusparse backend, cant pass nullptr for buffer to preprocess if(bufferSize == 0) { bufferSize = 4; } #endif void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); // HIPSPARSE pointer mode host #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSpMM_preprocess( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); #endif // HIPSPARSE pointer mode device #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSpMM_preprocess( handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); #endif if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseSpMM(handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSpMM(handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hC_1.data(), dC_1, sizeof(T) * nnz_C, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hC_2.data(), dC_2, sizeof(T) * nnz_C, hipMemcpyDeviceToHost)); // CPU host_csrmm(A_m, n, A_n, transA, transB, h_alpha, hcsr_row_ptr.data(), hcsr_col_ind.data(), hcsr_val.data(), hB.data(), (J)ldb, orderB, h_beta, hC_gold.data(), (J)ldc, orderC, idx_base, false); unit_check_near(1, nnz_C, 1, hC_gold.data(), hC_1.data()); unit_check_near(1, nnz_C, 1, hC_gold.data(), hC_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSpMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSpMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = spmm_gflop_count(n, nnz_A, (I)C_m * (I)C_n, h_beta != make_DataType(0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gbyte_count = csrmm_gbyte_count( A_m, nnz_A, (I)B_m * (I)B_n, (I)C_m * (I)C_n, h_beta != make_DataType(0)); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::K, k, display_key_t::nnzA, nnz_A, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::algorithm, hipsparse_spmmalg2string(alg), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(B)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C2)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPMM_CSR_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_spmv_coo.hpp000066400000000000000000000352561501764003400233520ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPMV_COO_HPP #define TESTING_SPMV_COO_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse_test; void testing_spmv_coo_bad_arg(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION > 10010 \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) int64_t m = 100; int64_t n = 100; int64_t nnz = 100; int64_t safe_size = 100; float alpha = 0.6; float beta = 0.2; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; #if(!defined(CUDART_VERSION)) hipsparseSpMVAlg_t alg = HIPSPARSE_MV_ALG_DEFAULT; #else #if(CUDART_VERSION >= 12000) hipsparseSpMVAlg_t alg = HIPSPARSE_SPMV_COO_ALG1; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 12000) hipsparseSpMVAlg_t alg = HIPSPARSE_MV_ALG_DEFAULT; #endif #endif std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* drow = (int*)drow_managed.get(); int* dcol = (int*)dcol_managed.get(); float* dval = (float*)dval_managed.get(); float* dx = (float*)dx_managed.get(); float* dy = (float*)dy_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SpMV structures hipsparseSpMatDescr_t A; hipsparseDnVecDescr_t x, y; size_t bsize; // Create SpMV structures verify_hipsparse_status_success( hipsparseCreateCoo(&A, m, n, nnz, drow, dcol, dval, idxType, idxBase, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnVec(&x, n, dx, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnVec(&y, m, dy, dataType), "success"); // SpMV buffer verify_hipsparse_status_invalid_handle( hipsparseSpMV_bufferSize(nullptr, transA, &alpha, A, x, &beta, y, dataType, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize(handle, transA, nullptr, A, x, &beta, y, dataType, alg, &bsize), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize( handle, transA, &alpha, nullptr, x, &beta, y, dataType, alg, &bsize), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize( handle, transA, &alpha, A, nullptr, &beta, y, dataType, alg, &bsize), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize(handle, transA, &alpha, A, x, nullptr, y, dataType, alg, &bsize), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize( handle, transA, &alpha, A, x, &beta, nullptr, dataType, alg, &bsize), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize(handle, transA, &alpha, A, x, &beta, y, dataType, alg, nullptr), "Error: bsize is nullptr"); // SpMV verify_hipsparse_status_invalid_handle( hipsparseSpMV(nullptr, transA, &alpha, A, x, &beta, y, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, nullptr, A, x, &beta, y, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, &alpha, nullptr, x, &beta, y, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, &alpha, A, nullptr, &beta, y, dataType, alg, dbuf), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, &alpha, A, x, nullptr, y, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, &alpha, A, x, &beta, nullptr, dataType, alg, dbuf), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, &alpha, A, x, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnVec(x), "success"); verify_hipsparse_status_success(hipsparseDestroyDnVec(y), "success"); #endif } template hipsparseStatus_t testing_spmv_coo(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION > 10010 \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) I m = argus.M; I n = argus.N; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseSpMVAlg_t alg = static_cast(argus.spmv_alg); std::string filename = argus.filename; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hrow_ptr; std::vector hcol_ind; std::vector hval; // Initial Data on CPU srand(12345ULL); I nnz; if(!generate_csr_matrix(filename, m, n, nnz, hrow_ptr, hcol_ind, hval, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hrow_ind(nnz); // Convert to COO for(I i = 0; i < m; ++i) { for(I j = hrow_ptr[i]; j < hrow_ptr[i + 1]; ++j) { hrow_ind[j - idx_base] = i + idx_base; } } std::vector hx(n); std::vector hy_1(m); std::vector hy_2(m); std::vector hy_gold(m); hipsparseInit(hx, 1, n); hipsparseInit(hy_1, 1, m); // copy vector is easy in STL; hy_gold = hx: save a copy in hy_gold which will be output of CPU hy_2 = hy_1; hy_gold = hy_1; // allocate memory on device auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * n), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* drow = (I*)drow_managed.get(); I* dcol = (I*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dx = (T*)dx_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(drow, hrow_ind.data(), sizeof(I) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcol_ind.data(), sizeof(I) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hval.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx, hx.data(), sizeof(T) * n, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_1, hy_1.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_2, hy_2.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t A; CHECK_HIPSPARSE_ERROR( hipsparseCreateCoo(&A, m, n, nnz, drow, dcol, dval, typeI, idx_base, typeT)); // Create dense vectors hipsparseDnVecDescr_t x, y1, y2; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&x, n, dx, typeT)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&y1, m, dy_1, typeT)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&y2, m, dy_2, typeT)); // Query SpMV buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSpMV_bufferSize( handle, transA, &h_alpha, A, x, &h_beta, y1, typeT, alg, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); if(argus.unit_check) { // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseSpMV(handle, transA, &h_alpha, A, x, &h_beta, y1, typeT, alg, buffer)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSpMV(handle, transA, d_alpha, A, x, d_beta, y2, typeT, alg, buffer)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hy_1.data(), dy_1, sizeof(T) * m, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_2.data(), dy_2, sizeof(T) * m, hipMemcpyDeviceToHost)); // Host SpMV #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(I i = 0; i < m; ++i) { hy_gold[i] = testing_mult(h_beta, hy_gold[i]); } for(I i = 0; i < nnz; ++i) { hy_gold[hrow_ind[i] - idx_base] = testing_fma(testing_mult(h_alpha, hval[i]), hx[hcol_ind[i] - idx_base], hy_gold[hrow_ind[i] - idx_base]); } unit_check_near(1, m, 1, hy_gold.data(), hy_1.data()); unit_check_near(1, m, 1, hy_gold.data(), hy_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseSpMV(handle, transA, &h_alpha, A, x, &h_beta, y1, typeT, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseSpMV(handle, transA, &h_alpha, A, x, &h_beta, y1, typeT, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = spmv_gflop_count(m, nnz, h_beta != make_DataType(0.0)); double gbyte_count = coomv_gbyte_count(m, n, nnz, h_beta != make_DataType(0.0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::transA, transA, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::algorithm, hipsparse_spmvalg2string(alg), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(x)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y2)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPMV_COO_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_spmv_coo_aos.hpp000066400000000000000000000346271501764003400242150ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPMV_COO_AOS_HPP #define TESTING_SPMV_COO_AOS_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse_test; void testing_spmv_coo_aos_bad_arg(void) { #if(!defined(CUDART_VERSION) || (CUDART_VERSION > 10010 && CUDART_VERSION < 12000) \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1 && CUDART_VERSION < 12000)) int64_t m = 100; int64_t n = 100; int64_t nnz = 100; int64_t safe_size = 100; float alpha = 0.6; float beta = 0.2; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; #if(!defined(CUDART_VERSION)) hipsparseSpMVAlg_t alg = HIPSPARSE_MV_ALG_DEFAULT; #else #if(CUDART_VERSION >= 12000) hipsparseSpMVAlg_t alg = HIPSPARSE_SPMV_ALG_DEFAULT; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 12000) hipsparseSpMVAlg_t alg = HIPSPARSE_MV_ALG_DEFAULT; #endif #endif std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* dind = (int*)dind_managed.get(); float* dval = (float*)dval_managed.get(); float* dx = (float*)dx_managed.get(); float* dy = (float*)dy_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SpMV structures hipsparseSpMatDescr_t A; hipsparseDnVecDescr_t x, y; size_t bsize; // Create SpMV structures verify_hipsparse_status_success( hipsparseCreateCooAoS(&A, m, n, nnz, dind, dval, idxType, idxBase, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnVec(&x, n, dx, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnVec(&y, m, dy, dataType), "success"); // SpMV buffer verify_hipsparse_status_invalid_handle( hipsparseSpMV_bufferSize(nullptr, transA, &alpha, A, x, &beta, y, dataType, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize(handle, transA, nullptr, A, x, &beta, y, dataType, alg, &bsize), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize( handle, transA, &alpha, nullptr, x, &beta, y, dataType, alg, &bsize), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize( handle, transA, &alpha, A, nullptr, &beta, y, dataType, alg, &bsize), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize(handle, transA, &alpha, A, x, nullptr, y, dataType, alg, &bsize), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize( handle, transA, &alpha, A, x, &beta, nullptr, dataType, alg, &bsize), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize(handle, transA, &alpha, A, x, &beta, y, dataType, alg, nullptr), "Error: bsize is nullptr"); // SpMV verify_hipsparse_status_invalid_handle( hipsparseSpMV(nullptr, transA, &alpha, A, x, &beta, y, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, nullptr, A, x, &beta, y, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, &alpha, nullptr, x, &beta, y, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, &alpha, A, nullptr, &beta, y, dataType, alg, dbuf), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, &alpha, A, x, nullptr, y, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, &alpha, A, x, &beta, nullptr, dataType, alg, dbuf), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, &alpha, A, x, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnVec(x), "success"); verify_hipsparse_status_success(hipsparseDestroyDnVec(y), "success"); #endif } template hipsparseStatus_t testing_spmv_coo_aos(Arguments argus) { #if(!defined(CUDART_VERSION) || (CUDART_VERSION >= 10010 && CUDART_VERSION < 12000)) I m = argus.M; I n = argus.N; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseSpMVAlg_t alg = static_cast(argus.spmv_alg); std::string filename = argus.filename; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hrow_ptr; std::vector hcol_ind; std::vector hval; // Initial Data on CPU srand(12345ULL); I nnz; if(!generate_csr_matrix(filename, m, n, nnz, hrow_ptr, hcol_ind, hval, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hind(2 * nnz); // Convert to COO (AoS) for(I i = 0; i < m; ++i) { for(I j = hrow_ptr[i] - idx_base; j < hrow_ptr[i + 1] - idx_base; ++j) { hind[2 * j] = i + idx_base; hind[2 * j + 1] = hcol_ind[j]; } } std::vector hx(n); std::vector hy_1(m); std::vector hy_2(m); std::vector hy_gold(m); hipsparseInit(hx, 1, n); hipsparseInit(hy_1, 1, m); // copy vector is easy in STL; hy_gold = hx: save a copy in hy_gold which will be output of CPU hy_2 = hy_1; hy_gold = hy_1; // allocate memory on device auto dind_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * 2 * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * n), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* dind = (I*)dind_managed.get(); T* dval = (T*)dval_managed.get(); T* dx = (T*)dx_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dind, hind.data(), sizeof(I) * 2 * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hval.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx, hx.data(), sizeof(T) * n, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_1, hy_1.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_2, hy_2.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t A; CHECK_HIPSPARSE_ERROR(hipsparseCreateCooAoS(&A, m, n, nnz, dind, dval, typeI, idx_base, typeT)); // Create dense vectors hipsparseDnVecDescr_t x, y1, y2; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&x, n, dx, typeT)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&y1, m, dy_1, typeT)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&y2, m, dy_2, typeT)); // Query SpMV buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSpMV_bufferSize( handle, transA, &h_alpha, A, x, &h_beta, y1, typeT, alg, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); if(argus.unit_check) { // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseSpMV(handle, transA, &h_alpha, A, x, &h_beta, y1, typeT, alg, buffer)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSpMV(handle, transA, d_alpha, A, x, d_beta, y2, typeT, alg, buffer)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hy_1.data(), dy_1, sizeof(T) * m, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_2.data(), dy_2, sizeof(T) * m, hipMemcpyDeviceToHost)); // Host SpMV #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(I i = 0; i < m; ++i) { hy_gold[i] = testing_mult(h_beta, hy_gold[i]); } for(I i = 0; i < nnz; ++i) { hy_gold[hind[2 * i] - idx_base] = testing_fma(testing_mult(h_alpha, hval[i]), hx[hind[2 * i + 1] - idx_base], hy_gold[hind[2 * i] - idx_base]); } unit_check_near(1, m, 1, hy_gold.data(), hy_1.data()); unit_check_near(1, m, 1, hy_gold.data(), hy_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseSpMV(handle, transA, &h_alpha, A, x, &h_beta, y1, typeT, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseSpMV(handle, transA, &h_alpha, A, x, &h_beta, y1, typeT, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = spmv_gflop_count(m, nnz, h_beta != make_DataType(0.0)); double gbyte_count = coomv_gbyte_count(m, n, nnz, h_beta != make_DataType(0.0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::transA, transA, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::algorithm, hipsparse_spmvalg2string(alg), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(x)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y2)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPMV_COO_AOS_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_spmv_csr.hpp000066400000000000000000000430261501764003400233530ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2022 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPMV_CSR_HPP #define TESTING_SPMV_CSR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse_test; void testing_spmv_csr_bad_arg(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION > 10010 \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) int64_t m = 100; int64_t n = 100; int64_t nnz = 100; int64_t safe_size = 100; float alpha = 0.6; float beta = 0.2; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; #if(!defined(CUDART_VERSION)) hipsparseSpMVAlg_t alg = HIPSPARSE_MV_ALG_DEFAULT; #else #if(CUDART_VERSION >= 12000) hipsparseSpMVAlg_t alg = HIPSPARSE_SPMV_ALG_DEFAULT; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 12000) hipsparseSpMVAlg_t alg = HIPSPARSE_MV_ALG_DEFAULT; #endif #endif std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); float* dval = (float*)dval_managed.get(); float* dx = (float*)dx_managed.get(); float* dy = (float*)dy_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SpMV structures hipsparseSpMatDescr_t A; hipsparseDnVecDescr_t x, y; size_t bsize; // Create SpMV structures verify_hipsparse_status_success( hipsparseCreateCsr(&A, m, n, nnz, dptr, dcol, dval, idxType, idxType, idxBase, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnVec(&x, n, dx, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnVec(&y, m, dy, dataType), "success"); // SpMV buffer verify_hipsparse_status_invalid_handle( hipsparseSpMV_bufferSize(nullptr, transA, &alpha, A, x, &beta, y, dataType, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize(handle, transA, nullptr, A, x, &beta, y, dataType, alg, &bsize), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize( handle, transA, &alpha, nullptr, x, &beta, y, dataType, alg, &bsize), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize( handle, transA, &alpha, A, nullptr, &beta, y, dataType, alg, &bsize), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize(handle, transA, &alpha, A, x, nullptr, y, dataType, alg, &bsize), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize( handle, transA, &alpha, A, x, &beta, nullptr, dataType, alg, &bsize), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize(handle, transA, &alpha, A, x, &beta, y, dataType, alg, nullptr), "Error: bsize is nullptr"); // SpMV preprocess (optional) verify_hipsparse_status_invalid_handle( hipsparseSpMV_preprocess(nullptr, transA, &alpha, A, x, &beta, y, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_preprocess(handle, transA, nullptr, A, x, &beta, y, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_preprocess(handle, transA, &alpha, nullptr, x, &beta, y, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_preprocess(handle, transA, &alpha, A, nullptr, &beta, y, dataType, alg, dbuf), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_preprocess(handle, transA, &alpha, A, x, nullptr, y, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_preprocess(handle, transA, &alpha, A, x, &beta, nullptr, dataType, alg, dbuf), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_preprocess( handle, transA, &alpha, A, x, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // SpMV verify_hipsparse_status_invalid_handle( hipsparseSpMV(nullptr, transA, &alpha, A, x, &beta, y, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, nullptr, A, x, &beta, y, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, &alpha, nullptr, x, &beta, y, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, &alpha, A, nullptr, &beta, y, dataType, alg, dbuf), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, &alpha, A, x, nullptr, y, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, &alpha, A, x, &beta, nullptr, dataType, alg, dbuf), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, &alpha, A, x, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnVec(x), "success"); verify_hipsparse_status_success(hipsparseDestroyDnVec(y), "success"); #endif } template hipsparseStatus_t testing_spmv_csr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION > 10010 \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) J m = argus.M; J n = argus.N; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseSpMVAlg_t alg = static_cast(argus.spmv_alg); std::string filename = argus.filename; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipsparseIndexType_t typeJ = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hcsr_row_ptr; std::vector hcol_ind; std::vector hval; // Initial Data on CPU srand(12345ULL); I nnz; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcol_ind, hval, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hx(n); std::vector hy_1(m); std::vector hy_2(m); std::vector hy_gold(m); hipsparseInit(hx, 1, n); hipsparseInit(hy_1, 1, m); // copy vector is easy in STL; hy_gold = hx: save a copy in hy_gold which will be output of CPU hy_2 = hy_1; hy_gold = hy_1; // allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (m + 1)), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * n), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* dptr = (I*)dptr_managed.get(); J* dcol = (J*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dx = (T*)dx_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsr_row_ptr.data(), sizeof(I) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcol_ind.data(), sizeof(J) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hval.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx, hx.data(), sizeof(T) * n, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_1, hy_1.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_2, hy_2.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t A; CHECK_HIPSPARSE_ERROR( hipsparseCreateCsr(&A, m, n, nnz, dptr, dcol, dval, typeI, typeJ, idx_base, typeT)); // Create dense vectors hipsparseDnVecDescr_t x, y1, y2; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&x, n, dx, typeT)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&y1, m, dy_1, typeT)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&y2, m, dy_2, typeT)); // Query SpMV buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSpMV_bufferSize( handle, transA, &h_alpha, A, x, &h_beta, y1, typeT, alg, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); // Preprocess (optional) CHECK_HIPSPARSE_ERROR( hipsparseSpMV_preprocess(handle, transA, &h_alpha, A, x, &h_beta, y1, typeT, alg, buffer)); if(argus.unit_check) { // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseSpMV(handle, transA, &h_alpha, A, x, &h_beta, y1, typeT, alg, buffer)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSpMV(handle, transA, d_alpha, A, x, d_beta, y2, typeT, alg, buffer)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hy_1.data(), dy_1, sizeof(T) * m, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_2.data(), dy_2, sizeof(T) * m, hipMemcpyDeviceToHost)); // Query for warpSize hipDeviceProp_t prop; hipGetDeviceProperties(&prop, 0); int WF_SIZE; I nnz_per_row = nnz / m; if(prop.warpSize == 32) { if(nnz_per_row < 4) WF_SIZE = 2; else if(nnz_per_row < 8) WF_SIZE = 4; else if(nnz_per_row < 16) WF_SIZE = 8; else if(nnz_per_row < 32) WF_SIZE = 16; else WF_SIZE = 32; } else if(prop.warpSize == 64) { if(nnz_per_row < 4) WF_SIZE = 2; else if(nnz_per_row < 8) WF_SIZE = 4; else if(nnz_per_row < 16) WF_SIZE = 8; else if(nnz_per_row < 32) WF_SIZE = 16; else if(nnz_per_row < 64) WF_SIZE = 32; else WF_SIZE = 64; } else { return HIPSPARSE_STATUS_INTERNAL_ERROR; } for(J i = 0; i < m; ++i) { std::vector sum(WF_SIZE, make_DataType(0.0)); for(I j = hcsr_row_ptr[i] - idx_base; j < hcsr_row_ptr[i + 1] - idx_base; j += WF_SIZE) { for(int k = 0; k < WF_SIZE; ++k) { if(j + k < hcsr_row_ptr[i + 1] - idx_base) { sum[k] = testing_fma(testing_mult(h_alpha, hval[j + k]), hx[hcol_ind[j + k] - idx_base], sum[k]); } } } for(int j = 1; j < WF_SIZE; j <<= 1) { for(int k = 0; k < WF_SIZE - j; ++k) { sum[k] = sum[k] + sum[k + j]; } } if(h_beta == make_DataType(0.0)) { hy_gold[i] = sum[0]; } else { hy_gold[i] = testing_fma(h_beta, hy_gold[i], sum[0]); } } unit_check_near(1, m, 1, hy_gold.data(), hy_1.data()); unit_check_near(1, m, 1, hy_gold.data(), hy_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseSpMV(handle, transA, &h_alpha, A, x, &h_beta, y1, typeT, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseSpMV(handle, transA, &h_alpha, A, x, &h_beta, y1, typeT, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = spmv_gflop_count(m, nnz, h_beta != make_DataType(0.0)); double gbyte_count = csrmv_gbyte_count(m, n, nnz, h_beta != make_DataType(0.0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::transA, transA, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::algorithm, hipsparse_spmvalg2string(alg), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(x)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y2)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPMV_CSR_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_spsm_coo.hpp000066400000000000000000000447731501764003400233530ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPSM_COO_HPP #define TESTING_SPSM_COO_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse_test; void testing_spsm_coo_bad_arg(void) { #if(!defined(CUDART_VERSION)) int64_t m = 100; int64_t n = 100; int64_t k = 100; int64_t nnz = 100; int64_t safe_size = 100; float alpha = 0.6; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; hipsparseSpSMAlg_t alg = HIPSPARSE_SPSM_ALG_DEFAULT; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dC_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* drow = (int*)drow_managed.get(); int* dcol = (int*)dcol_managed.get(); float* dval = (float*)dval_managed.get(); float* dB = (float*)dB_managed.get(); float* dC = (float*)dC_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SpSM structures hipsparseSpMatDescr_t A; hipsparseDnVecDescr_t B, C; hipsparseSpSMDescr_t descr; verify_hipsparse_status_success(hipsparseSpSM_createDescr(&descr), "success"); size_t bsize; // Create SpSM structures verify_hipsparse_status_success( hipsparseCreateCoo(&A, m, n, nnz, drow, dcol, dval, idxType, idxBase, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&B, m, k, m, dB, dataType, order), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&C, m, k, m, dC, dataType, order), "success"); // SpSM buffer verify_hipsparse_status_invalid_handle(hipsparseSpSM_bufferSize( nullptr, transA, transB, &alpha, A, B, C, dataType, alg, descr, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_bufferSize( handle, transA, transB, nullptr, A, B, C, dataType, alg, descr, &bsize), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_bufferSize( handle, transA, transB, &alpha, nullptr, B, C, dataType, alg, descr, &bsize), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_bufferSize( handle, transA, transB, &alpha, A, nullptr, C, dataType, alg, descr, &bsize), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_bufferSize( handle, transA, transB, &alpha, A, B, nullptr, dataType, alg, descr, &bsize), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_bufferSize( handle, transA, transB, &alpha, A, B, C, dataType, alg, nullptr, &bsize), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_bufferSize( handle, transA, transB, &alpha, A, B, C, dataType, alg, descr, nullptr), "Error: bsize is nullptr"); // SpSM analysis verify_hipsparse_status_invalid_handle(hipsparseSpSM_analysis( nullptr, transA, transB, &alpha, A, B, C, dataType, alg, descr, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_analysis( handle, transA, transB, nullptr, A, B, C, dataType, alg, descr, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_analysis( handle, transA, transB, &alpha, nullptr, B, C, dataType, alg, descr, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_analysis( handle, transA, transB, &alpha, A, nullptr, C, dataType, alg, descr, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_analysis( handle, transA, transB, &alpha, A, B, nullptr, dataType, alg, descr, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_analysis( handle, transA, transB, &alpha, A, B, C, dataType, alg, nullptr, dbuf), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_analysis( handle, transA, transB, &alpha, A, B, C, dataType, alg, descr, nullptr), "Error: dbuf is nullptr"); // SpSM solve verify_hipsparse_status_invalid_handle( hipsparseSpSM_solve(nullptr, transA, transB, &alpha, A, B, C, dataType, alg, descr, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_solve(handle, transA, transB, nullptr, A, B, C, dataType, alg, descr, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_solve( handle, transA, transB, &alpha, nullptr, B, C, dataType, alg, descr, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_solve( handle, transA, transB, &alpha, A, nullptr, C, dataType, alg, descr, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_solve( handle, transA, transB, &alpha, A, B, nullptr, dataType, alg, descr, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_solve(handle, transA, transB, &alpha, A, B, C, dataType, alg, nullptr, dbuf), "Error: descr is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseSpSM_destroyDescr(descr), "success"); verify_hipsparse_status_success(hipsparseDestroySpMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(B), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(C), "success"); #endif } template hipsparseStatus_t testing_spsm_coo(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11031) I m = argus.M; I n = argus.N; I k = argus.K; T h_alpha = make_DataType(argus.alpha); hipsparseOperation_t transA = argus.transA; hipsparseOperation_t transB = argus.transB; hipsparseOrder_t orderB = argus.orderB; hipsparseOrder_t orderC = argus.orderC; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseDiagType_t diag = argus.diag_type; hipsparseFillMode_t uplo = argus.fill_mode; hipsparseSpSMAlg_t alg = static_cast(argus.spsm_alg); std::string filename = argus.filename; #if(defined(CUDART_VERSION)) if(orderB != orderC) { return HIPSPARSE_STATUS_SUCCESS; } #endif // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hrow_ptr; std::vector hcol_ind; std::vector hval; // Initial Data on CPU srand(12345ULL); I nnz; if(!generate_csr_matrix(filename, m, n, nnz, hrow_ptr, hcol_ind, hval, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } if(m != n) { // Skip non-square matrices return HIPSPARSE_STATUS_SUCCESS; } std::vector hrow_ind(nnz); // Convert to COO for(I i = 0; i < m; ++i) { for(I j = hrow_ptr[i]; j < hrow_ptr[i + 1]; ++j) { hrow_ind[j - idx_base] = i + idx_base; } } // Some matrix properties I B_m = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k; I B_n = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : m; I C_m = m; I C_n = k; int ld_multiplier_B = 1; int ld_multiplier_C = 1; int64_t ldb = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * m) : (int64_t(ld_multiplier_B) * k)) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * k) : (int64_t(ld_multiplier_B) * m)); int64_t ldc = (orderC == HIPSPARSE_ORDER_COL) ? (int64_t(ld_multiplier_C) * m) : (int64_t(ld_multiplier_C) * k); ldb = std::max(int64_t(1), ldb); ldc = std::max(int64_t(1), ldc); int64_t nrowB = (orderB == HIPSPARSE_ORDER_COL) ? ldb : B_m; int64_t ncolB = (orderB == HIPSPARSE_ORDER_COL) ? B_n : ldb; int64_t nrowC = (orderC == HIPSPARSE_ORDER_COL) ? ldc : C_m; int64_t ncolC = (orderC == HIPSPARSE_ORDER_COL) ? C_n : ldc; int64_t nnz_B = nrowB * ncolB; int64_t nnz_C = nrowC * ncolC; std::vector hB(nnz_B); std::vector hC_1(nnz_C); std::vector hC_2(nnz_C); std::vector hC_gold(nnz_C); hipsparseInit(hB, 1, nnz_B); hC_1 = hB; hC_2 = hC_1; hC_gold = hC_1; // allocate memory on device auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_B), device_free}; auto dC_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_C), device_free}; auto dC_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_C), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* drow = (I*)drow_managed.get(); I* dcol = (I*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dB = (T*)dB_managed.get(); T* dC_1 = (T*)dC_1_managed.get(); T* dC_2 = (T*)dC_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(drow, hrow_ind.data(), sizeof(I) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcol_ind.data(), sizeof(I) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hval.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_1, hC_1.data(), sizeof(T) * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_2, hC_2.data(), sizeof(T) * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); hipsparseSpSMDescr_t descr; CHECK_HIPSPARSE_ERROR(hipsparseSpSM_createDescr(&descr)); // Create matrices hipsparseSpMatDescr_t A; CHECK_HIPSPARSE_ERROR( hipsparseCreateCoo(&A, m, n, nnz, drow, dcol, dval, typeI, idx_base, typeT)); // Create dense matrices hipsparseDnMatDescr_t B, C1, C2; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&B, B_m, B_n, ldb, dB, typeT, orderB)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C1, C_m, C_n, ldc, dC_1, typeT, orderC)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C2, C_m, C_n, ldc, dC_2, typeT, orderC)); CHECK_HIPSPARSE_ERROR( hipsparseSpMatSetAttribute(A, HIPSPARSE_SPMAT_FILL_MODE, &uplo, sizeof(uplo))); CHECK_HIPSPARSE_ERROR( hipsparseSpMatSetAttribute(A, HIPSPARSE_SPMAT_DIAG_TYPE, &diag, sizeof(diag))); // Query SpSM buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSpSM_bufferSize( handle, transA, transB, &h_alpha, A, B, C1, typeT, alg, descr, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSpSM_analysis( handle, transA, transB, &h_alpha, A, B, C1, typeT, alg, descr, buffer)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSpSM_analysis( handle, transA, transB, d_alpha, A, B, C2, typeT, alg, descr, buffer)); if(argus.unit_check) { // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSpSM_solve( handle, transA, transB, &h_alpha, A, B, C1, typeT, alg, descr, buffer)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSpSM_solve( handle, transA, transB, d_alpha, A, B, C2, typeT, alg, descr, buffer)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hC_1.data(), dC_1, sizeof(T) * nnz_C, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hC_2.data(), dC_2, sizeof(T) * nnz_C, hipMemcpyDeviceToHost)); I struct_pivot = -1; I numeric_pivot = -1; host_coosm(m, k, nnz, transA, transB, h_alpha, hrow_ind, hcol_ind, hval, hB, (I)ldb, orderB, hC_gold, (I)ldc, orderC, diag, uplo, idx_base, &struct_pivot, &numeric_pivot); if(struct_pivot == -1 && numeric_pivot == -1) { unit_check_near(1, nnz_C, 1, hC_gold.data(), hC_1.data()); unit_check_near(1, nnz_C, 1, hC_gold.data(), hC_2.data()); } } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSpSM_solve( handle, transA, transB, &h_alpha, A, B, C1, typeT, alg, descr, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSpSM_solve( handle, transA, transB, &h_alpha, A, B, C1, typeT, alg, descr, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = spsv_gflop_count(m, nnz, diag) * k; double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gbyte_count = coosv_gbyte_count(m, nnz) * k; double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::K, k, display_key_t::nnz, nnz, display_key_t::alpha, h_alpha, display_key_t::algorithm, hipsparse_spsmalg2string(alg), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSpSM_destroyDescr(descr)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(B)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C2)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPSM_COO_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_spsm_csr.hpp000066400000000000000000000446611501764003400233560ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPSM_CSR_HPP #define TESTING_SPSM_CSR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse_test; void testing_spsm_csr_bad_arg(void) { #if(!defined(CUDART_VERSION)) int64_t m = 100; int64_t n = 100; int64_t k = 100; int64_t nnz = 100; int64_t safe_size = 100; float alpha = 0.6; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; hipsparseSpSMAlg_t alg = HIPSPARSE_SPSM_ALG_DEFAULT; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dC_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); float* dval = (float*)dval_managed.get(); float* dB = (float*)dB_managed.get(); float* dC = (float*)dC_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SpSM structures hipsparseSpMatDescr_t A; hipsparseDnMatDescr_t B, C; hipsparseSpSMDescr_t descr; verify_hipsparse_status_success(hipsparseSpSM_createDescr(&descr), "success"); size_t bsize; // Create SpSM structures verify_hipsparse_status_success( hipsparseCreateCsr(&A, m, n, nnz, dptr, dcol, dval, idxType, idxType, idxBase, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&B, m, k, m, dB, dataType, order), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&C, m, k, m, dC, dataType, order), "success"); // SpSM buffer verify_hipsparse_status_invalid_handle(hipsparseSpSM_bufferSize( nullptr, transA, transB, &alpha, A, B, C, dataType, alg, descr, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_bufferSize( handle, transA, transB, nullptr, A, B, C, dataType, alg, descr, &bsize), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_bufferSize( handle, transA, transB, &alpha, nullptr, B, C, dataType, alg, descr, &bsize), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_bufferSize( handle, transA, transB, &alpha, A, nullptr, C, dataType, alg, descr, &bsize), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_bufferSize( handle, transA, transB, &alpha, A, B, nullptr, dataType, alg, descr, &bsize), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_bufferSize( handle, transA, transB, &alpha, A, B, C, dataType, alg, nullptr, &bsize), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_bufferSize( handle, transA, transB, &alpha, A, B, C, dataType, alg, descr, nullptr), "Error: bsize is nullptr"); // SpSM analysis verify_hipsparse_status_invalid_handle(hipsparseSpSM_analysis( nullptr, transA, transB, &alpha, A, B, C, dataType, alg, descr, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_analysis( handle, transA, transB, nullptr, A, B, C, dataType, alg, descr, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_analysis( handle, transA, transB, &alpha, nullptr, B, C, dataType, alg, descr, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_analysis( handle, transA, transB, &alpha, A, nullptr, C, dataType, alg, descr, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_analysis( handle, transA, transB, &alpha, A, B, nullptr, dataType, alg, descr, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_analysis( handle, transA, transB, &alpha, A, B, C, dataType, alg, nullptr, dbuf), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_analysis( handle, transA, transB, &alpha, A, B, C, dataType, alg, descr, nullptr), "Error: dbuf is nullptr"); // SpSM solve verify_hipsparse_status_invalid_handle( hipsparseSpSM_solve(nullptr, transA, transB, &alpha, A, B, C, dataType, alg, descr, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_solve(handle, transA, transB, nullptr, A, B, C, dataType, alg, descr, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_solve( handle, transA, transB, &alpha, nullptr, B, C, dataType, alg, descr, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_solve( handle, transA, transB, &alpha, A, nullptr, C, dataType, alg, descr, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_solve( handle, transA, transB, &alpha, A, B, nullptr, dataType, alg, descr, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_solve(handle, transA, transB, &alpha, A, B, C, dataType, alg, nullptr, dbuf), "Error: descr is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseSpSM_destroyDescr(descr), "success"); verify_hipsparse_status_success(hipsparseDestroySpMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(B), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(C), "success"); #endif } template hipsparseStatus_t testing_spsm_csr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11031) J m = argus.M; J n = argus.N; J k = argus.K; T h_alpha = make_DataType(argus.alpha); hipsparseOperation_t transA = argus.transA; hipsparseOperation_t transB = argus.transB; hipsparseOrder_t orderB = argus.orderB; hipsparseOrder_t orderC = argus.orderC; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseDiagType_t diag = argus.diag_type; hipsparseFillMode_t uplo = argus.fill_mode; hipsparseSpSMAlg_t alg = static_cast(argus.spsm_alg); std::string filename = argus.filename; #if(defined(CUDART_VERSION)) if(orderB != orderC) { return HIPSPARSE_STATUS_SUCCESS; } #endif // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipsparseIndexType_t typeJ = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Initial Data on CPU srand(12345ULL); I nnz; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } if(m != n) { // Skip non-square matrices return HIPSPARSE_STATUS_SUCCESS; } // Some matrix properties J B_m = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k; J B_n = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : m; J C_m = m; J C_n = k; int ld_multiplier_B = 1; int ld_multiplier_C = 1; int64_t ldb = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * m) : (int64_t(ld_multiplier_B) * k)) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * k) : (int64_t(ld_multiplier_B) * m)); int64_t ldc = (orderC == HIPSPARSE_ORDER_COL) ? (int64_t(ld_multiplier_C) * m) : (int64_t(ld_multiplier_C) * k); ldb = std::max(int64_t(1), ldb); ldc = std::max(int64_t(1), ldc); int64_t nrowB = (orderB == HIPSPARSE_ORDER_COL) ? ldb : B_m; int64_t ncolB = (orderB == HIPSPARSE_ORDER_COL) ? B_n : ldb; int64_t nrowC = (orderC == HIPSPARSE_ORDER_COL) ? ldc : C_m; int64_t ncolC = (orderC == HIPSPARSE_ORDER_COL) ? C_n : ldc; int64_t nnz_B = nrowB * ncolB; int64_t nnz_C = nrowC * ncolC; std::vector hB(nnz_B); std::vector hC_1(nnz_C); std::vector hC_2(nnz_C); std::vector hC_gold(nnz_C); hipsparseInit(hB, 1, nnz_B); hC_1 = hB; hC_2 = hC_1; hC_gold = hC_1; // allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (m + 1)), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_B), device_free}; auto dC_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_C), device_free}; auto dC_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_C), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* dptr = (I*)dptr_managed.get(); J* dcol = (J*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dB = (T*)dB_managed.get(); T* dC_1 = (T*)dC_1_managed.get(); T* dC_2 = (T*)dC_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsr_row_ptr.data(), sizeof(I) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcsr_col_ind.data(), sizeof(J) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_1, hC_1.data(), sizeof(T) * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_2, hC_2.data(), sizeof(T) * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); hipsparseSpSMDescr_t descr; CHECK_HIPSPARSE_ERROR(hipsparseSpSM_createDescr(&descr)); // Create matrices hipsparseSpMatDescr_t A; CHECK_HIPSPARSE_ERROR( hipsparseCreateCsr(&A, m, m, nnz, dptr, dcol, dval, typeI, typeJ, idx_base, typeT)); // Create dense matrices hipsparseDnMatDescr_t B, C1, C2; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&B, B_m, B_n, ldb, dB, typeT, orderB)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C1, C_m, C_n, ldc, dC_1, typeT, orderC)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C2, C_m, C_n, ldc, dC_2, typeT, orderC)); CHECK_HIPSPARSE_ERROR( hipsparseSpMatSetAttribute(A, HIPSPARSE_SPMAT_FILL_MODE, &uplo, sizeof(uplo))); CHECK_HIPSPARSE_ERROR( hipsparseSpMatSetAttribute(A, HIPSPARSE_SPMAT_DIAG_TYPE, &diag, sizeof(diag))); // Query SpSM buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSpSM_bufferSize( handle, transA, transB, &h_alpha, A, B, C1, typeT, alg, descr, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSpSM_analysis( handle, transA, transB, &h_alpha, A, B, C1, typeT, alg, descr, buffer)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSpSM_analysis( handle, transA, transB, d_alpha, A, B, C2, typeT, alg, descr, buffer)); if(argus.unit_check) { // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSpSM_solve( handle, transA, transB, &h_alpha, A, B, C1, typeT, alg, descr, buffer)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSpSM_solve( handle, transA, transB, d_alpha, A, B, C2, typeT, alg, descr, buffer)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hC_1.data(), dC_1, sizeof(T) * nnz_C, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hC_2.data(), dC_2, sizeof(T) * nnz_C, hipMemcpyDeviceToHost)); J struct_pivot = -1; J numeric_pivot = -1; host_csrsm(m, k, nnz, transA, transB, h_alpha, hcsr_row_ptr, hcsr_col_ind, hcsr_val, hB, (J)ldb, orderB, hC_gold, (J)ldc, orderC, diag, uplo, idx_base, &struct_pivot, &numeric_pivot); if(struct_pivot == -1 && numeric_pivot == -1) { unit_check_near(1, nnz_C, 1, hC_gold.data(), hC_1.data()); unit_check_near(1, nnz_C, 1, hC_gold.data(), hC_2.data()); } } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSpSM_solve( handle, transA, transB, &h_alpha, A, B, C1, typeT, alg, descr, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSpSM_solve( handle, transA, transB, &h_alpha, A, B, C1, typeT, alg, descr, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = spsv_gflop_count(m, nnz, diag) * k; double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gbyte_count = csrsv_gbyte_count(m, nnz) * k; double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::K, k, display_key_t::nnz, nnz, display_key_t::alpha, h_alpha, display_key_t::algorithm, hipsparse_spsmalg2string(alg), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSpSM_destroyDescr(descr)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(B)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C2)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPSM_CSR_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_spsv_coo.hpp000066400000000000000000000372131501764003400233530ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPSV_COO_HPP #define TESTING_SPSV_COO_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse_test; void testing_spsv_coo_bad_arg(void) { #if(!defined(CUDART_VERSION)) int64_t m = 100; int64_t n = 100; int64_t nnz = 100; int64_t safe_size = 100; float alpha = 0.6; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; hipsparseSpSVAlg_t alg = HIPSPARSE_SPSV_ALG_DEFAULT; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* drow = (int*)drow_managed.get(); int* dcol = (int*)dcol_managed.get(); float* dval = (float*)dval_managed.get(); float* dx = (float*)dx_managed.get(); float* dy = (float*)dy_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SpSV structures hipsparseSpMatDescr_t A; hipsparseDnVecDescr_t x, y; hipsparseSpSVDescr_t descr; verify_hipsparse_status_success(hipsparseSpSV_createDescr(&descr), "success"); size_t bsize; // Create SpSV structures verify_hipsparse_status_success( hipsparseCreateCoo(&A, m, n, nnz, drow, dcol, dval, idxType, idxBase, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnVec(&x, m, dx, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnVec(&y, m, dy, dataType), "success"); // SpSV buffer verify_hipsparse_status_invalid_handle( hipsparseSpSV_bufferSize(nullptr, transA, &alpha, A, x, y, dataType, alg, descr, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_bufferSize(handle, transA, nullptr, A, x, y, dataType, alg, descr, &bsize), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_bufferSize( handle, transA, &alpha, nullptr, x, y, dataType, alg, descr, &bsize), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_bufferSize( handle, transA, &alpha, A, nullptr, y, dataType, alg, descr, &bsize), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_bufferSize( handle, transA, &alpha, A, x, nullptr, dataType, alg, descr, &bsize), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_bufferSize(handle, transA, &alpha, A, x, y, dataType, alg, descr, nullptr), "Error: bsize is nullptr"); // SpSV analysis verify_hipsparse_status_invalid_handle( hipsparseSpSV_analysis(nullptr, transA, &alpha, A, x, y, dataType, alg, descr, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_analysis(handle, transA, nullptr, A, x, y, dataType, alg, descr, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_analysis(handle, transA, &alpha, nullptr, x, y, dataType, alg, descr, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_analysis(handle, transA, &alpha, A, nullptr, y, dataType, alg, descr, dbuf), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_analysis(handle, transA, &alpha, A, x, nullptr, dataType, alg, descr, dbuf), "Error: y is nullptr"); #if(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_pointer( hipsparseSpSV_analysis(handle, transA, &alpha, A, x, y, dataType, alg, descr, nullptr), "Error: dbuf is nullptr"); #endif // SpSV solve verify_hipsparse_status_invalid_handle( hipsparseSpSV_solve(nullptr, transA, &alpha, A, x, y, dataType, alg, descr)); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_solve(handle, transA, nullptr, A, x, y, dataType, alg, descr), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_solve(handle, transA, &alpha, nullptr, x, y, dataType, alg, descr), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_solve(handle, transA, &alpha, A, nullptr, y, dataType, alg, descr), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_solve(handle, transA, &alpha, A, x, nullptr, dataType, alg, descr), "Error: y is nullptr"); #if(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_pointer( hipsparseSpSV_solve(handle, transA, &alpha, A, x, y, dataType, alg, nullptr), "Error: descr is nullptr"); #endif // Destruct verify_hipsparse_status_success(hipsparseSpSV_destroyDescr(descr), "success"); verify_hipsparse_status_success(hipsparseDestroySpMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnVec(x), "success"); verify_hipsparse_status_success(hipsparseDestroyDnVec(y), "success"); #endif } template hipsparseStatus_t testing_spsv_coo(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11030) I m = argus.M; I n = argus.N; T h_alpha = make_DataType(argus.alpha); hipsparseOperation_t transA = argus.transA; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseDiagType_t diag = argus.diag_type; hipsparseFillMode_t uplo = argus.fill_mode; hipsparseSpSVAlg_t alg = static_cast(argus.spsv_alg); std::string filename = argus.filename; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hrow_ptr; std::vector hcol_ind; std::vector hval; // Initial Data on CPU srand(12345ULL); I nnz; if(!generate_csr_matrix(filename, m, n, nnz, hrow_ptr, hcol_ind, hval, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hrow_ind(nnz); // Convert to COO for(I i = 0; i < m; ++i) { for(I j = hrow_ptr[i]; j < hrow_ptr[i + 1]; ++j) { hrow_ind[j - idx_base] = i + idx_base; } } std::vector hx(m); std::vector hy_1(m); std::vector hy_2(m); std::vector hy_gold(m); hipsparseInit(hx, 1, m); hipsparseInit(hy_1, 1, m); // copy vector is easy in STL; hy_gold = hx: save a copy in hy_gold which will be output of CPU hy_2 = hy_1; hy_gold = hy_1; // allocate memory on device auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* drow = (I*)drow_managed.get(); I* dcol = (I*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dx = (T*)dx_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(drow, hrow_ind.data(), sizeof(I) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcol_ind.data(), sizeof(I) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hval.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx, hx.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_1, hy_1.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_2, hy_2.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); hipsparseSpSVDescr_t descr; CHECK_HIPSPARSE_ERROR(hipsparseSpSV_createDescr(&descr)); // Create matrices hipsparseSpMatDescr_t A; CHECK_HIPSPARSE_ERROR( hipsparseCreateCoo(&A, m, n, nnz, drow, dcol, dval, typeI, idx_base, typeT)); // Create dense vectors hipsparseDnVecDescr_t x, y1, y2; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&x, m, dx, typeT)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&y1, m, dy_1, typeT)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&y2, m, dy_2, typeT)); CHECK_HIPSPARSE_ERROR( hipsparseSpMatSetAttribute(A, HIPSPARSE_SPMAT_FILL_MODE, &uplo, sizeof(uplo))); CHECK_HIPSPARSE_ERROR( hipsparseSpMatSetAttribute(A, HIPSPARSE_SPMAT_DIAG_TYPE, &diag, sizeof(diag))); // Query SpSV buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSpSV_bufferSize( handle, transA, &h_alpha, A, x, y1, typeT, alg, descr, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseSpSV_analysis(handle, transA, &h_alpha, A, x, y1, typeT, alg, descr, buffer)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSpSV_analysis(handle, transA, d_alpha, A, x, y2, typeT, alg, descr, buffer)); if(argus.unit_check) { // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseSpSV_solve(handle, transA, &h_alpha, A, x, y1, typeT, alg, descr)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSpSV_solve(handle, transA, d_alpha, A, x, y2, typeT, alg, descr)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hy_1.data(), dy_1, sizeof(T) * m, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_2.data(), dy_2, sizeof(T) * m, hipMemcpyDeviceToHost)); I struct_pivot = -1; I numeric_pivot = -1; host_coosv(transA, m, nnz, h_alpha, hrow_ind, hcol_ind, hval, hx, hy_gold, diag, uplo, idx_base, &struct_pivot, &numeric_pivot); if(struct_pivot == -1 && numeric_pivot == -1) { unit_check_near(1, m, 1, hy_gold.data(), hy_1.data()); unit_check_near(1, m, 1, hy_gold.data(), hy_2.data()); } } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseSpSV_solve(handle, transA, &h_alpha, A, x, y1, typeT, alg, descr)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseSpSV_solve(handle, transA, &h_alpha, A, x, y1, typeT, alg, descr)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = spsv_gflop_count(m, nnz, diag); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gbyte_count = coosv_gbyte_count(m, nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::alpha, h_alpha, display_key_t::algorithm, hipsparse_spsvalg2string(alg), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSpSV_destroyDescr(descr)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(x)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y2)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPSV_COO_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_spsv_csr.hpp000066400000000000000000000371441501764003400233650ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPSV_CSR_HPP #define TESTING_SPSV_CSR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse_test; void testing_spsv_csr_bad_arg(void) { #if(!defined(CUDART_VERSION)) int64_t m = 100; int64_t n = 100; int64_t nnz = 100; int64_t safe_size = 100; float alpha = 0.6; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; hipsparseSpSVAlg_t alg = HIPSPARSE_SPSV_ALG_DEFAULT; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); float* dval = (float*)dval_managed.get(); float* dx = (float*)dx_managed.get(); float* dy = (float*)dy_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SpSV structures hipsparseSpMatDescr_t A; hipsparseDnVecDescr_t x, y; hipsparseSpSVDescr_t descr; verify_hipsparse_status_success(hipsparseSpSV_createDescr(&descr), "success"); size_t bsize; // Create SpSV structures verify_hipsparse_status_success( hipsparseCreateCsr(&A, m, n, nnz, dptr, dcol, dval, idxType, idxType, idxBase, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnVec(&x, m, dx, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnVec(&y, m, dy, dataType), "success"); // SpSV buffer verify_hipsparse_status_invalid_handle( hipsparseSpSV_bufferSize(nullptr, transA, &alpha, A, x, y, dataType, alg, descr, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_bufferSize(handle, transA, nullptr, A, x, y, dataType, alg, descr, &bsize), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_bufferSize( handle, transA, &alpha, nullptr, x, y, dataType, alg, descr, &bsize), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_bufferSize( handle, transA, &alpha, A, nullptr, y, dataType, alg, descr, &bsize), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_bufferSize( handle, transA, &alpha, A, x, nullptr, dataType, alg, descr, &bsize), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_bufferSize(handle, transA, &alpha, A, x, y, dataType, alg, descr, nullptr), "Error: bsize is nullptr"); // SpSV analysis verify_hipsparse_status_invalid_handle( hipsparseSpSV_analysis(nullptr, transA, &alpha, A, x, y, dataType, alg, descr, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_analysis(handle, transA, nullptr, A, x, y, dataType, alg, descr, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_analysis(handle, transA, &alpha, nullptr, x, y, dataType, alg, descr, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_analysis(handle, transA, &alpha, A, nullptr, y, dataType, alg, descr, dbuf), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_analysis(handle, transA, &alpha, A, x, nullptr, dataType, alg, descr, dbuf), "Error: y is nullptr"); #if(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_pointer( hipsparseSpSV_analysis(handle, transA, &alpha, A, x, y, dataType, alg, descr, nullptr), "Error: dbuf is nullptr"); #endif // SpSV solve verify_hipsparse_status_invalid_handle( hipsparseSpSV_solve(nullptr, transA, &alpha, A, x, y, dataType, alg, descr)); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_solve(handle, transA, nullptr, A, x, y, dataType, alg, descr), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_solve(handle, transA, &alpha, nullptr, x, y, dataType, alg, descr), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_solve(handle, transA, &alpha, A, nullptr, y, dataType, alg, descr), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_solve(handle, transA, &alpha, A, x, nullptr, dataType, alg, descr), "Error: y is nullptr"); #if(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_pointer( hipsparseSpSV_solve(handle, transA, &alpha, A, x, y, dataType, alg, nullptr), "Error: descr is nullptr"); #endif // Destruct verify_hipsparse_status_success(hipsparseSpSV_destroyDescr(descr), "success"); verify_hipsparse_status_success(hipsparseDestroySpMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnVec(x), "success"); verify_hipsparse_status_success(hipsparseDestroyDnVec(y), "success"); #endif } template hipsparseStatus_t testing_spsv_csr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11030) J m = argus.M; J n = argus.N; T h_alpha = make_DataType(argus.alpha); hipsparseOperation_t transA = argus.transA; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseDiagType_t diag = argus.diag_type; hipsparseFillMode_t uplo = argus.fill_mode; hipsparseSpSVAlg_t alg = static_cast(argus.spsv_alg); std::string filename = argus.filename; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipsparseIndexType_t typeJ = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Initial Data on CPU srand(12345ULL); I nnz; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hx(m); std::vector hy_1(m); std::vector hy_2(m); std::vector hy_gold(m); hipsparseInit(hx, 1, m); hipsparseInit(hy_1, 1, m); // copy vector is easy in STL; hy_gold = hx: save a copy in hy_gold which will be output of CPU hy_2 = hy_1; hy_gold = hy_1; // allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (m + 1)), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* dptr = (I*)dptr_managed.get(); J* dcol = (J*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dx = (T*)dx_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsr_row_ptr.data(), sizeof(I) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcsr_col_ind.data(), sizeof(J) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx, hx.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_1, hy_1.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_2, hy_2.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); hipsparseSpSVDescr_t descr; CHECK_HIPSPARSE_ERROR(hipsparseSpSV_createDescr(&descr)); // Create matrices hipsparseSpMatDescr_t A; CHECK_HIPSPARSE_ERROR( hipsparseCreateCsr(&A, m, n, nnz, dptr, dcol, dval, typeI, typeJ, idx_base, typeT)); // Create dense vectors hipsparseDnVecDescr_t x, y1, y2; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&x, m, dx, typeT)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&y1, m, dy_1, typeT)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&y2, m, dy_2, typeT)); CHECK_HIPSPARSE_ERROR( hipsparseSpMatSetAttribute(A, HIPSPARSE_SPMAT_FILL_MODE, &uplo, sizeof(uplo))); CHECK_HIPSPARSE_ERROR( hipsparseSpMatSetAttribute(A, HIPSPARSE_SPMAT_DIAG_TYPE, &diag, sizeof(diag))); // Query SpSV buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSpSV_bufferSize( handle, transA, &h_alpha, A, x, y1, typeT, alg, descr, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseSpSV_analysis(handle, transA, &h_alpha, A, x, y1, typeT, alg, descr, buffer)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSpSV_analysis(handle, transA, d_alpha, A, x, y2, typeT, alg, descr, buffer)); if(argus.unit_check) { // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseSpSV_solve(handle, transA, &h_alpha, A, x, y1, typeT, alg, descr)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSpSV_solve(handle, transA, d_alpha, A, x, y2, typeT, alg, descr)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hy_1.data(), dy_1, sizeof(T) * m, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_2.data(), dy_2, sizeof(T) * m, hipMemcpyDeviceToHost)); J struct_pivot = -1; J numeric_pivot = -1; host_csrsv(transA, m, nnz, h_alpha, hcsr_row_ptr.data(), hcsr_col_ind.data(), hcsr_val.data(), hx.data(), hy_gold.data(), diag, uplo, idx_base, &struct_pivot, &numeric_pivot); if(struct_pivot == -1 && numeric_pivot == -1) { unit_check_near(1, m, 1, hy_gold.data(), hy_1.data()); unit_check_near(1, m, 1, hy_gold.data(), hy_2.data()); } } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseSpSV_solve(handle, transA, &h_alpha, A, x, y1, typeT, alg, descr)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseSpSV_solve(handle, transA, &h_alpha, A, x, y1, typeT, alg, descr)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = spsv_gflop_count(m, nnz, diag); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gbyte_count = csrsv_gbyte_count(m, nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::alpha, h_alpha, display_key_t::algorithm, hipsparse_spsvalg2string(alg), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSpSV_destroyDescr(descr)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(x)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y2)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPSV_CSR_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_spvec_descr.hpp000066400000000000000000000135171501764003400240210ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPVEC_DESCR_HPP #define TESTING_SPVEC_DESCR_HPP #include "hipsparse_test_unique_ptr.hpp" #ifdef GOOGLE_TEST #include #endif #include using namespace hipsparse_test; void testing_spvec_descr_bad_arg(void) { #if(!defined(CUDART_VERSION)) int64_t size = 100; int64_t nnz = 100; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipDataType dataType = HIP_R_32F; // Allocate memory on device auto idx_data_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto val_data_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * nnz), device_free}; int* idx_data = (int*)idx_data_managed.get(); float* val_data = (float*)val_data_managed.get(); hipsparseSpVecDescr_t x; // hipsparseCreateSpVec verify_hipsparse_status_invalid_pointer( hipsparseCreateSpVec(nullptr, size, nnz, idx_data, val_data, idxType, idxBase, dataType), "Error: x is nullptr"); verify_hipsparse_status_invalid_size( hipsparseCreateSpVec(&x, -1, nnz, idx_data, val_data, idxType, idxBase, dataType), "Error: size is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateSpVec(&x, size, -1, idx_data, val_data, idxType, idxBase, dataType), "Error: nnz is < 0"); verify_hipsparse_status_invalid_pointer( hipsparseCreateSpVec(&x, size, nnz, nullptr, val_data, idxType, idxBase, dataType), "Error: idx_data is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCreateSpVec(&x, size, nnz, idx_data, nullptr, idxType, idxBase, dataType), "Error: val_data is nullptr"); // hipsparseDestroySpVec verify_hipsparse_status_invalid_pointer(hipsparseDestroySpVec(nullptr), "Error: x is nullptr"); // Create valid descriptor verify_hipsparse_status_success( hipsparseCreateSpVec(&x, size, nnz, idx_data, val_data, idxType, idxBase, dataType), "Success"); // hipsparseSpVecGet void* idx; void* data; verify_hipsparse_status_invalid_pointer( hipsparseSpVecGet(nullptr, &size, &nnz, &idx, &data, &idxType, &idxBase, &dataType), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpVecGet(x, nullptr, &nnz, &idx, &data, &idxType, &idxBase, &dataType), "Error: size is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpVecGet(x, &size, nullptr, &idx, &data, &idxType, &idxBase, &dataType), "Error: nnz is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpVecGet(x, &size, &nnz, nullptr, &data, &idxType, &idxBase, &dataType), "Error: idx is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpVecGet(x, &size, &nnz, &idx, nullptr, &idxType, &idxBase, &dataType), "Error: val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpVecGet(x, &size, &nnz, &idx, &data, nullptr, &idxBase, &dataType), "Error: idxType is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpVecGet(x, &size, &nnz, &idx, &data, &idxType, nullptr, &dataType), "Error: idxBase is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpVecGet(x, &size, &nnz, &idx, &data, &idxType, &idxBase, nullptr), "Error: dataType is nullptr"); // hipsparseSpVecGetIndexBase verify_hipsparse_status_invalid_pointer(hipsparseSpVecGetIndexBase(nullptr, &idxBase), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpVecGetIndexBase(x, nullptr), "Error: idxBase is nullptr"); // hipsparseSpVecGetValues verify_hipsparse_status_invalid_pointer(hipsparseSpVecGetValues(nullptr, &data), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpVecGetValues(x, nullptr), "Error: val is nullptr"); // hipsparseSpVecSetValues verify_hipsparse_status_invalid_pointer(hipsparseSpVecSetValues(nullptr, data), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpVecSetValues(x, nullptr), "Error: val is nullptr"); // Destroy valid descriptor verify_hipsparse_status_success(hipsparseDestroySpVec(x), "Success"); #endif } #endif // TESTING_SPVEC_DESCR_HPP hipSPARSE-rocm-6.4.3/clients/include/testing_spvv.hpp000066400000000000000000000245661501764003400225250ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPVV_HPP #define TESTING_SPVV_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include using namespace hipsparse_test; void testing_spvv_bad_arg(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION > 10010 \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) int64_t size = 100; int64_t nnz = 100; float result; hipsparseOperation_t opType = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipDataType dataType = HIP_R_32F; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * nnz), device_free}; auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * size), device_free}; float* dx_val = (float*)dx_val_managed.get(); int* dx_ind = (int*)dx_ind_managed.get(); float* dy = (float*)dy_managed.get(); // Structures hipsparseSpVecDescr_t x; hipsparseDnVecDescr_t y; verify_hipsparse_status_success( hipsparseCreateSpVec(&x, size, nnz, dx_ind, dx_val, idxType, idxBase, dataType), "Success"); verify_hipsparse_status_success(hipsparseCreateDnVec(&y, size, dy, dataType), "Success"); // SpVV bufferSize size_t bufferSize; verify_hipsparse_status_invalid_handle( hipsparseSpVV_bufferSize(nullptr, opType, x, y, &result, dataType, &bufferSize)); verify_hipsparse_status_invalid_pointer( hipsparseSpVV_bufferSize(handle, opType, nullptr, y, &result, dataType, &bufferSize), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpVV_bufferSize(handle, opType, x, nullptr, &result, dataType, &bufferSize), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpVV_bufferSize(handle, opType, x, y, nullptr, dataType, &bufferSize), "Error: result is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpVV_bufferSize(handle, opType, x, y, &result, dataType, nullptr), "Error: bufferSize is nullptr"); // SpVV void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, 100)); verify_hipsparse_status_invalid_handle( hipsparseSpVV(nullptr, opType, x, y, &result, dataType, buffer)); verify_hipsparse_status_invalid_pointer( hipsparseSpVV(handle, opType, nullptr, y, &result, dataType, buffer), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpVV(handle, opType, x, nullptr, &result, dataType, buffer), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpVV(handle, opType, x, y, nullptr, dataType, buffer), "Error: result is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpVV(handle, opType, x, y, &result, dataType, nullptr), "Error: buffer is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpVec(x), "Success"); verify_hipsparse_status_success(hipsparseDestroyDnVec(y), "Success"); CHECK_HIP_ERROR(hipFree(buffer)); #endif } template hipsparseStatus_t testing_spvv(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION > 10010 \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) I size = argus.N; I nnz = argus.nnz; hipsparseOperation_t trans = argus.transA; hipsparseIndexBase_t idxBase = argus.baseA; // Index and data type hipsparseIndexType_t idxType = getIndexType(); hipDataType dataType = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; hipStream_t stream; CHECK_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // Host structures std::vector hx_ind(nnz); std::vector hx_val(nnz); std::vector hy(size); // Initial Data on CPU srand(12345ULL); hipsparseInitIndex(hx_ind.data(), nnz, 1, size); hipsparseInit(hx_val, 1, nnz); hipsparseInit(hy, 1, size); // Allocate memory on device auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz), device_free}; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * size), device_free}; auto dresult_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* dx_ind = (I*)dx_ind_managed.get(); T* dx_val = (T*)dx_val_managed.get(); T* dy = (T*)dy_managed.get(); T* dresult = (T*)dresult_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dx_ind, hx_ind.data(), sizeof(I) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx_val, hx_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy, hy.data(), sizeof(T) * size, hipMemcpyHostToDevice)); // Create structures hipsparseSpVecDescr_t x; hipsparseDnVecDescr_t y; CHECK_HIPSPARSE_ERROR( hipsparseCreateSpVec(&x, size, nnz, dx_ind, dx_val, idxType, idxBase, dataType)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&y, size, dy, dataType)); T hresult; T hresult_gold; T hresult_copied_from_device; // SpVV_bufferSize size_t bufferSize; CHECK_HIPSPARSE_ERROR( hipsparseSpVV_bufferSize(handle, trans, x, y, &hresult, dataType, &bufferSize)); void* externalBuffer; CHECK_HIP_ERROR(hipMalloc(&externalBuffer, bufferSize)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseSpVV(handle, trans, x, y, &hresult, dataType, externalBuffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSpVV(handle, trans, x, y, dresult, dataType, externalBuffer)); // Copy output from device to CPU CHECK_HIP_ERROR( hipMemcpy(&hresult_copied_from_device, dresult, sizeof(T), hipMemcpyDeviceToHost)); // CPU solution if(trans == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE) { hresult_gold = make_DataType(0); for(I i = 0; i < nnz; ++i) { hresult_gold = hresult_gold + testing_mult(testing_conj(hx_val[i]), hy[hx_ind[i] - idxBase]); } } else { hresult_gold = make_DataType(0); for(I i = 0; i < nnz; ++i) { hresult_gold = hresult_gold + testing_mult(hx_val[i], hy[hx_ind[i] - idxBase]); } } // Verify results against host unit_check_general(1, 1, 1, &hresult_gold, &hresult); unit_check_general(1, 1, 1, &hresult_gold, &hresult_copied_from_device); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseSpVV(handle, trans, x, y, &hresult, dataType, externalBuffer)); CHECK_HIP_ERROR(hipStreamSynchronize(stream)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseSpVV(handle, trans, x, y, &hresult, dataType, externalBuffer)); CHECK_HIP_ERROR(hipStreamSynchronize(stream)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = doti_gflop_count(nnz); double gbyte_count = doti_gbyte_count(nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); display_timing_info(display_key_t::nnz, nnz, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(externalBuffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpVec(x)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPVV_HPP hipSPARSE-rocm-6.4.3/clients/include/unit.hpp000066400000000000000000000043241501764003400207370ustar00rootroot00000000000000/* ************************************************************************ * 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-6.4.3/clients/include/utility.hpp000066400000000000000000006476231501764003400215020ustar00rootroot00000000000000/* ************************************************************************ * 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 #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, hipsparseOrder_t order, float sparsity_ratio = 0.3) { if(order == HIPSPARSE_ORDER_COL) { for(int j = 0; j < n; ++j) { for(int i = 0; i < m; ++i) { const float d = ((float)rand()) / ((float)RAND_MAX); A[j * lda + i] = (d < sparsity_ratio) ? testing_div(make_DataType(rand()), make_DataType(RAND_MAX)) : make_DataType(0); } } } else { for(int j = 0; j < m; ++j) { for(int i = 0; i < n; ++i) { const float d = ((float)rand()) / ((float)RAND_MAX); A[j * lda + i] = (d < sparsity_ratio) ? testing_div(make_DataType(rand()), make_DataType(RAND_MAX)) : make_DataType(0); } } } } /* ============================================================================================ */ /*! \brief Generate a random sparse matrix in COO format */ template void gen_matrix_coo(I m, I n, I nnz, std::vector& row_ind, std::vector& col_ind, std::vector& val, hipsparseIndexBase_t idx_base) { if((I)row_ind.size() != nnz) { row_ind.resize(nnz); } if((I)col_ind.size() != nnz) { col_ind.resize(nnz); } if((I)val.size() != nnz) { val.resize(nnz); } // Uniform distributed row indices for(I i = 0; i < nnz; ++i) { row_ind[i] = rand() % m; } // Sort row indices std::sort(row_ind.begin(), row_ind.end()); // Sample column indices std::vector check(nnz, false); { I i = 0; while(i < nnz) { I begin = i; while(row_ind[i] == row_ind[begin]) { ++i; if(i >= nnz) { break; } } // Sample i disjunct column indices I idx = begin; while(idx < i) { #define MM_PI 3.1415 // Normal distribution around the diagonal I rng = (i - begin) * sqrt(-2.0 * log((double)rand() / RAND_MAX)) * cos(2.0 * MM_PI * (double)rand() / RAND_MAX); if(m <= n) { rng += row_ind[begin]; } // Repeat if running out of bounds if(rng < 0 || rng > n - 1) { continue; } // Check for disjunct column index in current row if(!check[rng]) { check[rng] = true; col_ind[idx] = rng; ++idx; } } // Reset disjunct check array for(I j = begin; j < i; ++j) { check[col_ind[j]] = false; } // Partially sort column indices std::sort(&col_ind[begin], &col_ind[i]); } } // Correct index base accordingly if(idx_base == HIPSPARSE_INDEX_BASE_ONE) { for(I i = 0; i < nnz; ++i) { ++row_ind[i]; ++col_ind[i]; } } // Sample random values for(I i = 0; i < nnz; ++i) { val[i] = random_generator(); //(double) rand() / RAND_MAX; } } /* ============================================================================================ */ /*! \brief Read matrix from mtx file in COO format */ template static void read_mtx_value(std::istringstream& is, I& row, I& col, float& val) { is >> row >> col >> val; } template static void read_mtx_value(std::istringstream& is, I& row, I& col, double& val) { is >> row >> col >> val; } template static void read_mtx_value(std::istringstream& is, I& row, I& col, hipComplex& val) { float real; float imag; is >> row >> col >> real >> imag; val = make_DataType(real, imag); } template static void read_mtx_value(std::istringstream& is, I& row, I& col, hipDoubleComplex& val) { double real; double imag; is >> row >> col >> real >> imag; val = make_DataType(real, imag); } template static void sort(std::vector& perm, std::vector& unsorted_row, std::vector& unsorted_col) { std::sort(perm.begin(), perm.end(), [&](const I& a, const I& b) { if(unsorted_row[a] < unsorted_row[b]) { return true; } else if(unsorted_row[a] == unsorted_row[b]) { return (unsorted_col[a] < unsorted_col[b]); } else { return false; } }); } template inline void scan(const char* line, I* nrow, I* ncol, int64_t* nnz) { sscanf(line, "%d %d %ld", nrow, ncol, nnz); } template <> inline void scan(const char* line, int64_t* nrow, int64_t* ncol, int64_t* nnz) { sscanf(line, "%ld %ld %ld", nrow, ncol, nnz); } template int read_mtx_matrix(const char* filename, I& nrow, I& ncol, int64_t& nnz, std::vector& row, std::vector& col, std::vector& val, hipsparseIndexBase_t idx_base) { const char* env = getenv("GTEST_LISTENER"); if(!env || strcmp(env, "NO_PASS_LINE_IN_LOG")) { printf("Reading matrix %s...", filename); fflush(stdout); } FILE* f = fopen(filename, "r"); if(!f) { fprintf(stderr, "Failed to open matrix file %s because it does not exist. Please download the " "matrix file using the install script with -c flag.", filename); return -1; } char line[1024]; // Check for banner if(!fgets(line, 1024, f)) { return -1; } char banner[16]; char array[16]; char coord[16]; char data[16]; char type[16]; // Extract banner if(sscanf(line, "%15s %15s %15s %15s %15s", banner, array, coord, data, type) != 5) { return -1; } // Convert to lower case for(char* p = array; *p != '\0'; *p = tolower(*p), p++) ; for(char* p = coord; *p != '\0'; *p = tolower(*p), p++) ; for(char* p = data; *p != '\0'; *p = tolower(*p), p++) ; for(char* p = type; *p != '\0'; *p = tolower(*p), p++) ; // Check banner if(strncmp(line, "%%MatrixMarket", 14) != 0) { return -1; } // Check array type if(strcmp(array, "matrix") != 0) { return -1; } // Check coord if(strcmp(coord, "coordinate") != 0) { return -1; } // Check data if(strcmp(data, "real") != 0 && strcmp(data, "integer") != 0 && strcmp(data, "pattern") != 0) { return -1; } // Check type if(strcmp(type, "general") != 0 && strcmp(type, "symmetric") != 0) { return -1; } // Symmetric flag int symm = !strcmp(type, "symmetric"); // Skip comments while(fgets(line, 1024, f)) { if(line[0] != '%') { break; } } // Read dimensions int64_t snnz; scan(line, &nrow, &ncol, &snnz); nnz = symm ? (snnz - nrow) * 2 + nrow : snnz; std::vector unsorted_row(nnz); std::vector unsorted_col(nnz); std::vector unsorted_val(nnz); // Read entries int64_t idx = 0; while(fgets(line, 1024, f)) { if(idx >= nnz) { return 1; } I irow; I icol; T ival; std::istringstream ss(line); if(!strcmp(data, "pattern")) { ss >> irow >> icol; ival = make_DataType(1.0); } else { read_mtx_value(ss, irow, icol, ival); } if(idx_base == HIPSPARSE_INDEX_BASE_ZERO) { --irow; --icol; } unsorted_row[idx] = irow; unsorted_col[idx] = icol; unsorted_val[idx] = ival; ++idx; if(symm && irow != icol) { if(idx >= nnz) { return 1; } unsorted_row[idx] = icol; unsorted_col[idx] = irow; unsorted_val[idx] = ival; ++idx; } } fclose(f); row.resize(nnz); col.resize(nnz); val.resize(nnz); // Sort by row and column index std::vector perm(nnz); for(int64_t i = 0; i < nnz; ++i) { perm[i] = i; } sort(perm, unsorted_row, unsorted_col); for(int64_t i = 0; i < nnz; ++i) { row[i] = unsorted_row[perm[i]]; col[i] = unsorted_col[perm[i]]; val[i] = unsorted_val[perm[i]]; } if(!env || strcmp(env, "NO_PASS_LINE_IN_LOG")) { printf("done.\n"); fflush(stdout); } return 0; } /* ============================================================================================ */ /*! \brief Read matrix from binary file in CSR format */ template int read_bin_matrix(const char* filename, J& nrow, J& ncol, I& nnz, std::vector& ptr, std::vector& col, std::vector& val, hipsparseIndexBase_t idx_base) { const char* env = getenv("GTEST_LISTENER"); if(!env || strcmp(env, "NO_PASS_LINE_IN_LOG")) { printf("Reading matrix %s...", filename); fflush(stdout); } FILE* f = fopen(filename, "rb"); if(!f) { return -1; } int err; int nrowf, ncolf, nnzf; err = fread(&nrowf, sizeof(int), 1, f); err |= fread(&ncolf, sizeof(int), 1, f); err |= fread(&nnzf, sizeof(int), 1, f); if(!err) { fclose(f); return -1; } nrow = (J)nrowf; ncol = (J)ncolf; nnz = (I)nnzf; // Allocate memory std::vector ptrf(nrow + 1); std::vector colf(nnz); std::vector valf(nnz); ptr.resize(nrow + 1); col.resize(nnz); val.resize(nnz); err |= fread(ptrf.data(), sizeof(int), nrow + 1, f); err |= fread(colf.data(), sizeof(int), nnz, f); err |= fread(valf.data(), sizeof(double), nnz, f); if(!err) { fclose(f); return -1; } fclose(f); for(J i = 0; i < nrow + 1; ++i) { ptr[i] = (I)ptrf[i]; } for(I i = 0; i < nnz; ++i) { col[i] = (J)colf[i]; val[i] = make_DataType(valf[i]); } if(idx_base == HIPSPARSE_INDEX_BASE_ONE) { for(J i = 0; i < nrow + 1; ++i) { ++ptr[i]; } for(I i = 0; i < nnz; ++i) { ++col[i]; } } if(!env || strcmp(env, "NO_PASS_LINE_IN_LOG")) { printf("done.\n"); fflush(stdout); } return 0; } /* ============================================================================================ */ /*! \brief Generate CSR matrix from file. File can be either mtx or bin. If filename is empty, a random matrix is generated*/ template bool generate_csr_matrix(const std::string filename, J& nrow, J& ncol, I& nnz, std::vector& csr_row_ptr, std::vector& csr_col_ind, std::vector& csr_val, hipsparseIndexBase_t idx_base) { // If no filename passed, generate matrix if(filename == "") { double scale = 0.02; if(nrow > 1000 || ncol > 1000) { scale = 2.0 / std::max(nrow, ncol); } nnz = nrow * scale * ncol; std::vector coo_row_ind; gen_matrix_coo(nrow, ncol, (J)nnz, coo_row_ind, csr_col_ind, csr_val, idx_base); csr_row_ptr.resize(nrow + 1, 0); for(int i = 0; i < nnz; ++i) { ++csr_row_ptr[coo_row_ind[i] + 1 - idx_base]; } csr_row_ptr[0] = idx_base; for(int i = 0; i < nrow; ++i) { csr_row_ptr[i + 1] += csr_row_ptr[i]; } return true; } else { std::string extension = filename.substr(filename.find_last_of(".") + 1); if(extension == "bin") { if(read_bin_matrix( filename.c_str(), nrow, ncol, nnz, csr_row_ptr, csr_col_ind, csr_val, idx_base) == 0) { return true; } } else if(extension == "mtx") { int64_t nnz_count; std::vector coo_row_ind; if(read_mtx_matrix(filename.c_str(), nrow, ncol, nnz_count, coo_row_ind, csr_col_ind, csr_val, idx_base) == 0) { if(nnz_count < std::numeric_limits::max()) { nnz = (I)nnz_count; csr_row_ptr.resize(nrow + 1, 0); for(int i = 0; i < nnz; ++i) { ++csr_row_ptr[coo_row_ind[i] + 1 - idx_base]; } csr_row_ptr[0] = idx_base; for(int i = 0; i < nrow; ++i) { csr_row_ptr[i + 1] += csr_row_ptr[i]; } return true; } } } } return false; } /* ============================================================================================ */ /*! \brief Generate COO matrix from file. File can be either mtx or bin. If filename is empty, a random matrix is generated*/ template bool generate_coo_matrix(const std::string filename, I& nrow, I& ncol, I& nnz, std::vector& coo_row_ind, std::vector& coo_col_ind, std::vector& coo_val, hipsparseIndexBase_t idx_base) { // If no filename passed, generate matrix if(filename == "") { double scale = 0.02; if(nrow > 1000 || ncol > 1000) { scale = 2.0 / std::max(nrow, ncol); } nnz = nrow * scale * ncol; gen_matrix_coo(nrow, ncol, nnz, coo_row_ind, coo_col_ind, coo_val, idx_base); return true; } else { std::string extension = filename.substr(filename.find_last_of(".") + 1); if(extension == "bin") { std::vector csr_row_ptr; if(read_bin_matrix( filename.c_str(), nrow, ncol, nnz, csr_row_ptr, coo_col_ind, coo_val, idx_base) == 0) { coo_row_ind.resize(nnz); for(I i = 0; i < nrow; ++i) { I row_begin = csr_row_ptr[i] - idx_base; I row_end = csr_row_ptr[i + 1] - idx_base; for(I j = row_begin; j < row_end; ++j) { coo_row_ind[j] = i + idx_base; } } return true; } } else if(extension == "mtx") { int64_t nnz_count; if(read_mtx_matrix(filename.c_str(), nrow, ncol, nnz_count, coo_row_ind, coo_col_ind, coo_val, idx_base) == 0) { if(nnz_count < std::numeric_limits::max()) { nnz = (I)nnz_count; return true; } } } } return false; } /* ============================================================================================ */ /*! \brief Compute incomplete LU factorization without fill-ins and no pivoting using CSR * matrix storage format. */ static inline float testing_neg(float val) { return -val; } static inline double testing_neg(double val) { return -val; } static inline hipComplex testing_neg(hipComplex val) { hipComplex ret; ret.x = -val.x; ret.y = -val.y; return ret; } static inline hipDoubleComplex testing_neg(hipDoubleComplex val) { hipDoubleComplex ret; ret.x = -val.x; ret.y = -val.y; return ret; } template void host_nnz(hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const T* A, int lda, int* nnzPerRowColumn, int* nnzTotalDevHostPtr) { int mn = (dirA == HIPSPARSE_DIRECTION_ROW) ? m : n; #ifdef _OPENMP #pragma omp parallel for #endif for(int j = 0; j < mn; ++j) { nnzPerRowColumn[j] = 0; } for(int j = 0; j < n; ++j) { for(int i = 0; i < m; ++i) { if(A[j * lda + i] != make_DataType(0)) { if(dirA == HIPSPARSE_DIRECTION_ROW) { nnzPerRowColumn[i] += 1; } else { nnzPerRowColumn[j] += 1; } } } } int sum = 0; #ifdef _OPENMP #pragma omp parallel for reduction(+ : sum) #endif for(int j = 0; j < mn; ++j) { sum = sum + nnzPerRowColumn[j]; } nnzTotalDevHostPtr[0] = sum; } template void host_dense2csx(int m, int n, hipsparseIndexBase_t base, const T* A, int ld, const int* nnz_per_row_columns, T* csx_val, int* csx_row_col_ptr, int* csx_col_row_ind) { static constexpr T s_zero = {}; int len = (HIPSPARSE_DIRECTION_ROW == DIRA) ? m : n; *csx_row_col_ptr = base; for(int i = 0; i < len; ++i) { csx_row_col_ptr[i + 1] = nnz_per_row_columns[i] + csx_row_col_ptr[i]; } switch(DIRA) { case HIPSPARSE_DIRECTION_COLUMN: { for(int j = 0; j < n; ++j) { for(int i = 0; i < m; ++i) { if(A[j * ld + i] != s_zero) { *csx_val++ = A[j * ld + i]; *csx_col_row_ind++ = i + base; } } } break; } case HIPSPARSE_DIRECTION_ROW: { // // Does not matter having an orthogonal traversal ... testing only. // Otherwise, we would use csxRowPtrA to store the shifts. // and once the job is done a simple memory move would reinitialize the csxRowPtrA to its initial state) // for(int i = 0; i < m; ++i) { for(int j = 0; j < n; ++j) { if(A[j * ld + i] != s_zero) { *csx_val++ = A[j * ld + i]; *csx_col_row_ind++ = j + base; } } } break; } } } template void host_prune_dense2csr(int m, int n, const std::vector& A, int lda, hipsparseIndexBase_t base, T threshold, int& nnz, std::vector& csr_val, std::vector& csr_row_ptr, std::vector& csr_col_ind) { csr_row_ptr.resize(m + 1, 0); csr_row_ptr[0] = base; #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < m; i++) { for(int j = 0; j < n; j++) { if(testing_abs(A[lda * j + i]) > threshold) { csr_row_ptr[i + 1]++; } } } for(int i = 1; i <= m; i++) { csr_row_ptr[i] += csr_row_ptr[i - 1]; } nnz = csr_row_ptr[m] - csr_row_ptr[0]; csr_col_ind.resize(nnz); csr_val.resize(nnz); int index = 0; for(int i = 0; i < m; i++) { for(int j = 0; j < n; j++) { if(testing_abs(A[lda * j + i]) > threshold) { csr_val[index] = A[lda * j + i]; csr_col_ind[index] = j + base; index++; } } } } template void host_prune_dense2csr_by_percentage(int m, int n, const std::vector& A, int lda, hipsparseIndexBase_t base, T percentage, int& nnz, std::vector& csr_val, std::vector& csr_row_ptr, std::vector& csr_col_ind) { int nnz_A = m * n; int pos = std::ceil(nnz_A * (percentage / 100)) - 1; pos = std::min(pos, nnz_A - 1); pos = std::max(pos, 0); std::vector sorted_A(nnz_A); for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { sorted_A[m * i + j] = std::abs(A[lda * i + j]); } } std::sort(sorted_A.begin(), sorted_A.end()); T threshold = (nnz_A > 0) ? sorted_A[pos] : make_DataType(0); host_prune_dense2csr(m, n, A, lda, base, threshold, nnz, csr_val, csr_row_ptr, csr_col_ind); } template void host_csx2dense(int m, int n, hipsparseIndexBase_t base, const T* csx_val, const int* csx_row_col_ptr, const int* csx_col_row_ind, T* A, int ld) { static constexpr T s_zero = {}; switch(DIRA) { case HIPSPARSE_DIRECTION_COLUMN: { for(int col = 0; col < n; ++col) { for(int row = 0; row < m; ++row) { A[row + ld * col] = s_zero; } const int bound = csx_row_col_ptr[col + 1] - base; for(int at = csx_row_col_ptr[col] - base; at < bound; ++at) { A[(csx_col_row_ind[at] - base) + ld * col] = csx_val[at]; } } break; } case HIPSPARSE_DIRECTION_ROW: { for(int row = 0; row < m; ++row) { for(int col = 0; col < n; ++col) { A[col * ld + row] = s_zero; } const int bound = csx_row_col_ptr[row + 1] - base; for(int at = csx_row_col_ptr[row] - base; at < bound; ++at) { A[(csx_col_row_ind[at] - base) * ld + row] = csx_val[at]; } } break; } } } template inline void host_csr_to_csr_compress(int M, int N, const std::vector& csr_row_ptr_A, const std::vector& csr_col_ind_A, const std::vector& csr_val_A, std::vector& csr_row_ptr_C, std::vector& csr_col_ind_C, std::vector& csr_val_C, hipsparseIndexBase_t base, T tol) { if(M <= 0 || N <= 0) { return; } // find how many entries will be in each compressed CSR matrix row std::vector nnz_per_row(M); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < M; i++) { int start = csr_row_ptr_A[i] - base; int end = csr_row_ptr_A[i + 1] - base; int count = 0; for(int j = start; j < end; j++) { if(testing_abs(csr_val_A[j]) > testing_real(tol) && testing_abs(csr_val_A[j]) > (std::numeric_limits::min)()) { count++; } } nnz_per_row[i] = count; } // add up total number of entries int nnz_C = 0; for(int i = 0; i < M; i++) { nnz_C += nnz_per_row[i]; } //column indices and value arrays for compressed CSR matrix csr_col_ind_C.resize(nnz_C); csr_val_C.resize(nnz_C); // fill in row pointer array for compressed CSR matrix csr_row_ptr_C.resize(M + 1); csr_row_ptr_C[0] = base; for(int i = 0; i < M; i++) { csr_row_ptr_C[i + 1] = csr_row_ptr_C[i] + nnz_per_row[i]; } // fill in column indices and value arrays for compressed CSR matrix #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < M; i++) { int start = csr_row_ptr_A[i] - base; int end = csr_row_ptr_A[i + 1] - base; int index = csr_row_ptr_C[i] - base; for(int j = start; j < end; j++) { if(testing_abs(csr_val_A[j]) > testing_real(tol) && testing_abs(csr_val_A[j]) > (std::numeric_limits::min)()) { csr_col_ind_C[index] = csr_col_ind_A[j]; csr_val_C[index] = csr_val_A[j]; index++; } } } } template inline void host_prune_csr_to_csr(int M, int N, int nnz_A, const std::vector& csr_row_ptr_A, const std::vector& csr_col_ind_A, const std::vector& csr_val_A, int& nnz_C, std::vector& csr_row_ptr_C, std::vector& csr_col_ind_C, std::vector& csr_val_C, hipsparseIndexBase_t csr_base_A, hipsparseIndexBase_t csr_base_C, T threshold) { csr_row_ptr_C.resize(M + 1, 0); csr_row_ptr_C[0] = csr_base_C; #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < M; i++) { for(int j = csr_row_ptr_A[i] - csr_base_A; j < csr_row_ptr_A[i + 1] - csr_base_A; j++) { if(testing_abs(csr_val_A[j]) > threshold && testing_abs(csr_val_A[j]) > (std::numeric_limits::min)()) { csr_row_ptr_C[i + 1]++; } } } for(int i = 1; i <= M; i++) { csr_row_ptr_C[i] += csr_row_ptr_C[i - 1]; } nnz_C = csr_row_ptr_C[M] - csr_row_ptr_C[0]; csr_col_ind_C.resize(nnz_C); csr_val_C.resize(nnz_C); int index = 0; for(int i = 0; i < M; i++) { for(int j = csr_row_ptr_A[i] - csr_base_A; j < csr_row_ptr_A[i + 1] - csr_base_A; j++) { if(testing_abs(csr_val_A[j]) > threshold && testing_abs(csr_val_A[j]) > (std::numeric_limits::min)()) { csr_col_ind_C[index] = (csr_col_ind_A[j] - csr_base_A) + csr_base_C; csr_val_C[index] = csr_val_A[j]; index++; } } } } template void host_prune_csr_to_csr_by_percentage(int M, int N, int nnz_A, const std::vector& csr_row_ptr_A, const std::vector& csr_col_ind_A, const std::vector& csr_val_A, int& nnz_C, std::vector& csr_row_ptr_C, std::vector& csr_col_ind_C, std::vector& csr_val_C, hipsparseIndexBase_t csr_base_A, hipsparseIndexBase_t csr_base_C, T percentage) { int pos = std::ceil(nnz_A * (percentage / 100)) - 1; pos = std::min(pos, nnz_A - 1); pos = std::max(pos, 0); std::vector sorted_A(nnz_A); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < nnz_A; i++) { sorted_A[i] = testing_abs(csr_val_A[i]); } std::sort(sorted_A.begin(), sorted_A.end()); T threshold = sorted_A[pos]; host_prune_csr_to_csr(M, N, nnz_A, csr_row_ptr_A, csr_col_ind_A, csr_val_A, nnz_C, csr_row_ptr_C, csr_col_ind_C, csr_val_C, csr_base_A, csr_base_C, threshold); } template inline void host_csr_to_csc(J M, J N, I nnz, const I* csr_row_ptr, const J* csr_col_ind, const T* csr_val, //const std::vector& csr_row_ptr, //const std::vector& csr_col_ind, //const std::vector& csr_val, std::vector& csc_row_ind, std::vector& csc_col_ptr, std::vector& csc_val, hipsparseAction_t action, hipsparseIndexBase_t base) { csc_row_ind.resize(nnz); csc_col_ptr.resize(N + 1, 0); csc_val.resize(nnz); // Determine nnz per column for(I i = 0; i < nnz; ++i) { ++csc_col_ptr[csr_col_ind[i] + 1 - base]; } // Scan for(J i = 0; i < N; ++i) { csc_col_ptr[i + 1] += csc_col_ptr[i]; } // Fill row indices and values for(J i = 0; i < M; ++i) { I row_begin = csr_row_ptr[i] - base; I row_end = csr_row_ptr[i + 1] - base; for(I j = row_begin; j < row_end; ++j) { J col = csr_col_ind[j] - base; I idx = csc_col_ptr[col]; csc_row_ind[idx] = i + base; csc_val[idx] = csr_val[j]; ++csc_col_ptr[col]; } } // Shift column pointer array for(J i = N; i > 0; --i) { csc_col_ptr[i] = csc_col_ptr[i - 1] + base; } csc_col_ptr[0] = base; } template inline void host_csr_to_bsr(hipsparseDirection_t direction, int M, int N, int block_dim, int& nnzb, hipsparseIndexBase_t csr_base, const std::vector& csr_row_ptr, const std::vector& csr_col_ind, const std::vector& csr_val, hipsparseIndexBase_t bsr_base, std::vector& bsr_row_ptr, std::vector& bsr_col_ind, std::vector& bsr_val) { int mb = (M + block_dim - 1) / block_dim; int nb = (N + block_dim - 1) / block_dim; // quick return if block_dim == 1 if(block_dim == 1) { bsr_row_ptr.resize(mb + 1, 0); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(size_t i = 0; i < csr_row_ptr.size(); i++) { bsr_row_ptr[i] = (csr_row_ptr[i] - csr_base) + bsr_base; } nnzb = bsr_row_ptr[mb] - bsr_row_ptr[0]; bsr_col_ind.resize(nnzb, 0); bsr_val.resize(nnzb * block_dim * block_dim, make_DataType(0)); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(size_t i = 0; i < csr_col_ind.size(); i++) { bsr_col_ind[i] = (csr_col_ind[i] - csr_base) + bsr_base; } #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(size_t i = 0; i < csr_val.size(); i++) { bsr_val[i] = csr_val[i]; } return; } // determine number of non-zero block columns for each block row of the bsr matrix bsr_row_ptr.resize(mb + 1, 0); bsr_row_ptr[0] = bsr_base; #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < mb; i++) { int start = csr_row_ptr[i * block_dim] - csr_base; int end = csr_row_ptr[std::min(M, block_dim * i + block_dim)] - csr_base; std::vector temp(nb, 0); for(int j = start; j < end; j++) { int blockCol = (csr_col_ind[j] - csr_base) / block_dim; temp[blockCol] = 1; } int sum = 0; for(size_t j = 0; j < temp.size(); j++) { sum += temp[j]; } bsr_row_ptr[i + 1] = sum; } for(int i = 0; i < mb; i++) { bsr_row_ptr[i + 1] += bsr_row_ptr[i]; } nnzb = bsr_row_ptr[mb] - bsr_row_ptr[0]; // find bsr col indices array bsr_col_ind.resize(nnzb, 0); bsr_val.resize(nnzb * block_dim * block_dim, make_DataType(0)); int colIndex = 0; for(int i = 0; i < mb; i++) { int start = csr_row_ptr[i * block_dim] - csr_base; int end = csr_row_ptr[std::min(M, block_dim * i + block_dim)] - csr_base; std::vector temp(nb, 0); for(int j = start; j < end; j++) { int blockCol = (csr_col_ind[j] - csr_base) / block_dim; temp[blockCol] = 1; } for(int j = 0; j < nb; j++) { if(temp[j] == 1) { bsr_col_ind[colIndex] = j + bsr_base; colIndex++; } } } // find bsr values array for(int i = 0; i < M; i++) { int blockRow = i / block_dim; int start = csr_row_ptr[i] - csr_base; int end = csr_row_ptr[i + 1] - csr_base; for(int j = start; j < end; j++) { int blockCol = (csr_col_ind[j] - csr_base) / block_dim; colIndex = -1; for(int k = bsr_row_ptr[blockRow] - bsr_base; k < bsr_row_ptr[blockRow + 1] - bsr_base; k++) { if(bsr_col_ind[k] - bsr_base == blockCol) { colIndex = k - (bsr_row_ptr[blockRow] - bsr_base); break; } } assert(colIndex != -1); int blockIndex = 0; if(direction == HIPSPARSE_DIRECTION_ROW) { blockIndex = (csr_col_ind[j] - csr_base) % block_dim + (i % block_dim) * block_dim; } else { blockIndex = ((csr_col_ind[j] - csr_base) % block_dim) * block_dim + (i % block_dim); } int index = (bsr_row_ptr[blockRow] - bsr_base) * block_dim * block_dim + colIndex * block_dim * block_dim + blockIndex; bsr_val[index] = csr_val[j]; } } } template void host_bsr_to_bsc(int mb, int nb, int nnzb, int bsr_dim, const int* bsr_row_ptr, const int* bsr_col_ind, const T* bsr_val, std::vector& bsc_row_ind, std::vector& bsc_col_ptr, std::vector& bsc_val, hipsparseIndexBase_t bsr_base, hipsparseIndexBase_t bsc_base) { bsc_row_ind.resize(nnzb); bsc_col_ptr.resize(nb + 1, 0); bsc_val.resize(nnzb * bsr_dim * bsr_dim); // Determine nnz per column for(int i = 0; i < nnzb; ++i) { ++bsc_col_ptr[bsr_col_ind[i] + 1 - bsr_base]; } // Scan for(int i = 0; i < nb; ++i) { bsc_col_ptr[i + 1] += bsc_col_ptr[i]; } // Fill row indices and values for(int i = 0; i < mb; ++i) { int row_begin = bsr_row_ptr[i] - bsr_base; int row_end = bsr_row_ptr[i + 1] - bsr_base; for(int j = row_begin; j < row_end; ++j) { int col = bsr_col_ind[j] - bsr_base; int idx = bsc_col_ptr[col]; bsc_row_ind[idx] = i + bsc_base; for(int bi = 0; bi < bsr_dim; ++bi) { for(int bj = 0; bj < bsr_dim; ++bj) { bsc_val[bsr_dim * bsr_dim * idx + bi + bj * bsr_dim] = bsr_val[bsr_dim * bsr_dim * j + bi * bsr_dim + bj]; } } ++bsc_col_ptr[col]; } } // Shift column pointer array for(int i = nb; i > 0; --i) { bsc_col_ptr[i] = bsc_col_ptr[i - 1] + bsc_base; } bsc_col_ptr[0] = bsc_base; } template inline void host_gebsr_to_csr(hipsparseDirection_t direction, int mb, int nb, int nnzb, const std::vector& bsr_val, const std::vector& bsr_row_ptr, const std::vector& bsr_col_ind, int row_block_dim, int col_block_dim, hipsparseIndexBase_t bsr_base, std::vector& csr_val, std::vector& csr_row_ptr, std::vector& csr_col_ind, hipsparseIndexBase_t csr_base) { csr_col_ind.resize(nnzb * row_block_dim * col_block_dim); csr_row_ptr.resize(mb * row_block_dim + 1); csr_val.resize(nnzb * row_block_dim * col_block_dim); int at = 0; csr_row_ptr[0] = csr_base; for(int i = 0; i < mb; ++i) { for(int r = 0; r < row_block_dim; ++r) { int row = i * row_block_dim + r; for(int k = bsr_row_ptr[i] - bsr_base; k < bsr_row_ptr[i + 1] - bsr_base; ++k) { int j = bsr_col_ind[k] - bsr_base; for(int c = 0; c < col_block_dim; ++c) { int col = col_block_dim * j + c; csr_col_ind[at] = col + csr_base; if(direction == HIPSPARSE_DIRECTION_ROW) { csr_val[at] = bsr_val[k * row_block_dim * col_block_dim + col_block_dim * r + c]; } else { csr_val[at] = bsr_val[k * row_block_dim * col_block_dim + row_block_dim * c + r]; } ++at; } } csr_row_ptr[row + 1] = csr_row_ptr[row] + (bsr_row_ptr[i + 1] - bsr_row_ptr[i]) * col_block_dim; } } } template inline void host_csr_to_gebsr(hipsparseDirection_t direction, int m, int n, int row_block_dim, int col_block_dim, int& nnzb, hipsparseIndexBase_t csr_base, const std::vector& csr_row_ptr, const std::vector& csr_col_ind, const std::vector& csr_val, hipsparseIndexBase_t bsr_base, std::vector& bsr_row_ptr, std::vector& bsr_col_ind, std::vector& bsr_val) { int mb = (m + row_block_dim - 1) / row_block_dim; int nnz = csr_col_ind.size(); bsr_row_ptr.resize(mb + 1, 0); std::vector temp(nnz); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < nnz; i++) { temp[i] = (csr_col_ind[i] - csr_base) / col_block_dim; } #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < mb; i++) { int frow = row_block_dim * i; int lrow = row_block_dim * (i + 1); if(lrow > m) { lrow = m; } int start = csr_row_ptr[frow] - csr_base; int end = csr_row_ptr[lrow] - csr_base; std::sort(temp.begin() + start, temp.begin() + end); } #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < mb; i++) { int frow = row_block_dim * i; int lrow = row_block_dim * (i + 1); if(lrow > m) { lrow = m; } int start = csr_row_ptr[frow] - csr_base; int end = csr_row_ptr[lrow] - csr_base; int col = -1; int count = 0; for(int j = start; j < end; j++) { if(temp[j] > col) { col = temp[j]; temp[j] = -1; temp[start + count] = col; count++; } else { temp[j] = -1; } } bsr_row_ptr[i + 1] = count; } // fill GEBSR row pointer array bsr_row_ptr[0] = bsr_base; for(int i = 0; i < mb; i++) { bsr_row_ptr[i + 1] += bsr_row_ptr[i]; } nnzb = bsr_row_ptr[mb] - bsr_row_ptr[0]; bsr_col_ind.resize(nnzb); bsr_val.resize(nnzb * row_block_dim * col_block_dim, make_DataType(0)); // fill GEBSR col indices array { int index = 0; for(int i = 0; i < nnz; i++) { if(temp[i] != -1) { bsr_col_ind[index] = temp[i] + bsr_base; index++; } } } // fill GEBSR values array #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < m; i++) { int start = csr_row_ptr[i] - csr_base; int end = csr_row_ptr[i + 1] - csr_base; int bstart = bsr_row_ptr[i / row_block_dim] - bsr_base; int bend = bsr_row_ptr[i / row_block_dim + 1] - bsr_base; int local_row = i % row_block_dim; for(int j = start; j < end; j++) { int col = csr_col_ind[j] - csr_base; int local_col = col % col_block_dim; { int index = 0; for(int k = bstart; k < bend; k++) { if(bsr_col_ind[k] - bsr_base == col / col_block_dim) { index = k; bstart = k; break; } } if(direction == HIPSPARSE_DIRECTION_ROW) { bsr_val[row_block_dim * col_block_dim * index + col_block_dim * local_row + local_col] = csr_val[j]; } else { bsr_val[row_block_dim * col_block_dim * index + row_block_dim * local_col + local_row] = csr_val[j]; } } } } } template inline void host_gebsr_to_gebsr(hipsparseDirection_t direction, int mb, int nb, int nnzb, const std::vector& bsr_val_A, const std::vector& bsr_row_ptr_A, const std::vector& bsr_col_ind_A, int row_block_dim_A, int col_block_dim_A, hipsparseIndexBase_t base_A, std::vector& bsr_val_C, std::vector& bsr_row_ptr_C, std::vector& bsr_col_ind_C, int row_block_dim_C, int col_block_dim_C, hipsparseIndexBase_t base_C) { int m = mb * row_block_dim_A; int n = nb * col_block_dim_A; // convert GEBSR to CSR format std::vector csr_row_ptr; std::vector csr_col_ind; std::vector csr_val; host_gebsr_to_csr(direction, mb, nb, nnzb, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, base_A, csr_val, csr_row_ptr, csr_col_ind, HIPSPARSE_INDEX_BASE_ZERO); // convert CSR to GEBSR format int nnzb_C; host_csr_to_gebsr(direction, m, n, row_block_dim_C, col_block_dim_C, nnzb_C, HIPSPARSE_INDEX_BASE_ZERO, csr_row_ptr, csr_col_ind, csr_val, base_C, bsr_row_ptr_C, bsr_col_ind_C, bsr_val_C); } template void host_gebsr_to_gebsc(int Mb, int Nb, int nnzb, const std::vector& bsr_row_ptr, const std::vector& bsr_col_ind, const std::vector& bsr_val, int row_block_dim, int col_block_dim, std::vector& bsc_row_ind, std::vector& bsc_col_ptr, std::vector& bsc_val, hipsparseAction_t action, hipsparseIndexBase_t base) { bsc_row_ind.resize(nnzb); bsc_col_ptr.resize(Nb + 1, 0); bsc_val.resize(nnzb); const int block_shift = row_block_dim * col_block_dim; // // Determine nnz per column // for(int i = 0; i < nnzb; ++i) { ++bsc_col_ptr[bsr_col_ind[i] + 1 - base]; } // Scan for(int i = 0; i < Nb; ++i) { bsc_col_ptr[i + 1] += bsc_col_ptr[i]; } // Fill row indices and values for(int i = 0; i < Mb; ++i) { const int row_begin = bsr_row_ptr[i] - base; const int row_end = bsr_row_ptr[i + 1] - base; for(int j = row_begin; j < row_end; ++j) { const int col = bsr_col_ind[j] - base; const int idx = bsc_col_ptr[col]; bsc_row_ind[idx] = i + base; for(int k = 0; k < block_shift; ++k) { bsc_val[idx * block_shift + k] = bsr_val[j * block_shift + k]; } ++bsc_col_ptr[col]; } } // Shift column pointer array for(int i = Nb; i > 0; --i) { bsc_col_ptr[i] = bsc_col_ptr[i - 1] + base; } bsc_col_ptr[0] = base; } template inline void host_bsr_to_csr(hipsparseDirection_t direction, int Mb, int Nb, int block_dim, hipsparseIndexBase_t bsr_base, const std::vector& bsr_row_ptr, const std::vector& bsr_col_ind, const std::vector& bsr_val, hipsparseIndexBase_t csr_base, std::vector& csr_row_ptr, std::vector& csr_col_ind, std::vector& csr_val) { int m = Mb * block_dim; int nnzb = bsr_row_ptr[Mb] - bsr_row_ptr[0]; csr_row_ptr.resize(m + 1, 0); csr_col_ind.resize(nnzb * block_dim * block_dim, 0); csr_val.resize(nnzb * block_dim * block_dim, make_DataType(0)); // quick return if block_dim == 1 if(block_dim == 1) { #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(size_t i = 0; i < bsr_row_ptr.size(); i++) { csr_row_ptr[i] = (bsr_row_ptr[i] - bsr_base) + csr_base; } #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(size_t i = 0; i < bsr_col_ind.size(); i++) { csr_col_ind[i] = (bsr_col_ind[i] - bsr_base) + csr_base; } #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(size_t i = 0; i < bsr_val.size(); i++) { csr_val[i] = bsr_val[i]; } return; } csr_row_ptr[0] = csr_base; // find csr row ptr array for(int i = 0; i < Mb; i++) { int entries_in_row = block_dim * (bsr_row_ptr[i + 1] - bsr_row_ptr[i]); for(int j = 0; j < block_dim; j++) { csr_row_ptr[i * block_dim + j + 1] = csr_row_ptr[i * block_dim + j] + entries_in_row; } } int entries_in_block = block_dim * block_dim; // find csr col indices and values arrays #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < Mb; i++) { int entries_in_Row = (bsr_row_ptr[i + 1] - bsr_row_ptr[i]) * block_dim; int entries_in_row_sum = (bsr_row_ptr[i] - bsr_base) * entries_in_block; for(int j = bsr_row_ptr[i] - bsr_base; j < bsr_row_ptr[i + 1] - bsr_base; j++) { int col = bsr_col_ind[j] - bsr_base; int offset = entries_in_row_sum + block_dim * (j - (bsr_row_ptr[i] - bsr_base)); for(int k = 0; k < block_dim; k++) { for(int l = 0; l < block_dim; l++) { csr_col_ind[offset + k * entries_in_Row + l] = block_dim * col + l + csr_base; if(direction == HIPSPARSE_DIRECTION_ROW) { csr_val[offset + k * entries_in_Row + l] = bsr_val[j * entries_in_block + k * block_dim + l]; } else { csr_val[offset + k * entries_in_Row + l] = bsr_val[j * entries_in_block + k + block_dim * l]; } } } } } } template inline void host_bsrmv(hipsparseDirection_t dir, hipsparseOperation_t trans, int mb, int nb, int nnzb, T alpha, const int* bsr_row_ptr, const int* bsr_col_ind, const T* bsr_val, int bsr_dim, const T* x, T beta, T* y, hipsparseIndexBase_t base) { // Quick return if(alpha == make_DataType(0)) { if(beta != make_DataType(1)) { for(int i = 0; i < mb * bsr_dim; ++i) { y[i] = testing_mult(beta, y[i]); } } return; } int WFSIZE; if(bsr_dim == 2) { int blocks_per_row = nnzb / mb; if(blocks_per_row < 8) { WFSIZE = 4; } else if(blocks_per_row < 16) { WFSIZE = 8; } else if(blocks_per_row < 32) { WFSIZE = 16; } else if(blocks_per_row < 64) { WFSIZE = 32; } else { WFSIZE = 64; } } else if(bsr_dim <= 8) { WFSIZE = 8; } else if(bsr_dim <= 16) { WFSIZE = 16; } else { WFSIZE = 32; } #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int row = 0; row < mb; ++row) { int row_begin = bsr_row_ptr[row] - base; int row_end = bsr_row_ptr[row + 1] - base; if(bsr_dim == 2) { std::vector sum0(WFSIZE, make_DataType(0)); std::vector sum1(WFSIZE, make_DataType(0)); for(int j = row_begin; j < row_end; j += WFSIZE) { for(int k = 0; k < WFSIZE; ++k) { if(j + k < row_end) { int col = bsr_col_ind[j + k] - base; if(dir == HIPSPARSE_DIRECTION_COLUMN) { sum0[k] = testing_fma(bsr_val[bsr_dim * bsr_dim * (j + k) + 0], x[col * bsr_dim + 0], sum0[k]); sum1[k] = testing_fma(bsr_val[bsr_dim * bsr_dim * (j + k) + 1], x[col * bsr_dim + 0], sum1[k]); sum0[k] = testing_fma(bsr_val[bsr_dim * bsr_dim * (j + k) + 2], x[col * bsr_dim + 1], sum0[k]); sum1[k] = testing_fma(bsr_val[bsr_dim * bsr_dim * (j + k) + 3], x[col * bsr_dim + 1], sum1[k]); } else { sum0[k] = testing_fma(bsr_val[bsr_dim * bsr_dim * (j + k) + 0], x[col * bsr_dim + 0], sum0[k]); sum0[k] = testing_fma(bsr_val[bsr_dim * bsr_dim * (j + k) + 1], x[col * bsr_dim + 1], sum0[k]); sum1[k] = testing_fma(bsr_val[bsr_dim * bsr_dim * (j + k) + 2], x[col * bsr_dim + 0], sum1[k]); sum1[k] = testing_fma(bsr_val[bsr_dim * bsr_dim * (j + k) + 3], x[col * bsr_dim + 1], sum1[k]); } } } } for(int j = 1; j < WFSIZE; j <<= 1) { for(int k = 0; k < WFSIZE - j; ++k) { sum0[k] = sum0[k] + sum0[k + j]; sum1[k] = sum1[k] + sum1[k + j]; } } if(beta != make_DataType(0)) { y[row * bsr_dim + 0] = testing_fma(beta, y[row * bsr_dim + 0], testing_mult(alpha, sum0[0])); y[row * bsr_dim + 1] = testing_fma(beta, y[row * bsr_dim + 1], testing_mult(alpha, sum1[0])); } else { y[row * bsr_dim + 0] = testing_mult(alpha, sum0[0]); y[row * bsr_dim + 1] = testing_mult(alpha, sum1[0]); } } else { for(int bi = 0; bi < bsr_dim; ++bi) { std::vector sum(WFSIZE, make_DataType(0)); for(int j = row_begin; j < row_end; ++j) { int col = bsr_col_ind[j] - base; for(int bj = 0; bj < bsr_dim; bj += WFSIZE) { for(int k = 0; k < WFSIZE; ++k) { if(bj + k < bsr_dim) { if(dir == HIPSPARSE_DIRECTION_COLUMN) { sum[k] = testing_fma( bsr_val[bsr_dim * bsr_dim * j + bsr_dim * (bj + k) + bi], x[bsr_dim * col + (bj + k)], sum[k]); } else { sum[k] = testing_fma( bsr_val[bsr_dim * bsr_dim * j + bsr_dim * bi + (bj + k)], x[bsr_dim * col + (bj + k)], sum[k]); } } } } } for(int j = 1; j < WFSIZE; j <<= 1) { for(int k = 0; k < WFSIZE - j; ++k) { sum[k] = sum[k] + sum[k + j]; } } if(beta != make_DataType(0)) { y[row * bsr_dim + bi] = testing_fma(beta, y[row * bsr_dim + bi], testing_mult(alpha, sum[0])); } else { y[row * bsr_dim + bi] = testing_mult(alpha, sum[0]); } } } } } template inline void host_csrmv(hipsparseOperation_t trans, J M, J N, I nnz, T alpha, const I* csr_row_ptr, const J* csr_col_ind, const T* csr_val, const T* x, T beta, T* y, hipsparseIndexBase_t base) { if(trans == HIPSPARSE_OPERATION_NON_TRANSPOSE) { // Get device properties int dev; hipDeviceProp_t prop; hipGetDevice(&dev); hipGetDeviceProperties(&prop, dev); int WF_SIZE; J nnz_per_row = (M == 0) ? 0 : (nnz / M); if(nnz_per_row < 4) WF_SIZE = 2; else if(nnz_per_row < 8) WF_SIZE = 4; else if(nnz_per_row < 16) WF_SIZE = 8; else if(nnz_per_row < 32) WF_SIZE = 16; else if(nnz_per_row < 64 || prop.warpSize == 32) WF_SIZE = 32; else WF_SIZE = 64; for(J i = 0; i < M; ++i) { I row_begin = csr_row_ptr[i] - base; I row_end = csr_row_ptr[i + 1] - base; std::vector sum(WF_SIZE, static_cast(0)); for(I j = row_begin; j < row_end; j += WF_SIZE) { for(int k = 0; k < WF_SIZE; ++k) { if(j + k < row_end) { sum[k] = testing_fma(testing_mult(alpha, csr_val[j + k]), x[csr_col_ind[j + k] - base], sum[k]); } } } for(int j = 1; j < WF_SIZE; j <<= 1) { for(int k = 0; k < WF_SIZE - j; ++k) { sum[k] = sum[k] + sum[k + j]; } } if(beta == make_DataType(0.0)) { y[i] = sum[0]; } else { y[i] = testing_fma(beta, y[i], sum[0]); } } } else { // Scale y with beta for(J i = 0; i < N; ++i) { y[i] = testing_mult(y[i], beta); } // Transposed SpMV for(J i = 0; i < M; ++i) { I row_begin = csr_row_ptr[i] - base; I row_end = csr_row_ptr[i + 1] - base; T row_val = testing_mult(alpha, x[i]); for(I j = row_begin; j < row_end; ++j) { J col = csr_col_ind[j] - base; T val = (trans == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE) ? testing_conj(csr_val[j]) : csr_val[j]; y[col] = testing_fma(val, row_val, y[col]); } } } } template inline void host_bsrmm(int Mb, int N, int Kb, int block_dim, hipsparseDirection_t dir, hipsparseOperation_t transA, hipsparseOperation_t transB, T alpha, const std::vector& bsr_row_ptr_A, const std::vector& bsr_col_ind_A, const std::vector& bsr_val_A, const std::vector& B, int ldb, T beta, std::vector& C, int ldc, hipsparseIndexBase_t base) { if(transA != HIPSPARSE_OPERATION_NON_TRANSPOSE) { return; } if(transB != HIPSPARSE_OPERATION_NON_TRANSPOSE && transB != HIPSPARSE_OPERATION_TRANSPOSE) { return; } int M = Mb * block_dim; #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < M; i++) { int local_row = i % block_dim; int row_begin = bsr_row_ptr_A[i / block_dim] - base; int row_end = bsr_row_ptr_A[i / block_dim + 1] - base; for(int j = 0; j < N; j++) { int idx_C = i + j * ldc; T sum = make_DataType(0.0); for(int s = row_begin; s < row_end; s++) { for(int t = 0; t < block_dim; t++) { int idx_A = (dir == HIPSPARSE_DIRECTION_ROW) ? block_dim * block_dim * s + block_dim * local_row + t : block_dim * block_dim * s + block_dim * t + local_row; int idx_B = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? j * ldb + block_dim * (bsr_col_ind_A[s] - base) + t : (block_dim * (bsr_col_ind_A[s] - base) + t) * ldb + j; sum = sum + testing_mult(alpha, testing_mult(bsr_val_A[idx_A], B[idx_B])); } } if(beta == make_DataType(0.0)) { C[idx_C] = sum; } else { C[idx_C] = sum + testing_mult(beta, C[idx_C]); } } } } template void host_csrmm(J M, J N, J K, hipsparseOperation_t transA, hipsparseOperation_t transB, T alpha, const I* csr_row_ptr_A, const J* csr_col_ind_A, const T* csr_val_A, const T* B, J ldb, hipsparseOrder_t orderB, T beta, T* C, J ldc, hipsparseOrder_t orderC, hipsparseIndexBase_t base, bool force_conj_A) { bool conj_A = (transA == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE || force_conj_A); bool conj_B = (transB == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE); if(transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) { #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(J i = 0; i < M; i++) { for(J j = 0; j < N; ++j) { I row_begin = csr_row_ptr_A[i] - base; I row_end = csr_row_ptr_A[i + 1] - base; J idx_C = orderC == HIPSPARSE_ORDER_COL ? i + j * ldc : i * ldc + j; T sum = make_DataType(0); for(I k = row_begin; k < row_end; ++k) { J idx_B = 0; if((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE && orderB == HIPSPARSE_ORDER_COL) || (transB == HIPSPARSE_OPERATION_TRANSPOSE && orderB != HIPSPARSE_ORDER_COL) || (transB == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE && orderB != HIPSPARSE_ORDER_COL)) { idx_B = (csr_col_ind_A[k] - base + j * ldb); } else { idx_B = (j + (csr_col_ind_A[k] - base) * ldb); } sum = testing_fma( testing_conj(csr_val_A[k], conj_A), testing_conj(B[idx_B], conj_B), sum); } if(beta == make_DataType(0)) { C[idx_C] = testing_mult(alpha, sum); } else { C[idx_C] = testing_fma(beta, C[idx_C], testing_mult(alpha, sum)); } } } } else { // scale C by beta for(J i = 0; i < K; i++) { for(J j = 0; j < N; ++j) { J idx_C = (orderC == HIPSPARSE_ORDER_COL) ? i + j * ldc : i * ldc + j; C[idx_C] = testing_mult(beta, C[idx_C]); } } for(J i = 0; i < M; i++) { I row_begin = csr_row_ptr_A[i] - base; I row_end = csr_row_ptr_A[i + 1] - base; for(J j = 0; j < N; ++j) { for(I k = row_begin; k < row_end; ++k) { J col = csr_col_ind_A[k] - base; T val = testing_conj(csr_val_A[k], conj_A); J idx_B = 0; if((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE && orderB == HIPSPARSE_ORDER_COL) || (transB == HIPSPARSE_OPERATION_TRANSPOSE && orderB != HIPSPARSE_ORDER_COL) || (transB == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE && orderB != HIPSPARSE_ORDER_COL)) { idx_B = (i + j * ldb); } else { idx_B = (j + i * ldb); } J idx_C = (orderC == HIPSPARSE_ORDER_COL) ? col + j * ldc : col * ldc + j; C[idx_C] = C[idx_C] + testing_mult(alpha, testing_mult(val, testing_conj(B[idx_B], conj_B))); } } } } } template void host_csrmm_batched(J M, J N, J K, J batch_count_A, J offsets_batch_stride_A, I columns_values_batch_stride_A, hipsparseOperation_t transA, hipsparseOperation_t transB, T alpha, const I* csr_row_ptr_A, const J* csr_col_ind_A, const T* csr_val_A, const T* B, J ldb, J batch_count_B, I batch_stride_B, hipsparseOrder_t order_B, T beta, T* C, J ldc, J batch_count_C, I batch_stride_C, hipsparseOrder_t order_C, hipsparseIndexBase_t base, bool force_conj_A) { bool Ci_A_Bi = (batch_count_A == 1 && batch_count_B == batch_count_C); bool Ci_Ai_B = (batch_count_B == 1 && batch_count_A == batch_count_C); bool Ci_Ai_Bi = (batch_count_A == batch_count_C && batch_count_A == batch_count_B); if(!Ci_A_Bi && !Ci_Ai_B && !Ci_Ai_Bi) { return; } if(Ci_A_Bi) { for(J i = 0; i < batch_count_C; i++) { host_csrmm(M, N, K, transA, transB, alpha, csr_row_ptr_A, csr_col_ind_A, csr_val_A, B + batch_stride_B * i, ldb, order_B, beta, C + batch_stride_C * i, ldc, order_C, base, force_conj_A); } } else if(Ci_Ai_B) { for(J i = 0; i < batch_count_C; i++) { host_csrmm(M, N, K, transA, transB, alpha, csr_row_ptr_A + offsets_batch_stride_A * i, csr_col_ind_A + columns_values_batch_stride_A * i, csr_val_A + columns_values_batch_stride_A * i, B, ldb, order_B, beta, C + batch_stride_C * i, ldc, order_C, base, force_conj_A); } } else if(Ci_Ai_Bi) { for(J i = 0; i < batch_count_C; i++) { host_csrmm(M, N, K, transA, transB, alpha, csr_row_ptr_A + offsets_batch_stride_A * i, csr_col_ind_A + columns_values_batch_stride_A * i, csr_val_A + columns_values_batch_stride_A * i, B + batch_stride_B * i, ldb, order_B, beta, C + batch_stride_C * i, ldc, order_C, base, force_conj_A); } } } template void host_cscmm(J M, J N, J K, hipsparseOperation_t transA, hipsparseOperation_t transB, T alpha, const I* csc_col_ptr_A, const J* csc_row_ind_A, const T* csc_val_A, const T* B, J ldb, hipsparseOrder_t order_B, T beta, T* C, J ldc, hipsparseOrder_t order_C, hipsparseIndexBase_t base) { switch(transA) { case HIPSPARSE_OPERATION_NON_TRANSPOSE: { return host_csrmm(K, N, M, HIPSPARSE_OPERATION_TRANSPOSE, transB, alpha, csc_col_ptr_A, csc_row_ind_A, csc_val_A, B, ldb, order_B, beta, C, ldc, order_C, base, false); } case HIPSPARSE_OPERATION_TRANSPOSE: { return host_csrmm(K, N, M, HIPSPARSE_OPERATION_NON_TRANSPOSE, transB, alpha, csc_col_ptr_A, csc_row_ind_A, csc_val_A, B, ldb, order_B, beta, C, ldc, order_C, base, false); } case HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE: { return host_csrmm(K, N, M, HIPSPARSE_OPERATION_NON_TRANSPOSE, transB, alpha, csc_col_ptr_A, csc_row_ind_A, csc_val_A, B, ldb, order_B, beta, C, ldc, order_C, base, true); } } } template void host_cscmm_batched(J M, J N, J K, J batch_count_A, I offsets_batch_stride_A, I rows_values_batch_stride_A, hipsparseOperation_t transA, hipsparseOperation_t transB, T alpha, const I* csc_col_ptr_A, const J* csc_row_ind_A, const T* csc_val_A, const T* B, J ldb, J batch_count_B, I batch_stride_B, hipsparseOrder_t order_B, T beta, T* C, J ldc, J batch_count_C, I batch_stride_C, hipsparseOrder_t order_C, hipsparseIndexBase_t base) { switch(transA) { case HIPSPARSE_OPERATION_NON_TRANSPOSE: { return host_csrmm_batched(K, N, M, batch_count_A, offsets_batch_stride_A, rows_values_batch_stride_A, HIPSPARSE_OPERATION_TRANSPOSE, transB, alpha, csc_col_ptr_A, csc_row_ind_A, csc_val_A, B, ldb, batch_count_B, batch_stride_B, order_B, beta, C, ldc, batch_count_C, batch_stride_C, order_C, base, false); } case HIPSPARSE_OPERATION_TRANSPOSE: { return host_csrmm_batched(K, N, M, batch_count_A, offsets_batch_stride_A, rows_values_batch_stride_A, HIPSPARSE_OPERATION_NON_TRANSPOSE, transB, alpha, csc_col_ptr_A, csc_row_ind_A, csc_val_A, B, ldb, batch_count_B, batch_stride_B, order_B, beta, C, ldc, batch_count_C, batch_stride_C, order_C, base, false); } case HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE: { return host_csrmm_batched(K, N, M, batch_count_A, offsets_batch_stride_A, rows_values_batch_stride_A, HIPSPARSE_OPERATION_NON_TRANSPOSE, transB, alpha, csc_col_ptr_A, csc_row_ind_A, csc_val_A, B, ldb, batch_count_B, batch_stride_B, order_B, beta, C, ldc, batch_count_C, batch_stride_C, order_C, base, true); } } } template void host_coomm(I M, I N, I K, I nnz, hipsparseOperation_t transA, hipsparseOperation_t transB, T alpha, const I* coo_row_ind_A, const I* coo_col_ind_A, const T* coo_val_A, const T* B, I ldb, hipsparseOrder_t order_B, T beta, T* C, I ldc, hipsparseOrder_t order_C, hipsparseIndexBase_t base) { bool conj_A = (transA == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE); bool conj_B = (transB == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE); if(transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) { for(I j = 0; j < N; j++) { #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(I i = 0; i < M; ++i) { I idx_C = (order_C == HIPSPARSE_ORDER_COL) ? i + j * ldc : i * ldc + j; C[idx_C] = testing_mult(beta, C[idx_C]); } } #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(I j = 0; j < N; j++) { for(I i = 0; i < nnz; ++i) { I row = coo_row_ind_A[i] - base; I col = coo_col_ind_A[i] - base; T val = testing_mult(alpha, coo_val_A[i]); I idx_C = (order_C == HIPSPARSE_ORDER_COL) ? row + j * ldc : row * ldc + j; I idx_B = 0; if((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE && order_B == HIPSPARSE_ORDER_COL) || (transB != HIPSPARSE_OPERATION_NON_TRANSPOSE && order_B != HIPSPARSE_ORDER_COL)) { idx_B = (col + j * ldb); } else { idx_B = (j + col * ldb); } C[idx_C] = testing_fma(val, testing_conj(B[idx_B], conj_B), C[idx_C]); } } } else { for(I j = 0; j < N; j++) { #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(I i = 0; i < K; ++i) { I idx_C = (order_C == HIPSPARSE_ORDER_COL) ? i + j * ldc : i * ldc + j; C[idx_C] = testing_mult(beta, C[idx_C]); } } #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(I j = 0; j < N; j++) { for(I i = 0; i < nnz; ++i) { I row = coo_row_ind_A[i] - base; I col = coo_col_ind_A[i] - base; T val = testing_mult(alpha, testing_conj(coo_val_A[i], conj_A)); I idx_C = (order_C == HIPSPARSE_ORDER_COL) ? col + j * ldc : col * ldc + j; I idx_B = 0; if((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE && order_B == HIPSPARSE_ORDER_COL) || (transB != HIPSPARSE_OPERATION_NON_TRANSPOSE && order_B != HIPSPARSE_ORDER_COL)) { idx_B = (row + j * ldb); } else { idx_B = (j + row * ldb); } C[idx_C] = testing_fma(val, testing_conj(B[idx_B], conj_B), C[idx_C]); } } } } template void host_coomm_batched(I M, I N, I K, I nnz, I batch_count_A, I batch_stride_A, hipsparseOperation_t transA, hipsparseOperation_t transB, T alpha, const I* coo_row_ind_A, const I* coo_col_ind_A, const T* coo_val_A, const T* B, I ldb, I batch_count_B, I batch_stride_B, hipsparseOrder_t order_B, T beta, T* C, I ldc, I batch_count_C, I batch_stride_C, hipsparseOrder_t order_C, hipsparseIndexBase_t base) { bool Ci_A_Bi = (batch_count_A == 1 && batch_count_B == batch_count_C); bool Ci_Ai_B = (batch_count_B == 1 && batch_count_A == batch_count_C); bool Ci_Ai_Bi = (batch_count_A == batch_count_C && batch_count_A == batch_count_B); if(!Ci_A_Bi && !Ci_Ai_B && !Ci_Ai_Bi) { return; } if(Ci_A_Bi) { for(I i = 0; i < batch_count_C; i++) { host_coomm(M, N, K, nnz, transA, transB, alpha, coo_row_ind_A, coo_col_ind_A, coo_val_A, B + batch_stride_B * i, ldb, order_B, beta, C + batch_stride_C * i, ldc, order_C, base); } } else if(Ci_Ai_B) { for(I i = 0; i < batch_count_C; i++) { host_coomm(M, N, K, nnz, transA, transB, alpha, coo_row_ind_A + batch_stride_A * i, coo_col_ind_A + batch_stride_A * i, coo_val_A + batch_stride_A * i, B, ldb, order_B, beta, C + batch_stride_C * i, ldc, order_C, base); } } else if(Ci_Ai_Bi) { for(I i = 0; i < batch_count_C; i++) { host_coomm(M, N, K, nnz, transA, transB, alpha, coo_row_ind_A + batch_stride_A * i, coo_col_ind_A + batch_stride_A * i, coo_val_A + batch_stride_A * i, B + batch_stride_B * i, ldb, order_B, beta, C + batch_stride_C * i, ldc, order_C, base); } } } template int csrilu0(int m, const int* ptr, const int* col, T* val, hipsparseIndexBase_t idx_base, bool boost, double boost_tol, T boost_val) { // pointer of upper part of each row std::vector diag_offset(m); std::vector nnz_entries(m, 0); // ai = 0 to N loop over all rows for(int ai = 0; ai < m; ++ai) { // ai-th row entries int row_start = ptr[ai] - idx_base; int row_end = ptr[ai + 1] - idx_base; int j; // nnz position of ai-th row in val array for(j = row_start; j < row_end; ++j) { nnz_entries[col[j] - idx_base] = j; } bool has_diag = false; // loop over ai-th row nnz entries for(j = row_start; j < row_end; ++j) { // if nnz entry is in lower matrix if(col[j] - idx_base < ai) { int col_j = col[j] - idx_base; int diag_j = diag_offset[col_j]; T diag_val = val[diag_j]; if(boost) { diag_val = (boost_tol >= testing_abs(diag_val)) ? boost_val : diag_val; val[diag_j] = diag_val; } else { // Check for numeric pivot if(diag_val == make_DataType(0.0)) { // Numerical zero diagonal return col_j + idx_base; } } // multiplication factor val[j] = testing_div(val[j], diag_val); // loop over upper offset pointer and do linear combination for nnz entry for(int k = diag_j + 1; k < ptr[col_j + 1] - idx_base; ++k) { // if nnz at this position do linear combination if(nnz_entries[col[k] - idx_base] != 0) { int idx = nnz_entries[col[k] - idx_base]; val[idx] = testing_fma(testing_neg(val[j]), val[k], val[idx]); } } } else if(col[j] - idx_base == ai) { has_diag = true; break; } else { break; } } if(!has_diag) { // Structural zero digonal return ai + idx_base; } // set diagonal pointer to diagonal element diag_offset[ai] = j; // clear nnz entries for(j = row_start; j < row_end; ++j) { nnz_entries[col[j] - idx_base] = 0; } } return -1; } template inline void host_bsrilu02(hipsparseDirection_t dir, int mb, int bsr_dim, const std::vector& bsr_row_ptr, const std::vector& bsr_col_ind, std::vector& bsr_val, hipsparseIndexBase_t base, int* struct_pivot, int* numeric_pivot, bool boost, double boost_tol, T boost_val) { // Initialize pivots *struct_pivot = mb + 1; *numeric_pivot = mb + 1; // Temporary vector to hold diagonal offset to access diagonal BSR block std::vector diag_offset(mb); std::vector nnz_entries(mb, -1); // First diagonal block is index 0 if(mb > 0) { diag_offset[0] = 0; } // Loop over all BSR rows for(int i = 0; i < mb; ++i) { // Flag whether we have a diagonal block or not bool has_diag = false; // BSR column entry and exit point int row_begin = bsr_row_ptr[i] - base; int row_end = bsr_row_ptr[i + 1] - base; int j; // Set up entry points for linear combination for(j = row_begin; j < row_end; ++j) { int col_j = bsr_col_ind[j] - base; nnz_entries[col_j] = j; } // Process lower diagonal BSR blocks (diagonal BSR block is excluded) for(j = row_begin; j < row_end; ++j) { // Column index of current BSR block int bsr_col = bsr_col_ind[j] - base; // If this is a diagonal block, set diagonal flag to true and skip // all upcoming blocks as we exceed the lower matrix part if(bsr_col == i) { has_diag = true; break; } // Skip all upper matrix blocks if(bsr_col > i) { break; } // Process all lower matrix BSR blocks // Obtain corresponding row entry and exit point that corresponds with the // current BSR column. Actually, we skip all lower matrix column indices, // therefore starting with the diagonal entry. int diag_j = diag_offset[bsr_col]; int row_end_j = bsr_row_ptr[bsr_col + 1] - base; // Loop through all rows within the BSR block for(int bi = 0; bi < bsr_dim; ++bi) { T diag = bsr_val[BSR_IND(diag_j, bi, bi, dir)]; // Process all rows within the BSR block for(int bk = 0; bk < bsr_dim; ++bk) { T val = bsr_val[BSR_IND(j, bk, bi, dir)]; // Multiplication factor bsr_val[BSR_IND(j, bk, bi, dir)] = val = testing_div(val, diag); // Loop through columns of bk-th row and do linear combination for(int bj = bi + 1; bj < bsr_dim; ++bj) { bsr_val[BSR_IND(j, bk, bj, dir)] = testing_fma(-val, bsr_val[BSR_IND(diag_j, bi, bj, dir)], bsr_val[BSR_IND(j, bk, bj, dir)]); } } } // Loop over upper offset pointer and do linear combination for nnz entry for(int k = diag_j + 1; k < row_end_j; ++k) { int bsr_col_k = bsr_col_ind[k] - base; if(nnz_entries[bsr_col_k] != -1) { int m = nnz_entries[bsr_col_k]; // Loop through all rows within the BSR block for(int bi = 0; bi < bsr_dim; ++bi) { // Loop through columns of bi-th row and do linear combination for(int bj = 0; bj < bsr_dim; ++bj) { T sum = make_DataType(0); for(int bk = 0; bk < bsr_dim; ++bk) { sum = testing_fma(bsr_val[BSR_IND(j, bi, bk, dir)], bsr_val[BSR_IND(k, bk, bj, dir)], sum); } bsr_val[BSR_IND(m, bi, bj, dir)] = bsr_val[BSR_IND(m, bi, bj, dir)] - sum; } } } } } // Check for structural pivot if(!has_diag) { *struct_pivot = std::min(*struct_pivot, i + base); break; } // Process diagonal if(bsr_col_ind[j] - base == i) { // Loop through all rows within the BSR block for(int bi = 0; bi < bsr_dim; ++bi) { T diag = bsr_val[BSR_IND(j, bi, bi, dir)]; if(boost) { diag = (boost_tol >= testing_abs(diag)) ? boost_val : diag; bsr_val[BSR_IND(j, bi, bi, dir)] = diag; } else { // Check for numeric pivot if(diag == make_DataType(0)) { *numeric_pivot = std::min(*numeric_pivot, bsr_col_ind[j]); continue; } } // Process all rows within the BSR block after bi-th row for(int bk = bi + 1; bk < bsr_dim; ++bk) { T val = bsr_val[BSR_IND(j, bk, bi, dir)]; // Multiplication factor bsr_val[BSR_IND(j, bk, bi, dir)] = val = testing_div(val, diag); // Loop through remaining columns of bk-th row and do linear combination for(int bj = bi + 1; bj < bsr_dim; ++bj) { bsr_val[BSR_IND(j, bk, bj, dir)] = testing_fma(-val, bsr_val[BSR_IND(j, bi, bj, dir)], bsr_val[BSR_IND(j, bk, bj, dir)]); } } } } // Store diagonal BSR block entry point int row_diag = diag_offset[i] = j; // Process upper diagonal BSR blocks for(j = row_diag + 1; j < row_end; ++j) { // Loop through all rows within the BSR block for(int bi = 0; bi < bsr_dim; ++bi) { // Process all rows within the BSR block after bi-th row for(int bk = bi + 1; bk < bsr_dim; ++bk) { // Loop through columns of bk-th row and do linear combination for(int bj = 0; bj < bsr_dim; ++bj) { bsr_val[BSR_IND(j, bk, bj, dir)] = testing_fma(-bsr_val[BSR_IND(row_diag, bk, bi, dir)], bsr_val[BSR_IND(j, bi, bj, dir)], bsr_val[BSR_IND(j, bk, bj, dir)]); } } } } // Reset entry points for(j = row_begin; j < row_end; ++j) { int col_j = bsr_col_ind[j] - base; nnz_entries[col_j] = -1; } } *struct_pivot = (*struct_pivot == mb + 1) ? -1 : *struct_pivot; *numeric_pivot = (*numeric_pivot == mb + 1) ? -1 : *numeric_pivot; } template inline void host_bsric02(hipsparseDirection_t direction, int Mb, int block_dim, const std::vector& bsr_row_ptr, const std::vector& bsr_col_ind, std::vector& bsr_val, hipsparseIndexBase_t base, int* struct_pivot, int* numeric_pivot) { int M = Mb * block_dim; // Initialize pivot *struct_pivot = -1; *numeric_pivot = -1; if(bsr_col_ind.size() == 0 && bsr_val.size() == 0) { return; } // pointer of upper part of each row std::vector diag_block_offset(Mb); std::vector diag_offset(M, -1); std::vector nnz_entries(M, -1); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < Mb; i++) { int row_begin = bsr_row_ptr[i] - base; int row_end = bsr_row_ptr[i + 1] - base; for(int j = row_begin; j < row_end; j++) { if(bsr_col_ind[j] - base == i) { diag_block_offset[i] = j; break; } } } for(int i = 0; i < M; i++) { int local_row = i % block_dim; int row_begin = bsr_row_ptr[i / block_dim] - base; int row_end = bsr_row_ptr[i / block_dim + 1] - base; for(int j = row_begin; j < row_end; j++) { int block_col_j = bsr_col_ind[j] - base; for(int k = 0; k < block_dim; k++) { if(direction == HIPSPARSE_DIRECTION_ROW) { nnz_entries[block_dim * block_col_j + k] = block_dim * block_dim * j + block_dim * local_row + k; } else { nnz_entries[block_dim * block_col_j + k] = block_dim * block_dim * j + block_dim * k + local_row; } } } T sum = make_DataType(0); int diag_val_index = -1; bool has_diag = false; bool break_outer_loop = false; for(int j = row_begin; j < row_end; j++) { int block_col_j = bsr_col_ind[j] - base; for(int k = 0; k < block_dim; k++) { int col_j = block_dim * block_col_j + k; // Mark diagonal and skip row if(col_j == i) { diag_val_index = block_dim * block_dim * j + block_dim * k + k; has_diag = true; break_outer_loop = true; break; } // Skip upper triangular if(col_j > i) { break_outer_loop = true; break; } T val_j; if(direction == HIPSPARSE_DIRECTION_ROW) { val_j = bsr_val[block_dim * block_dim * j + block_dim * local_row + k]; } else { val_j = bsr_val[block_dim * block_dim * j + block_dim * k + local_row]; } int local_row_j = col_j % block_dim; int row_begin_j = bsr_row_ptr[col_j / block_dim] - base; int row_end_j = diag_block_offset[col_j / block_dim]; int row_diag_j = diag_offset[col_j]; T local_sum = make_DataType(0); T inv_diag = row_diag_j != -1 ? bsr_val[row_diag_j] : make_DataType(0); // Check for numeric zero if(inv_diag == make_DataType(0)) { // Numerical non-invertible block diagonal if(*numeric_pivot == -1) { *numeric_pivot = block_col_j + base; } *numeric_pivot = std::min(*numeric_pivot, block_col_j + base); inv_diag = make_DataType(1); } inv_diag = testing_div(make_DataType(1), inv_diag); // loop over upper offset pointer and do linear combination for nnz entry for(int l = row_begin_j; l < row_end_j + 1; l++) { int block_col_l = bsr_col_ind[l] - base; for(int m = 0; m < block_dim; m++) { int idx = nnz_entries[block_dim * block_col_l + m]; if(idx != -1 && block_dim * block_col_l + m < col_j) { if(direction == HIPSPARSE_DIRECTION_ROW) { local_sum = testing_fma(bsr_val[block_dim * block_dim * l + block_dim * local_row_j + m], testing_conj(bsr_val[idx]), local_sum); } else { local_sum = testing_fma(bsr_val[block_dim * block_dim * l + block_dim * m + local_row_j], testing_conj(bsr_val[idx]), local_sum); } } } } val_j = testing_mult((val_j - local_sum), inv_diag); sum = testing_fma(val_j, testing_conj(val_j), sum); if(direction == HIPSPARSE_DIRECTION_ROW) { bsr_val[block_dim * block_dim * j + block_dim * local_row + k] = val_j; } else { bsr_val[block_dim * block_dim * j + block_dim * k + local_row] = val_j; } } if(break_outer_loop) { break; } } if(!has_diag) { // Structural missing block diagonal if(*struct_pivot == -1) { *struct_pivot = i / block_dim + base; } } // Process diagonal entry if(has_diag) { T diag_entry = make_DataType(std::sqrt(testing_abs(bsr_val[diag_val_index] - sum))); bsr_val[diag_val_index] = diag_entry; if(diag_entry == make_DataType(0)) { // Numerical non-invertible block diagonal if(*numeric_pivot == -1) { *numeric_pivot = i / block_dim + base; } *numeric_pivot = std::min(*numeric_pivot, i / block_dim + base); } // Store diagonal offset diag_offset[i] = diag_val_index; } for(int j = row_begin; j < row_end; j++) { int block_col_j = bsr_col_ind[j] - base; for(int k = 0; k < block_dim; k++) { if(direction == HIPSPARSE_DIRECTION_ROW) { nnz_entries[block_dim * block_col_j + k] = -1; } else { nnz_entries[block_dim * block_col_j + k] = -1; } } } } } template void csric0(int M, const int* csr_row_ptr, const int* csr_col_ind, T* csr_val, hipsparseIndexBase_t idx_base, int& struct_pivot, int& numeric_pivot) { // Initialize pivot struct_pivot = -1; numeric_pivot = -1; // pointer of upper part of each row std::vector diag_offset(M); std::vector nnz_entries(M, 0); // ai = 0 to N loop over all rows for(int ai = 0; ai < M; ++ai) { // ai-th row entries int row_begin = csr_row_ptr[ai] - idx_base; int row_end = csr_row_ptr[ai + 1] - idx_base; int j; // nnz position of ai-th row in val array for(j = row_begin; j < row_end; ++j) { nnz_entries[csr_col_ind[j] - idx_base] = j; } T sum = make_DataType(0.0); bool has_diag = false; // loop over ai-th row nnz entries for(j = row_begin; j < row_end; ++j) { int col_j = csr_col_ind[j] - idx_base; T val_j = csr_val[j]; // Mark diagonal and skip row if(col_j == ai) { has_diag = true; break; } // Skip upper triangular if(col_j > ai) { break; } int row_begin_j = csr_row_ptr[col_j] - idx_base; int row_diag_j = diag_offset[col_j]; T local_sum = make_DataType(0.0); T inv_diag = csr_val[row_diag_j]; // Check for numeric zero if(inv_diag == make_DataType(0.0)) { // Numerical zero diagonal numeric_pivot = col_j + idx_base; return; } inv_diag = testing_div(make_DataType(1.0), inv_diag); // loop over upper offset pointer and do linear combination for nnz entry for(int k = row_begin_j; k < row_diag_j; ++k) { int col_k = csr_col_ind[k] - idx_base; // if nnz at this position do linear combination if(nnz_entries[col_k] != 0) { int idx = nnz_entries[col_k]; local_sum = testing_fma(csr_val[k], testing_conj(csr_val[idx]), local_sum); } } val_j = testing_mult((val_j - local_sum), inv_diag); sum = testing_fma(val_j, testing_conj(val_j), sum); csr_val[j] = val_j; } if(!has_diag) { // Structural (and numerical) zero diagonal struct_pivot = ai + idx_base; numeric_pivot = ai + idx_base; return; } // Process diagonal entry T diag_entry = make_DataType(std::sqrt(testing_abs(csr_val[j] - sum))); csr_val[j] = diag_entry; // Store diagonal offset diag_offset[ai] = j; // clear nnz entries for(j = row_begin; j < row_end; ++j) { nnz_entries[csr_col_ind[j] - idx_base] = 0; } } } /* ============================================================================================ */ /*! \brief Sparse triangular system solve using CSR storage format. */ template static inline void host_lssolve(J M, J nrhs, hipsparseOperation_t transB, T alpha, const std::vector& csr_row_ptr, const std::vector& csr_col_ind, const std::vector& csr_val, std::vector& B, J ldb, hipsparseOrder_t order_B, hipsparseDiagType_t diag_type, hipsparseIndexBase_t base, J* struct_pivot, J* numeric_pivot) { // Get device properties int dev; hipDeviceProp_t prop; 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 && order_B == HIPSPARSE_ORDER_COL) ? i * ldb + row : row * ldb + i; if(transB == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE) { temp[0] = testing_mult(alpha, testing_conj(B[idx_B])); } else { temp[0] = testing_mult(alpha, B[idx_B]); } I diag = -1; I row_begin = csr_row_ptr[row] - base; I row_end = csr_row_ptr[row + 1] - base; T diag_val = make_DataType(0.0); for(I l = row_begin; l < row_end; l += prop.warpSize) { for(int k = 0; k < prop.warpSize; ++k) { I j = l + k; // Do not run out of bounds if(j >= row_end) { break; } J local_col = csr_col_ind[j] - base; T local_val = csr_val[j]; if(local_val == make_DataType(0.0) && local_col == row && diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { // Numerical zero pivot found, avoid division by 0 and store // index for later use *numeric_pivot = std::min(*numeric_pivot, row + base); local_val = make_DataType(1.0); } // Ignore all entries that are above the diagonal if(local_col > row) { break; } // Diagonal entry if(local_col == row) { // If diagonal type is non unit, do division by diagonal entry // This is not required for unit diagonal for obvious reasons if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { diag = j; diag_val = testing_div(make_DataType(1.0), local_val); } break; } // Lower triangular part J idx = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE && order_B == HIPSPARSE_ORDER_COL) ? i * ldb + local_col : local_col * ldb + i; T neg_val = testing_mult(make_DataType(-1.0), local_val); if(transB == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE) { temp[k] = testing_fma(neg_val, testing_conj(B[idx]), temp[k]); } else { temp[k] = testing_fma(neg_val, B[idx], temp[k]); } } } for(int j = 1; j < prop.warpSize; j <<= 1) { for(int k = 0; k < prop.warpSize - j; ++k) { temp[k] = temp[k] + temp[k + j]; } } if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { if(diag == -1) { *struct_pivot = std::min(*struct_pivot, row + base); } B[idx_B] = testing_mult(temp[0], diag_val); } else { B[idx_B] = temp[0]; } } } } template static inline void host_ussolve(J M, J nrhs, hipsparseOperation_t transB, T alpha, const std::vector& csr_row_ptr, const std::vector& csr_col_ind, const std::vector& csr_val, std::vector& B, J ldb, hipsparseOrder_t order_B, hipsparseDiagType_t diag_type, hipsparseIndexBase_t base, J* struct_pivot, J* numeric_pivot) { // Get device properties int dev; hipDeviceProp_t prop; 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 && order_B == HIPSPARSE_ORDER_COL) ? i * ldb + row : row * ldb + i; if(transB == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE) { temp[0] = testing_mult(alpha, testing_conj(B[idx_B])); } else { temp[0] = testing_mult(alpha, B[idx_B]); } I diag = -1; I row_begin = csr_row_ptr[row] - base; I row_end = csr_row_ptr[row + 1] - base; T diag_val = make_DataType(0.0); for(I l = row_end - 1; l >= row_begin; l -= prop.warpSize) { for(int k = 0; k < prop.warpSize; ++k) { I j = l - k; // Do not run out of bounds if(j < row_begin) { break; } J local_col = csr_col_ind[j] - base; T local_val = csr_val[j]; // Ignore all entries that are below the diagonal if(local_col < row) { continue; } // Diagonal entry if(local_col == row) { if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { // Check for numerical zero if(local_val == make_DataType(0.0)) { *numeric_pivot = std::min(*numeric_pivot, row + base); local_val = make_DataType(1.0); } diag = j; diag_val = testing_div(make_DataType(1.0), local_val); } continue; } // Upper triangular part J idx = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE && order_B == HIPSPARSE_ORDER_COL) ? i * ldb + local_col : local_col * ldb + i; T neg_val = testing_mult(make_DataType(-1.0), local_val); if(transB == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE) { temp[k] = testing_fma(neg_val, testing_conj(B[idx]), temp[k]); } else { temp[k] = testing_fma(neg_val, B[idx], temp[k]); } } } for(int j = 1; j < prop.warpSize; j <<= 1) { for(int k = 0; k < prop.warpSize - j; ++k) { temp[k] = temp[k] + temp[k + j]; } } if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { if(diag == -1) { *struct_pivot = std::min(*struct_pivot, row + base); } B[idx_B] = testing_mult(temp[0], diag_val); } else { B[idx_B] = temp[0]; } } } } template void host_bsrsm(int mb, int nrhs, int nnzb, hipsparseDirection_t dir, hipsparseOperation_t transA, hipsparseOperation_t transX, T alpha, const int* bsr_row_ptr, const int* bsr_col_ind, const T* bsr_val, int bsr_dim, const T* B, int ldb, T* X, int ldx, hipsparseDiagType_t diag_type, hipsparseFillMode_t fill_mode, hipsparseIndexBase_t base, int* struct_pivot, int* numeric_pivot) { // Initialize pivot *struct_pivot = mb + 1; *numeric_pivot = mb + 1; if(transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) { if(fill_mode == HIPSPARSE_FILL_MODE_LOWER) { bsr_lsolve(dir, transX, mb, nrhs, alpha, bsr_row_ptr, bsr_col_ind, bsr_val, bsr_dim, B, ldb, X, ldx, diag_type, base, struct_pivot, numeric_pivot); } else { bsr_usolve(dir, transX, mb, nrhs, alpha, bsr_row_ptr, bsr_col_ind, bsr_val, bsr_dim, B, ldb, X, ldx, diag_type, base, struct_pivot, numeric_pivot); } } else if(transA == HIPSPARSE_OPERATION_TRANSPOSE) { // Transpose matrix std::vector bsrt_row_ptr(mb + 1); std::vector bsrt_col_ind(nnzb); std::vector bsrt_val(nnzb * bsr_dim * bsr_dim); host_bsr_to_bsc(mb, mb, nnzb, bsr_dim, bsr_row_ptr, bsr_col_ind, bsr_val, bsrt_col_ind, bsrt_row_ptr, bsrt_val, base, base); if(fill_mode == HIPSPARSE_FILL_MODE_LOWER) { bsr_usolve(dir, transX, mb, nrhs, alpha, bsrt_row_ptr.data(), bsrt_col_ind.data(), bsrt_val.data(), bsr_dim, B, ldb, X, ldx, diag_type, base, struct_pivot, numeric_pivot); } else { bsr_lsolve(dir, transX, mb, nrhs, alpha, bsrt_row_ptr.data(), bsrt_col_ind.data(), bsrt_val.data(), bsr_dim, B, ldb, X, ldx, diag_type, base, struct_pivot, numeric_pivot); } } *numeric_pivot = std::min(*numeric_pivot, *struct_pivot); *struct_pivot = (*struct_pivot == mb + 1) ? -1 : *struct_pivot; *numeric_pivot = (*numeric_pivot == mb + 1) ? -1 : *numeric_pivot; } template void host_csr_lsolve(J M, T alpha, const I* csr_row_ptr, const J* csr_col_ind, const T* csr_val, const T* x, T* y, hipsparseDiagType_t diag_type, hipsparseIndexBase_t base, J* struct_pivot, J* numeric_pivot) { // Get device properties int dev; hipDeviceProp_t prop; 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_csrsm2(J M, J nrhs, I nnz, hipsparseOperation_t transA, hipsparseOperation_t transB, T alpha, const std::vector& csr_row_ptr, const std::vector& csr_col_ind, const std::vector& csr_val, std::vector& B, J ldb, hipsparseOrder_t order_B, hipsparseDiagType_t diag_type, hipsparseFillMode_t fill_mode, hipsparseIndexBase_t base, J* struct_pivot, J* numeric_pivot) { // Initialize pivot *struct_pivot = M + 1; *numeric_pivot = M + 1; if(transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) { if(fill_mode == HIPSPARSE_FILL_MODE_LOWER) { host_lssolve(M, nrhs, transB, alpha, csr_row_ptr, csr_col_ind, csr_val, B, ldb, order_B, diag_type, base, struct_pivot, numeric_pivot); } else { host_ussolve(M, nrhs, transB, alpha, csr_row_ptr, csr_col_ind, csr_val, B, ldb, order_B, diag_type, base, struct_pivot, numeric_pivot); } } else if(transA == HIPSPARSE_OPERATION_TRANSPOSE || transA == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE) { // Transpose matrix std::vector csrt_row_ptr(M + 1); std::vector csrt_col_ind(nnz); std::vector csrt_val(nnz); host_csr_to_csc(M, M, nnz, csr_row_ptr.data(), csr_col_ind.data(), csr_val.data(), csrt_col_ind, csrt_row_ptr, csrt_val, HIPSPARSE_ACTION_NUMERIC, base); if(transA == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE) { for(size_t i = 0; i < csrt_val.size(); i++) { csrt_val[i] = testing_conj(csrt_val[i]); } } if(fill_mode == HIPSPARSE_FILL_MODE_LOWER) { host_ussolve(M, nrhs, transB, alpha, csrt_row_ptr, csrt_col_ind, csrt_val, B, ldb, order_B, diag_type, base, struct_pivot, numeric_pivot); } else { host_lssolve(M, nrhs, transB, alpha, csrt_row_ptr, csrt_col_ind, csrt_val, B, ldb, order_B, diag_type, base, struct_pivot, numeric_pivot); } } *numeric_pivot = std::min(*numeric_pivot, *struct_pivot); *struct_pivot = (*struct_pivot == M + 1) ? -1 : *struct_pivot; *numeric_pivot = (*numeric_pivot == M + 1) ? -1 : *numeric_pivot; } template void host_csrsm(J M, J nrhs, I nnz, hipsparseOperation_t trans_A, hipsparseOperation_t trans_B, T alpha, const std::vector& csr_row_ptr, const std::vector& csr_col_ind, const std::vector& csr_val, const std::vector& B, J ldb, hipsparseOrder_t order_B, std::vector& C, J ldc, hipsparseOrder_t order_C, hipsparseDiagType_t diag_type, hipsparseFillMode_t fill_mode, hipsparseIndexBase_t base, J* struct_pivot, J* numeric_pivot) { J B_m = (trans_B == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? M : nrhs; J B_n = (trans_B == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? nrhs : M; J C_m = M; J C_n = nrhs; // Copy B to C if(order_B == HIPSPARSE_ORDER_COL) { if(trans_B == HIPSPARSE_OPERATION_NON_TRANSPOSE) { if(order_C == HIPSPARSE_ORDER_COL) { for(J j = 0; j < B_n; j++) { for(J i = 0; i < B_m; i++) { C[i + ldc * j] = B[i + ldb * j]; } } } else { for(J j = 0; j < B_n; j++) { for(J i = 0; i < B_m; i++) { C[i * ldc + j] = B[i + ldb * j]; } } } } else { if(order_C == HIPSPARSE_ORDER_COL) { for(J j = 0; j < B_n; j++) { for(J i = 0; i < B_m; i++) { C[i * ldc + j] = B[i + ldb * j]; } } } else { for(J j = 0; j < B_n; j++) { for(J i = 0; i < B_m; i++) { C[i + ldc * j] = B[i + ldb * j]; } } } } } else { if(trans_B == HIPSPARSE_OPERATION_NON_TRANSPOSE) { if(order_C == HIPSPARSE_ORDER_COL) { for(J j = 0; j < B_n; j++) { for(J i = 0; i < B_m; i++) { C[i + ldc * j] = B[ldb * i + j]; } } } else { for(J j = 0; j < B_n; j++) { for(J i = 0; i < B_m; i++) { C[i * ldc + j] = B[ldb * i + j]; } } } } else { if(order_C == HIPSPARSE_ORDER_COL) { for(J j = 0; j < B_n; j++) { for(J i = 0; i < B_m; i++) { C[i * ldc + j] = B[ldb * i + j]; } } } else { for(J j = 0; j < B_n; j++) { for(J i = 0; i < B_m; i++) { C[i + ldc * j] = B[ldb * i + j]; } } } } } if(trans_B == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE) { if(order_C == HIPSPARSE_ORDER_COL) { for(J j = 0; j < C_n; j++) { for(J i = 0; i < C_m; i++) { C[i + ldc * j] = testing_conj(C[i + ldc * j]); } } } else { for(J i = 0; i < C_m; i++) { for(J j = 0; j < C_n; j++) { C[ldc * i + j] = testing_conj(C[ldc * i + j]); } } } } hipsparseOperation_t trans_C = HIPSPARSE_OPERATION_NON_TRANSPOSE; host_csrsm2(M, nrhs, nnz, trans_A, trans_C, alpha, csr_row_ptr, csr_col_ind, csr_val, C, ldc, order_C, diag_type, fill_mode, base, struct_pivot, numeric_pivot); } template void host_coosm(I M, I nrhs, I nnz, hipsparseOperation_t transA, hipsparseOperation_t transB, T alpha, const std::vector& coo_row_ind, const std::vector& coo_col_ind, const std::vector& coo_val, const std::vector& B, I ldb, hipsparseOrder_t order_B, std::vector& C, I ldc, hipsparseOrder_t order_C, hipsparseDiagType_t diag_type, hipsparseFillMode_t fill_mode, hipsparseIndexBase_t base, I* struct_pivot, I* numeric_pivot) { I B_m = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? M : nrhs; I B_n = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? nrhs : M; I C_m = M; I C_n = nrhs; // Copy B to C if(order_B == HIPSPARSE_ORDER_COL) { if(transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) { if(order_C == HIPSPARSE_ORDER_COL) { for(I j = 0; j < B_n; j++) { for(I i = 0; i < B_m; i++) { C[i + ldc * j] = B[i + ldb * j]; } } } else { for(I j = 0; j < B_n; j++) { for(I i = 0; i < B_m; i++) { C[i * ldc + j] = B[i + ldb * j]; } } } } else { if(order_C == HIPSPARSE_ORDER_COL) { for(I j = 0; j < B_n; j++) { for(I i = 0; i < B_m; i++) { C[i * ldc + j] = B[i + ldb * j]; } } } else { for(I j = 0; j < B_n; j++) { for(I i = 0; i < B_m; i++) { C[i + ldc * j] = B[i + ldb * j]; } } } } } else { if(transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) { if(order_C == HIPSPARSE_ORDER_COL) { for(I j = 0; j < B_n; j++) { for(I i = 0; i < B_m; i++) { C[i + ldc * j] = B[ldb * i + j]; } } } else { for(I j = 0; j < B_n; j++) { for(I i = 0; i < B_m; i++) { C[i * ldc + j] = B[ldb * i + j]; } } } } else { if(order_C == HIPSPARSE_ORDER_COL) { for(I j = 0; j < B_n; j++) { for(I i = 0; i < B_m; i++) { C[i * ldc + j] = B[ldb * i + j]; } } } else { for(I j = 0; j < B_n; j++) { for(I i = 0; i < B_m; i++) { C[i + ldc * j] = B[ldb * i + j]; } } } } } if(transB == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE) { if(order_C == HIPSPARSE_ORDER_COL) { for(I j = 0; j < C_n; j++) { for(I i = 0; i < C_m; i++) { C[i + ldc * j] = testing_conj(C[i + ldc * j]); } } } else { for(I i = 0; i < C_m; i++) { for(I j = 0; j < C_n; j++) { C[ldc * i + j] = testing_conj(C[ldc * i + j]); } } } } hipsparseOperation_t transC = HIPSPARSE_OPERATION_NON_TRANSPOSE; std::vector csr_row_ptr(M + 1); //host_coo_to_csr(M, coo_row_ind, csr_row_ptr, base); // coo2csr on host for(I i = 0; i < nnz; ++i) { ++csr_row_ptr[coo_row_ind[i] + 1 - base]; } csr_row_ptr[0] = base; for(I i = 0; i < M; ++i) { csr_row_ptr[i + 1] += csr_row_ptr[i]; } host_csrsm2(M, nrhs, nnz, transA, transC, alpha, csr_row_ptr, coo_col_ind, coo_val, C, ldc, order_C, diag_type, fill_mode, base, struct_pivot, numeric_pivot); } /* ============================================================================================ */ /*! \brief Sparse triangular lower solve using BSR storage format. */ template void bsr_lsolve(hipsparseDirection_t dir, hipsparseOperation_t trans_X, int mb, int nrhs, T alpha, const int* bsr_row_ptr, const int* bsr_col_ind, const T* bsr_val, int bsr_dim, const T* B, int ldb, T* X, int ldx, hipsparseDiagType_t diag_type, hipsparseIndexBase_t base, int* struct_pivot, int* numeric_pivot) { #ifdef _OPENMP #pragma omp parallel for #endif for(int i = 0; i < nrhs; ++i) { // Process lower triangular part for(int bsr_row = 0; bsr_row < mb; ++bsr_row) { int bsr_row_begin = bsr_row_ptr[bsr_row] - base; int bsr_row_end = bsr_row_ptr[bsr_row + 1] - base; // Loop over blocks rows for(int bi = 0; bi < bsr_dim; ++bi) { int diag = -1; int local_row = bsr_row * bsr_dim + bi; int idx_B = (trans_X == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? i * ldb + local_row : local_row * ldb + i; int idx_X = (trans_X == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? i * ldx + local_row : local_row * ldx + i; T sum = testing_mult(alpha, B[idx_B]); T diag_val = make_DataType(0); // Loop over BSR columns for(int j = bsr_row_begin; j < bsr_row_end; ++j) { int bsr_col = bsr_col_ind[j] - base; // Loop over blocks columns for(int bj = 0; bj < bsr_dim; ++bj) { int local_col = bsr_col * bsr_dim + bj; T local_val = (dir == HIPSPARSE_DIRECTION_ROW) ? bsr_val[bsr_dim * bsr_dim * j + bi * bsr_dim + bj] : bsr_val[bsr_dim * bsr_dim * j + bi + bj * bsr_dim]; if(local_val == make_DataType(0) && local_col == local_row && diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { // Numerical zero pivot found, avoid division by 0 // and store index for later use. *numeric_pivot = std::min(*numeric_pivot, bsr_row + base); local_val = make_DataType(1); } // Ignore all entries that are above the diagonal if(local_col > local_row) { break; } // Diagonal if(local_col == local_row) { // If diagonal type is non unit, do division by diagonal entry // This is not required for unit diagonal for obvious reasons if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { diag = j; diag_val = testing_div(make_DataType(1), local_val); } break; } // Lower triangular part int idx = (trans_X == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? i * ldx + local_col : local_col * ldx + i; sum = testing_fma(-local_val, X[idx], sum); } } if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { if(diag == -1) { *struct_pivot = std::min(*struct_pivot, bsr_row + base); } X[idx_X] = testing_mult(sum, diag_val); } else { X[idx_X] = sum; } } } } } /* ============================================================================================ */ /*! \brief Sparse triangular upper solve using BSR storage format. */ template void bsr_usolve(hipsparseDirection_t dir, hipsparseOperation_t trans_X, int mb, int nrhs, T alpha, const int* bsr_row_ptr, const int* bsr_col_ind, const T* bsr_val, int bsr_dim, const T* B, int ldb, T* X, int ldx, hipsparseDiagType_t diag_type, hipsparseIndexBase_t base, int* struct_pivot, int* numeric_pivot) { #ifdef _OPENMP #pragma omp parallel for #endif for(int i = 0; i < nrhs; ++i) { // Process upper triangular part for(int bsr_row = mb - 1; bsr_row >= 0; --bsr_row) { int bsr_row_begin = bsr_row_ptr[bsr_row] - base; int bsr_row_end = bsr_row_ptr[bsr_row + 1] - base; for(int bi = bsr_dim - 1; bi >= 0; --bi) { int local_row = bsr_row * bsr_dim + bi; int idx_B = (trans_X == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? i * ldb + local_row : local_row * ldb + i; int idx_X = (trans_X == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? i * ldx + local_row : local_row * ldx + i; T sum = testing_mult(alpha, B[idx_B]); int diag = -1; T diag_val = make_DataType(0); for(int j = bsr_row_end - 1; j >= bsr_row_begin; --j) { int bsr_col = bsr_col_ind[j] - base; for(int bj = bsr_dim - 1; bj >= 0; --bj) { int local_col = bsr_col * bsr_dim + bj; T local_val = dir == HIPSPARSE_DIRECTION_ROW ? bsr_val[bsr_dim * bsr_dim * j + bi * bsr_dim + bj] : bsr_val[bsr_dim * bsr_dim * j + bi + bj * bsr_dim]; // Ignore all entries that are below the diagonal if(local_col < local_row) { continue; } // Diagonal if(local_col == local_row) { if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { // Check for numerical zero if(local_val == make_DataType(0)) { *numeric_pivot = std::min(*numeric_pivot, bsr_row + base); local_val = make_DataType(1); } diag = j; diag_val = testing_div(make_DataType(1), local_val); } continue; } // Upper triangular part int idx = (trans_X == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? i * ldx + local_col : local_col * ldx + i; sum = testing_fma(-local_val, X[idx], sum); } } if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { if(diag == -1) { *struct_pivot = std::min(*struct_pivot, bsr_row + base); } X[idx_X] = testing_mult(sum, diag_val); } else { X[idx_X] = sum; } } } } } template void bsrsv(hipsparseOperation_t trans, hipsparseDirection_t dir, int mb, int nnzb, T alpha, const int* bsr_row_ptr, const int* bsr_col_ind, const T* bsr_val, int bsr_dim, const T* x, T* y, hipsparseDiagType_t diag_type, hipsparseFillMode_t fill_mode, hipsparseIndexBase_t base, int* struct_pivot, int* numeric_pivot) { // Initialize pivot *struct_pivot = mb + 1; *numeric_pivot = mb + 1; if(trans == HIPSPARSE_OPERATION_NON_TRANSPOSE) { if(fill_mode == HIPSPARSE_FILL_MODE_LOWER) { bsr_lsolve(dir, HIPSPARSE_OPERATION_NON_TRANSPOSE, mb, 1, alpha, bsr_row_ptr, bsr_col_ind, bsr_val, bsr_dim, x, mb * bsr_dim, y, mb * bsr_dim, diag_type, base, struct_pivot, numeric_pivot); } else { bsr_usolve(dir, HIPSPARSE_OPERATION_NON_TRANSPOSE, mb, 1, alpha, bsr_row_ptr, bsr_col_ind, bsr_val, bsr_dim, x, mb * bsr_dim, y, mb * bsr_dim, diag_type, base, struct_pivot, numeric_pivot); } } else if(trans == HIPSPARSE_OPERATION_TRANSPOSE) { // Transpose matrix std::vector bsrt_row_ptr; std::vector bsrt_col_ind; std::vector bsrt_val; host_bsr_to_bsc(mb, mb, nnzb, bsr_dim, bsr_row_ptr, bsr_col_ind, bsr_val, bsrt_col_ind, bsrt_row_ptr, bsrt_val, base, base); if(fill_mode == HIPSPARSE_FILL_MODE_LOWER) { bsr_usolve(dir, HIPSPARSE_OPERATION_NON_TRANSPOSE, mb, 1, alpha, bsrt_row_ptr.data(), bsrt_col_ind.data(), bsrt_val.data(), bsr_dim, x, mb * bsr_dim, y, mb * bsr_dim, diag_type, base, struct_pivot, numeric_pivot); } else { bsr_lsolve(dir, HIPSPARSE_OPERATION_NON_TRANSPOSE, mb, 1, alpha, bsrt_row_ptr.data(), bsrt_col_ind.data(), bsrt_val.data(), bsr_dim, x, mb * bsr_dim, y, mb * bsr_dim, diag_type, base, struct_pivot, numeric_pivot); } } *numeric_pivot = std::min(*numeric_pivot, *struct_pivot); *struct_pivot = (*struct_pivot == mb + 1) ? -1 : *struct_pivot; *numeric_pivot = (*numeric_pivot == mb + 1) ? -1 : *numeric_pivot; } /* ============================================================================================ */ /*! \brief Sparse triangular lower solve using CSR storage format. */ template int csr_lsolve(hipsparseOperation_t trans, int m, const int* ptr, const int* col, const T* val, T alpha, const T* x, T* y, hipsparseIndexBase_t idx_base, hipsparseDiagType_t diag_type, unsigned int wf_size) { const int* csr_row_ptr = ptr; const int* csr_col_ind = col; const T* csr_val = val; std::vector vptr; std::vector vcol; std::vector vval; if(trans == HIPSPARSE_OPERATION_TRANSPOSE) { int nnz = ptr[m] - idx_base; vptr.resize(m + 1); vcol.resize(nnz); vval.resize(nnz); // Transpose transpose_csr( m, m, nnz, ptr, col, val, vptr.data(), vcol.data(), vval.data(), idx_base, idx_base); csr_row_ptr = vptr.data(); csr_col_ind = vcol.data(); csr_val = vval.data(); } int pivot = (std::numeric_limits::max)(); std::vector temp(wf_size); for(int i = 0; i < m; ++i) { temp.assign(wf_size, make_DataType(0.0)); temp[0] = testing_mult(alpha, x[i]); int diag = -1; int row_begin = csr_row_ptr[i] - idx_base; int row_end = csr_row_ptr[i + 1] - idx_base; T diag_val = make_DataType(0.0); for(int l = row_begin; l < row_end; l += wf_size) { for(unsigned int k = 0; k < wf_size; ++k) { int j = l + k; // Do not run out of bounds if(j >= row_end) { break; } int col_j = csr_col_ind[j] - idx_base; T val_j = csr_val[j]; if(col_j < i) { // Lower part temp[k] = testing_fma(-csr_val[j], y[col_j], temp[k]); } else if(col_j == i) { // Diagonal if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { // Check for numerical zero if(val_j == make_DataType(0.0)) { pivot = std::min(pivot, i + idx_base); val_j = make_DataType(1.0); } diag = j; diag_val = testing_div(make_DataType(1.0), val_j); } break; } else { // Upper part break; } } } for(unsigned int j = 1; j < wf_size; j <<= 1) { for(unsigned int k = 0; k < wf_size - j; ++k) { temp[k] = temp[k] + temp[k + j]; } } if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { if(diag == -1) { pivot = std::min(pivot, i + idx_base); } y[i] = testing_mult(temp[0], diag_val); } else { y[i] = temp[0]; } } if(pivot != (std::numeric_limits::max)()) { return pivot; } return -1; } /* ============================================================================================ */ /*! \brief Sparse triangular upper solve using CSR storage format. */ template int csr_usolve(hipsparseOperation_t trans, int m, const int* ptr, const int* col, const T* val, T alpha, const T* x, T* y, hipsparseIndexBase_t idx_base, hipsparseDiagType_t diag_type, unsigned int wf_size) { const int* csr_row_ptr = ptr; const int* csr_col_ind = col; const T* csr_val = val; std::vector vptr; std::vector vcol; std::vector vval; if(trans == HIPSPARSE_OPERATION_TRANSPOSE) { int nnz = ptr[m] - idx_base; vptr.resize(m + 1); vcol.resize(nnz); vval.resize(nnz); // Transpose transpose_csr( m, m, nnz, ptr, col, val, vptr.data(), vcol.data(), vval.data(), idx_base, idx_base); csr_row_ptr = vptr.data(); csr_col_ind = vcol.data(); csr_val = vval.data(); } int pivot = (std::numeric_limits::max)(); std::vector temp(wf_size); for(int i = m - 1; i >= 0; --i) { temp.assign(wf_size, make_DataType(0.0)); temp[0] = testing_mult(alpha, x[i]); int diag = -1; int row_begin = csr_row_ptr[i] - idx_base; int row_end = csr_row_ptr[i + 1] - idx_base; T diag_val = make_DataType(0.0); for(int l = row_end - 1; l >= row_begin; l -= wf_size) { for(unsigned int k = 0; k < wf_size; ++k) { int j = l - k; // Do not run out of bounds if(j < row_begin) { break; } int col_j = csr_col_ind[j] - idx_base; T val_j = csr_val[j]; if(col_j < i) { // Lower part continue; } else if(col_j == i) { // Diagonal if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { // Check for numerical zero if(val_j == make_DataType(0.0)) { pivot = std::min(pivot, i + idx_base); val_j = make_DataType(1.0); } diag = j; diag_val = testing_div(make_DataType(1.0), val_j); } continue; } else { // Upper part temp[k] = testing_fma(-csr_val[j], y[col_j], temp[k]); } } } for(unsigned int j = 1; j < wf_size; j <<= 1) { for(unsigned int k = 0; k < wf_size - j; ++k) { temp[k] = temp[k] + temp[k + j]; } } if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { if(diag == -1) { pivot = std::min(pivot, i + idx_base); } y[i] = testing_mult(temp[0], diag_val); } else { y[i] = temp[0]; } } if(pivot != (std::numeric_limits::max)()) { return pivot; } return -1; } /* ============================================================================================ */ /*! \brief Transpose sparse matrix using CSR storage format. */ template void transpose_csr(J m, J n, I nnz, const I* csr_row_ptr_A, const J* csr_col_ind_A, const T* csr_val_A, I* csr_row_ptr_B, J* csr_col_ind_B, T* csr_val_B, hipsparseIndexBase_t idx_base_A, hipsparseIndexBase_t idx_base_B) { memset(csr_row_ptr_B, 0, sizeof(I) * (n + 1)); // Determine nnz per column for(I i = 0; i < nnz; ++i) { ++csr_row_ptr_B[csr_col_ind_A[i] + 1 - idx_base_A]; } // Scan for(J i = 0; i < n; ++i) { csr_row_ptr_B[i + 1] += csr_row_ptr_B[i]; } // Fill row indices and values for(J i = 0; i < m; ++i) { I row_begin = csr_row_ptr_A[i] - idx_base_A; I row_end = csr_row_ptr_A[i + 1] - idx_base_A; for(I j = row_begin; j < row_end; ++j) { J col = csr_col_ind_A[j] - idx_base_A; I idx = csr_row_ptr_B[col]; csr_col_ind_B[idx] = i + idx_base_B; csr_val_B[idx] = csr_val_A[j]; ++csr_row_ptr_B[col]; } } // Shift column pointer array for(J i = n; i > 0; --i) { csr_row_ptr_B[i] = csr_row_ptr_B[i - 1] + idx_base_B; } csr_row_ptr_B[0] = idx_base_B; } /* ============================================================================================ */ /*! \brief Transpose sparse matrix using CSR storage format. */ template void transpose_bsr(int mb, int nb, int nnzb, int bsr_dim, const int* bsr_row_ptr_A, const int* bsr_col_ind_A, const T* bsr_val_A, int* bsr_row_ptr_B, int* bsr_col_ind_B, T* bsr_val_B, hipsparseIndexBase_t idx_base_A, hipsparseIndexBase_t idx_base_B) { memset(bsr_row_ptr_B, 0, sizeof(int) * (nb + 1)); // Determine nnz per column for(int i = 0; i < nnzb; ++i) { ++bsr_row_ptr_B[bsr_col_ind_A[i] + 1 - idx_base_A]; } // Scan for(int i = 0; i < nb; ++i) { bsr_row_ptr_B[i + 1] += bsr_row_ptr_B[i]; } // Fill row indices and values for(int i = 0; i < mb; ++i) { int row_begin = bsr_row_ptr_A[i] - idx_base_A; int row_end = bsr_row_ptr_A[i + 1] - idx_base_A; for(int j = row_begin; j < row_end; ++j) { int col = bsr_col_ind_A[j] - idx_base_A; int idx = bsr_row_ptr_B[col]; bsr_col_ind_B[idx] = i + idx_base_B; for(int bi = 0; bi < bsr_dim; ++bi) { for(int bj = 0; bj < bsr_dim; ++bj) { bsr_val_B[bsr_dim * bsr_dim * idx + bi + bj * bsr_dim] = bsr_val_A[bsr_dim * bsr_dim * j + bi * bsr_dim + bj]; } } ++bsr_row_ptr_B[col]; } } // Shift column pointer array for(int i = nb; i > 0; --i) { bsr_row_ptr_B[i] = bsr_row_ptr_B[i - 1] + idx_base_B; } bsr_row_ptr_B[0] = idx_base_B; } /* ============================================================================================ */ /*! \brief Compute sparse matrix sparse matrix addition. */ template static int host_csrgeam_nnz(int M, int N, T alpha, const int* csr_row_ptr_A, const int* csr_col_ind_A, T beta, const int* csr_row_ptr_B, const int* csr_col_ind_B, int* csr_row_ptr_C, hipsparseIndexBase_t base_A, hipsparseIndexBase_t base_B, hipsparseIndexBase_t base_C) { #ifdef _OPENMP #pragma omp parallel #endif { std::vector nnz(N, -1); #ifdef _OPENMP int nthreads = omp_get_num_threads(); int tid = omp_get_thread_num(); #else int nthreads = 1; int tid = 0; #endif int rows_per_thread = (M + nthreads - 1) / nthreads; int chunk_begin = rows_per_thread * tid; int chunk_end = std::min(chunk_begin + rows_per_thread, M); // Index base csr_row_ptr_C[0] = base_C; // Loop over rows for(int i = chunk_begin; i < chunk_end; ++i) { // Initialize csr row pointer with previous row offset csr_row_ptr_C[i + 1] = 0; int row_begin_A = csr_row_ptr_A[i] - base_A; int row_end_A = csr_row_ptr_A[i + 1] - base_A; // Loop over columns of A for(int j = row_begin_A; j < row_end_A; ++j) { int col_A = csr_col_ind_A[j] - base_A; nnz[col_A] = i; ++csr_row_ptr_C[i + 1]; } int row_begin_B = csr_row_ptr_B[i] - base_B; int row_end_B = csr_row_ptr_B[i + 1] - base_B; // Loop over columns of B for(int j = row_begin_B; j < row_end_B; ++j) { int col_B = csr_col_ind_B[j] - base_B; // Check if a new nnz is generated if(nnz[col_B] != i) { nnz[col_B] = i; ++csr_row_ptr_C[i + 1]; } } } } // Scan to obtain row offsets for(int i = 0; i < M; ++i) { csr_row_ptr_C[i + 1] += csr_row_ptr_C[i]; } return csr_row_ptr_C[M] - base_C; } template static void host_csrgeam(int M, int N, T alpha, const int* csr_row_ptr_A, const int* csr_col_ind_A, const T* csr_val_A, T beta, const int* csr_row_ptr_B, const int* csr_col_ind_B, const T* csr_val_B, const int* csr_row_ptr_C, int* csr_col_ind_C, T* csr_val_C, hipsparseIndexBase_t base_A, hipsparseIndexBase_t base_B, hipsparseIndexBase_t base_C) { #ifdef _OPENMP #pragma omp parallel #endif { std::vector nnz(N, -1); #ifdef _OPENMP int nthreads = omp_get_num_threads(); int tid = omp_get_thread_num(); #else int nthreads = 1; int tid = 0; #endif int rows_per_thread = (M + nthreads - 1) / nthreads; int chunk_begin = rows_per_thread * tid; int chunk_end = std::min(chunk_begin + rows_per_thread, M); // Loop over rows for(int i = chunk_begin; i < chunk_end; ++i) { int row_begin_C = csr_row_ptr_C[i] - base_C; int row_end_C = row_begin_C; int row_begin_A = csr_row_ptr_A[i] - base_A; int row_end_A = csr_row_ptr_A[i + 1] - base_A; // Copy A into C for(int j = row_begin_A; j < row_end_A; ++j) { // Current column of A int col_A = csr_col_ind_A[j] - base_A; // Current value of A T val_A = testing_mult(alpha, csr_val_A[j]); nnz[col_A] = row_end_C; csr_col_ind_C[row_end_C] = col_A + base_C; csr_val_C[row_end_C] = val_A; ++row_end_C; } int row_begin_B = csr_row_ptr_B[i] - base_B; int row_end_B = csr_row_ptr_B[i + 1] - base_B; // Loop over columns of B for(int j = row_begin_B; j < row_end_B; ++j) { // Current column of B int col_B = csr_col_ind_B[j] - base_B; // Current value of B T val_B = testing_mult(beta, csr_val_B[j]); // Check if a new nnz is generated or if the value is added if(nnz[col_B] < row_begin_C) { nnz[col_B] = row_end_C; csr_col_ind_C[row_end_C] = col_B + base_C; csr_val_C[row_end_C] = val_B; ++row_end_C; } else { csr_val_C[nnz[col_B]] = csr_val_C[nnz[col_B]] + val_B; } } } } int nnz = csr_row_ptr_C[M] - base_C; std::vector col(nnz); std::vector val(nnz); for(int i = 0; i < nnz; ++i) { col[i] = csr_col_ind_C[i]; val[i] = csr_val_C[i]; } #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < M; ++i) { int row_begin = csr_row_ptr_C[i] - base_C; int row_end = csr_row_ptr_C[i + 1] - base_C; int row_nnz = row_end - row_begin; std::vector perm(row_nnz); for(int j = 0; j < row_nnz; ++j) { perm[j] = j; } int* col_entry = &col[row_begin]; T* val_entry = &val[row_begin]; std::sort(perm.begin(), perm.end(), [&](const int& a, const int& b) { return col_entry[a] <= col_entry[b]; }); for(int j = 0; j < row_nnz; ++j) { csr_col_ind_C[row_begin + j] = col_entry[perm[j]]; csr_val_C[row_begin + j] = val_entry[perm[j]]; } } } /* ============================================================================================ */ /*! \brief Compute sparse matrix sparse matrix multiplication. */ template static I host_csrgemm2_nnz(J m, J n, J k, const T* alpha, const I* csr_row_ptr_A, const J* csr_col_ind_A, const I* csr_row_ptr_B, const J* csr_col_ind_B, const T* beta, const I* csr_row_ptr_D, const J* csr_col_ind_D, I* csr_row_ptr_C, hipsparseIndexBase_t idx_base_A, hipsparseIndexBase_t idx_base_B, hipsparseIndexBase_t idx_base_C, hipsparseIndexBase_t idx_base_D) { #ifdef _OPENMP #pragma omp parallel #endif { std::vector nnz(n, -1); #ifdef _OPENMP int nthreads = omp_get_num_threads(); int tid = omp_get_thread_num(); #else int nthreads = 1; int tid = 0; #endif J rows_per_thread = (m + nthreads - 1) / nthreads; J chunk_begin = rows_per_thread * tid; J chunk_end = std::min(chunk_begin + rows_per_thread, m); // Index base csr_row_ptr_C[0] = idx_base_C; // Loop over rows of A for(J i = chunk_begin; i < chunk_end; ++i) { // Initialize csr row pointer with previous row offset csr_row_ptr_C[i + 1] = 0; if(alpha) { I row_begin_A = csr_row_ptr_A[i] - idx_base_A; I row_end_A = csr_row_ptr_A[i + 1] - idx_base_A; // Loop over columns of A for(I j = row_begin_A; j < row_end_A; ++j) { // Current column of A J col_A = csr_col_ind_A[j] - idx_base_A; I row_begin_B = csr_row_ptr_B[col_A] - idx_base_B; I row_end_B = csr_row_ptr_B[col_A + 1] - idx_base_B; // Loop over columns of B in row col_A for(I irow = row_begin_B; irow < row_end_B; ++irow) { // Current column of B J col_B = csr_col_ind_B[irow] - idx_base_B; // Check if a new nnz is generated if(nnz[col_B] != i) { nnz[col_B] = i; ++csr_row_ptr_C[i + 1]; } } } } // Add nnz of D if beta != 0 if(beta) { I row_begin_D = csr_row_ptr_D[i] - idx_base_D; I row_end_D = csr_row_ptr_D[i + 1] - idx_base_D; // Loop over columns of D for(I j = row_begin_D; j < row_end_D; ++j) { J col_D = csr_col_ind_D[j] - idx_base_D; // Check if a new nnz is generated if(nnz[col_D] != i) { nnz[col_D] = i; ++csr_row_ptr_C[i + 1]; } } } } } // Scan to obtain row offsets for(J i = 0; i < m; ++i) { csr_row_ptr_C[i + 1] += csr_row_ptr_C[i]; } return csr_row_ptr_C[m] - idx_base_C; } template static void host_csrgemm2(J m, J n, J k, const T* alpha, const I* csr_row_ptr_A, const J* csr_col_ind_A, const T* csr_val_A, const I* csr_row_ptr_B, const J* csr_col_ind_B, const T* csr_val_B, const T* beta, const I* csr_row_ptr_D, const J* csr_col_ind_D, const T* csr_val_D, const I* csr_row_ptr_C, J* csr_col_ind_C, T* csr_val_C, hipsparseIndexBase_t idx_base_A, hipsparseIndexBase_t idx_base_B, hipsparseIndexBase_t idx_base_C, hipsparseIndexBase_t idx_base_D) { #ifdef _OPENMP #pragma omp parallel #endif { std::vector nnz(n, -1); #ifdef _OPENMP int nthreads = omp_get_num_threads(); int tid = omp_get_thread_num(); #else int nthreads = 1; int tid = 0; #endif J rows_per_thread = (m + nthreads - 1) / nthreads; J chunk_begin = rows_per_thread * tid; J chunk_end = std::min(chunk_begin + rows_per_thread, m); // Loop over rows of A for(J i = chunk_begin; i < chunk_end; ++i) { I row_begin_C = csr_row_ptr_C[i] - idx_base_C; I row_end_C = row_begin_C; if(alpha) { I row_begin_A = csr_row_ptr_A[i] - idx_base_A; I row_end_A = csr_row_ptr_A[i + 1] - idx_base_A; // Loop over columns of A for(I j = row_begin_A; j < row_end_A; ++j) { // Current column of A J col_A = csr_col_ind_A[j] - idx_base_A; // Current value of A T val_A = testing_mult(*alpha, csr_val_A[j]); I row_begin_B = csr_row_ptr_B[col_A] - idx_base_B; I row_end_B = csr_row_ptr_B[col_A + 1] - idx_base_B; // Loop over columns of B in row col_A for(I l = row_begin_B; l < row_end_B; ++l) { // Current column of B J col_B = csr_col_ind_B[l] - idx_base_B; // Current value of B T val_B = csr_val_B[l]; // Check if a new nnz is generated or if the product is appended if(nnz[col_B] < row_begin_C) { nnz[col_B] = row_end_C; csr_col_ind_C[row_end_C] = col_B + idx_base_C; csr_val_C[row_end_C] = testing_mult(val_A, val_B); ++row_end_C; } else { csr_val_C[nnz[col_B]] = csr_val_C[nnz[col_B]] + testing_mult(val_A, val_B); } } } } // Add nnz of D if beta != 0 if(beta) { I row_begin_D = csr_row_ptr_D[i] - idx_base_D; I row_end_D = csr_row_ptr_D[i + 1] - idx_base_D; // Loop over columns of D for(I j = row_begin_D; j < row_end_D; ++j) { // Current column of D J col_D = csr_col_ind_D[j] - idx_base_D; // Current value of D T val_D = testing_mult(*beta, csr_val_D[j]); // Check if a new nnz is generated or if the value is added if(nnz[col_D] < row_begin_C) { nnz[col_D] = row_end_C; csr_col_ind_C[row_end_C] = col_D + idx_base_C; csr_val_C[row_end_C] = val_D; ++row_end_C; } else { csr_val_C[nnz[col_D]] = csr_val_C[nnz[col_D]] + val_D; } } } } } I nnz_C = csr_row_ptr_C[m] - idx_base_C; std::vector col(nnz_C); std::vector val(nnz_C); memcpy(col.data(), csr_col_ind_C, sizeof(J) * nnz_C); memcpy(val.data(), csr_val_C, sizeof(T) * nnz_C); #ifdef _OPENMP #pragma omp parallel for #endif for(J i = 0; i < m; ++i) { I row_begin = csr_row_ptr_C[i] - idx_base_C; I row_end = csr_row_ptr_C[i + 1] - idx_base_C; J row_nnz = row_end - row_begin; std::vector perm(row_nnz); for(J j = 0; j < row_nnz; ++j) { perm[j] = j; } J* col_entry = &col[row_begin]; T* val_entry = &val[row_begin]; std::sort(perm.begin(), perm.end(), [&](const I& a, const I& b) { return col_entry[a] <= col_entry[b]; }); for(J j = 0; j < row_nnz; ++j) { csr_col_ind_C[row_begin + j] = col_entry[perm[j]]; csr_val_C[row_begin + j] = val_entry[perm[j]]; } } } #ifdef __cplusplus extern "C" { #endif /* ============================================================================================ */ /* query for hipsparse version and git commit SHA-1. */ void query_version(char* version); /* ============================================================================================ */ /* device query and print out their ID and name */ int query_device_property(); /* set current device to device_id */ void set_device(int device_id); /* ============================================================================================ */ /* timing: HIP only provides very limited timers function clock() and not general; hipsparse sync CPU and device and use more accurate CPU timer*/ /*! \brief CPU Timer(in microsecond): synchronize with the default device and return wall time */ double get_time_us(void); /*! \brief CPU Timer(in microsecond): synchronize with given queue/stream and return wall time */ double get_time_us_sync(hipStream_t stream); #ifdef __cplusplus } #endif inline void missing_file_error_message(const char* filename) { std::cerr << "#" << std::endl; std::cerr << "# error:" << std::endl; std::cerr << "# cannot open file '" << filename << "'" << std::endl; std::cerr << "#" << std::endl; std::cerr << "# PLEASE READ CAREFULLY !" << std::endl; std::cerr << "#" << std::endl; std::cerr << "# What could be the reason of this error: " << std::endl; std::cerr << "# You are running the testing application and it expects to find the file " "at the specified location. This means that either you did not download the test " "matrices, or you did not specify the location of the folder containing your " "files. If you want to specify the location of the folder containing your files, " "then you will find the needed information with 'hipsparse-test --help'." "If you need to download matrices, then a cmake script " "'hipsparse_clientmatrices.cmake' is available from the hipsparse client package." << std::endl; std::cerr << "#" << std::endl; std::cerr << "# Examples: 'hipsparse_clientmatrices.cmake -DCMAKE_MATRICES_DIR='" << std::endl; std::cerr << "# 'hipsparse-test --matrices-dir '" << std::endl; std::cerr << "# (or 'export " "HIPSPARSE_CLIENTS_MATRICES_DIR=;hipsparse-test')" << std::endl; std::cerr << "#" << std::endl; } static const char* s_hipsparse_clients_matrices_dir = nullptr; inline const char* get_hipsparse_clients_matrices_dir() { return s_hipsparse_clients_matrices_dir; } inline std::string get_filename(const std::string& bin_file) { const char* matrices_dir = get_hipsparse_clients_matrices_dir(); if(matrices_dir == nullptr) { matrices_dir = getenv("HIPSPARSE_CLIENTS_MATRICES_DIR"); } std::string r; if(matrices_dir != nullptr) { r = std::string(matrices_dir) + "/" + bin_file; } else { r = hipsparse_exepath() + "../matrices/" + bin_file; } FILE* tmpf = fopen(r.c_str(), "r"); if(!tmpf) { missing_file_error_message(r.c_str()); std::cerr << "exit(HIPSPARSE_STATUS_INTERNAL_ERROR)" << std::endl; exit(HIPSPARSE_STATUS_INTERNAL_ERROR); } else { fclose(tmpf); } return r; } struct testhyb { int m; int n; hipsparseHybPartition_t partition; int ell_nnz; int ell_width; int* ell_col_ind; void* ell_val; int coo_nnz; int* coo_row_ind; int* coo_col_ind; void* coo_val; }; template hipsparseIndexType_t getIndexType() { return (typeid(I) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; } template hipDataType getDataType() { return (typeid(T) == typeid(float)) ? HIP_R_32F : ((typeid(T) == typeid(double)) ? HIP_R_64F : ((typeid(T) == typeid(hipComplex) ? HIP_C_32F : HIP_C_64F))); } #endif // TESTING_UTILITY_HPP hipSPARSE-rocm-6.4.3/clients/samples/000077500000000000000000000000001501764003400172655ustar00rootroot00000000000000hipSPARSE-rocm-6.4.3/clients/samples/CMakeLists.txt000066400000000000000000000065661501764003400220420ustar00rootroot00000000000000# ######################################################################## # 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-6.4.3/clients/samples/example_csrmv.cpp000066400000000000000000000126641501764003400226470ustar00rootroot00000000000000/* ************************************************************************ * 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-6.4.3/clients/samples/example_fortran_auxiliary.f90000066400000000000000000000134631501764003400250710ustar00rootroot00000000000000!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! 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-6.4.3/clients/samples/example_fortran_bsric02.f90000066400000000000000000000242171501764003400243250ustar00rootroot00000000000000!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! 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-6.4.3/clients/samples/example_fortran_bsrilu02.f90000066400000000000000000000242421501764003400245210ustar00rootroot00000000000000!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! 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-6.4.3/clients/samples/example_fortran_bsrmm.f90000066400000000000000000000205351501764003400242000ustar00rootroot00000000000000!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! 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-6.4.3/clients/samples/example_fortran_csric02.f90000066400000000000000000000215401501764003400243220ustar00rootroot00000000000000!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! 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-6.4.3/clients/samples/example_fortran_csrilu02.f90000066400000000000000000000214151501764003400245210ustar00rootroot00000000000000!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! 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-6.4.3/clients/samples/example_fortran_csrsm2.f90000066400000000000000000000247021501764003400242710ustar00rootroot00000000000000!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! 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-6.4.3/clients/samples/example_fortran_csrsv2.f90000066400000000000000000000224021501764003400242750ustar00rootroot00000000000000!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! 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-6.4.3/clients/samples/example_fortran_dotci.f90000066400000000000000000000135251501764003400241630ustar00rootroot00000000000000!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! 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-6.4.3/clients/samples/example_fortran_roti.f90000066400000000000000000000135521501764003400240360ustar00rootroot00000000000000!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! 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-6.4.3/clients/samples/example_fortran_spmv.f90000066400000000000000000000426111501764003400240440ustar00rootroot00000000000000!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! 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-6.4.3/clients/samples/example_handle.cpp000066400000000000000000000033661501764003400227470ustar00rootroot00000000000000/* ************************************************************************ * 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-6.4.3/clients/samples/example_hybmv.cpp000066400000000000000000000121261501764003400226330ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2018-2024 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #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); // Clean up hipFree(dx); hipFree(dy); return 0; } hipSPARSE-rocm-6.4.3/clients/tests/000077500000000000000000000000001501764003400167635ustar00rootroot00000000000000hipSPARSE-rocm-6.4.3/clients/tests/CMakeLists.txt000066400000000000000000000151341501764003400215270ustar00rootroot00000000000000# ######################################################################## # 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_dnmat_descr.cpp test_dnvec_descr.cpp test_const_spmat_descr.cpp test_const_spvec_descr.cpp test_const_dnmat_descr.cpp test_const_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") add_dependencies(hipsparse-test hipsparse-common) 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/rocsparse.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-6.4.3/clients/tests/hipsparse_gtest_main.cpp000066400000000000000000000174621501764003400237110ustar00rootroot00000000000000/* ************************************************************************ * 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); } }; hipsparseStatus_t hipsparse_record_output_legend(const std::string& s) { return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparse_record_output(const std::string& s) { return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparse_record_timing(double msec, double gflops, double gbs) { return HIPSPARSE_STATUS_SUCCESS; } bool display_timing_info_is_stdout_disabled() { return HIPSPARSE_STATUS_SUCCESS; } /* ===================================================================== Main function: =================================================================== */ 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-6.4.3/clients/tests/test_axpby.cpp000066400000000000000000000070151501764003400216540ustar00rootroot00000000000000/* ************************************************************************ * 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 typedef hipsparseIndexBase_t base; typedef std::tuple axpby_tuple; int axpby_N_range[] = {22031}; int axpby_nnz_range[] = {0, 5, 1000, 10000}; std::vector axpby_alpha_range = {1.0, 0.0}; base axpby_idx_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; class parameterized_axpby : public testing::TestWithParam { protected: parameterized_axpby() {} virtual ~parameterized_axpby() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_axpby_arguments(axpby_tuple tup) { Arguments arg; arg.N = std::get<0>(tup); arg.nnz = std::get<1>(tup); arg.alpha = std::get<2>(tup); arg.baseA = std::get<3>(tup); arg.timing = 0; return arg; } #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) TEST(axpby_bad_arg, axpby_float) { testing_axpby_bad_arg(); } TEST_P(parameterized_axpby, axpby_i32_float) { Arguments arg = setup_axpby_arguments(GetParam()); hipsparseStatus_t status = testing_axpby(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_axpby, axpby_i64_double) { Arguments arg = setup_axpby_arguments(GetParam()); hipsparseStatus_t status = testing_axpby(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_axpby, axpby_i32_float_complex) { Arguments arg = setup_axpby_arguments(GetParam()); hipsparseStatus_t status = testing_axpby(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_axpby, axpby_i64_double_complex) { Arguments arg = setup_axpby_arguments(GetParam()); hipsparseStatus_t status = testing_axpby(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(axpby, parameterized_axpby, testing::Combine(testing::ValuesIn(axpby_N_range), testing::ValuesIn(axpby_nnz_range), testing::ValuesIn(axpby_alpha_range), testing::ValuesIn(axpby_idx_base_range))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_axpyi.cpp000066400000000000000000000070151501764003400216630ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {15332}; int axpyi_nnz_range[] = {0, 10, 500, 7111}; 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.baseA = std::get<3>(tup); arg.timing = 0; return arg; } #if(!defined(CUDART_VERSION) || 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); } 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))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_bsr2csr.cpp000066400000000000000000000144631501764003400221160ustar00rootroot00000000000000/* ************************************************************************ * 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, 21453}; int bsr2csr_N_range[] = {0, 12766, 29285}; int bsr2csr_block_dim_range[] = {1, 2, 4, 7, 16}; hipsparseIndexBase_t bsr2csr_csr_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; hipsparseIndexBase_t bsr2csr_bsr_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; hipsparseDirection_t bsr2csr_dir_range[] = {HIPSPARSE_DIRECTION_ROW, HIPSPARSE_DIRECTION_COLUMN}; int bsr2csr_block_dim_range_bin[] = {5, 7, 12}; 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.baseA = std::get<3>(tup); arg.baseB = 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.baseA = std::get<1>(tup); arg.baseB = 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; } 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); } 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-6.4.3/clients/tests/test_bsric02.cpp000066400000000000000000000137001501764003400217730ustar00rootroot00000000000000/* ************************************************************************ * 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 hipsparseSolvePolicy_t solve_policy; typedef std::tuple bsric02_tuple; typedef std::tuple bsric02_bin_tuple; int bsric02_M_range[] = {50, 426}; int bsric02_dim_range[] = {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}; solve_policy bsric02_solve_policy_range[] = {HIPSPARSE_SOLVE_POLICY_NO_LEVEL, HIPSPARSE_SOLVE_POLICY_USE_LEVEL}; 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.baseA = std::get<3>(tup); arg.solve_policy = std::get<4>(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.baseA = std::get<2>(tup); arg.solve_policy = std::get<3>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<4>(tup); // Get current executables absolute path // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) 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); } 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), testing::ValuesIn(bsric02_solve_policy_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_solve_policy_range), testing::ValuesIn(bsric02_bin))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_bsrilu02.cpp000066400000000000000000000164261501764003400222010ustar00rootroot00000000000000/* ************************************************************************ * 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 hipsparseSolvePolicy_t solve_policy; typedef std::tuple bsrilu02_tuple; typedef std::tuple bsrilu02_bin_tuple; int bsrilu02_M_range[] = {0, 50, 426}; int bsrilu02_dim_range[] = {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}; solve_policy bsrilu02_solve_policy_range[] = {HIPSPARSE_SOLVE_POLICY_NO_LEVEL, HIPSPARSE_SOLVE_POLICY_USE_LEVEL}; 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.baseA = std::get<7>(tup); arg.solve_policy = std::get<8>(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.baseA = std::get<6>(tup); arg.solve_policy = 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; } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) 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); } 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), testing::ValuesIn(bsrilu02_solve_policy_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_solve_policy_range), testing::ValuesIn(bsrilu02_bin))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_bsrmm.cpp000066400000000000000000000171301501764003400216500ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {42, 2059}; int bsrmm_N_range[] = {7, 78}; int bsrmm_K_range[] = {50, 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, 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.baseA = 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.baseA = 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; } 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); } 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-6.4.3/clients/tests/test_bsrmv.cpp000066400000000000000000000137541501764003400216710ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {0, 500, 7111}; int bsr_N_range[] = {0, 842, 4441}; int bsr_dim_range[] = {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.baseA = 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.baseA = 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; } 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); } 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-6.4.3/clients/tests/test_bsrsm2.cpp000066400000000000000000000156431501764003400217470ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse_arguments.hpp" #include "testing_bsrsm2.hpp" #include #include #include typedef std::tuple bsrsm2_tuple; typedef std::tuple bsrsm2_bin_tuple; int bsrsm2_M_range[] = {50}; int bsrsm2_N_range[] = {15}; int bsrsm2_dim_range[] = {2, 3}; double bsrsm2_alpha_range[] = {2.0}; hipsparseIndexBase_t bsrsm2_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; hipsparseDirection_t bsrsm2_dir_range[] = {HIPSPARSE_DIRECTION_ROW, HIPSPARSE_DIRECTION_COLUMN}; hipsparseOperation_t bsrsm2_transA_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_TRANSPOSE}; hipsparseOperation_t bsrsm2_transB_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_TRANSPOSE}; std::string bsrsm2_bin[] = {"nos3.bin"}; class parameterized_bsrsm2 : public testing::TestWithParam { protected: parameterized_bsrsm2() {} virtual ~parameterized_bsrsm2() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_bsrsm2_bin : public testing::TestWithParam { protected: parameterized_bsrsm2_bin() {} virtual ~parameterized_bsrsm2_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_bsrsm2_arguments(bsrsm2_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.block_dim = std::get<2>(tup); arg.alpha = std::get<3>(tup); arg.dirA = std::get<4>(tup); arg.baseA = std::get<5>(tup); arg.transA = std::get<6>(tup); arg.transB = std::get<7>(tup); arg.timing = 0; return arg; } Arguments setup_bsrsm2_arguments(bsrsm2_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = std::get<0>(tup); arg.block_dim = std::get<1>(tup); arg.alpha = std::get<2>(tup); arg.dirA = std::get<3>(tup); arg.baseA = std::get<4>(tup); arg.transA = std::get<5>(tup); arg.transB = std::get<6>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<7>(tup); // Get current executables absolute path // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) TEST(bsrsm2_bad_arg, bsrsm2_float) { testing_bsrsm2_bad_arg(); } TEST_P(parameterized_bsrsm2, bsrsm2_float) { Arguments arg = setup_bsrsm2_arguments(GetParam()); hipsparseStatus_t status = testing_bsrsm2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_bsrsm2, bsrsm2_double) { Arguments arg = setup_bsrsm2_arguments(GetParam()); hipsparseStatus_t status = testing_bsrsm2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_bsrsm2, bsrsm2_float_complex) { Arguments arg = setup_bsrsm2_arguments(GetParam()); hipsparseStatus_t status = testing_bsrsm2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_bsrsm2, bsrsm2_double_complex) { Arguments arg = setup_bsrsm2_arguments(GetParam()); hipsparseStatus_t status = testing_bsrsm2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_bsrsm2_bin, bsrsm2_bin_float) { Arguments arg = setup_bsrsm2_arguments(GetParam()); hipsparseStatus_t status = testing_bsrsm2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_bsrsm2_bin, bsrsm2_bin_double) { Arguments arg = setup_bsrsm2_arguments(GetParam()); hipsparseStatus_t status = testing_bsrsm2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(bsrsm2, parameterized_bsrsm2, testing::Combine(testing::ValuesIn(bsrsm2_M_range), testing::ValuesIn(bsrsm2_N_range), testing::ValuesIn(bsrsm2_dim_range), testing::ValuesIn(bsrsm2_alpha_range), testing::ValuesIn(bsrsm2_dir_range), testing::ValuesIn(bsrsm2_idxbase_range), testing::ValuesIn(bsrsm2_transA_range), testing::ValuesIn(bsrsm2_transB_range))); INSTANTIATE_TEST_SUITE_P(bsrsm2_bin, parameterized_bsrsm2_bin, testing::Combine(testing::ValuesIn(bsrsm2_N_range), testing::ValuesIn(bsrsm2_dim_range), testing::ValuesIn(bsrsm2_alpha_range), testing::ValuesIn(bsrsm2_dir_range), testing::ValuesIn(bsrsm2_idxbase_range), testing::ValuesIn(bsrsm2_transA_range), testing::ValuesIn(bsrsm2_transB_range), testing::ValuesIn(bsrsm2_bin))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_bsrsv2.cpp000066400000000000000000000161161501764003400217540ustar00rootroot00000000000000/* ************************************************************************ * 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 hipsparseSolvePolicy_t policy; typedef std::tuple bsrsv2_tuple; typedef std::tuple bsrsv2_bin_tuple; int bsrsv2_M_range[] = {0, 647}; int bsrsv2_dim_range[] = {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}; policy bsrsv2_policy_range[] = {HIPSPARSE_SOLVE_POLICY_NO_LEVEL, HIPSPARSE_SOLVE_POLICY_USE_LEVEL}; 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.baseA = 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.solve_policy = std::get<8>(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.baseA = 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.solve_policy = 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; } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) 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); } 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), testing::ValuesIn(bsrsv2_policy_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_policy_range), testing::ValuesIn(bsrsv2_bin))); #endifhipSPARSE-rocm-6.4.3/clients/tests/test_bsrxmv.cpp000066400000000000000000000044511501764003400220530ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse_arguments.hpp" #include "testing_bsrxmv.hpp" #include #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) TEST(bsrxmv_bad_arg, bsrxmv_bad_arg_float) { testing_bsrxmv_bad_arg(); } TEST(bsrxmv_bad_arg, bsrxmv_bad_arg_double) { testing_bsrxmv_bad_arg(); } TEST(bsrxmv_bad_arg, bsrxmv_bad_arg_float_complex) { testing_bsrxmv_bad_arg(); } TEST(bsrxmv_bad_arg, bsrxmv_bad_arg_double_complex) { testing_bsrxmv_bad_arg(); } TEST(bsrxmv, bsrxmv_float) { Arguments arg; hipsparseStatus_t status = testing_bsrxmv(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(bsrxmv, bsrxmv_double) { Arguments arg; hipsparseStatus_t status = testing_bsrxmv(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(bsrxmv, bsrxmv_hipComplex) { Arguments arg; hipsparseStatus_t status = testing_bsrxmv(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endifhipSPARSE-rocm-6.4.3/clients/tests/test_const_dnmat_descr.cpp000066400000000000000000000027521501764003400242250ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2023 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "testing_const_dnmat_descr.hpp" #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) TEST(const_dnmat_descr_bad_arg, const_dnmat_descr_float) { testing_const_dnmat_descr_bad_arg(); } #endif hipSPARSE-rocm-6.4.3/clients/tests/test_const_dnvec_descr.cpp000066400000000000000000000027521501764003400242210ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2023 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "testing_const_dnvec_descr.hpp" #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) TEST(const_dnvec_descr_bad_arg, const_dnvec_descr_float) { testing_const_dnvec_descr_bad_arg(); } #endif hipSPARSE-rocm-6.4.3/clients/tests/test_const_spmat_descr.cpp000066400000000000000000000027521501764003400242460ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2023 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "testing_const_spmat_descr.hpp" #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) TEST(const_spmat_descr_bad_arg, const_spmat_descr_float) { testing_const_spmat_descr_bad_arg(); } #endif hipSPARSE-rocm-6.4.3/clients/tests/test_const_spvec_descr.cpp000066400000000000000000000027521501764003400242420ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2023 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "testing_const_spvec_descr.hpp" #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) TEST(const_spvec_descr_bad_arg, const_spvec_descr_float) { testing_const_spvec_descr_bad_arg(); } #endif hipSPARSE-rocm-6.4.3/clients/tests/test_coo2csr.cpp000066400000000000000000000111401501764003400220750ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {0, 10, 500, 872, 1000}; int coo2csr_N_range[] = {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.baseA = 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.baseA = std::get<0>(tup); arg.timing = 0; std::string bin_file = std::get<1>(tup); arg.filename = get_filename(bin_file); return arg; } TEST(coo2csr_bad_arg, coo2csr) { testing_coo2csr_bad_arg(); } TEST_P(parameterized_coo2csr, coo2csr_float) { 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_float) { Arguments arg = setup_coo2csr_arguments(GetParam()); hipsparseStatus_t status = testing_coo2csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } 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-6.4.3/clients/tests/test_coosort.cpp000066400000000000000000000120261501764003400222170ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {0, 10, 500, 3872, 10000}; int coosort_N_range[] = {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.permute = std::get<3>(tup); arg.baseA = 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.permute = std::get<1>(tup); arg.baseA = 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; } 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); } 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-6.4.3/clients/tests/test_csc2dense.cpp000066400000000000000000000072251501764003400224050ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {0, 10, 500, 872, 1000}; int csc2dense_N_range[] = {0, 33, 242, 623, 1000}; int csc2dense_LD_range[] = {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.baseA = std::get<3>(tup); return arg; } #if(!defined(CUDART_VERSION) || 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); } 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))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_cscsort.cpp000066400000000000000000000107711501764003400222140ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {0, 10, 500, 872, 1000}; int cscsort_N_range[] = {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[] = {"mac_econ_fwd500.bin", "mc2depi.bin", "ASIC_320k.bin", "nos2.bin", "nos4.bin", "nos6.bin", "amazon0312.bin", "sme3Dc.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.permute = std::get<2>(tup); arg.baseA = 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.permute = std::get<0>(tup); arg.baseA = 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; } 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); } 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-6.4.3/clients/tests/test_csr2bsr.cpp000066400000000000000000000144011501764003400221060ustar00rootroot00000000000000/* ************************************************************************ * 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, 21453}; int csr2bsr_N_range[] = {0, 623, 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", "nos2.bin", "nos4.bin", "nos6.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.baseA = std::get<3>(tup); arg.baseB = 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.baseA = std::get<1>(tup); arg.baseB = 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; } 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); } 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-6.4.3/clients/tests/test_csr2coo.cpp000066400000000000000000000112511501764003400221000ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {0, 10, 500, 872, 1000}; int csr2coo_N_range[] = {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.baseA = 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.baseA = 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; } TEST(csr2coo_bad_arg, csr2coo) { testing_csr2coo_bad_arg(); } TEST_P(parameterized_csr2coo, csr2coo_float) { 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_float) { Arguments arg = setup_csr2coo_arguments(GetParam()); hipsparseStatus_t status = testing_csr2coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } 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-6.4.3/clients/tests/test_csr2csc.cpp000066400000000000000000000132571501764003400221000ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {0, 10, 500, 872, 1000}; int csr2csc_N_range[] = {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.baseA = 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.baseA = 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; } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) 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); } 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))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_csr2csc_ex2.cpp000066400000000000000000000145371501764003400226600ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {0, 10, 500, 872, 1000}; int csr2csc_ex2_N_range[] = {0, 33, 242, 623, 1000}; hipsparseAction_t csr2csc_ex2_action_range[] = {HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_ACTION_SYMBOLIC}; hipsparseIndexBase_t csr2csc_ex2_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; hipsparseCsr2CscAlg_t csr2csc_ex2_alg_range[] = {HIPSPARSE_CSR2CSC_ALG1}; 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.baseA = std::get<3>(tup); arg.csr2csc_alg = std::get<4>(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.baseA = std::get<1>(tup); arg.csr2csc_alg = std::get<2>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<3>(tup); // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) 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); } 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_base_range), testing::ValuesIn(csr2csc_ex2_alg_range))); INSTANTIATE_TEST_SUITE_P(csr2csc_ex2_bin, parameterized_csr2csc_ex2_bin, testing::Combine(testing::ValuesIn(csr2csc_ex2_action_range), testing::ValuesIn(csr2csc_ex2_base_range), testing::ValuesIn(csr2csc_ex2_alg_range), testing::ValuesIn(csr2csc_ex2_bin))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_csr2csr_compress.cpp000066400000000000000000000132701501764003400240250ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {10, 500, 872, 9375, 30327}; int csr2csr_compress_N_range[] = {33, 242, 623, 9184, 30645}; double csr2csr_compress_alpha_range[] = {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.baseA = 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.baseA = 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; } 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); } 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-6.4.3/clients/tests/test_csr2dense.cpp000066400000000000000000000072241501764003400224230ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {0, 10, 500, 872, 1000}; int csr2dense_N_range[] = {0, 33, 242, 623, 1000}; int csr2dense_LD_range[] = {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.baseA = std::get<3>(tup); return arg; } #if(!defined(CUDART_VERSION) || 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); } 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))); #endifhipSPARSE-rocm-6.4.3/clients/tests/test_csr2gebsr.cpp000066400000000000000000000160701501764003400224260ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {0, 13095}; int csr2gebsr_N_range[] = {0, 12766}; int csr2gebsr_row_block_dim_range[] = {1, 2, 7}; int csr2gebsr_col_block_dim_range[] = {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", "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.baseA = std::get<4>(tup); arg.baseB = 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.baseA = std::get<2>(tup); arg.baseB = 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; } 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); } 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-6.4.3/clients/tests/test_csr2hyb.cpp000066400000000000000000000132401501764003400221020ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {0, 10, 500, 872, 1000}; int csr2hyb_N_range[] = {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.baseA = 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.baseA = 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; } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) 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); } 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))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_csrcolor.cpp000066400000000000000000000041141501764003400223540ustar00rootroot00000000000000/* ************************************************************************ * 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 < 13000) 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-6.4.3/clients/tests/test_csrgeam.cpp000066400000000000000000000155631501764003400221610ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {0, 50, 647, 1799}; int csrgeam_N_range[] = {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.baseA = std::get<4>(tup); #ifdef __HIP_PLATFORM_NVIDIA__ // There is a bug with index base in cusparse arg.baseB = std::get<4>(tup); arg.baseC = std::get<4>(tup); #else arg.baseB = std::get<5>(tup); arg.baseC = 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.baseA = std::get<2>(tup); #ifdef __HIP_PLATFORM_NVIDIA__ // There is a bug with index base in cusparse arg.baseB = std::get<2>(tup); arg.baseC = std::get<2>(tup); #else arg.baseB = std::get<3>(tup); arg.baseC = 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; } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) 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); } 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))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_csrgeam2.cpp000066400000000000000000000142361501764003400222370ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {0, 50, 647, 1799}; int csrgeam2_N_range[] = {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.baseA = std::get<4>(tup); arg.baseB = std::get<5>(tup); arg.baseC = 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.baseA = std::get<2>(tup); arg.baseB = std::get<3>(tup); arg.baseC = 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-6.4.3/clients/tests/test_csrgemm.cpp000066400000000000000000000150541501764003400221700ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {0, 647, 1799}; int csrgemm_N_range[] = {0, 523, 3712}; int csrgemm_K_range[] = {0, 254, 1942}; base csrgemm_idxbaseA_range[] = {HIPSPARSE_INDEX_BASE_ZERO}; base csrgemm_idxbaseB_range[] = {HIPSPARSE_INDEX_BASE_ONE}; base csrgemm_idxbaseC_range[] = {HIPSPARSE_INDEX_BASE_ZERO}; trans csrgemm_transA_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE}; trans csrgemm_transB_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE}; std::string csrgemm_bin[] = {"mc2depi.bin", "scircuit.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.baseA = std::get<3>(tup); arg.baseB = std::get<4>(tup); arg.baseC = 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.baseA = std::get<0>(tup); arg.baseB = std::get<1>(tup); arg.baseC = 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; } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) 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); } 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))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_csrgemm2_a.cpp000066400000000000000000000143071501764003400225520ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {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.baseA = std::get<4>(tup); arg.baseB = std::get<5>(tup); arg.baseC = 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.baseA = std::get<1>(tup); arg.baseB = std::get<2>(tup); arg.baseC = 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; } #if(!defined(CUDART_VERSION) || 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); } 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))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_csrgemm2_b.cpp000066400000000000000000000132531501764003400225520ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {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.baseC = std::get<3>(tup); arg.baseD = 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.baseC = std::get<1>(tup); arg.baseD = 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; } #if(!defined(CUDART_VERSION) || 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); } 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))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_csric02.cpp000066400000000000000000000124071501764003400217770ustar00rootroot00000000000000/* ************************************************************************ * 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 hipsparseSolvePolicy_t solve_policy; typedef std::tuple csric02_tuple; typedef std::tuple csric02_bin_tuple; int csric02_M_range[] = {0, 50, 426}; base csric02_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; solve_policy csric02_solve_policy_range[] = {HIPSPARSE_SOLVE_POLICY_NO_LEVEL, HIPSPARSE_SOLVE_POLICY_USE_LEVEL}; 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.baseA = std::get<1>(tup); arg.solve_policy = std::get<2>(tup); arg.timing = 0; return arg; } Arguments setup_csric02_arguments(csric02_bin_tuple tup) { Arguments arg; arg.M = -99; arg.baseA = std::get<0>(tup); arg.solve_policy = std::get<1>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<2>(tup); // Get current executables absolute path // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) 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); } INSTANTIATE_TEST_SUITE_P(csric02, parameterized_csric02, testing::Combine(testing::ValuesIn(csric02_M_range), testing::ValuesIn(csric02_idxbase_range), testing::ValuesIn(csric02_solve_policy_range))); INSTANTIATE_TEST_SUITE_P(csric02_bin, parameterized_csric02_bin, testing::Combine(testing::ValuesIn(csric02_idxbase_range), testing::ValuesIn(csric02_solve_policy_range), testing::ValuesIn(csric02_bin))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_csrilu02.cpp000066400000000000000000000157171501764003400222040ustar00rootroot00000000000000/* ************************************************************************ * 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 hipsparseSolvePolicy_t solve_policy; typedef std::tuple csrilu02_tuple; typedef std::tuple csrilu02_bin_tuple; int csrilu02_M_range[] = {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}; solve_policy csrilu02_solve_policy_range[] = {HIPSPARSE_SOLVE_POLICY_NO_LEVEL, HIPSPARSE_SOLVE_POLICY_USE_LEVEL}; #if(!defined(CUDART_VERSION)) std::string csrilu02_bin[] = { "mac_econ_fwd500.bin", "rma10.bin", "nos1.bin", "nos2.bin", "nos3.bin", "nos5.bin", "nos6.bin"}; #elif(CUDART_VERSION >= 11080) std::string csrilu02_bin[] = {"mac_econ_fwd500.bin", "nos3.bin", "nos5.bin", "nos6.bin"}; #else // Note: There was a bug in csrilu02 where an infinite loop could occur on large matrices. // This was fixed in cusparse 11.8 std::string csrilu02_bin[] = {"nos3.bin", "nos5.bin", "nos6.bin"}; #endif 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.baseA = std::get<5>(tup); arg.solve_policy = std::get<6>(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.baseA = std::get<4>(tup); arg.solve_policy = 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; } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) 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); } 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), testing::ValuesIn(csrilu02_solve_policy_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_solve_policy_range), testing::ValuesIn(csrilu02_bin))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_csrilusv.cpp000066400000000000000000000063531501764003400224070ustar00rootroot00000000000000/* ************************************************************************ * 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.baseA = 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; } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) 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); } INSTANTIATE_TEST_SUITE_P(csrilusv_bin, parameterized_csrilusv_bin, testing::Combine(testing::ValuesIn(csrilusv_idxbase_range), testing::ValuesIn(csrilusv_bin))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_csrmm.cpp000066400000000000000000000150341501764003400216520ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {0, 275, 1059}; int csrmm_N_range[] = {0, 78}; int csrmm_K_range[] = {0, 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", "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.baseA = 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.baseA = 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; } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) 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); } 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))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_csrmv.cpp000066400000000000000000000141621501764003400216640ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {0, 500, 7111}; int csr_N_range[] = {0, 842, 4441}; std::vector csr_alpha_range = {3.0}; std::vector csr_beta_range = {1.0}; // clang-format off trans csr_trans_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_TRANSPOSE, HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE}; // clang-format on 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.baseA = 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.baseA = 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; } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) 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); } 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))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_csrsm2.cpp000066400000000000000000000160421501764003400217420ustar00rootroot00000000000000/* ************************************************************************ * 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 hipsparseSolvePolicy_t policy; typedef std::tuple csrsm2_tuple; typedef std::tuple csrsm2_bin_tuple; int csrsm2_M_range[] = {0, 124, 9381}; int csrsm2_nrhs_range[] = {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}; policy csrsm2_policy_range[] = {HIPSPARSE_SOLVE_POLICY_NO_LEVEL, HIPSPARSE_SOLVE_POLICY_USE_LEVEL}; 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.baseA = 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.solve_policy = std::get<8>(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.baseA = 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.solve_policy = 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; } #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), testing::ValuesIn(csrsm2_policy_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_policy_range), testing::ValuesIn(csrsm2_bin))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_csrsort.cpp000066400000000000000000000113451501764003400222310ustar00rootroot00000000000000/* ************************************************************************ * 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; #if defined(__HIP_PLATFORM_AMD__) int csrsort_M_range[] = {0, 10, 500, 872, 1000}; int csrsort_N_range[] = {0, 33, 242, 623, 1000}; int csrsort_perm[] = {0, 1}; #elif defined(__HIP_PLATFORM_NVIDIA__) // cusparse does not allow without permutation int csrsort_M_range[] = {10, 500, 872, 1000}; int csrsort_N_range[] = {33, 242, 623, 1000}; int csrsort_perm[] = {1}; #endif hipsparseIndexBase_t csrsort_base[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; std::string csrsort_bin[] = {"rma10.bin", "bibd_22_8.bin", "scircuit.bin", "bmwcra_1.bin", "nos1.bin", "nos3.bin", "nos5.bin", "nos7.bin", "Chebyshev4.bin", "webbase-1M.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.permute = std::get<2>(tup); arg.baseA = 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.permute = std::get<0>(tup); arg.baseA = 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; } 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); } 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-6.4.3/clients/tests/test_csrsv2.cpp000066400000000000000000000153411501764003400217540ustar00rootroot00000000000000/* ************************************************************************ * 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 hipsparseSolvePolicy_t policy; typedef std::tuple csrsv2_tuple; typedef std::tuple csrsv2_bin_tuple; int csrsv2_M_range[] = {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}; policy csrsv2_policy_range[] = {HIPSPARSE_SOLVE_POLICY_NO_LEVEL, HIPSPARSE_SOLVE_POLICY_USE_LEVEL}; 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.baseA = 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.solve_policy = std::get<6>(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.baseA = 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.solve_policy = 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; } #if(!defined(CUDART_VERSION) || 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); } 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), testing::ValuesIn(csrsv2_policy_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_policy_range), testing::ValuesIn(csrsv2_bin))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_csru2csr.cpp000066400000000000000000000076551501764003400223110ustar00rootroot00000000000000/* ************************************************************************ * 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 "utility.hpp" #include #include #include typedef std::tuple csru2csr_tuple; typedef std::tuple csru2csr_bin_tuple; int csru2csr_M_range[] = {51314}; int csru2csr_N_range[] = {12963}; hipsparseIndexBase_t csru2csr_base[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; std::string csru2csr_bin[] = {"nos3.bin"}; class parameterized_csru2csr : public testing::TestWithParam { protected: parameterized_csru2csr() {} virtual ~parameterized_csru2csr() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_csru2csr_bin : public testing::TestWithParam { protected: parameterized_csru2csr_bin() {} virtual ~parameterized_csru2csr_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_csru2csr_arguments(csru2csr_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.baseA = std::get<2>(tup); arg.timing = 0; return arg; } Arguments setup_csru2csr_arguments(csru2csr_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = -99; arg.baseA = 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; } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) TEST(csru2csr_bad_arg, csru2csr) { testing_csru2csr_bad_arg(); } TEST_P(parameterized_csru2csr, csru2csr_float) { Arguments arg = setup_csru2csr_arguments(GetParam()); hipsparseStatus_t status = testing_csru2csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_csru2csr_bin, csru2csr_bin_float) { Arguments arg = setup_csru2csr_arguments(GetParam()); hipsparseStatus_t status = testing_csru2csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(csru2csr, parameterized_csru2csr, testing::Combine(testing::ValuesIn(csru2csr_M_range), testing::ValuesIn(csru2csr_N_range), testing::ValuesIn(csru2csr_base))); INSTANTIATE_TEST_SUITE_P(csru2csr_bin, parameterized_csru2csr_bin, testing::Combine(testing::ValuesIn(csru2csr_base), testing::ValuesIn(csru2csr_bin))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_dense2csc.cpp000066400000000000000000000072051501764003400224030ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {0, 10, 500, 872, 1000}; int dense2csc_N_range[] = {0, 33, 242, 623, 1000}; int dense2csc_LD_range[] = {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; } 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); } 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-6.4.3/clients/tests/test_dense2csr.cpp000066400000000000000000000072541501764003400224260ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {0, 10, 500, 872, 1000}; int dense2csr_N_range[] = {0, 33, 242, 623, 1000}; int dense2csr_LD_range[] = {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.baseA = std::get<3>(tup); return arg; } 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); } 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-6.4.3/clients/tests/test_dense_to_sparse_coo.cpp000066400000000000000000000067761501764003400245630ustar00rootroot00000000000000/* ************************************************************************ * 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 "utility.hpp" #include #include #include typedef std::tuple dense_to_sparse_coo_tuple; int dense_to_sparse_coo_M_range[] = {100}; int dense_to_sparse_coo_N_range[] = {10}; hipsparseIndexBase_t dense_to_sparse_coo_base[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; hipsparseOrder_t dense_to_sparse_coo_order[] = {HIPSPARSE_ORDER_COL, HIPSPARSE_ORDER_ROW}; hipsparseDenseToSparseAlg_t dense_to_sparse_coo_alg[] = {HIPSPARSE_DENSETOSPARSE_ALG_DEFAULT}; class parameterized_dense_to_sparse_coo : public testing::TestWithParam { protected: parameterized_dense_to_sparse_coo() {} virtual ~parameterized_dense_to_sparse_coo() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_dense_to_sparse_coo_arguments(dense_to_sparse_coo_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.baseA = std::get<2>(tup); arg.orderA = std::get<3>(tup); arg.dense2sparse_alg = std::get<4>(tup); arg.timing = 0; return arg; } #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) TEST(dense_to_sparse_coo_bad_arg, dense_to_sparse_coo) { testing_dense_to_sparse_coo_bad_arg(); } TEST_P(parameterized_dense_to_sparse_coo, dense_to_sparse_coo_float) { Arguments arg = setup_dense_to_sparse_coo_arguments(GetParam()); hipsparseStatus_t status = testing_dense_to_sparse_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(dense_to_sparse_coo, parameterized_dense_to_sparse_coo, testing::Combine(testing::ValuesIn(dense_to_sparse_coo_M_range), testing::ValuesIn(dense_to_sparse_coo_N_range), testing::ValuesIn(dense_to_sparse_coo_base), testing::ValuesIn(dense_to_sparse_coo_order), testing::ValuesIn(dense_to_sparse_coo_alg))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_dense_to_sparse_csc.cpp000066400000000000000000000070031501764003400245330ustar00rootroot00000000000000/* ************************************************************************ * 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 "utility.hpp" #include #include #include typedef std::tuple dense_to_sparse_csc_tuple; int dense_to_sparse_csc_M_range[] = {100}; int dense_to_sparse_csc_N_range[] = {10}; hipsparseIndexBase_t dense_to_sparse_csc_base[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; hipsparseOrder_t dense_to_sparse_csc_order[] = {HIPSPARSE_ORDER_COL, HIPSPARSE_ORDER_ROW}; hipsparseDenseToSparseAlg_t dense_to_sparse_csc_alg[] = {HIPSPARSE_DENSETOSPARSE_ALG_DEFAULT}; class parameterized_dense_to_sparse_csc : public testing::TestWithParam { protected: parameterized_dense_to_sparse_csc() {} virtual ~parameterized_dense_to_sparse_csc() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_dense_to_sparse_csc_arguments(dense_to_sparse_csc_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.baseA = std::get<2>(tup); arg.orderA = std::get<3>(tup); arg.dense2sparse_alg = std::get<4>(tup); arg.timing = 0; return arg; } #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) TEST(dense_to_sparse_csc_bad_arg, dense_to_sparse_csc) { testing_dense_to_sparse_csc_bad_arg(); } TEST_P(parameterized_dense_to_sparse_csc, dense_to_sparse_csc_float) { Arguments arg = setup_dense_to_sparse_csc_arguments(GetParam()); hipsparseStatus_t status = testing_dense_to_sparse_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(dense_to_sparse_csc, parameterized_dense_to_sparse_csc, testing::Combine(testing::ValuesIn(dense_to_sparse_csc_M_range), testing::ValuesIn(dense_to_sparse_csc_N_range), testing::ValuesIn(dense_to_sparse_csc_base), testing::ValuesIn(dense_to_sparse_csc_order), testing::ValuesIn(dense_to_sparse_csc_alg))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_dense_to_sparse_csr.cpp000066400000000000000000000070031501764003400245520ustar00rootroot00000000000000/* ************************************************************************ * 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 "utility.hpp" #include #include #include typedef std::tuple dense_to_sparse_csr_tuple; int dense_to_sparse_csr_M_range[] = {100}; int dense_to_sparse_csr_N_range[] = {10}; hipsparseIndexBase_t dense_to_sparse_csr_base[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; hipsparseOrder_t dense_to_sparse_csr_order[] = {HIPSPARSE_ORDER_COL, HIPSPARSE_ORDER_ROW}; hipsparseDenseToSparseAlg_t dense_to_sparse_csr_alg[] = {HIPSPARSE_DENSETOSPARSE_ALG_DEFAULT}; class parameterized_dense_to_sparse_csr : public testing::TestWithParam { protected: parameterized_dense_to_sparse_csr() {} virtual ~parameterized_dense_to_sparse_csr() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_dense_to_sparse_csr_arguments(dense_to_sparse_csr_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.baseA = std::get<2>(tup); arg.orderA = std::get<3>(tup); arg.dense2sparse_alg = std::get<4>(tup); arg.timing = 0; return arg; } #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) TEST(dense_to_sparse_csr_bad_arg, dense_to_sparse_csr) { testing_dense_to_sparse_csr_bad_arg(); } TEST_P(parameterized_dense_to_sparse_csr, dense_to_sparse_csr_float) { Arguments arg = setup_dense_to_sparse_csr_arguments(GetParam()); hipsparseStatus_t status = testing_dense_to_sparse_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(dense_to_sparse_csr, parameterized_dense_to_sparse_csr, testing::Combine(testing::ValuesIn(dense_to_sparse_csr_M_range), testing::ValuesIn(dense_to_sparse_csr_N_range), testing::ValuesIn(dense_to_sparse_csr_base), testing::ValuesIn(dense_to_sparse_csr_order), testing::ValuesIn(dense_to_sparse_csr_alg))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_dnmat_descr.cpp000066400000000000000000000027221501764003400230140ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2023 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "testing_dnmat_descr.hpp" #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) TEST(dnmat_descr_bad_arg, dnmat_descr_float) { testing_dnmat_descr_bad_arg(); } #endif hipSPARSE-rocm-6.4.3/clients/tests/test_dnvec_descr.cpp000066400000000000000000000030271501764003400230070ustar00rootroot00000000000000/* ************************************************************************ * 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" #if(!defined(CUDART_VERSION) || CUDART_VERSION > 10010 \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) TEST(dnvec_descr_bad_arg, dnvec_descr_float) { testing_dnvec_descr_bad_arg(); } #endif hipSPARSE-rocm-6.4.3/clients/tests/test_dotci.cpp000066400000000000000000000057171501764003400216420ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {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.baseA = std::get<2>(tup); arg.timing = 0; return arg; } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) 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); } 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))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_doti.cpp000066400000000000000000000065201501764003400214700ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {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.baseA = std::get<2>(tup); arg.timing = 0; return arg; } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) 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); } 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))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_gather.cpp000066400000000000000000000052621501764003400220050ustar00rootroot00000000000000/* ************************************************************************ * 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 "utility.hpp" #include #include #include typedef std::tuple gather_tuple; int gather_N_range[] = {15332}; int gather_nnz_range[] = {500}; hipsparseIndexBase_t gather_base[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; class parameterized_gather : public testing::TestWithParam { protected: parameterized_gather() {} virtual ~parameterized_gather() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_gather_arguments(gather_tuple tup) { Arguments arg; arg.N = std::get<0>(tup); arg.nnz = std::get<1>(tup); arg.baseA = std::get<2>(tup); arg.timing = 0; return arg; } #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) TEST(gather_bad_arg, gather) { testing_gather_bad_arg(); } TEST_P(parameterized_gather, gather_float) { Arguments arg = setup_gather_arguments(GetParam()); hipsparseStatus_t status = testing_gather(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(gather, parameterized_gather, testing::Combine(testing::ValuesIn(gather_N_range), testing::ValuesIn(gather_nnz_range), testing::ValuesIn(gather_base))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_gebsr2csr.cpp000066400000000000000000000155731501764003400224350ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {872, 21453}; int gebsr2csr_N_range[] = {623, 29285}; int gebsr2csr_row_block_dim_range[] = {2, 4, 8}; int gebsr2csr_col_block_dim_range[] = {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.baseA = std::get<4>(tup); arg.baseB = 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.baseA = std::get<2>(tup); arg.baseB = 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; } 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); } 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-6.4.3/clients/tests/test_gebsr2gebsc.cpp000066400000000000000000000146401501764003400227230ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {0, 10, 872}; int gebsr2gebsc_N_range[] = {0, 33, 623}; int gebsr2gebsc_row_block_dim_range[] = {1, 2, 7}; int gebsr2gebsc_col_block_dim_range[] = {1, 3, 4}; 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.baseA = 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.baseA = 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; } 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); } 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-6.4.3/clients/tests/test_gebsr2gebsr.cpp000066400000000000000000000200511501764003400227330ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {0, 872, 13095, 21453}; int gebsr2gebsr_N_range[] = {0, 623, 12766, 29285}; int gebsr2gebsr_row_block_dim_A_range[] = {2}; int gebsr2gebsr_col_block_dim_A_range[] = {5}; int gebsr2gebsr_row_block_dim_C_range[] = {3}; int gebsr2gebsr_col_block_dim_C_range[] = {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.baseA = std::get<6>(tup); arg.baseB = 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.baseA = std::get<4>(tup); arg.baseB = 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; } 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); } 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-6.4.3/clients/tests/test_gemmi.cpp000066400000000000000000000123011501764003400216210ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {0, 19, 78, 482}; int gemmi_N_range[] = {0, 42, 275, 759}; int gemmi_K_range[] = {0, 50, 173, 1375}; double gemmi_alpha_range[] = {-0.5}; double gemmi_beta_range[] = {0.5}; 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; } #if(!defined(CUDART_VERSION) || 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); } 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))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_gemvi.cpp000066400000000000000000000077271501764003400216520ustar00rootroot00000000000000/* ************************************************************************ * 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 #include typedef std::tuple gemvi_tuple; int gemvi_M_range[] = {1291}; int gemvi_N_range[] = {724}; int gemvi_nnz_range[] = {237}; double gemvi_alpha_range[] = {-0.5, 2.0}; double gemvi_beta_range[] = {0.5, 0.0}; hipsparseOperation_t gemvi_trans_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE}; hipsparseIndexBase_t gemvi_idx_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; class parameterized_gemvi : public testing::TestWithParam { protected: parameterized_gemvi() {} virtual ~parameterized_gemvi() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_gemvi_arguments(gemvi_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.nnz = std::get<2>(tup); arg.alpha = std::get<3>(tup); arg.beta = std::get<4>(tup); arg.transA = std::get<5>(tup); arg.baseA = std::get<6>(tup); arg.timing = 0; return arg; } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) TEST(gemvi_bad_arg, gemvi_float) { testing_gemvi_bad_arg(); } TEST_P(parameterized_gemvi, gemvi_float) { Arguments arg = setup_gemvi_arguments(GetParam()); hipsparseStatus_t status = testing_gemvi(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gemvi, gemvi_double) { Arguments arg = setup_gemvi_arguments(GetParam()); hipsparseStatus_t status = testing_gemvi(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gemvi, gemvi_float_complex) { Arguments arg = setup_gemvi_arguments(GetParam()); hipsparseStatus_t status = testing_gemvi(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gemvi, gemvi_double_complex) { Arguments arg = setup_gemvi_arguments(GetParam()); hipsparseStatus_t status = testing_gemvi(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(gemvi, parameterized_gemvi, testing::Combine(testing::ValuesIn(gemvi_M_range), testing::ValuesIn(gemvi_N_range), testing::ValuesIn(gemvi_nnz_range), testing::ValuesIn(gemvi_alpha_range), testing::ValuesIn(gemvi_beta_range), testing::ValuesIn(gemvi_trans_range), testing::ValuesIn(gemvi_idx_base_range))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_gpsv_interleaved_batch.cpp000066400000000000000000000073271501764003400252410ustar00rootroot00000000000000/* ************************************************************************ * 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 "utility.hpp" #include #include typedef std::tuple gpsv_interleaved_batch_tuple; int gpsv_interleaved_batch_M_range[] = {512}; int gpsv_interleaved_batch_batch_count_range[] = {512}; int gpsv_interleaved_batch_algo_range[] = {0}; class parameterized_gpsv_interleaved_batch : public testing::TestWithParam { protected: parameterized_gpsv_interleaved_batch() {} virtual ~parameterized_gpsv_interleaved_batch() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_gpsv_interleaved_batch_arguments(gpsv_interleaved_batch_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.batch_count = std::get<1>(tup); arg.gpsv_alg = std::get<2>(tup); arg.timing = 0; return arg; } TEST(gpsv_interleaved_batch_bad_arg, gpsv_interleaved_batch_float) { testing_gpsv_interleaved_batch_bad_arg(); } TEST_P(parameterized_gpsv_interleaved_batch, gpsv_interleaved_batch_float) { Arguments arg = setup_gpsv_interleaved_batch_arguments(GetParam()); hipsparseStatus_t status = testing_gpsv_interleaved_batch(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gpsv_interleaved_batch, gpsv_interleaved_batch_double) { Arguments arg = setup_gpsv_interleaved_batch_arguments(GetParam()); hipsparseStatus_t status = testing_gpsv_interleaved_batch(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gpsv_interleaved_batch, gpsv_interleaved_batch_float_complex) { Arguments arg = setup_gpsv_interleaved_batch_arguments(GetParam()); hipsparseStatus_t status = testing_gpsv_interleaved_batch(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gpsv_interleaved_batch, gpsv_interleaved_batch_double_complex) { Arguments arg = setup_gpsv_interleaved_batch_arguments(GetParam()); hipsparseStatus_t status = testing_gpsv_interleaved_batch(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P( gpsv_interleaved_batch, parameterized_gpsv_interleaved_batch, testing::Combine(testing::ValuesIn(gpsv_interleaved_batch_M_range), testing::ValuesIn(gpsv_interleaved_batch_batch_count_range), testing::ValuesIn(gpsv_interleaved_batch_algo_range))); hipSPARSE-rocm-6.4.3/clients/tests/test_gthr.cpp000066400000000000000000000065171501764003400215030ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {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.baseA = std::get<2>(tup); arg.timing = 0; return arg; } #if(!defined(CUDART_VERSION) || 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); } 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))); #endifhipSPARSE-rocm-6.4.3/clients/tests/test_gthrz.cpp000066400000000000000000000065621501764003400216750ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {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.baseA = std::get<2>(tup); arg.timing = 0; return arg; } #if(!defined(CUDART_VERSION) || 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); } 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))); #endifhipSPARSE-rocm-6.4.3/clients/tests/test_gtsv.cpp000066400000000000000000000057161501764003400215220ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "testing_gtsv.hpp" #include #include typedef std::tuple gtsv_tuple; int gtsv_M_range[] = {512}; int gtsv_N_range[] = {512}; class parameterized_gtsv : public testing::TestWithParam { protected: parameterized_gtsv() {} virtual ~parameterized_gtsv() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_gtsv_arguments(gtsv_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.timing = 0; return arg; } TEST(gtsv_bad_arg, gtsv_float) { testing_gtsv2_bad_arg(); } TEST_P(parameterized_gtsv, gtsv_float) { Arguments arg = setup_gtsv_arguments(GetParam()); hipsparseStatus_t status = testing_gtsv2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gtsv, gtsv_double) { Arguments arg = setup_gtsv_arguments(GetParam()); hipsparseStatus_t status = testing_gtsv2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gtsv, gtsv_float_complex) { Arguments arg = setup_gtsv_arguments(GetParam()); hipsparseStatus_t status = testing_gtsv2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gtsv, gtsv_double_complex) { Arguments arg = setup_gtsv_arguments(GetParam()); hipsparseStatus_t status = testing_gtsv2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(gtsv, parameterized_gtsv, testing::Combine(testing::ValuesIn(gtsv_M_range), testing::ValuesIn(gtsv_N_range))); hipSPARSE-rocm-6.4.3/clients/tests/test_gtsv2_nopivot.cpp000066400000000000000000000063621501764003400233600ustar00rootroot00000000000000/* ************************************************************************ * 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 #include typedef std::tuple gtsv2_nopivot_tuple; int gtsv2_nopivot_M_range[] = {512}; int gtsv2_nopivot_N_range[] = {512}; class parameterized_gtsv2_nopivot : public testing::TestWithParam { protected: parameterized_gtsv2_nopivot() {} virtual ~parameterized_gtsv2_nopivot() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_gtsv2_nopivot_arguments(gtsv2_nopivot_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.timing = 0; return arg; } TEST(gtsv2_nopivot_bad_arg, gtsv2_nopivot_float) { testing_gtsv2_nopivot_bad_arg(); } TEST_P(parameterized_gtsv2_nopivot, gtsv2_nopivot_float) { Arguments arg = setup_gtsv2_nopivot_arguments(GetParam()); hipsparseStatus_t status = testing_gtsv2_nopivot(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gtsv2_nopivot, gtsv2_nopivot_double) { Arguments arg = setup_gtsv2_nopivot_arguments(GetParam()); hipsparseStatus_t status = testing_gtsv2_nopivot(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gtsv2_nopivot, gtsv2_nopivot_float_complex) { Arguments arg = setup_gtsv2_nopivot_arguments(GetParam()); hipsparseStatus_t status = testing_gtsv2_nopivot(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gtsv2_nopivot, gtsv2_nopivot_double_complex) { Arguments arg = setup_gtsv2_nopivot_arguments(GetParam()); hipsparseStatus_t status = testing_gtsv2_nopivot(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(gtsv2_nopivot, parameterized_gtsv2_nopivot, testing::Combine(testing::ValuesIn(gtsv2_nopivot_M_range), testing::ValuesIn(gtsv2_nopivot_N_range))); hipSPARSE-rocm-6.4.3/clients/tests/test_gtsv2_strided_batch.cpp000066400000000000000000000066531501764003400244640ustar00rootroot00000000000000/* ************************************************************************ * 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 #include typedef std::tuple gtsv2_strided_batch_tuple; int gtsv2_strided_batch_M_range[] = {512}; int gtsv2_strided_batch_batch_count_range[] = {512}; class parameterized_gtsv2_strided_batch : public testing::TestWithParam { protected: parameterized_gtsv2_strided_batch() {} virtual ~parameterized_gtsv2_strided_batch() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_gtsv2_strided_batch_arguments(gtsv2_strided_batch_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.batch_count = std::get<1>(tup); arg.timing = 0; return arg; } TEST(gtsv2_strided_batch_bad_arg, gtsv2_strided_batch_float) { testing_gtsv2_strided_batch_bad_arg(); } TEST_P(parameterized_gtsv2_strided_batch, gtsv2_strided_batch_float) { Arguments arg = setup_gtsv2_strided_batch_arguments(GetParam()); hipsparseStatus_t status = testing_gtsv2_strided_batch(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gtsv2_strided_batch, gtsv2_strided_batch_double) { Arguments arg = setup_gtsv2_strided_batch_arguments(GetParam()); hipsparseStatus_t status = testing_gtsv2_strided_batch(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gtsv2_strided_batch, gtsv2_strided_batch_float_complex) { Arguments arg = setup_gtsv2_strided_batch_arguments(GetParam()); hipsparseStatus_t status = testing_gtsv2_strided_batch(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gtsv2_strided_batch, gtsv2_strided_batch_double_complex) { Arguments arg = setup_gtsv2_strided_batch_arguments(GetParam()); hipsparseStatus_t status = testing_gtsv2_strided_batch(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P( gtsv2_strided_batch, parameterized_gtsv2_strided_batch, testing::Combine(testing::ValuesIn(gtsv2_strided_batch_M_range), testing::ValuesIn(gtsv2_strided_batch_batch_count_range))); hipSPARSE-rocm-6.4.3/clients/tests/test_gtsv_interleaved_batch.cpp000066400000000000000000000073271501764003400252450ustar00rootroot00000000000000/* ************************************************************************ * 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 "utility.hpp" #include #include typedef std::tuple gtsv_interleaved_batch_tuple; int gtsv_interleaved_batch_M_range[] = {512}; int gtsv_interleaved_batch_batch_count_range[] = {512}; int gtsv_interleaved_batch_algo_range[] = {0}; class parameterized_gtsv_interleaved_batch : public testing::TestWithParam { protected: parameterized_gtsv_interleaved_batch() {} virtual ~parameterized_gtsv_interleaved_batch() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_gtsv_interleaved_batch_arguments(gtsv_interleaved_batch_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.batch_count = std::get<1>(tup); arg.gtsv_alg = std::get<2>(tup); arg.timing = 0; return arg; } TEST(gtsv_interleaved_batch_bad_arg, gtsv_interleaved_batch_float) { testing_gtsv_interleaved_batch_bad_arg(); } TEST_P(parameterized_gtsv_interleaved_batch, gtsv_interleaved_batch_float) { Arguments arg = setup_gtsv_interleaved_batch_arguments(GetParam()); hipsparseStatus_t status = testing_gtsv_interleaved_batch(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gtsv_interleaved_batch, gtsv_interleaved_batch_double) { Arguments arg = setup_gtsv_interleaved_batch_arguments(GetParam()); hipsparseStatus_t status = testing_gtsv_interleaved_batch(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gtsv_interleaved_batch, gtsv_interleaved_batch_float_complex) { Arguments arg = setup_gtsv_interleaved_batch_arguments(GetParam()); hipsparseStatus_t status = testing_gtsv_interleaved_batch(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gtsv_interleaved_batch, gtsv_interleaved_batch_double_complex) { Arguments arg = setup_gtsv_interleaved_batch_arguments(GetParam()); hipsparseStatus_t status = testing_gtsv_interleaved_batch(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P( gtsv_interleaved_batch, parameterized_gtsv_interleaved_batch, testing::Combine(testing::ValuesIn(gtsv_interleaved_batch_M_range), testing::ValuesIn(gtsv_interleaved_batch_batch_count_range), testing::ValuesIn(gtsv_interleaved_batch_algo_range))); hipSPARSE-rocm-6.4.3/clients/tests/test_hyb2csr.cpp000066400000000000000000000123371501764003400221100ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {0, 10, 500, 872, 1000}; int hyb2csr_N_range[] = {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.baseA = 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.baseA = 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; } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) 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); } 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))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_hybmv.cpp000066400000000000000000000141101501764003400216500ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {0, 10, 500, 7111, 10000}; int hyb_N_range[] = {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.baseA = 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.baseA = 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; } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) 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); } 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))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_identity.cpp000066400000000000000000000042731501764003400223650ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {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; } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) 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); } INSTANTIATE_TEST_SUITE_P(identity, parameterized_identity, testing::ValuesIn(identity_N_range)); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_nnz.cpp000066400000000000000000000061441501764003400213400ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "testing_nnz.hpp" #include "utility.hpp" #include #include #include typedef std::tuple nnz_tuple; int nnz_M_range[] = {0, 10, 500, 872, 1000}; int nnz_N_range[] = {0, 33, 242, 623, 1000}; int nnz_LD_range[] = {1000}; class parameterized_nnz : public testing::TestWithParam { protected: parameterized_nnz() {} virtual ~parameterized_nnz() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_nnz_arguments(nnz_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.lda = std::get<2>(tup); return arg; } TEST(nnz_bad_arg, nnz) { testing_nnz_bad_arg(); } TEST_P(parameterized_nnz, nnz_float) { Arguments arg = setup_nnz_arguments(GetParam()); hipsparseStatus_t status = testing_nnz(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_nnz, nnz_double) { Arguments arg = setup_nnz_arguments(GetParam()); hipsparseStatus_t status = testing_nnz(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_nnz, nnz_float_complex) { Arguments arg = setup_nnz_arguments(GetParam()); hipsparseStatus_t status = testing_nnz(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_nnz, nnz_double_complex) { Arguments arg = setup_nnz_arguments(GetParam()); hipsparseStatus_t status = testing_nnz(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(nnz, parameterized_nnz, testing::Combine(testing::ValuesIn(nnz_M_range), testing::ValuesIn(nnz_N_range), testing::ValuesIn(nnz_LD_range))); hipSPARSE-rocm-6.4.3/clients/tests/test_prune_csr2csr.cpp000066400000000000000000000130541501764003400233230ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {10, 500, 872, 27463, 35327}; int prune_csr2csr_N_range[] = {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.baseA = std::get<3>(tup); arg.baseB = 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.baseA = std::get<1>(tup); arg.baseB = 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; } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) 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); } 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))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_prune_csr2csr_by_percentage.cpp000066400000000000000000000151111501764003400262060ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {10, 872, 46532}; int prune_csr2csr_by_percentage_N_range[] = {33, 623, 59264}; double prune_csr2csr_by_percentage_range[] = {75.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.baseA = std::get<3>(tup); arg.baseB = 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.baseA = std::get<1>(tup); arg.baseB = 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; } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) 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); } 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))); #endifhipSPARSE-rocm-6.4.3/clients/tests/test_prune_dense2csr.cpp000066400000000000000000000073031501764003400236320ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {0, 10, 500, 872, 1000}; int prune_dense2csr_N_range[] = {0, 33, 242, 623, 1000}; int prune_dense2csr_LD_range[] = {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.baseA = std::get<4>(tup); return arg; } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) 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); } 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))); #endifhipSPARSE-rocm-6.4.3/clients/tests/test_prune_dense2csr_by_percentage.cpp000066400000000000000000000075301501764003400265230ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {0, 10, 500, 872, 1000}; int prune_dense2csr_by_percentage_N_range[] = {0, 33, 242, 623, 1000}; int prune_dense2csr_by_percentage_LD_range[] = {1000}; double prune_dense2csr_by_percentage_range[] = {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.baseA = std::get<4>(tup); return arg; } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) 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); } 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))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_rot.cpp000066400000000000000000000063111501764003400213330ustar00rootroot00000000000000/* ************************************************************************ * 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 typedef hipsparseIndexBase_t base; typedef std::tuple rot_tuple; int rot_N_range[] = {12000, 15332, 22031}; int rot_nnz_range[] = {0, 5, 10, 500, 1000, 7111, 10000}; double rot_c_range[] = {-2.0, 0.0, 1.0}; double rot_s_range[] = {-3.0, 0.0, 4.0}; base rot_idx_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; class parameterized_rot : public testing::TestWithParam { protected: parameterized_rot() {} virtual ~parameterized_rot() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_rot_arguments(rot_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.baseA = std::get<4>(tup); arg.timing = 0; return arg; } #if(!defined(CUDART_VERSION) || (CUDART_VERSION >= 11000 && CUDART_VERSION < 13000)) TEST(rot_bad_arg, rot_float) { testing_rot_bad_arg(); } TEST_P(parameterized_rot, rot_i32_float) { Arguments arg = setup_rot_arguments(GetParam()); hipsparseStatus_t status = testing_rot(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_rot, rot_i64_double) { Arguments arg = setup_rot_arguments(GetParam()); hipsparseStatus_t status = testing_rot(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(rot, parameterized_rot, testing::Combine(testing::ValuesIn(rot_N_range), testing::ValuesIn(rot_nnz_range), testing::ValuesIn(rot_c_range), testing::ValuesIn(rot_s_range), testing::ValuesIn(rot_idx_base_range))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_roti.cpp000066400000000000000000000063461501764003400215140ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {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.baseA = std::get<4>(tup); arg.timing = 0; return arg; } #if(!defined(CUDART_VERSION) || 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); } 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))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_scatter.cpp000066400000000000000000000067041501764003400222020ustar00rootroot00000000000000/* ************************************************************************ * 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 typedef hipsparseIndexBase_t base; typedef std::tuple scatter_tuple; int scatter_N_range[] = {12000, 15332, 22031}; int scatter_nnz_range[] = {0, 5, 10, 500, 1000, 7111, 10000}; base scatter_idx_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; class parameterized_scatter : public testing::TestWithParam { protected: parameterized_scatter() {} virtual ~parameterized_scatter() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_scatter_arguments(scatter_tuple tup) { Arguments arg; arg.N = std::get<0>(tup); arg.nnz = std::get<1>(tup); arg.baseA = std::get<2>(tup); arg.timing = 0; return arg; } #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) TEST(scatter_bad_arg, scatter_float) { testing_scatter_bad_arg(); } TEST_P(parameterized_scatter, scatter_i32_float) { Arguments arg = setup_scatter_arguments(GetParam()); hipsparseStatus_t status = testing_scatter(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_scatter, scatter_i64_double) { Arguments arg = setup_scatter_arguments(GetParam()); hipsparseStatus_t status = testing_scatter(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_scatter, scatter_i32_float_complex) { Arguments arg = setup_scatter_arguments(GetParam()); hipsparseStatus_t status = testing_scatter(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_scatter, scatter_i64_double_complex) { Arguments arg = setup_scatter_arguments(GetParam()); hipsparseStatus_t status = testing_scatter(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(scatter, parameterized_scatter, testing::Combine(testing::ValuesIn(scatter_N_range), testing::ValuesIn(scatter_nnz_range), testing::ValuesIn(scatter_idx_base_range))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_sctr.cpp000066400000000000000000000065201501764003400215040ustar00rootroot00000000000000/* ************************************************************************ * 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[] = {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.baseA = std::get<2>(tup); arg.timing = 0; return arg; } #if(!defined(CUDART_VERSION) || 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); } 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))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_sddmm_coo.cpp000066400000000000000000000177251501764003400225060ustar00rootroot00000000000000/* ************************************************************************ * 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 struct alpha_beta { double alpha; double beta; }; typedef std::tuple sddmm_coo_tuple; typedef std::tuple sddmm_coo_bin_tuple; int sddmm_coo_M_range[] = {50}; int sddmm_coo_N_range[] = {84}; int sddmm_coo_K_range[] = {5}; alpha_beta sddmm_coo_alpha_beta_range[] = {{2.0, 1.0}}; hipsparseOperation_t sddmm_coo_transA_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_TRANSPOSE}; hipsparseOperation_t sddmm_coo_transB_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_TRANSPOSE}; hipsparseOrder_t sddmm_coo_orderA_range[] = {HIPSPARSE_ORDER_COL, HIPSPARSE_ORDER_ROW}; hipsparseOrder_t sddmm_coo_orderB_range[] = {HIPSPARSE_ORDER_COL, HIPSPARSE_ORDER_ROW}; hipsparseIndexBase_t sddmm_coo_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; hipsparseSDDMMAlg_t sddmm_coo_alg_range[] = {HIPSPARSE_SDDMM_ALG_DEFAULT}; std::string sddmm_coo_bin[] = {"nos2.bin", "nos4.bin", "nos6.bin", "Chebyshev4.bin"}; class parameterized_sddmm_coo : public testing::TestWithParam { protected: parameterized_sddmm_coo() {} virtual ~parameterized_sddmm_coo() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_sddmm_coo_bin : public testing::TestWithParam { protected: parameterized_sddmm_coo_bin() {} virtual ~parameterized_sddmm_coo_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_sddmm_coo_arguments(sddmm_coo_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.K = std::get<2>(tup); arg.alpha = std::get<3>(tup).alpha; arg.beta = std::get<3>(tup).beta; arg.transA = std::get<4>(tup); arg.transB = std::get<5>(tup); arg.orderA = std::get<6>(tup); arg.orderB = std::get<7>(tup); arg.baseA = std::get<8>(tup); arg.sddmm_alg = std::get<9>(tup); arg.timing = 0; return arg; } Arguments setup_sddmm_coo_arguments(sddmm_coo_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = -99; arg.K = std::get<0>(tup); arg.alpha = std::get<1>(tup).alpha; arg.beta = std::get<1>(tup).beta; arg.transA = std::get<2>(tup); arg.transB = std::get<3>(tup); arg.orderA = std::get<4>(tup); arg.orderB = std::get<5>(tup); arg.baseA = std::get<6>(tup); arg.sddmm_alg = std::get<7>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<8>(tup); // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } // COO format not supported in cusparse #if(!defined(CUDART_VERSION)) TEST(sddmm_coo_bad_arg, sddmm_coo_float) { testing_sddmm_coo_bad_arg(); } TEST_P(parameterized_sddmm_coo, sddmm_coo_i32_float) { Arguments arg = setup_sddmm_coo_arguments(GetParam()); hipsparseStatus_t status = testing_sddmm_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sddmm_coo, sddmm_coo_i64_double) { Arguments arg = setup_sddmm_coo_arguments(GetParam()); hipsparseStatus_t status = testing_sddmm_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sddmm_coo, sddmm_coo_i32_float_complex) { Arguments arg = setup_sddmm_coo_arguments(GetParam()); hipsparseStatus_t status = testing_sddmm_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sddmm_coo, sddmm_coo_i64_double_complex) { Arguments arg = setup_sddmm_coo_arguments(GetParam()); hipsparseStatus_t status = testing_sddmm_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sddmm_coo_bin, sddmm_coo_bin_i32_float) { Arguments arg = setup_sddmm_coo_arguments(GetParam()); hipsparseStatus_t status = testing_sddmm_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sddmm_coo_bin, sddmm_coo_bin_i64_double) { Arguments arg = setup_sddmm_coo_arguments(GetParam()); hipsparseStatus_t status = testing_sddmm_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(sddmm_coo, parameterized_sddmm_coo, testing::Combine(testing::ValuesIn(sddmm_coo_M_range), testing::ValuesIn(sddmm_coo_N_range), testing::ValuesIn(sddmm_coo_K_range), testing::ValuesIn(sddmm_coo_alpha_beta_range), testing::ValuesIn(sddmm_coo_transA_range), testing::ValuesIn(sddmm_coo_transB_range), testing::ValuesIn(sddmm_coo_orderA_range), testing::ValuesIn(sddmm_coo_orderB_range), testing::ValuesIn(sddmm_coo_idxbase_range), testing::ValuesIn(sddmm_coo_alg_range))); INSTANTIATE_TEST_SUITE_P(sddmm_coo_bin, parameterized_sddmm_coo_bin, testing::Combine(testing::ValuesIn(sddmm_coo_K_range), testing::ValuesIn(sddmm_coo_alpha_beta_range), testing::ValuesIn(sddmm_coo_transA_range), testing::ValuesIn(sddmm_coo_transB_range), testing::ValuesIn(sddmm_coo_orderA_range), testing::ValuesIn(sddmm_coo_orderB_range), testing::ValuesIn(sddmm_coo_idxbase_range), testing::ValuesIn(sddmm_coo_alg_range), testing::ValuesIn(sddmm_coo_bin))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_sddmm_coo_aos.cpp000066400000000000000000000204231501764003400233350ustar00rootroot00000000000000/* ************************************************************************ * 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 struct alpha_beta { double alpha; double beta; }; typedef std::tuple sddmm_coo_aos_tuple; typedef std::tuple sddmm_coo_aos_bin_tuple; int sddmm_coo_aos_M_range[] = {50}; int sddmm_coo_aos_N_range[] = {84}; int sddmm_coo_aos_K_range[] = {5}; alpha_beta sddmm_coo_aos_alpha_beta_range[] = {{2.0, 1.0}}; hipsparseOperation_t sddmm_coo_aos_transA_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_TRANSPOSE}; hipsparseOperation_t sddmm_coo_aos_transB_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_TRANSPOSE}; hipsparseOrder_t sddmm_coo_aos_orderA_range[] = {HIPSPARSE_ORDER_COL, HIPSPARSE_ORDER_ROW}; hipsparseOrder_t sddmm_coo_aos_orderB_range[] = {HIPSPARSE_ORDER_COL, HIPSPARSE_ORDER_ROW}; hipsparseIndexBase_t sddmm_coo_aos_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; hipsparseSDDMMAlg_t sddmm_coo_aos_alg_range[] = {HIPSPARSE_SDDMM_ALG_DEFAULT}; std::string sddmm_coo_aos_bin[] = {"nos1.bin", "nos3.bin", "nos5.bin", "nos7.bin", "shipsec1.bin"}; class parameterized_sddmm_coo_aos : public testing::TestWithParam { protected: parameterized_sddmm_coo_aos() {} virtual ~parameterized_sddmm_coo_aos() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_sddmm_coo_aos_bin : public testing::TestWithParam { protected: parameterized_sddmm_coo_aos_bin() {} virtual ~parameterized_sddmm_coo_aos_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_sddmm_coo_aos_arguments(sddmm_coo_aos_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.K = std::get<2>(tup); arg.alpha = std::get<3>(tup).alpha; arg.beta = std::get<3>(tup).beta; arg.transA = std::get<4>(tup); arg.transB = std::get<5>(tup); arg.orderA = std::get<6>(tup); arg.orderB = std::get<7>(tup); arg.baseC = std::get<8>(tup); arg.sddmm_alg = std::get<9>(tup); arg.timing = 0; return arg; } Arguments setup_sddmm_coo_aos_arguments(sddmm_coo_aos_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = -99; arg.K = std::get<0>(tup); arg.alpha = std::get<1>(tup).alpha; arg.beta = std::get<1>(tup).beta; arg.transA = std::get<2>(tup); arg.transB = std::get<3>(tup); arg.orderA = std::get<4>(tup); arg.orderB = std::get<5>(tup); arg.baseC = std::get<6>(tup); arg.sddmm_alg = std::get<7>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<8>(tup); // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } // 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_P(parameterized_sddmm_coo_aos, sddmm_coo_aos_i32_float) { Arguments arg = setup_sddmm_coo_aos_arguments(GetParam()); hipsparseStatus_t status = testing_sddmm_coo_aos(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sddmm_coo_aos, sddmm_coo_aos_i64_double) { Arguments arg = setup_sddmm_coo_aos_arguments(GetParam()); hipsparseStatus_t status = testing_sddmm_coo_aos(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sddmm_coo_aos, sddmm_coo_aos_i32_float_complex) { Arguments arg = setup_sddmm_coo_aos_arguments(GetParam()); hipsparseStatus_t status = testing_sddmm_coo_aos(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sddmm_coo_aos, sddmm_coo_aos_i64_double_complex) { Arguments arg = setup_sddmm_coo_aos_arguments(GetParam()); hipsparseStatus_t status = testing_sddmm_coo_aos(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sddmm_coo_aos_bin, sddmm_coo_aos_bin_i32_float) { Arguments arg = setup_sddmm_coo_aos_arguments(GetParam()); hipsparseStatus_t status = testing_sddmm_coo_aos(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sddmm_coo_aos_bin, sddmm_coo_aos_bin_i64_double) { Arguments arg = setup_sddmm_coo_aos_arguments(GetParam()); hipsparseStatus_t status = testing_sddmm_coo_aos(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(sddmm_coo_aos, parameterized_sddmm_coo_aos, testing::Combine(testing::ValuesIn(sddmm_coo_aos_M_range), testing::ValuesIn(sddmm_coo_aos_N_range), testing::ValuesIn(sddmm_coo_aos_K_range), testing::ValuesIn(sddmm_coo_aos_alpha_beta_range), testing::ValuesIn(sddmm_coo_aos_transA_range), testing::ValuesIn(sddmm_coo_aos_transB_range), testing::ValuesIn(sddmm_coo_aos_orderA_range), testing::ValuesIn(sddmm_coo_aos_orderB_range), testing::ValuesIn(sddmm_coo_aos_idxbase_range), testing::ValuesIn(sddmm_coo_aos_alg_range))); INSTANTIATE_TEST_SUITE_P(sddmm_coo_aos_bin, parameterized_sddmm_coo_aos_bin, testing::Combine(testing::ValuesIn(sddmm_coo_aos_K_range), testing::ValuesIn(sddmm_coo_aos_alpha_beta_range), testing::ValuesIn(sddmm_coo_aos_transA_range), testing::ValuesIn(sddmm_coo_aos_transB_range), testing::ValuesIn(sddmm_coo_aos_orderA_range), testing::ValuesIn(sddmm_coo_aos_orderB_range), testing::ValuesIn(sddmm_coo_aos_idxbase_range), testing::ValuesIn(sddmm_coo_aos_alg_range), testing::ValuesIn(sddmm_coo_aos_bin))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_sddmm_csc.cpp000066400000000000000000000200251501764003400224610ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "testing_sddmm_csc.hpp" #include struct alpha_beta { double alpha; double beta; }; typedef std::tuple sddmm_csc_tuple; typedef std::tuple sddmm_csc_bin_tuple; int sddmm_csc_M_range[] = {50}; int sddmm_csc_N_range[] = {84}; int sddmm_csc_K_range[] = {5}; alpha_beta sddmm_csc_alpha_beta_range[] = {{2.0, 1.0}}; hipsparseOperation_t sddmm_csc_transA_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_TRANSPOSE}; hipsparseOperation_t sddmm_csc_transB_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_TRANSPOSE}; hipsparseOrder_t sddmm_csc_orderA_range[] = {HIPSPARSE_ORDER_COL, HIPSPARSE_ORDER_ROW}; hipsparseOrder_t sddmm_csc_orderB_range[] = {HIPSPARSE_ORDER_COL, HIPSPARSE_ORDER_ROW}; hipsparseIndexBase_t sddmm_csc_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; hipsparseSDDMMAlg_t sddmm_csc_alg_range[] = {HIPSPARSE_SDDMM_ALG_DEFAULT}; std::string sddmm_csc_bin[] = {"nos1.bin", "nos3.bin", "nos5.bin", "nos7.bin", "shipsec1.bin"}; class parameterized_sddmm_csc : public testing::TestWithParam { protected: parameterized_sddmm_csc() {} virtual ~parameterized_sddmm_csc() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_sddmm_csc_bin : public testing::TestWithParam { protected: parameterized_sddmm_csc_bin() {} virtual ~parameterized_sddmm_csc_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_sddmm_csc_arguments(sddmm_csc_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.K = std::get<2>(tup); arg.alpha = std::get<3>(tup).alpha; arg.beta = std::get<3>(tup).beta; arg.transA = std::get<4>(tup); arg.transB = std::get<5>(tup); arg.orderA = std::get<6>(tup); arg.orderB = std::get<7>(tup); arg.baseA = std::get<8>(tup); arg.sddmm_alg = std::get<9>(tup); arg.timing = 0; return arg; } Arguments setup_sddmm_csc_arguments(sddmm_csc_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = -99; arg.K = std::get<0>(tup); arg.alpha = std::get<1>(tup).alpha; arg.beta = std::get<1>(tup).beta; arg.transA = std::get<2>(tup); arg.transB = std::get<3>(tup); arg.orderA = std::get<4>(tup); arg.orderB = std::get<5>(tup); arg.baseA = std::get<6>(tup); arg.sddmm_alg = std::get<7>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<8>(tup); // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } // CSC format not supported in cusparse #if(!defined(CUDART_VERSION)) TEST(sddmm_csc_bad_arg, sddmm_csc_float) { testing_sddmm_csc_bad_arg(); } TEST_P(parameterized_sddmm_csc, sddmm_csc_i32_float) { Arguments arg = setup_sddmm_csc_arguments(GetParam()); hipsparseStatus_t status = testing_sddmm_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sddmm_csc, sddmm_csc_i64_double) { Arguments arg = setup_sddmm_csc_arguments(GetParam()); hipsparseStatus_t status = testing_sddmm_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sddmm_csc, sddmm_csc_i32_float_complex) { Arguments arg = setup_sddmm_csc_arguments(GetParam()); hipsparseStatus_t status = testing_sddmm_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sddmm_csc, sddmm_csc_i64_double_complex) { Arguments arg = setup_sddmm_csc_arguments(GetParam()); hipsparseStatus_t status = testing_sddmm_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sddmm_csc_bin, sddmm_csc_bin_i32_float) { Arguments arg = setup_sddmm_csc_arguments(GetParam()); hipsparseStatus_t status = testing_sddmm_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sddmm_csc_bin, sddmm_csc_bin_i64_double) { Arguments arg = setup_sddmm_csc_arguments(GetParam()); hipsparseStatus_t status = testing_sddmm_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(sddmm_csc, parameterized_sddmm_csc, testing::Combine(testing::ValuesIn(sddmm_csc_M_range), testing::ValuesIn(sddmm_csc_N_range), testing::ValuesIn(sddmm_csc_K_range), testing::ValuesIn(sddmm_csc_alpha_beta_range), testing::ValuesIn(sddmm_csc_transA_range), testing::ValuesIn(sddmm_csc_transB_range), testing::ValuesIn(sddmm_csc_orderA_range), testing::ValuesIn(sddmm_csc_orderB_range), testing::ValuesIn(sddmm_csc_idxbase_range), testing::ValuesIn(sddmm_csc_alg_range))); INSTANTIATE_TEST_SUITE_P(sddmm_csc_bin, parameterized_sddmm_csc_bin, testing::Combine(testing::ValuesIn(sddmm_csc_K_range), testing::ValuesIn(sddmm_csc_alpha_beta_range), testing::ValuesIn(sddmm_csc_transA_range), testing::ValuesIn(sddmm_csc_transB_range), testing::ValuesIn(sddmm_csc_orderA_range), testing::ValuesIn(sddmm_csc_orderB_range), testing::ValuesIn(sddmm_csc_idxbase_range), testing::ValuesIn(sddmm_csc_alg_range), testing::ValuesIn(sddmm_csc_bin))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_sddmm_csr.cpp000066400000000000000000000200131501764003400224750ustar00rootroot00000000000000/* ************************************************************************ * 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 struct alpha_beta { double alpha; double beta; }; typedef std::tuple sddmm_csr_tuple; typedef std::tuple sddmm_csr_bin_tuple; int sddmm_csr_M_range[] = {50}; int sddmm_csr_N_range[] = {84}; int sddmm_csr_K_range[] = {5}; alpha_beta sddmm_csr_alpha_beta_range[] = {{2.0, 1.0}}; hipsparseOperation_t sddmm_csr_transA_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_TRANSPOSE}; hipsparseOperation_t sddmm_csr_transB_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_TRANSPOSE}; hipsparseOrder_t sddmm_csr_orderA_range[] = {HIPSPARSE_ORDER_COL, HIPSPARSE_ORDER_ROW}; hipsparseOrder_t sddmm_csr_orderB_range[] = {HIPSPARSE_ORDER_COL, HIPSPARSE_ORDER_ROW}; hipsparseIndexBase_t sddmm_csr_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; hipsparseSDDMMAlg_t sddmm_csr_alg_range[] = {HIPSPARSE_SDDMM_ALG_DEFAULT}; std::string sddmm_csr_bin[] = {"nos2.bin", "nos4.bin", "nos6.bin", "Chebyshev4.bin"}; class parameterized_sddmm_csr : public testing::TestWithParam { protected: parameterized_sddmm_csr() {} virtual ~parameterized_sddmm_csr() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_sddmm_csr_bin : public testing::TestWithParam { protected: parameterized_sddmm_csr_bin() {} virtual ~parameterized_sddmm_csr_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_sddmm_csr_arguments(sddmm_csr_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.K = std::get<2>(tup); arg.alpha = std::get<3>(tup).alpha; arg.beta = std::get<3>(tup).beta; arg.transA = std::get<4>(tup); arg.transB = std::get<5>(tup); arg.orderA = std::get<6>(tup); arg.orderB = std::get<7>(tup); arg.baseA = std::get<8>(tup); arg.sddmm_alg = std::get<9>(tup); arg.timing = 0; return arg; } Arguments setup_sddmm_csr_arguments(sddmm_csr_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = -99; arg.K = std::get<0>(tup); arg.alpha = std::get<1>(tup).alpha; arg.beta = std::get<1>(tup).beta; arg.transA = std::get<2>(tup); arg.transB = std::get<3>(tup); arg.orderA = std::get<4>(tup); arg.orderB = std::get<5>(tup); arg.baseA = std::get<6>(tup); arg.sddmm_alg = std::get<7>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<8>(tup); // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } // csr format not supported in cusparse #if(!defined(CUDART_VERSION)) TEST(sddmm_csr_bad_arg, sddmm_csr_float) { testing_sddmm_csr_bad_arg(); } TEST_P(parameterized_sddmm_csr, sddmm_csr_i32_float) { Arguments arg = setup_sddmm_csr_arguments(GetParam()); hipsparseStatus_t status = testing_sddmm_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sddmm_csr, sddmm_csr_i64_double) { Arguments arg = setup_sddmm_csr_arguments(GetParam()); hipsparseStatus_t status = testing_sddmm_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sddmm_csr, sddmm_csr_i32_float_complex) { Arguments arg = setup_sddmm_csr_arguments(GetParam()); hipsparseStatus_t status = testing_sddmm_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sddmm_csr, sddmm_csr_i64_double_complex) { Arguments arg = setup_sddmm_csr_arguments(GetParam()); hipsparseStatus_t status = testing_sddmm_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sddmm_csr_bin, sddmm_csr_bin_i32_float) { Arguments arg = setup_sddmm_csr_arguments(GetParam()); hipsparseStatus_t status = testing_sddmm_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sddmm_csr_bin, sddmm_csr_bin_i64_double) { Arguments arg = setup_sddmm_csr_arguments(GetParam()); hipsparseStatus_t status = testing_sddmm_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(sddmm_csr, parameterized_sddmm_csr, testing::Combine(testing::ValuesIn(sddmm_csr_M_range), testing::ValuesIn(sddmm_csr_N_range), testing::ValuesIn(sddmm_csr_K_range), testing::ValuesIn(sddmm_csr_alpha_beta_range), testing::ValuesIn(sddmm_csr_transA_range), testing::ValuesIn(sddmm_csr_transB_range), testing::ValuesIn(sddmm_csr_orderA_range), testing::ValuesIn(sddmm_csr_orderB_range), testing::ValuesIn(sddmm_csr_idxbase_range), testing::ValuesIn(sddmm_csr_alg_range))); INSTANTIATE_TEST_SUITE_P(sddmm_csr_bin, parameterized_sddmm_csr_bin, testing::Combine(testing::ValuesIn(sddmm_csr_K_range), testing::ValuesIn(sddmm_csr_alpha_beta_range), testing::ValuesIn(sddmm_csr_transA_range), testing::ValuesIn(sddmm_csr_transB_range), testing::ValuesIn(sddmm_csr_orderA_range), testing::ValuesIn(sddmm_csr_orderB_range), testing::ValuesIn(sddmm_csr_idxbase_range), testing::ValuesIn(sddmm_csr_alg_range), testing::ValuesIn(sddmm_csr_bin))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_sparse_to_dense_coo.cpp000066400000000000000000000152761501764003400245560ustar00rootroot00000000000000/* ************************************************************************ * 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 typedef std::tuple sparse_to_dense_coo_tuple; typedef std::tuple sparse_to_dense_coo_bin_tuple; int sparse_to_dense_coo_M_range[] = {50}; int sparse_to_dense_coo_N_range[] = {5}; hipsparseOrder_t sparse_to_dense_coo_order_range[] = {HIPSPARSE_ORDER_COL, HIPSPARSE_ORDER_ROW}; hipsparseIndexBase_t sparse_to_dense_coo_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; hipsparseSparseToDenseAlg_t sparse_to_dense_coo_alg_range[] = {HIPSPARSE_SPARSETODENSE_ALG_DEFAULT}; std::string sparse_to_dense_coo_bin[] = {"nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin", "bibd_22_8.bin"}; class parameterized_sparse_to_dense_coo : public testing::TestWithParam { protected: parameterized_sparse_to_dense_coo() {} virtual ~parameterized_sparse_to_dense_coo() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_sparse_to_dense_coo_bin : public testing::TestWithParam { protected: parameterized_sparse_to_dense_coo_bin() {} virtual ~parameterized_sparse_to_dense_coo_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_sparse_to_dense_coo_arguments(sparse_to_dense_coo_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.orderA = std::get<2>(tup); arg.baseA = std::get<3>(tup); arg.sparse2dense_alg = std::get<4>(tup); arg.timing = 0; return arg; } Arguments setup_sparse_to_dense_coo_arguments(sparse_to_dense_coo_bin_tuple tup) { Arguments arg; arg.orderA = std::get<0>(tup); arg.baseA = std::get<1>(tup); arg.sparse2dense_alg = std::get<2>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<3>(tup); // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) TEST(sparse_to_dense_coo_bad_arg, sparse_to_dense_coo_float) { testing_sparse_to_dense_coo_bad_arg(); } TEST_P(parameterized_sparse_to_dense_coo, sparse_to_dense_coo_i32_float) { Arguments arg = setup_sparse_to_dense_coo_arguments(GetParam()); hipsparseStatus_t status = testing_sparse_to_dense_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sparse_to_dense_coo, sparse_to_dense_coo_i64_double) { Arguments arg = setup_sparse_to_dense_coo_arguments(GetParam()); hipsparseStatus_t status = testing_sparse_to_dense_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sparse_to_dense_coo, sparse_to_dense_coo_i32_float_complex) { Arguments arg = setup_sparse_to_dense_coo_arguments(GetParam()); hipsparseStatus_t status = testing_sparse_to_dense_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sparse_to_dense_coo, sparse_to_dense_coo_i64_double_complex) { Arguments arg = setup_sparse_to_dense_coo_arguments(GetParam()); hipsparseStatus_t status = testing_sparse_to_dense_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sparse_to_dense_coo_bin, sparse_to_dense_coo_bin_i32_float) { Arguments arg = setup_sparse_to_dense_coo_arguments(GetParam()); hipsparseStatus_t status = testing_sparse_to_dense_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sparse_to_dense_coo_bin, sparse_to_dense_coo_bin_i64_double) { Arguments arg = setup_sparse_to_dense_coo_arguments(GetParam()); hipsparseStatus_t status = testing_sparse_to_dense_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(sparse_to_dense_coo, parameterized_sparse_to_dense_coo, testing::Combine(testing::ValuesIn(sparse_to_dense_coo_M_range), testing::ValuesIn(sparse_to_dense_coo_N_range), testing::ValuesIn(sparse_to_dense_coo_order_range), testing::ValuesIn(sparse_to_dense_coo_idxbase_range), testing::ValuesIn(sparse_to_dense_coo_alg_range))); INSTANTIATE_TEST_SUITE_P(sparse_to_dense_coo_bin, parameterized_sparse_to_dense_coo_bin, testing::Combine(testing::ValuesIn(sparse_to_dense_coo_order_range), testing::ValuesIn(sparse_to_dense_coo_idxbase_range), testing::ValuesIn(sparse_to_dense_coo_alg_range), testing::ValuesIn(sparse_to_dense_coo_bin))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_sparse_to_dense_csc.cpp000066400000000000000000000153641501764003400245440ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "testing_sparse_to_dense_csc.hpp" #include typedef std::tuple sparse_to_dense_csc_tuple; typedef std::tuple sparse_to_dense_csc_bin_tuple; int sparse_to_dense_csc_M_range[] = {50}; int sparse_to_dense_csc_N_range[] = {5}; hipsparseOrder_t sparse_to_dense_csc_order_range[] = {HIPSPARSE_ORDER_COL, HIPSPARSE_ORDER_ROW}; hipsparseIndexBase_t sparse_to_dense_csc_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; hipsparseSparseToDenseAlg_t sparse_to_dense_csc_alg_range[] = {HIPSPARSE_SPARSETODENSE_ALG_DEFAULT}; std::string sparse_to_dense_csc_bin[] = {"nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin", "bibd_22_8.bin"}; class parameterized_sparse_to_dense_csc : public testing::TestWithParam { protected: parameterized_sparse_to_dense_csc() {} virtual ~parameterized_sparse_to_dense_csc() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_sparse_to_dense_csc_bin : public testing::TestWithParam { protected: parameterized_sparse_to_dense_csc_bin() {} virtual ~parameterized_sparse_to_dense_csc_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_sparse_to_dense_csc_arguments(sparse_to_dense_csc_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.orderA = std::get<2>(tup); arg.baseA = std::get<3>(tup); arg.sparse2dense_alg = std::get<4>(tup); arg.timing = 0; return arg; } Arguments setup_sparse_to_dense_csc_arguments(sparse_to_dense_csc_bin_tuple tup) { Arguments arg; arg.orderA = std::get<0>(tup); arg.baseA = std::get<1>(tup); arg.sparse2dense_alg = std::get<2>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<3>(tup); // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) TEST(sparse_to_dense_csc_bad_arg, sparse_to_dense_csc_float) { testing_sparse_to_dense_csc_bad_arg(); } TEST_P(parameterized_sparse_to_dense_csc, sparse_to_dense_csc_i32_float) { Arguments arg = setup_sparse_to_dense_csc_arguments(GetParam()); hipsparseStatus_t status = testing_sparse_to_dense_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sparse_to_dense_csc, sparse_to_dense_csc_i64_double) { Arguments arg = setup_sparse_to_dense_csc_arguments(GetParam()); hipsparseStatus_t status = testing_sparse_to_dense_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sparse_to_dense_csc, sparse_to_dense_csc_i32_float_complex) { Arguments arg = setup_sparse_to_dense_csc_arguments(GetParam()); hipsparseStatus_t status = testing_sparse_to_dense_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sparse_to_dense_csc, sparse_to_dense_csc_i64_double_complex) { Arguments arg = setup_sparse_to_dense_csc_arguments(GetParam()); hipsparseStatus_t status = testing_sparse_to_dense_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sparse_to_dense_csc_bin, sparse_to_dense_csc_bin_i32_float) { Arguments arg = setup_sparse_to_dense_csc_arguments(GetParam()); hipsparseStatus_t status = testing_sparse_to_dense_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sparse_to_dense_csc_bin, sparse_to_dense_csc_bin_i64_double) { Arguments arg = setup_sparse_to_dense_csc_arguments(GetParam()); hipsparseStatus_t status = testing_sparse_to_dense_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(sparse_to_dense_csc, parameterized_sparse_to_dense_csc, testing::Combine(testing::ValuesIn(sparse_to_dense_csc_M_range), testing::ValuesIn(sparse_to_dense_csc_N_range), testing::ValuesIn(sparse_to_dense_csc_order_range), testing::ValuesIn(sparse_to_dense_csc_idxbase_range), testing::ValuesIn(sparse_to_dense_csc_alg_range))); INSTANTIATE_TEST_SUITE_P(sparse_to_dense_csc_bin, parameterized_sparse_to_dense_csc_bin, testing::Combine(testing::ValuesIn(sparse_to_dense_csc_order_range), testing::ValuesIn(sparse_to_dense_csc_idxbase_range), testing::ValuesIn(sparse_to_dense_csc_alg_range), testing::ValuesIn(sparse_to_dense_csc_bin))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_sparse_to_dense_csr.cpp000066400000000000000000000153641501764003400245630ustar00rootroot00000000000000/* ************************************************************************ * 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 typedef std::tuple sparse_to_dense_csr_tuple; typedef std::tuple sparse_to_dense_csr_bin_tuple; int sparse_to_dense_csr_M_range[] = {50}; int sparse_to_dense_csr_N_range[] = {5}; hipsparseOrder_t sparse_to_dense_csr_order_range[] = {HIPSPARSE_ORDER_COL, HIPSPARSE_ORDER_ROW}; hipsparseIndexBase_t sparse_to_dense_csr_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; hipsparseSparseToDenseAlg_t sparse_to_dense_csr_alg_range[] = {HIPSPARSE_SPARSETODENSE_ALG_DEFAULT}; std::string sparse_to_dense_csr_bin[] = {"nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin", "bibd_22_8.bin"}; class parameterized_sparse_to_dense_csr : public testing::TestWithParam { protected: parameterized_sparse_to_dense_csr() {} virtual ~parameterized_sparse_to_dense_csr() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_sparse_to_dense_csr_bin : public testing::TestWithParam { protected: parameterized_sparse_to_dense_csr_bin() {} virtual ~parameterized_sparse_to_dense_csr_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_sparse_to_dense_csr_arguments(sparse_to_dense_csr_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.orderA = std::get<2>(tup); arg.baseA = std::get<3>(tup); arg.sparse2dense_alg = std::get<4>(tup); arg.timing = 0; return arg; } Arguments setup_sparse_to_dense_csr_arguments(sparse_to_dense_csr_bin_tuple tup) { Arguments arg; arg.orderA = std::get<0>(tup); arg.baseA = std::get<1>(tup); arg.sparse2dense_alg = std::get<2>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<3>(tup); // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) TEST(sparse_to_dense_csr_bad_arg, sparse_to_dense_csr_float) { testing_sparse_to_dense_csr_bad_arg(); } TEST_P(parameterized_sparse_to_dense_csr, sparse_to_dense_csr_i32_float) { Arguments arg = setup_sparse_to_dense_csr_arguments(GetParam()); hipsparseStatus_t status = testing_sparse_to_dense_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sparse_to_dense_csr, sparse_to_dense_csr_i64_double) { Arguments arg = setup_sparse_to_dense_csr_arguments(GetParam()); hipsparseStatus_t status = testing_sparse_to_dense_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sparse_to_dense_csr, sparse_to_dense_csr_i32_float_complex) { Arguments arg = setup_sparse_to_dense_csr_arguments(GetParam()); hipsparseStatus_t status = testing_sparse_to_dense_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sparse_to_dense_csr, sparse_to_dense_csr_i64_double_complex) { Arguments arg = setup_sparse_to_dense_csr_arguments(GetParam()); hipsparseStatus_t status = testing_sparse_to_dense_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sparse_to_dense_csr_bin, sparse_to_dense_csr_bin_i32_float) { Arguments arg = setup_sparse_to_dense_csr_arguments(GetParam()); hipsparseStatus_t status = testing_sparse_to_dense_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sparse_to_dense_csr_bin, sparse_to_dense_csr_bin_i64_double) { Arguments arg = setup_sparse_to_dense_csr_arguments(GetParam()); hipsparseStatus_t status = testing_sparse_to_dense_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(sparse_to_dense_csr, parameterized_sparse_to_dense_csr, testing::Combine(testing::ValuesIn(sparse_to_dense_csr_M_range), testing::ValuesIn(sparse_to_dense_csr_N_range), testing::ValuesIn(sparse_to_dense_csr_order_range), testing::ValuesIn(sparse_to_dense_csr_idxbase_range), testing::ValuesIn(sparse_to_dense_csr_alg_range))); INSTANTIATE_TEST_SUITE_P(sparse_to_dense_csr_bin, parameterized_sparse_to_dense_csr_bin, testing::Combine(testing::ValuesIn(sparse_to_dense_csr_order_range), testing::ValuesIn(sparse_to_dense_csr_idxbase_range), testing::ValuesIn(sparse_to_dense_csr_alg_range), testing::ValuesIn(sparse_to_dense_csr_bin))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_spgemm_csr.cpp000066400000000000000000000163651501764003400227000ustar00rootroot00000000000000/* ************************************************************************ * 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 typedef std::tuple spgemm_csr_tuple; typedef std::tuple spgemm_csr_bin_tuple; int spgemm_csr_M_range[] = {567, 1149}; int spgemm_csr_K_range[] = {649, 2148}; std::vector spgemm_csr_alpha_range = {2.0}; #if(!defined(CUDART_VERSION)) hipsparseIndexBase_t spgemm_csr_idxbaseA_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; hipsparseIndexBase_t spgemm_csr_idxbaseB_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; hipsparseIndexBase_t spgemm_csr_idxbaseC_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; #else // All matrices must use the same base index in cusparse hipsparseIndexBase_t spgemm_csr_idxbaseA_range[] = {HIPSPARSE_INDEX_BASE_ZERO}; hipsparseIndexBase_t spgemm_csr_idxbaseB_range[] = {HIPSPARSE_INDEX_BASE_ZERO}; hipsparseIndexBase_t spgemm_csr_idxbaseC_range[] = {HIPSPARSE_INDEX_BASE_ZERO}; #endif hipsparseSpGEMMAlg_t spgemm_csr_alg_range[] = {HIPSPARSE_SPGEMM_DEFAULT}; std::string spgemm_csr_bin[] = {"nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin"}; class parameterized_spgemm_csr : public testing::TestWithParam { protected: parameterized_spgemm_csr() {} virtual ~parameterized_spgemm_csr() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_spgemm_csr_bin : public testing::TestWithParam { protected: parameterized_spgemm_csr_bin() {} virtual ~parameterized_spgemm_csr_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_spgemm_csr_arguments(spgemm_csr_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.K = std::get<1>(tup); arg.alpha = std::get<2>(tup); arg.baseA = std::get<3>(tup); arg.baseB = std::get<4>(tup); arg.baseC = std::get<5>(tup); arg.spgemm_alg = std::get<6>(tup); arg.timing = 0; return arg; } Arguments setup_spgemm_csr_arguments(spgemm_csr_bin_tuple tup) { Arguments arg; arg.M = -99; arg.K = -99; arg.alpha = std::get<0>(tup); arg.baseA = std::get<1>(tup); arg.baseB = std::get<2>(tup); arg.baseC = std::get<3>(tup); arg.spgemm_alg = std::get<4>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<5>(tup); // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) TEST(spgemm_csr_bad_arg, spgemm_csr_float) { testing_spgemm_csr_bad_arg(); } TEST_P(parameterized_spgemm_csr, spgemm_csr_i32_float) { Arguments arg = setup_spgemm_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spgemm_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spgemm_csr, spgemm_csr_i32_float_complex) { Arguments arg = setup_spgemm_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spgemm_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spgemm_csr_bin, spgemm_csr_bin_i32_float) { Arguments arg = setup_spgemm_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spgemm_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } // 64 bit indices not supported in cusparse #if(!defined(CUDART_VERSION)) TEST_P(parameterized_spgemm_csr, spgemm_csr_i64_double) { Arguments arg = setup_spgemm_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spgemm_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spgemm_csr, spgemm_csr_i64_double_complex) { Arguments arg = setup_spgemm_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spgemm_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spgemm_csr_bin, spgemm_csr_bin_i64_double) { Arguments arg = setup_spgemm_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spgemm_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(spgemm_csr, parameterized_spgemm_csr, testing::Combine(testing::ValuesIn(spgemm_csr_M_range), testing::ValuesIn(spgemm_csr_K_range), testing::ValuesIn(spgemm_csr_alpha_range), testing::ValuesIn(spgemm_csr_idxbaseA_range), testing::ValuesIn(spgemm_csr_idxbaseB_range), testing::ValuesIn(spgemm_csr_idxbaseC_range), testing::ValuesIn(spgemm_csr_alg_range))); INSTANTIATE_TEST_SUITE_P(spgemm_csr_bin, parameterized_spgemm_csr_bin, testing::Combine(testing::ValuesIn(spgemm_csr_alpha_range), testing::ValuesIn(spgemm_csr_idxbaseA_range), testing::ValuesIn(spgemm_csr_idxbaseB_range), testing::ValuesIn(spgemm_csr_idxbaseC_range), testing::ValuesIn(spgemm_csr_alg_range), testing::ValuesIn(spgemm_csr_bin))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_spgemmreuse_csr.cpp000066400000000000000000000171201501764003400237320ustar00rootroot00000000000000/* ************************************************************************ * 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 typedef std::tuple spgemmreuse_csr_tuple; typedef std::tuple spgemmreuse_csr_bin_tuple; int spgemmreuse_csr_M_range[] = {77, 981}; int spgemmreuse_csr_K_range[] = {64, 1723}; std::vector spgemmreuse_csr_alpha_range = {2.0}; #if(!defined(CUDART_VERSION)) hipsparseIndexBase_t spgemmreuse_csr_idxbaseA_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; hipsparseIndexBase_t spgemmreuse_csr_idxbaseB_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; hipsparseIndexBase_t spgemmreuse_csr_idxbaseC_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; #else // All matrices must use the same base index in cusparse hipsparseIndexBase_t spgemmreuse_csr_idxbaseA_range[] = {HIPSPARSE_INDEX_BASE_ZERO}; hipsparseIndexBase_t spgemmreuse_csr_idxbaseB_range[] = {HIPSPARSE_INDEX_BASE_ZERO}; hipsparseIndexBase_t spgemmreuse_csr_idxbaseC_range[] = {HIPSPARSE_INDEX_BASE_ZERO}; #endif hipsparseSpGEMMAlg_t spgemmreuse_csr_alg_range[] = {HIPSPARSE_SPGEMM_DEFAULT}; std::string spgemmreuse_csr_bin[] = {"nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin"}; class parameterized_spgemmreuse_csr : public testing::TestWithParam { protected: parameterized_spgemmreuse_csr() {} virtual ~parameterized_spgemmreuse_csr() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_spgemmreuse_csr_bin : public testing::TestWithParam { protected: parameterized_spgemmreuse_csr_bin() {} virtual ~parameterized_spgemmreuse_csr_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_spgemmreuse_csr_arguments(spgemmreuse_csr_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.K = std::get<1>(tup); arg.alpha = std::get<2>(tup); arg.baseA = std::get<3>(tup); arg.baseB = std::get<4>(tup); arg.baseC = std::get<5>(tup); arg.spgemm_alg = std::get<6>(tup); arg.timing = 0; return arg; } Arguments setup_spgemmreuse_csr_arguments(spgemmreuse_csr_bin_tuple tup) { Arguments arg; arg.M = -99; arg.K = -99; arg.alpha = std::get<0>(tup); arg.baseA = std::get<1>(tup); arg.baseB = std::get<2>(tup); arg.baseC = std::get<3>(tup); arg.spgemm_alg = std::get<4>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<5>(tup); // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11031) TEST(spgemmreuse_csr_bad_arg, spgemmreuse_csr_float) { testing_spgemmreuse_csr_bad_arg(); } TEST_P(parameterized_spgemmreuse_csr, spgemmreuse_csr_i32_float) { Arguments arg = setup_spgemmreuse_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spgemmreuse_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spgemmreuse_csr, spgemmreuse_csr_i32_float_complex) { Arguments arg = setup_spgemmreuse_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spgemmreuse_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spgemmreuse_csr_bin, spgemmreuse_csr_bin_i32_float) { Arguments arg = setup_spgemmreuse_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spgemmreuse_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } // 64 bit indices not supported in cusparse #if(!defined(CUDART_VERSION)) TEST_P(parameterized_spgemmreuse_csr, spgemmreuse_csr_i64_double) { Arguments arg = setup_spgemmreuse_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spgemmreuse_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spgemmreuse_csr, spgemmreuse_csr_i64_double_complex) { Arguments arg = setup_spgemmreuse_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spgemmreuse_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spgemmreuse_csr_bin, spgemmreuse_csr_bin_i64_double) { Arguments arg = setup_spgemmreuse_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spgemmreuse_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(spgemmreuse_csr, parameterized_spgemmreuse_csr, testing::Combine(testing::ValuesIn(spgemmreuse_csr_M_range), testing::ValuesIn(spgemmreuse_csr_K_range), testing::ValuesIn(spgemmreuse_csr_alpha_range), testing::ValuesIn(spgemmreuse_csr_idxbaseA_range), testing::ValuesIn(spgemmreuse_csr_idxbaseB_range), testing::ValuesIn(spgemmreuse_csr_idxbaseC_range), testing::ValuesIn(spgemmreuse_csr_alg_range))); INSTANTIATE_TEST_SUITE_P(spgemmreuse_csr_bin, parameterized_spgemmreuse_csr_bin, testing::Combine(testing::ValuesIn(spgemmreuse_csr_alpha_range), testing::ValuesIn(spgemmreuse_csr_idxbaseA_range), testing::ValuesIn(spgemmreuse_csr_idxbaseB_range), testing::ValuesIn(spgemmreuse_csr_idxbaseC_range), testing::ValuesIn(spgemmreuse_csr_alg_range), testing::ValuesIn(spgemmreuse_csr_bin))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_spmat_descr.cpp000066400000000000000000000032101501764003400230260ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "testing_spmat_descr.hpp" // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(spmat_descr_bad_arg, spmat_descr_float) { testing_spmat_descr_bad_arg(); } TEST(spmat_descr, spmat_descr) { hipsparseStatus_t status = testing_spmat_descr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif hipSPARSE-rocm-6.4.3/clients/tests/test_spmm_batched_coo.cpp000066400000000000000000000203541501764003400240200ustar00rootroot00000000000000/* ************************************************************************ * 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 typedef std::tuple spmm_batched_coo_tuple; typedef std::tuple spmm_batched_coo_bin_tuple; int spmm_batched_coo_M_range[] = {50}; int spmm_batched_coo_N_range[] = {5}; int spmm_batched_coo_K_range[] = {23}; std::vector spmm_batched_coo_alpha_range = {2.0}; std::vector spmm_batched_coo_beta_range = {1.0}; hipsparseOperation_t spmm_batched_coo_transA_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_TRANSPOSE}; hipsparseOperation_t spmm_batched_coo_transB_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_TRANSPOSE}; hipsparseOrder_t spmm_batched_coo_orderB_range[] = {HIPSPARSE_ORDER_COL, HIPSPARSE_ORDER_ROW}; hipsparseOrder_t spmm_batched_coo_orderC_range[] = {HIPSPARSE_ORDER_COL, HIPSPARSE_ORDER_ROW}; hipsparseIndexBase_t spmm_batched_coo_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO}; std::string spmm_batched_coo_bin[] = {"shipsec1.bin"}; class parameterized_spmm_batched_coo : public testing::TestWithParam { protected: parameterized_spmm_batched_coo() {} virtual ~parameterized_spmm_batched_coo() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_spmm_batched_coo_bin : public testing::TestWithParam { protected: parameterized_spmm_batched_coo_bin() {} virtual ~parameterized_spmm_batched_coo_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_spmm_batched_coo_arguments(spmm_batched_coo_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.transA = std::get<5>(tup); arg.transB = std::get<6>(tup); arg.orderB = std::get<7>(tup); arg.orderC = std::get<8>(tup); arg.baseA = std::get<9>(tup); arg.timing = 0; return arg; } Arguments setup_spmm_batched_coo_arguments(spmm_batched_coo_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.transA = std::get<3>(tup); arg.transB = std::get<4>(tup); arg.orderB = std::get<5>(tup); arg.orderC = std::get<6>(tup); arg.baseA = 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; } // batched_coo format not supported in cusparse #if(!defined(CUDART_VERSION)) TEST(spmm_batched_coo_bad_arg, spmm_batched_coo_float) { testing_spmm_batched_coo_bad_arg(); } TEST_P(parameterized_spmm_batched_coo, spmm_batched_coo_i32_float) { Arguments arg = setup_spmm_batched_coo_arguments(GetParam()); hipsparseStatus_t status = testing_spmm_batched_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmm_batched_coo, spmm_batched_coo_i32_float_complex) { Arguments arg = setup_spmm_batched_coo_arguments(GetParam()); hipsparseStatus_t status = testing_spmm_batched_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmm_batched_coo_bin, spmm_batched_coo_bin_i32_float) { Arguments arg = setup_spmm_batched_coo_arguments(GetParam()); hipsparseStatus_t status = testing_spmm_batched_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } // 64 bit indices not supported in cusparse for all algorithms #if(!defined(CUDART_VERSION)) TEST_P(parameterized_spmm_batched_coo, spmm_batched_coo_i64_double) { Arguments arg = setup_spmm_batched_coo_arguments(GetParam()); hipsparseStatus_t status = testing_spmm_batched_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmm_batched_coo, spmm_batched_coo_i64_double_complex) { Arguments arg = setup_spmm_batched_coo_arguments(GetParam()); hipsparseStatus_t status = testing_spmm_batched_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmm_batched_coo_bin, spmm_batched_coo_bin_i64_double) { Arguments arg = setup_spmm_batched_coo_arguments(GetParam()); hipsparseStatus_t status = testing_spmm_batched_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(spmm_batched_coo, parameterized_spmm_batched_coo, testing::Combine(testing::ValuesIn(spmm_batched_coo_M_range), testing::ValuesIn(spmm_batched_coo_N_range), testing::ValuesIn(spmm_batched_coo_K_range), testing::ValuesIn(spmm_batched_coo_alpha_range), testing::ValuesIn(spmm_batched_coo_beta_range), testing::ValuesIn(spmm_batched_coo_transA_range), testing::ValuesIn(spmm_batched_coo_transB_range), testing::ValuesIn(spmm_batched_coo_orderB_range), testing::ValuesIn(spmm_batched_coo_orderC_range), testing::ValuesIn(spmm_batched_coo_idxbase_range))); INSTANTIATE_TEST_SUITE_P(spmm_batched_coo_bin, parameterized_spmm_batched_coo_bin, testing::Combine(testing::ValuesIn(spmm_batched_coo_N_range), testing::ValuesIn(spmm_batched_coo_alpha_range), testing::ValuesIn(spmm_batched_coo_beta_range), testing::ValuesIn(spmm_batched_coo_transA_range), testing::ValuesIn(spmm_batched_coo_transB_range), testing::ValuesIn(spmm_batched_coo_orderB_range), testing::ValuesIn(spmm_batched_coo_orderC_range), testing::ValuesIn(spmm_batched_coo_idxbase_range), testing::ValuesIn(spmm_batched_coo_bin))); #endifhipSPARSE-rocm-6.4.3/clients/tests/test_spmm_batched_csc.cpp000066400000000000000000000205531501764003400240110ustar00rootroot00000000000000/* ************************************************************************ * 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 typedef std::tuple spmm_batched_csc_tuple; typedef std::tuple spmm_batched_csc_bin_tuple; int spmm_batched_csc_M_range[] = {50}; int spmm_batched_csc_N_range[] = {5}; int spmm_batched_csc_K_range[] = {84}; std::vector spmm_batched_csc_alpha_range = {2.0}; std::vector spmm_batched_csc_beta_range = {1.0}; hipsparseOperation_t spmm_batched_csc_transA_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_TRANSPOSE}; hipsparseOperation_t spmm_batched_csc_transB_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_TRANSPOSE}; hipsparseOrder_t spmm_batched_csc_orderB_range[] = {HIPSPARSE_ORDER_COL, HIPSPARSE_ORDER_ROW}; hipsparseOrder_t spmm_batched_csc_orderC_range[] = {HIPSPARSE_ORDER_COL, HIPSPARSE_ORDER_ROW}; hipsparseIndexBase_t spmm_batched_csc_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO}; std::string spmm_batched_csc_bin[] = {"nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin"}; class parameterized_spmm_batched_csc : public testing::TestWithParam { protected: parameterized_spmm_batched_csc() {} virtual ~parameterized_spmm_batched_csc() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_spmm_batched_csc_bin : public testing::TestWithParam { protected: parameterized_spmm_batched_csc_bin() {} virtual ~parameterized_spmm_batched_csc_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_spmm_batched_csc_arguments(spmm_batched_csc_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.K = std::get<2>(tup); arg.alpha = std::get<3>(tup); arg.beta = std::get<4>(tup); arg.transA = std::get<5>(tup); arg.transB = std::get<6>(tup); arg.orderB = std::get<7>(tup); arg.orderC = std::get<8>(tup); arg.baseA = std::get<9>(tup); arg.timing = 0; return arg; } Arguments setup_spmm_batched_csc_arguments(spmm_batched_csc_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.transA = std::get<3>(tup); arg.transB = std::get<4>(tup); arg.orderB = std::get<5>(tup); arg.orderC = std::get<6>(tup); arg.baseA = 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; } // batched_csc format not supported in cusparse #if(!defined(CUDART_VERSION)) TEST(spmm_batched_csc_bad_arg, spmm_batched_csc_float) { testing_spmm_batched_csc_bad_arg(); } TEST_P(parameterized_spmm_batched_csc, spmm_batched_csc_i32_float) { Arguments arg = setup_spmm_batched_csc_arguments(GetParam()); hipsparseStatus_t status = testing_spmm_batched_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmm_batched_csc, spmm_batched_csc_i32_float_complex) { Arguments arg = setup_spmm_batched_csc_arguments(GetParam()); hipsparseStatus_t status = testing_spmm_batched_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmm_batched_csc_bin, spmm_batched_csc_bin_i32_float) { Arguments arg = setup_spmm_batched_csc_arguments(GetParam()); hipsparseStatus_t status = testing_spmm_batched_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } // 64 bit indices not supported in cusparse for all algorithms #if(!defined(CUDART_VERSION)) TEST_P(parameterized_spmm_batched_csc, spmm_batched_csc_i64_double) { Arguments arg = setup_spmm_batched_csc_arguments(GetParam()); hipsparseStatus_t status = testing_spmm_batched_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmm_batched_csc, spmm_batched_csc_i64_double_complex) { Arguments arg = setup_spmm_batched_csc_arguments(GetParam()); hipsparseStatus_t status = testing_spmm_batched_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmm_batched_csc_bin, spmm_batched_csc_bin_i64_double) { Arguments arg = setup_spmm_batched_csc_arguments(GetParam()); hipsparseStatus_t status = testing_spmm_batched_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(spmm_batched_csc, parameterized_spmm_batched_csc, testing::Combine(testing::ValuesIn(spmm_batched_csc_M_range), testing::ValuesIn(spmm_batched_csc_N_range), testing::ValuesIn(spmm_batched_csc_K_range), testing::ValuesIn(spmm_batched_csc_alpha_range), testing::ValuesIn(spmm_batched_csc_beta_range), testing::ValuesIn(spmm_batched_csc_transA_range), testing::ValuesIn(spmm_batched_csc_transB_range), testing::ValuesIn(spmm_batched_csc_orderB_range), testing::ValuesIn(spmm_batched_csc_orderC_range), testing::ValuesIn(spmm_batched_csc_idxbase_range))); INSTANTIATE_TEST_SUITE_P(spmm_batched_csc_bin, parameterized_spmm_batched_csc_bin, testing::Combine(testing::ValuesIn(spmm_batched_csc_N_range), testing::ValuesIn(spmm_batched_csc_alpha_range), testing::ValuesIn(spmm_batched_csc_beta_range), testing::ValuesIn(spmm_batched_csc_transA_range), testing::ValuesIn(spmm_batched_csc_transB_range), testing::ValuesIn(spmm_batched_csc_orderB_range), testing::ValuesIn(spmm_batched_csc_orderC_range), testing::ValuesIn(spmm_batched_csc_idxbase_range), testing::ValuesIn(spmm_batched_csc_bin))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_spmm_batched_csr.cpp000066400000000000000000000205531501764003400240300ustar00rootroot00000000000000/* ************************************************************************ * 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 typedef std::tuple spmm_batched_csr_tuple; typedef std::tuple spmm_batched_csr_bin_tuple; int spmm_batched_csr_M_range[] = {50}; int spmm_batched_csr_N_range[] = {5}; int spmm_batched_csr_K_range[] = {84}; std::vector spmm_batched_csr_alpha_range = {2.0}; std::vector spmm_batched_csr_beta_range = {1.0}; hipsparseOperation_t spmm_batched_csr_transA_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_TRANSPOSE}; hipsparseOperation_t spmm_batched_csr_transB_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_TRANSPOSE}; hipsparseOrder_t spmm_batched_csr_orderB_range[] = {HIPSPARSE_ORDER_COL, HIPSPARSE_ORDER_ROW}; hipsparseOrder_t spmm_batched_csr_orderC_range[] = {HIPSPARSE_ORDER_COL, HIPSPARSE_ORDER_ROW}; hipsparseIndexBase_t spmm_batched_csr_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO}; std::string spmm_batched_csr_bin[] = {"nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin"}; class parameterized_spmm_batched_csr : public testing::TestWithParam { protected: parameterized_spmm_batched_csr() {} virtual ~parameterized_spmm_batched_csr() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_spmm_batched_csr_bin : public testing::TestWithParam { protected: parameterized_spmm_batched_csr_bin() {} virtual ~parameterized_spmm_batched_csr_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_spmm_batched_csr_arguments(spmm_batched_csr_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.transA = std::get<5>(tup); arg.transB = std::get<6>(tup); arg.orderB = std::get<7>(tup); arg.orderC = std::get<8>(tup); arg.baseA = std::get<9>(tup); arg.timing = 0; return arg; } Arguments setup_spmm_batched_csr_arguments(spmm_batched_csr_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.transA = std::get<3>(tup); arg.transB = std::get<4>(tup); arg.orderB = std::get<5>(tup); arg.orderC = std::get<6>(tup); arg.baseA = 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; } // batched_csr format not supported in cusparse #if(!defined(CUDART_VERSION)) TEST(spmm_batched_csr_bad_arg, spmm_batched_csr_float) { testing_spmm_batched_csr_bad_arg(); } TEST_P(parameterized_spmm_batched_csr, spmm_batched_csr_i32_float) { Arguments arg = setup_spmm_batched_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spmm_batched_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmm_batched_csr, spmm_batched_csr_i32_float_complex) { Arguments arg = setup_spmm_batched_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spmm_batched_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmm_batched_csr_bin, spmm_batched_csr_bin_i32_float) { Arguments arg = setup_spmm_batched_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spmm_batched_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } // 64 bit indices not supported in cusparse for all algorithms #if(!defined(CUDART_VERSION)) TEST_P(parameterized_spmm_batched_csr, spmm_batched_csr_i64_double) { Arguments arg = setup_spmm_batched_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spmm_batched_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmm_batched_csr, spmm_batched_csr_i64_double_complex) { Arguments arg = setup_spmm_batched_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spmm_batched_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmm_batched_csr_bin, spmm_batched_csr_bin_i64_double) { Arguments arg = setup_spmm_batched_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spmm_batched_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(spmm_batched_csr, parameterized_spmm_batched_csr, testing::Combine(testing::ValuesIn(spmm_batched_csr_M_range), testing::ValuesIn(spmm_batched_csr_N_range), testing::ValuesIn(spmm_batched_csr_K_range), testing::ValuesIn(spmm_batched_csr_alpha_range), testing::ValuesIn(spmm_batched_csr_beta_range), testing::ValuesIn(spmm_batched_csr_transA_range), testing::ValuesIn(spmm_batched_csr_transB_range), testing::ValuesIn(spmm_batched_csr_orderB_range), testing::ValuesIn(spmm_batched_csr_orderC_range), testing::ValuesIn(spmm_batched_csr_idxbase_range))); INSTANTIATE_TEST_SUITE_P(spmm_batched_csr_bin, parameterized_spmm_batched_csr_bin, testing::Combine(testing::ValuesIn(spmm_batched_csr_N_range), testing::ValuesIn(spmm_batched_csr_alpha_range), testing::ValuesIn(spmm_batched_csr_beta_range), testing::ValuesIn(spmm_batched_csr_transA_range), testing::ValuesIn(spmm_batched_csr_transB_range), testing::ValuesIn(spmm_batched_csr_orderB_range), testing::ValuesIn(spmm_batched_csr_orderC_range), testing::ValuesIn(spmm_batched_csr_idxbase_range), testing::ValuesIn(spmm_batched_csr_bin))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_spmm_bell.cpp000066400000000000000000000036601501764003400225050ustar00rootroot00000000000000/* ************************************************************************ * 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-6.4.3/clients/tests/test_spmm_coo.cpp000066400000000000000000000233231501764003400223450ustar00rootroot00000000000000/* ************************************************************************ * 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 struct alpha_beta { double alpha; double beta; }; typedef std::tuple spmm_coo_tuple; typedef std::tuple spmm_coo_bin_tuple; int spmm_coo_M_range[] = {50}; int spmm_coo_N_range[] = {5}; int spmm_coo_K_range[] = {84}; alpha_beta spmm_coo_alpha_beta_range[] = {{2.0, 1.0}}; hipsparseOperation_t spmm_coo_transA_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_TRANSPOSE}; hipsparseOperation_t spmm_coo_transB_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_TRANSPOSE}; hipsparseOrder_t spmm_coo_orderB_range[] = {HIPSPARSE_ORDER_COL, HIPSPARSE_ORDER_ROW}; hipsparseOrder_t spmm_coo_orderC_range[] = {HIPSPARSE_ORDER_COL, HIPSPARSE_ORDER_ROW}; hipsparseIndexBase_t spmm_coo_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; #if(!defined(CUDART_VERSION)) hipsparseSpMMAlg_t spmm_coo_alg_range[] = {HIPSPARSE_SPMM_ALG_DEFAULT, HIPSPARSE_SPMM_COO_ALG1, HIPSPARSE_SPMM_COO_ALG2, HIPSPARSE_SPMM_COO_ALG3, HIPSPARSE_SPMM_COO_ALG4}; #else #if(CUDART_VERSION >= 12000) hipsparseSpMMAlg_t spmm_coo_alg_range[] = {HIPSPARSE_SPMM_ALG_DEFAULT, HIPSPARSE_SPMM_COO_ALG1, HIPSPARSE_SPMM_COO_ALG2, HIPSPARSE_SPMM_COO_ALG3, HIPSPARSE_SPMM_COO_ALG4}; #elif(CUDART_VERSION >= 11021 && CUDART_VERSION < 12000) // Note: In cusparse 11.4, Alg2 fails with internal error when using A transposed, B and C // both column order. Skip Alg 2 here. Seems to pass in later versions of cusparse. hipsparseSpMMAlg_t spmm_coo_alg_range[] = {HIPSPARSE_SPMM_ALG_DEFAULT, HIPSPARSE_SPMM_COO_ALG1, HIPSPARSE_SPMM_COO_ALG3, HIPSPARSE_SPMM_COO_ALG4}; #elif(CUDART_VERSION >= 11003 && CUDART_VERSION < 11021) hipsparseSpMMAlg_t spmm_coo_alg_range[] = {HIPSPARSE_SPMM_ALG_DEFAULT, HIPSPARSE_SPMM_COO_ALG1, HIPSPARSE_SPMM_COO_ALG2, HIPSPARSE_SPMM_COO_ALG3, HIPSPARSE_SPMM_COO_ALG4}; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 11003) hipsparseSpMMAlg_t spmm_coo_alg_range[] = {HIPSPARSE_MM_ALG_DEFAULT, HIPSPARSE_COOMM_ALG1, HIPSPARSE_COOMM_ALG2, HIPSPARSE_COOMM_ALG3}; #endif #endif std::string spmm_coo_bin[] = {"nos1.bin", "nos4.bin", "nos5.bin", "Chebyshev4.bin"}; class parameterized_spmm_coo : public testing::TestWithParam { protected: parameterized_spmm_coo() {} virtual ~parameterized_spmm_coo() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_spmm_coo_bin : public testing::TestWithParam { protected: parameterized_spmm_coo_bin() {} virtual ~parameterized_spmm_coo_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_spmm_coo_arguments(spmm_coo_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.K = std::get<2>(tup); arg.alpha = std::get<3>(tup).alpha; arg.beta = std::get<3>(tup).beta; arg.transA = std::get<4>(tup); arg.transB = std::get<5>(tup); arg.orderB = std::get<6>(tup); arg.orderC = std::get<7>(tup); arg.baseA = std::get<8>(tup); arg.spmm_alg = std::get<9>(tup); arg.timing = 0; return arg; } Arguments setup_spmm_coo_arguments(spmm_coo_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = std::get<0>(tup); arg.K = -99; arg.alpha = std::get<1>(tup).alpha; arg.beta = std::get<1>(tup).beta; arg.transA = std::get<2>(tup); arg.transB = std::get<3>(tup); arg.orderB = std::get<4>(tup); arg.orderC = std::get<5>(tup); arg.baseA = std::get<6>(tup); arg.spmm_alg = std::get<7>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<8>(tup); // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(spmm_coo_bad_arg, spmm_coo_float) { testing_spmm_coo_bad_arg(); } TEST_P(parameterized_spmm_coo, spmm_coo_i32_float) { Arguments arg = setup_spmm_coo_arguments(GetParam()); hipsparseStatus_t status = testing_spmm_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmm_coo, spmm_coo_i32_float_complex) { Arguments arg = setup_spmm_coo_arguments(GetParam()); hipsparseStatus_t status = testing_spmm_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmm_coo_bin, spmm_coo_bin_i32_float) { Arguments arg = setup_spmm_coo_arguments(GetParam()); hipsparseStatus_t status = testing_spmm_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } // 64 bit indices not supported in cusparse for all algorithms #if(!defined(CUDART_VERSION)) TEST_P(parameterized_spmm_coo, spmm_coo_i64_double) { Arguments arg = setup_spmm_coo_arguments(GetParam()); hipsparseStatus_t status = testing_spmm_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmm_coo, spmm_coo_i64_double_complex) { Arguments arg = setup_spmm_coo_arguments(GetParam()); hipsparseStatus_t status = testing_spmm_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmm_coo_bin, spmm_coo_bin_i64_double) { Arguments arg = setup_spmm_coo_arguments(GetParam()); hipsparseStatus_t status = testing_spmm_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(spmm_coo, parameterized_spmm_coo, testing::Combine(testing::ValuesIn(spmm_coo_M_range), testing::ValuesIn(spmm_coo_N_range), testing::ValuesIn(spmm_coo_K_range), testing::ValuesIn(spmm_coo_alpha_beta_range), testing::ValuesIn(spmm_coo_transA_range), testing::ValuesIn(spmm_coo_transB_range), testing::ValuesIn(spmm_coo_orderB_range), testing::ValuesIn(spmm_coo_orderC_range), testing::ValuesIn(spmm_coo_idxbase_range), testing::ValuesIn(spmm_coo_alg_range))); INSTANTIATE_TEST_SUITE_P(spmm_coo_bin, parameterized_spmm_coo_bin, testing::Combine(testing::ValuesIn(spmm_coo_N_range), testing::ValuesIn(spmm_coo_alpha_beta_range), testing::ValuesIn(spmm_coo_transA_range), testing::ValuesIn(spmm_coo_transB_range), testing::ValuesIn(spmm_coo_orderB_range), testing::ValuesIn(spmm_coo_orderC_range), testing::ValuesIn(spmm_coo_idxbase_range), testing::ValuesIn(spmm_coo_alg_range), testing::ValuesIn(spmm_coo_bin))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_spmm_csc.cpp000066400000000000000000000217341501764003400223410ustar00rootroot00000000000000/* ************************************************************************ * 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 struct alpha_beta { double alpha; double beta; }; typedef std::tuple spmm_csc_tuple; typedef std::tuple spmm_csc_bin_tuple; int spmm_csc_M_range[] = {50}; int spmm_csc_N_range[] = {5}; int spmm_csc_K_range[] = {84}; alpha_beta spmm_csc_alpha_beta_range[] = {{2.0, 1.0}}; hipsparseOperation_t spmm_csc_transA_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_TRANSPOSE}; hipsparseOperation_t spmm_csc_transB_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_TRANSPOSE}; hipsparseOrder_t spmm_csc_orderB_range[] = {HIPSPARSE_ORDER_COL, HIPSPARSE_ORDER_ROW}; hipsparseOrder_t spmm_csc_orderC_range[] = {HIPSPARSE_ORDER_COL, HIPSPARSE_ORDER_ROW}; hipsparseIndexBase_t spmm_csc_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; #if(!defined(CUDART_VERSION)) hipsparseSpMMAlg_t spmm_csc_alg_range[] = {HIPSPARSE_SPMM_ALG_DEFAULT, HIPSPARSE_SPMM_CSR_ALG1, HIPSPARSE_SPMM_CSR_ALG2, HIPSPARSE_SPMM_CSR_ALG3}; #else // Alg3 not supported for CSC format #if(CUDART_VERSION >= 12000) hipsparseSpMMAlg_t spmm_csc_alg_range[] = {HIPSPARSE_SPMM_ALG_DEFAULT, HIPSPARSE_SPMM_CSR_ALG1, HIPSPARSE_SPMM_CSR_ALG2}; #elif(CUDART_VERSION >= 11021 && CUDART_VERSION < 12000) hipsparseSpMMAlg_t spmm_csc_alg_range[] = {HIPSPARSE_SPMM_ALG_DEFAULT, HIPSPARSE_SPMM_CSR_ALG1, HIPSPARSE_SPMM_CSR_ALG2}; #elif(CUDART_VERSION >= 11003 && CUDART_VERSION < 11021) hipsparseSpMMAlg_t spmm_csc_alg_range[] = {HIPSPARSE_SPMM_ALG_DEFAULT, HIPSPARSE_SPMM_CSR_ALG1, HIPSPARSE_SPMM_CSR_ALG2}; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 11003) hipsparseSpMMAlg_t spmm_csc_alg_range[] = {HIPSPARSE_MM_ALG_DEFAULT, HIPSPARSE_CSRMM_ALG1}; #endif #endif std::string spmm_csc_bin[] = {"nos1.bin", "nos3.bin", "nos5.bin", "nos7.bin", "Chebyshev4.bin", "shipsec1.bin"}; class parameterized_spmm_csc : public testing::TestWithParam { protected: parameterized_spmm_csc() {} virtual ~parameterized_spmm_csc() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_spmm_csc_bin : public testing::TestWithParam { protected: parameterized_spmm_csc_bin() {} virtual ~parameterized_spmm_csc_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_spmm_csc_arguments(spmm_csc_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.K = std::get<2>(tup); arg.alpha = std::get<3>(tup).alpha; arg.beta = std::get<3>(tup).beta; arg.transA = std::get<4>(tup); arg.transB = std::get<5>(tup); arg.orderB = std::get<6>(tup); arg.orderC = std::get<7>(tup); arg.baseA = std::get<8>(tup); arg.spmm_alg = std::get<9>(tup); arg.timing = 0; return arg; } Arguments setup_spmm_csc_arguments(spmm_csc_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = std::get<0>(tup); arg.K = -99; arg.alpha = std::get<1>(tup).alpha; arg.beta = std::get<1>(tup).beta; arg.transA = std::get<2>(tup); arg.transB = std::get<3>(tup); arg.orderB = std::get<4>(tup); arg.orderC = std::get<5>(tup); arg.baseA = std::get<6>(tup); arg.spmm_alg = std::get<7>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<8>(tup); // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(spmm_csc_bad_arg, spmm_csc_float) { testing_spmm_csc_bad_arg(); } TEST_P(parameterized_spmm_csc, spmm_csc_i32_float) { Arguments arg = setup_spmm_csc_arguments(GetParam()); hipsparseStatus_t status = testing_spmm_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmm_csc, spmm_csc_i32_float_complex) { Arguments arg = setup_spmm_csc_arguments(GetParam()); hipsparseStatus_t status = testing_spmm_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmm_csc_bin, spmm_csc_bin_i32_float) { Arguments arg = setup_spmm_csc_arguments(GetParam()); hipsparseStatus_t status = testing_spmm_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } // 64 bit indices not supported in cusparse for all algorithms #if(!defined(CUDART_VERSION)) TEST_P(parameterized_spmm_csc, spmm_csc_i64_double_complex) { Arguments arg = setup_spmm_csc_arguments(GetParam()); hipsparseStatus_t status = testing_spmm_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmm_csc_bin, spmm_csc_bin_i64_double) { Arguments arg = setup_spmm_csc_arguments(GetParam()); hipsparseStatus_t status = testing_spmm_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmm_csc, spmm_csc_i64_double) { Arguments arg = setup_spmm_csc_arguments(GetParam()); hipsparseStatus_t status = testing_spmm_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(spmm_csc, parameterized_spmm_csc, testing::Combine(testing::ValuesIn(spmm_csc_M_range), testing::ValuesIn(spmm_csc_N_range), testing::ValuesIn(spmm_csc_K_range), testing::ValuesIn(spmm_csc_alpha_beta_range), testing::ValuesIn(spmm_csc_transA_range), testing::ValuesIn(spmm_csc_transB_range), testing::ValuesIn(spmm_csc_orderB_range), testing::ValuesIn(spmm_csc_orderC_range), testing::ValuesIn(spmm_csc_idxbase_range), testing::ValuesIn(spmm_csc_alg_range))); INSTANTIATE_TEST_SUITE_P(spmm_csc_bin, parameterized_spmm_csc_bin, testing::Combine(testing::ValuesIn(spmm_csc_N_range), testing::ValuesIn(spmm_csc_alpha_beta_range), testing::ValuesIn(spmm_csc_transA_range), testing::ValuesIn(spmm_csc_transB_range), testing::ValuesIn(spmm_csc_orderB_range), testing::ValuesIn(spmm_csc_orderC_range), testing::ValuesIn(spmm_csc_idxbase_range), testing::ValuesIn(spmm_csc_alg_range), testing::ValuesIn(spmm_csc_bin))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_spmm_csr.cpp000066400000000000000000000220761501764003400223600ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse_arguments.hpp" #include "testing_spmm_csr.hpp" #include struct alpha_beta { double alpha; double beta; }; typedef std::tuple spmm_csr_tuple; typedef std::tuple spmm_csr_bin_tuple; int spmm_csr_M_range[] = {50}; int spmm_csr_N_range[] = {5}; int spmm_csr_K_range[] = {84}; alpha_beta spmm_csr_alpha_beta_range[] = {{2.0, 1.0}}; hipsparseOperation_t spmm_csr_transA_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_TRANSPOSE}; hipsparseOperation_t spmm_csr_transB_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_TRANSPOSE}; hipsparseOrder_t spmm_csr_orderB_range[] = {HIPSPARSE_ORDER_COL, HIPSPARSE_ORDER_ROW}; hipsparseOrder_t spmm_csr_orderC_range[] = {HIPSPARSE_ORDER_COL, HIPSPARSE_ORDER_ROW}; hipsparseIndexBase_t spmm_csr_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; #if(!defined(CUDART_VERSION)) hipsparseSpMMAlg_t spmm_csr_alg_range[] = {HIPSPARSE_SPMM_ALG_DEFAULT, HIPSPARSE_SPMM_CSR_ALG1, HIPSPARSE_SPMM_CSR_ALG2, HIPSPARSE_SPMM_CSR_ALG3}; #else // Alg3 not supported when A is transposed or conjugate transposed or when B is conjugate transposed #if(CUDART_VERSION >= 12000) hipsparseSpMMAlg_t spmm_csr_alg_range[] = {HIPSPARSE_SPMM_ALG_DEFAULT, HIPSPARSE_SPMM_CSR_ALG1, HIPSPARSE_SPMM_CSR_ALG2}; #elif(CUDART_VERSION >= 11021 && CUDART_VERSION < 12000) hipsparseSpMMAlg_t spmm_csr_alg_range[] = {HIPSPARSE_SPMM_ALG_DEFAULT, HIPSPARSE_SPMM_CSR_ALG1, HIPSPARSE_SPMM_CSR_ALG2}; #elif(CUDART_VERSION >= 11003 && CUDART_VERSION < 11021) hipsparseSpMMAlg_t spmm_csr_alg_range[] = {HIPSPARSE_SPMM_ALG_DEFAULT, HIPSPARSE_SPMM_CSR_ALG1, HIPSPARSE_SPMM_CSR_ALG2}; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 11003) hipsparseSpMMAlg_t spmm_csr_alg_range[] = {HIPSPARSE_MM_ALG_DEFAULT, HIPSPARSE_CSRMM_ALG1}; #endif #endif std::string spmm_csr_bin[] = {"nos2.bin", "nos4.bin", "nos5.bin", "nos7.bin", "Chebyshev4.bin", "shipsec1.bin"}; class parameterized_spmm_csr : public testing::TestWithParam { protected: parameterized_spmm_csr() {} virtual ~parameterized_spmm_csr() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_spmm_csr_bin : public testing::TestWithParam { protected: parameterized_spmm_csr_bin() {} virtual ~parameterized_spmm_csr_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_spmm_csr_arguments(spmm_csr_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.K = std::get<2>(tup); arg.alpha = std::get<3>(tup).alpha; arg.beta = std::get<3>(tup).beta; arg.transA = std::get<4>(tup); arg.transB = std::get<5>(tup); arg.orderB = std::get<6>(tup); arg.orderC = std::get<7>(tup); arg.baseA = std::get<8>(tup); arg.spmm_alg = std::get<9>(tup); arg.timing = 0; return arg; } Arguments setup_spmm_csr_arguments(spmm_csr_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = std::get<0>(tup); arg.K = -99; arg.alpha = std::get<1>(tup).alpha; arg.beta = std::get<1>(tup).beta; arg.transA = std::get<2>(tup); arg.transB = std::get<3>(tup); arg.orderB = std::get<4>(tup); arg.orderC = std::get<5>(tup); arg.baseA = std::get<6>(tup); arg.spmm_alg = std::get<7>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<8>(tup); // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(spmm_csr_bad_arg, spmm_csr_float) { testing_spmm_csr_bad_arg(); } TEST_P(parameterized_spmm_csr, spmm_csr_i32_float) { Arguments arg = setup_spmm_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spmm_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmm_csr, spmm_csr_i32_float_complex) { Arguments arg = setup_spmm_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spmm_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmm_csr_bin, spmm_csr_bin_i32_float) { Arguments arg = setup_spmm_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spmm_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } // 64 bit indices not supported in cusparse for all algorithms #if(!defined(CUDART_VERSION)) TEST_P(parameterized_spmm_csr, spmm_csr_i64_double) { Arguments arg = setup_spmm_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spmm_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmm_csr, spmm_csr_i64_double_complex) { Arguments arg = setup_spmm_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spmm_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmm_csr_bin, spmm_csr_bin_i64_double) { Arguments arg = setup_spmm_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spmm_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif INSTANTIATE_TEST_SUITE_P(spmm_csr, parameterized_spmm_csr, testing::Combine(testing::ValuesIn(spmm_csr_M_range), testing::ValuesIn(spmm_csr_N_range), testing::ValuesIn(spmm_csr_K_range), testing::ValuesIn(spmm_csr_alpha_beta_range), testing::ValuesIn(spmm_csr_transA_range), testing::ValuesIn(spmm_csr_transB_range), testing::ValuesIn(spmm_csr_orderB_range), testing::ValuesIn(spmm_csr_orderC_range), testing::ValuesIn(spmm_csr_idxbase_range), testing::ValuesIn(spmm_csr_alg_range))); INSTANTIATE_TEST_SUITE_P(spmm_csr_bin, parameterized_spmm_csr_bin, testing::Combine(testing::ValuesIn(spmm_csr_N_range), testing::ValuesIn(spmm_csr_alpha_beta_range), testing::ValuesIn(spmm_csr_transA_range), testing::ValuesIn(spmm_csr_transB_range), testing::ValuesIn(spmm_csr_orderB_range), testing::ValuesIn(spmm_csr_orderC_range), testing::ValuesIn(spmm_csr_idxbase_range), testing::ValuesIn(spmm_csr_alg_range), testing::ValuesIn(spmm_csr_bin))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_spmv_coo.cpp000066400000000000000000000163721501764003400223640ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse_arguments.hpp" #include "testing_spmv_coo.hpp" #include typedef std:: tuple spmv_coo_tuple; typedef std::tuple spmv_coo_bin_tuple; int spmv_coo_M_range[] = {50}; int spmv_coo_N_range[] = {84}; std::vector spmv_coo_alpha_range = {2.0}; std::vector spmv_coo_beta_range = {1.0}; hipsparseOperation_t spmv_coo_transA_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE}; hipsparseIndexBase_t spmv_coo_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; #if(!defined(CUDART_VERSION)) hipsparseSpMVAlg_t spmv_coo_alg_range[] = {HIPSPARSE_SPMV_ALG_DEFAULT, HIPSPARSE_SPMV_COO_ALG1, HIPSPARSE_SPMV_COO_ALG2}; #else #if(CUDART_VERSION >= 12000) hipsparseSpMVAlg_t spmv_coo_alg_range[] = {HIPSPARSE_SPMV_ALG_DEFAULT, HIPSPARSE_SPMV_COO_ALG1, HIPSPARSE_SPMV_COO_ALG2}; #elif(CUDART_VERSION >= 11021 && CUDART_VERSION < 12000) hipsparseSpMVAlg_t spmv_coo_alg_range[] = {HIPSPARSE_SPMV_ALG_DEFAULT, HIPSPARSE_SPMV_COO_ALG1, HIPSPARSE_SPMV_COO_ALG2}; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 11021) hipsparseSpMVAlg_t spmv_coo_alg_range[] = {HIPSPARSE_MV_ALG_DEFAULT, HIPSPARSE_COOMV_ALG}; #endif #endif std::string spmv_coo_bin[] = {"nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin", "Chebyshev4.bin", "shipsec1.bin"}; class parameterized_spmv_coo : public testing::TestWithParam { protected: parameterized_spmv_coo() {} virtual ~parameterized_spmv_coo() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_spmv_coo_bin : public testing::TestWithParam { protected: parameterized_spmv_coo_bin() {} virtual ~parameterized_spmv_coo_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_spmv_coo_arguments(spmv_coo_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.alpha = std::get<2>(tup); arg.beta = std::get<3>(tup); arg.transA = std::get<4>(tup); arg.baseA = std::get<5>(tup); arg.spmv_alg = std::get<6>(tup); arg.timing = 0; return arg; } Arguments setup_spmv_coo_arguments(spmv_coo_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = -99; arg.alpha = std::get<0>(tup); arg.beta = std::get<1>(tup); arg.transA = std::get<2>(tup); arg.baseA = std::get<3>(tup); arg.spmv_alg = std::get<4>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<5>(tup); // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(spmv_coo_bad_arg, spmv_coo_float) { testing_spmv_coo_bad_arg(); } TEST_P(parameterized_spmv_coo, spmv_coo_i32_float) { Arguments arg = setup_spmv_coo_arguments(GetParam()); hipsparseStatus_t status = testing_spmv_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmv_coo, spmv_coo_i64_double) { Arguments arg = setup_spmv_coo_arguments(GetParam()); hipsparseStatus_t status = testing_spmv_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmv_coo, spmv_coo_i32_float_complex) { Arguments arg = setup_spmv_coo_arguments(GetParam()); hipsparseStatus_t status = testing_spmv_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmv_coo, spmv_coo_i64_double_complex) { Arguments arg = setup_spmv_coo_arguments(GetParam()); hipsparseStatus_t status = testing_spmv_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmv_coo_bin, spmv_coo_bin_i32_float) { Arguments arg = setup_spmv_coo_arguments(GetParam()); hipsparseStatus_t status = testing_spmv_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmv_coo_bin, spmv_coo_bin_i64_double) { Arguments arg = setup_spmv_coo_arguments(GetParam()); hipsparseStatus_t status = testing_spmv_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(spmv_coo, parameterized_spmv_coo, testing::Combine(testing::ValuesIn(spmv_coo_M_range), testing::ValuesIn(spmv_coo_N_range), testing::ValuesIn(spmv_coo_alpha_range), testing::ValuesIn(spmv_coo_beta_range), testing::ValuesIn(spmv_coo_transA_range), testing::ValuesIn(spmv_coo_idxbase_range), testing::ValuesIn(spmv_coo_alg_range))); INSTANTIATE_TEST_SUITE_P(spmv_coo_bin, parameterized_spmv_coo_bin, testing::Combine(testing::ValuesIn(spmv_coo_alpha_range), testing::ValuesIn(spmv_coo_beta_range), testing::ValuesIn(spmv_coo_transA_range), testing::ValuesIn(spmv_coo_idxbase_range), testing::ValuesIn(spmv_coo_alg_range), testing::ValuesIn(spmv_coo_bin))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_spmv_coo_aos.cpp000066400000000000000000000170371501764003400232250ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse_arguments.hpp" #include "testing_spmv_coo_aos.hpp" #include typedef std:: tuple spmv_coo_aos_tuple; typedef std::tuple spmv_coo_aos_bin_tuple; int spmv_coo_aos_M_range[] = {50}; int spmv_coo_aos_N_range[] = {84}; std::vector spmv_coo_aos_alpha_range = {2.0}; std::vector spmv_coo_aos_beta_range = {1.0}; hipsparseOperation_t spmv_coo_aos_transA_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE}; hipsparseIndexBase_t spmv_coo_aos_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; #if(!defined(CUDART_VERSION)) hipsparseSpMVAlg_t spmv_coo_aos_alg_range[] = {HIPSPARSE_SPMV_ALG_DEFAULT, HIPSPARSE_SPMV_COO_ALG1, HIPSPARSE_SPMV_COO_ALG2}; #else // coo_aos format not supported in cusparse 12 or later #if(CUDART_VERSION >= 11021 && CUDART_VERSION < 12000) hipsparseSpMVAlg_t spmv_coo_aos_alg_range[] = {HIPSPARSE_SPMV_ALG_DEFAULT, HIPSPARSE_SPMV_COO_ALG1, HIPSPARSE_SPMV_COO_ALG2}; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 11021) hipsparseSpMVAlg_t spmv_coo_aos_alg_range[] = {HIPSPARSE_MV_ALG_DEFAULT, HIPSPARSE_COOMV_ALG}; #endif #endif std::string spmv_coo_aos_bin[] = {"nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin", "Chebyshev4.bin", "shipsec1.bin"}; class parameterized_spmv_coo_aos : public testing::TestWithParam { protected: parameterized_spmv_coo_aos() {} virtual ~parameterized_spmv_coo_aos() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_spmv_coo_aos_bin : public testing::TestWithParam { protected: parameterized_spmv_coo_aos_bin() {} virtual ~parameterized_spmv_coo_aos_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_spmv_coo_aos_arguments(spmv_coo_aos_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.alpha = std::get<2>(tup); arg.beta = std::get<3>(tup); arg.transA = std::get<4>(tup); arg.baseA = std::get<5>(tup); arg.spmv_alg = std::get<6>(tup); arg.timing = 0; return arg; } Arguments setup_spmv_coo_aos_arguments(spmv_coo_aos_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = -99; arg.alpha = std::get<0>(tup); arg.beta = std::get<1>(tup); arg.transA = std::get<2>(tup); arg.baseA = std::get<3>(tup); arg.spmv_alg = std::get<4>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<5>(tup); // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } // coo_aos format not supported in cusparse 12.0 or later #if(!defined(CUDART_VERSION) || (CUDART_VERSION >= 10010 && CUDART_VERSION < 12000)) TEST(spmv_coo_aos_bad_arg, spmv_coo_aos_float) { testing_spmv_coo_aos_bad_arg(); } TEST_P(parameterized_spmv_coo_aos, spmv_coo_aos_i32_float) { Arguments arg = setup_spmv_coo_aos_arguments(GetParam()); hipsparseStatus_t status = testing_spmv_coo_aos(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmv_coo_aos, spmv_coo_aos_i64_double) { Arguments arg = setup_spmv_coo_aos_arguments(GetParam()); hipsparseStatus_t status = testing_spmv_coo_aos(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmv_coo_aos, spmv_coo_aos_i32_float_complex) { Arguments arg = setup_spmv_coo_aos_arguments(GetParam()); hipsparseStatus_t status = testing_spmv_coo_aos(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmv_coo_aos, spmv_coo_aos_i64_double_complex) { Arguments arg = setup_spmv_coo_aos_arguments(GetParam()); hipsparseStatus_t status = testing_spmv_coo_aos(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmv_coo_aos_bin, spmv_coo_aos_bin_i32_float) { Arguments arg = setup_spmv_coo_aos_arguments(GetParam()); hipsparseStatus_t status = testing_spmv_coo_aos(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmv_coo_aos_bin, spmv_coo_aos_bin_i64_double) { Arguments arg = setup_spmv_coo_aos_arguments(GetParam()); hipsparseStatus_t status = testing_spmv_coo_aos(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(spmv_coo_aos, parameterized_spmv_coo_aos, testing::Combine(testing::ValuesIn(spmv_coo_aos_M_range), testing::ValuesIn(spmv_coo_aos_N_range), testing::ValuesIn(spmv_coo_aos_alpha_range), testing::ValuesIn(spmv_coo_aos_beta_range), testing::ValuesIn(spmv_coo_aos_transA_range), testing::ValuesIn(spmv_coo_aos_idxbase_range), testing::ValuesIn(spmv_coo_aos_alg_range))); INSTANTIATE_TEST_SUITE_P(spmv_coo_aos_bin, parameterized_spmv_coo_aos_bin, testing::Combine(testing::ValuesIn(spmv_coo_aos_alpha_range), testing::ValuesIn(spmv_coo_aos_beta_range), testing::ValuesIn(spmv_coo_aos_transA_range), testing::ValuesIn(spmv_coo_aos_idxbase_range), testing::ValuesIn(spmv_coo_aos_alg_range), testing::ValuesIn(spmv_coo_aos_bin))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_spmv_csr.cpp000066400000000000000000000165121501764003400223670ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse_arguments.hpp" #include "testing_spmv_csr.hpp" #include typedef std:: tuple spmv_csr_tuple; typedef std::tuple spmv_csr_bin_tuple; int spmv_csr_M_range[] = {50}; int spmv_csr_N_range[] = {84}; std::vector spmv_csr_alpha_range = {2.0}; std::vector spmv_csr_beta_range = {1.0}; hipsparseOperation_t spmv_csr_transA_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE}; hipsparseIndexBase_t spmv_csr_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; #if(!defined(CUDART_VERSION)) hipsparseSpMVAlg_t spmv_csr_alg_range[] = {HIPSPARSE_SPMV_ALG_DEFAULT, HIPSPARSE_SPMV_CSR_ALG1, HIPSPARSE_SPMV_CSR_ALG2}; #else #if(CUDART_VERSION >= 12000) hipsparseSpMVAlg_t spmv_csr_alg_range[] = {HIPSPARSE_SPMV_ALG_DEFAULT, HIPSPARSE_SPMV_CSR_ALG1, HIPSPARSE_SPMV_CSR_ALG2}; #elif(CUDART_VERSION >= 11021 && CUDART_VERSION < 12000) hipsparseSpMVAlg_t spmv_csr_alg_range[] = {HIPSPARSE_SPMV_ALG_DEFAULT, HIPSPARSE_SPMV_CSR_ALG1, HIPSPARSE_SPMV_CSR_ALG2}; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 11021) hipsparseSpMVAlg_t spmv_csr_alg_range[] = {HIPSPARSE_MV_ALG_DEFAULT, HIPSPARSE_CSRMV_ALG1, HIPSPARSE_CSRMV_ALG2}; #endif #endif std::string spmv_csr_bin[] = {"nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin", "Chebyshev4.bin", "shipsec1.bin"}; class parameterized_spmv_csr : public testing::TestWithParam { protected: parameterized_spmv_csr() {} virtual ~parameterized_spmv_csr() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_spmv_csr_bin : public testing::TestWithParam { protected: parameterized_spmv_csr_bin() {} virtual ~parameterized_spmv_csr_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_spmv_csr_arguments(spmv_csr_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.alpha = std::get<2>(tup); arg.beta = std::get<3>(tup); arg.transA = std::get<4>(tup); arg.baseA = std::get<5>(tup); arg.spmv_alg = std::get<6>(tup); arg.timing = 0; return arg; } Arguments setup_spmv_csr_arguments(spmv_csr_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = -99; arg.alpha = std::get<0>(tup); arg.beta = std::get<1>(tup); arg.transA = std::get<2>(tup); arg.baseA = std::get<3>(tup); arg.spmv_alg = std::get<4>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<5>(tup); // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(spmv_csr_bad_arg, spmv_csr_float) { testing_spmv_csr_bad_arg(); } TEST_P(parameterized_spmv_csr, spmv_csr_i32_float) { Arguments arg = setup_spmv_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spmv_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmv_csr, spmv_csr_i64_double) { Arguments arg = setup_spmv_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spmv_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmv_csr, spmv_csr_i32_float_complex) { Arguments arg = setup_spmv_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spmv_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmv_csr, spmv_csr_i64_double_complex) { Arguments arg = setup_spmv_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spmv_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmv_csr_bin, spmv_csr_bin_i32_float) { Arguments arg = setup_spmv_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spmv_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmv_csr_bin, spmv_csr_bin_i64_double) { Arguments arg = setup_spmv_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spmv_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(spmv_csr, parameterized_spmv_csr, testing::Combine(testing::ValuesIn(spmv_csr_M_range), testing::ValuesIn(spmv_csr_N_range), testing::ValuesIn(spmv_csr_alpha_range), testing::ValuesIn(spmv_csr_beta_range), testing::ValuesIn(spmv_csr_transA_range), testing::ValuesIn(spmv_csr_idxbase_range), testing::ValuesIn(spmv_csr_alg_range))); INSTANTIATE_TEST_SUITE_P(spmv_csr_bin, parameterized_spmv_csr_bin, testing::Combine(testing::ValuesIn(spmv_csr_alpha_range), testing::ValuesIn(spmv_csr_beta_range), testing::ValuesIn(spmv_csr_transA_range), testing::ValuesIn(spmv_csr_idxbase_range), testing::ValuesIn(spmv_csr_alg_range), testing::ValuesIn(spmv_csr_bin))); #endifhipSPARSE-rocm-6.4.3/clients/tests/test_spsm_coo.cpp000066400000000000000000000200421501764003400223460ustar00rootroot00000000000000/* ************************************************************************ * 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 struct M_N_K_alpha { int M; int N; int K; double alpha; }; typedef std::tuple spsm_coo_tuple; typedef std::tuple spsm_coo_bin_tuple; M_N_K_alpha spsm_coo_M_N_K_alpha_range[] = {{50, 50, 22, 2.0}}; hipsparseOperation_t spsm_coo_transA_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE}; hipsparseOperation_t spsm_coo_transB_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE}; hipsparseOrder_t spsm_coo_orderB_range[] = {HIPSPARSE_ORDER_COL, HIPSPARSE_ORDER_ROW}; hipsparseOrder_t spsm_coo_orderC_range[] = {HIPSPARSE_ORDER_COL, HIPSPARSE_ORDER_ROW}; hipsparseIndexBase_t spsm_coo_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO}; hipsparseDiagType_t spsm_coo_diag_type_range[] = {HIPSPARSE_DIAG_TYPE_NON_UNIT}; hipsparseFillMode_t spsm_coo_fill_mode_range[] = {HIPSPARSE_FILL_MODE_LOWER, HIPSPARSE_FILL_MODE_UPPER}; hipsparseSpSMAlg_t spsm_coo_alg_range[] = {HIPSPARSE_SPSM_ALG_DEFAULT}; std::string spsm_coo_bin[] = {"nos1.bin", "nos3.bin", "nos6.bin", "scircuit.bin"}; class parameterized_spsm_coo : public testing::TestWithParam { protected: parameterized_spsm_coo() {} virtual ~parameterized_spsm_coo() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_spsm_coo_bin : public testing::TestWithParam { protected: parameterized_spsm_coo_bin() {} virtual ~parameterized_spsm_coo_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_spsm_coo_arguments(spsm_coo_tuple tup) { Arguments arg; arg.M = std::get<0>(tup).M; arg.N = std::get<0>(tup).N; arg.K = std::get<0>(tup).K; arg.alpha = std::get<0>(tup).alpha; arg.transA = std::get<1>(tup); arg.transB = std::get<2>(tup); arg.orderB = std::get<3>(tup); arg.orderC = std::get<4>(tup); arg.baseA = std::get<5>(tup); arg.diag_type = std::get<6>(tup); arg.fill_mode = std::get<7>(tup); arg.spsm_alg = std::get<8>(tup); arg.timing = 0; return arg; } Arguments setup_spsm_coo_arguments(spsm_coo_bin_tuple tup) { Arguments arg; arg.K = std::get<0>(tup).K; arg.alpha = std::get<0>(tup).alpha; arg.transA = std::get<1>(tup); arg.transB = std::get<2>(tup); arg.orderB = std::get<3>(tup); arg.orderC = std::get<4>(tup); arg.baseA = std::get<5>(tup); arg.diag_type = std::get<6>(tup); arg.fill_mode = std::get<7>(tup); arg.spsm_alg = std::get<8>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<9>(tup); // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(spsm_coo_bad_arg, spsm_coo_float) { testing_spsm_coo_bad_arg(); } TEST_P(parameterized_spsm_coo, spsm_coo_i32_float) { Arguments arg = setup_spsm_coo_arguments(GetParam()); hipsparseStatus_t status = testing_spsm_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spsm_coo, spsm_coo_i64_double) { Arguments arg = setup_spsm_coo_arguments(GetParam()); hipsparseStatus_t status = testing_spsm_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spsm_coo, spsm_coo_i32_float_complex) { Arguments arg = setup_spsm_coo_arguments(GetParam()); hipsparseStatus_t status = testing_spsm_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spsm_coo, spsm_coo_i64_double_complex) { Arguments arg = setup_spsm_coo_arguments(GetParam()); hipsparseStatus_t status = testing_spsm_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spsm_coo_bin, spsm_coo_bin_i32_float) { Arguments arg = setup_spsm_coo_arguments(GetParam()); hipsparseStatus_t status = testing_spsm_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spsm_coo_bin, spsm_coo_bin_i64_double) { Arguments arg = setup_spsm_coo_arguments(GetParam()); hipsparseStatus_t status = testing_spsm_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(spsm_coo, parameterized_spsm_coo, testing::Combine(testing::ValuesIn(spsm_coo_M_N_K_alpha_range), testing::ValuesIn(spsm_coo_transA_range), testing::ValuesIn(spsm_coo_transB_range), testing::ValuesIn(spsm_coo_orderB_range), testing::ValuesIn(spsm_coo_orderC_range), testing::ValuesIn(spsm_coo_idxbase_range), testing::ValuesIn(spsm_coo_diag_type_range), testing::ValuesIn(spsm_coo_fill_mode_range), testing::ValuesIn(spsm_coo_alg_range))); INSTANTIATE_TEST_SUITE_P(spsm_coo_bin, parameterized_spsm_coo_bin, testing::Combine(testing::ValuesIn(spsm_coo_M_N_K_alpha_range), testing::ValuesIn(spsm_coo_transA_range), testing::ValuesIn(spsm_coo_transB_range), testing::ValuesIn(spsm_coo_orderB_range), testing::ValuesIn(spsm_coo_orderC_range), testing::ValuesIn(spsm_coo_idxbase_range), testing::ValuesIn(spsm_coo_diag_type_range), testing::ValuesIn(spsm_coo_fill_mode_range), testing::ValuesIn(spsm_coo_alg_range), testing::ValuesIn(spsm_coo_bin))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_spsm_csr.cpp000066400000000000000000000201301501764003400223530ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "testing_spsm_csr.hpp" #include struct M_N_K_alpha { int M; int N; int K; double alpha; }; typedef std::tuple spsm_csr_tuple; typedef std::tuple spsm_csr_bin_tuple; M_N_K_alpha spsm_csr_M_N_K_alpha_range[] = {{50, 50, 22, 2.0}}; hipsparseOperation_t spsm_csr_transA_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE}; hipsparseOperation_t spsm_csr_transB_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE}; hipsparseOrder_t spsm_csr_orderB_range[] = {HIPSPARSE_ORDER_COL, HIPSPARSE_ORDER_ROW}; hipsparseOrder_t spsm_csr_orderC_range[] = {HIPSPARSE_ORDER_COL, HIPSPARSE_ORDER_ROW}; hipsparseIndexBase_t spsm_csr_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO}; hipsparseDiagType_t spsm_csr_diag_type_range[] = {HIPSPARSE_DIAG_TYPE_NON_UNIT}; hipsparseFillMode_t spsm_csr_fill_mode_range[] = {HIPSPARSE_FILL_MODE_LOWER, HIPSPARSE_FILL_MODE_UPPER}; hipsparseSpSMAlg_t spsm_csr_alg_range[] = {HIPSPARSE_SPSM_ALG_DEFAULT}; std::string spsm_csr_bin[] = {"nos1.bin", "nos3.bin", "nos5.bin", "scircuit.bin"}; class parameterized_spsm_csr : public testing::TestWithParam { protected: parameterized_spsm_csr() {} virtual ~parameterized_spsm_csr() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_spsm_csr_bin : public testing::TestWithParam { protected: parameterized_spsm_csr_bin() {} virtual ~parameterized_spsm_csr_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_spsm_csr_arguments(spsm_csr_tuple tup) { Arguments arg; arg.M = std::get<0>(tup).M; arg.N = std::get<0>(tup).N; arg.K = std::get<0>(tup).K; arg.alpha = std::get<0>(tup).alpha; arg.transA = std::get<1>(tup); arg.transB = std::get<2>(tup); arg.orderB = std::get<3>(tup); arg.orderC = std::get<4>(tup); arg.baseA = std::get<5>(tup); arg.diag_type = std::get<6>(tup); arg.fill_mode = std::get<7>(tup); arg.spsm_alg = std::get<8>(tup); arg.timing = 0; return arg; } Arguments setup_spsm_csr_arguments(spsm_csr_bin_tuple tup) { Arguments arg; arg.K = std::get<0>(tup).K; arg.alpha = std::get<0>(tup).alpha; arg.transA = std::get<1>(tup); arg.transB = std::get<2>(tup); arg.orderB = std::get<3>(tup); arg.orderC = std::get<4>(tup); arg.baseA = std::get<5>(tup); arg.diag_type = std::get<6>(tup); arg.fill_mode = std::get<7>(tup); arg.spsm_alg = std::get<8>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<9>(tup); // Matrices are stored at the same path in matrices directory arg.filename = get_filename(bin_file); return arg; } #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(spsm_csr_bad_arg, spsm_csr_float) { testing_spsm_csr_bad_arg(); } TEST_P(parameterized_spsm_csr, spsm_csr_i32_float) { Arguments arg = setup_spsm_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spsm_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spsm_csr, spsm_csr_i64_double) { Arguments arg = setup_spsm_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spsm_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spsm_csr, spsm_csr_i32_float_complex) { Arguments arg = setup_spsm_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spsm_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spsm_csr, spsm_csr_i64_double_complex) { Arguments arg = setup_spsm_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spsm_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spsm_csr_bin, spsm_csr_bin_i32_float) { Arguments arg = setup_spsm_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spsm_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spsm_csr_bin, spsm_csr_bin_i64_double) { Arguments arg = setup_spsm_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spsm_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(spsm_csr, parameterized_spsm_csr, testing::Combine(testing::ValuesIn(spsm_csr_M_N_K_alpha_range), testing::ValuesIn(spsm_csr_transA_range), testing::ValuesIn(spsm_csr_transB_range), testing::ValuesIn(spsm_csr_orderB_range), testing::ValuesIn(spsm_csr_orderC_range), testing::ValuesIn(spsm_csr_idxbase_range), testing::ValuesIn(spsm_csr_diag_type_range), testing::ValuesIn(spsm_csr_fill_mode_range), testing::ValuesIn(spsm_csr_alg_range))); INSTANTIATE_TEST_SUITE_P(spsm_csr_bin, parameterized_spsm_csr_bin, testing::Combine(testing::ValuesIn(spsm_csr_M_N_K_alpha_range), testing::ValuesIn(spsm_csr_transA_range), testing::ValuesIn(spsm_csr_transB_range), testing::ValuesIn(spsm_csr_orderB_range), testing::ValuesIn(spsm_csr_orderC_range), testing::ValuesIn(spsm_csr_idxbase_range), testing::ValuesIn(spsm_csr_diag_type_range), testing::ValuesIn(spsm_csr_fill_mode_range), testing::ValuesIn(spsm_csr_alg_range), testing::ValuesIn(spsm_csr_bin))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_spsv_coo.cpp000066400000000000000000000162021501764003400223620ustar00rootroot00000000000000/* ************************************************************************ * 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 typedef std::tuple spsv_coo_tuple; typedef std::tuple spsv_coo_bin_tuple; int spsv_coo_M_range[] = {50}; int spsv_coo_N_range[] = {50}; std::vector spsv_coo_alpha_range = {2.0}; hipsparseOperation_t spsv_coo_transA_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE}; hipsparseIndexBase_t spsv_coo_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ONE}; hipsparseDiagType_t spsv_coo_diag_type_range[] = {HIPSPARSE_DIAG_TYPE_NON_UNIT}; hipsparseFillMode_t spsv_coo_fill_mode_range[] = {HIPSPARSE_FILL_MODE_LOWER, HIPSPARSE_FILL_MODE_UPPER}; hipsparseSpSVAlg_t spsv_coo_alg_range[] = {HIPSPARSE_SPSV_ALG_DEFAULT}; std::string spsv_coo_bin[] = {"nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin", "scircuit.bin"}; class parameterized_spsv_coo : public testing::TestWithParam { protected: parameterized_spsv_coo() {} virtual ~parameterized_spsv_coo() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_spsv_coo_bin : public testing::TestWithParam { protected: parameterized_spsv_coo_bin() {} virtual ~parameterized_spsv_coo_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_spsv_coo_arguments(spsv_coo_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.alpha = std::get<2>(tup); arg.transA = std::get<3>(tup); arg.baseA = std::get<4>(tup); arg.diag_type = std::get<5>(tup); arg.fill_mode = std::get<6>(tup); arg.spsv_alg = std::get<7>(tup); arg.timing = 0; return arg; } Arguments setup_spsv_coo_arguments(spsv_coo_bin_tuple tup) { Arguments arg; arg.alpha = std::get<0>(tup); arg.transA = std::get<1>(tup); arg.baseA = std::get<2>(tup); arg.diag_type = std::get<3>(tup); arg.fill_mode = std::get<4>(tup); arg.spsv_alg = 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; } #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(spsv_coo_bad_arg, spsv_coo_float) { testing_spsv_coo_bad_arg(); } TEST_P(parameterized_spsv_coo, spsv_coo_i32_float) { Arguments arg = setup_spsv_coo_arguments(GetParam()); hipsparseStatus_t status = testing_spsv_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spsv_coo, spsv_coo_i64_double) { Arguments arg = setup_spsv_coo_arguments(GetParam()); hipsparseStatus_t status = testing_spsv_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spsv_coo, spsv_coo_i32_float_complex) { Arguments arg = setup_spsv_coo_arguments(GetParam()); hipsparseStatus_t status = testing_spsv_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spsv_coo, spsv_coo_i64_double_complex) { Arguments arg = setup_spsv_coo_arguments(GetParam()); hipsparseStatus_t status = testing_spsv_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spsv_coo_bin, spsv_coo_bin_i32_float) { Arguments arg = setup_spsv_coo_arguments(GetParam()); hipsparseStatus_t status = testing_spsv_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spsv_coo_bin, spsv_coo_bin_i64_double) { Arguments arg = setup_spsv_coo_arguments(GetParam()); hipsparseStatus_t status = testing_spsv_coo(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(spsv_coo, parameterized_spsv_coo, testing::Combine(testing::ValuesIn(spsv_coo_M_range), testing::ValuesIn(spsv_coo_N_range), testing::ValuesIn(spsv_coo_alpha_range), testing::ValuesIn(spsv_coo_transA_range), testing::ValuesIn(spsv_coo_idxbase_range), testing::ValuesIn(spsv_coo_diag_type_range), testing::ValuesIn(spsv_coo_fill_mode_range), testing::ValuesIn(spsv_coo_alg_range))); INSTANTIATE_TEST_SUITE_P(spsv_coo_bin, parameterized_spsv_coo_bin, testing::Combine(testing::ValuesIn(spsv_coo_alpha_range), testing::ValuesIn(spsv_coo_transA_range), testing::ValuesIn(spsv_coo_idxbase_range), testing::ValuesIn(spsv_coo_diag_type_range), testing::ValuesIn(spsv_coo_fill_mode_range), testing::ValuesIn(spsv_coo_alg_range), testing::ValuesIn(spsv_coo_bin))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_spsv_csr.cpp000066400000000000000000000163331501764003400223760ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse_arguments.hpp" #include "testing_spsv_csr.hpp" #include typedef std::tuple spsv_csr_tuple; typedef std::tuple spsv_csr_bin_tuple; int spsv_csr_M_range[] = {50}; int spsv_csr_N_range[] = {50}; std::vector spsv_csr_alpha_range = {2.0}; hipsparseOperation_t spsv_csr_transA_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE}; hipsparseIndexBase_t spsv_csr_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ONE}; hipsparseDiagType_t spsv_csr_diag_type_range[] = {HIPSPARSE_DIAG_TYPE_NON_UNIT}; hipsparseFillMode_t spsv_csr_fill_mode_range[] = {HIPSPARSE_FILL_MODE_LOWER, HIPSPARSE_FILL_MODE_UPPER}; hipsparseSpSVAlg_t spsv_csr_alg_range[] = {HIPSPARSE_SPSV_ALG_DEFAULT}; std::string spsv_csr_bin[] = {"nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin", "scircuit.bin"}; class parameterized_spsv_csr : public testing::TestWithParam { protected: parameterized_spsv_csr() {} virtual ~parameterized_spsv_csr() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_spsv_csr_bin : public testing::TestWithParam { protected: parameterized_spsv_csr_bin() {} virtual ~parameterized_spsv_csr_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_spsv_csr_arguments(spsv_csr_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.alpha = std::get<2>(tup); arg.transA = std::get<3>(tup); arg.baseA = std::get<4>(tup); arg.diag_type = std::get<5>(tup); arg.fill_mode = std::get<6>(tup); arg.spsv_alg = std::get<7>(tup); arg.timing = 0; return arg; } Arguments setup_spsv_csr_arguments(spsv_csr_bin_tuple tup) { Arguments arg; arg.alpha = std::get<0>(tup); arg.transA = std::get<1>(tup); arg.baseA = std::get<2>(tup); arg.diag_type = std::get<3>(tup); arg.fill_mode = std::get<4>(tup); arg.spsv_alg = 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; } #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(spsv_csr_bad_arg, spsv_csr_float) { testing_spsv_csr_bad_arg(); } TEST_P(parameterized_spsv_csr, spsv_csr_i32_float) { Arguments arg = setup_spsv_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spsv_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spsv_csr, spsv_csr_i64_double) { Arguments arg = setup_spsv_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spsv_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spsv_csr, spsv_csr_i32_float_complex) { Arguments arg = setup_spsv_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spsv_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spsv_csr, spsv_csr_i64_double_complex) { Arguments arg = setup_spsv_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spsv_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spsv_csr_bin, spsv_csr_bin_i32_float) { Arguments arg = setup_spsv_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spsv_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spsv_csr_bin, spsv_csr_bin_i64_double) { Arguments arg = setup_spsv_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spsv_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(spsv_csr, parameterized_spsv_csr, testing::Combine(testing::ValuesIn(spsv_csr_M_range), testing::ValuesIn(spsv_csr_N_range), testing::ValuesIn(spsv_csr_alpha_range), testing::ValuesIn(spsv_csr_transA_range), testing::ValuesIn(spsv_csr_idxbase_range), testing::ValuesIn(spsv_csr_diag_type_range), testing::ValuesIn(spsv_csr_fill_mode_range), testing::ValuesIn(spsv_csr_alg_range))); INSTANTIATE_TEST_SUITE_P(spsv_csr_bin, parameterized_spsv_csr_bin, testing::Combine(testing::ValuesIn(spsv_csr_alpha_range), testing::ValuesIn(spsv_csr_transA_range), testing::ValuesIn(spsv_csr_idxbase_range), testing::ValuesIn(spsv_csr_diag_type_range), testing::ValuesIn(spsv_csr_fill_mode_range), testing::ValuesIn(spsv_csr_alg_range), testing::ValuesIn(spsv_csr_bin))); #endif hipSPARSE-rocm-6.4.3/clients/tests/test_spvec_descr.cpp000066400000000000000000000027751501764003400230410ustar00rootroot00000000000000/* ************************************************************************ * 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-6.4.3/clients/tests/test_spvv.cpp000066400000000000000000000107341501764003400215310ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "testing_spvv.hpp" #include typedef std::tuple spvv_tuple; typedef std::tuple spvv_bin_tuple; int spvv_N_range[] = {50, 750, 2135}; int spvv_nnz_range[] = {5, 45}; hipsparseOperation_t spvv_trans_real_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE}; hipsparseOperation_t spvv_trans_complex_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE}; hipsparseIndexBase_t spvv_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; class parameterized_spvv_real : public testing::TestWithParam { protected: parameterized_spvv_real() {} virtual ~parameterized_spvv_real() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_spvv_complex : public testing::TestWithParam { protected: parameterized_spvv_complex() {} virtual ~parameterized_spvv_complex() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_spvv_arguments(spvv_tuple tup) { Arguments arg; arg.N = std::get<0>(tup); arg.nnz = std::get<1>(tup); arg.transA = std::get<2>(tup); arg.baseA = std::get<3>(tup); arg.timing = 0; return arg; } #if(!defined(CUDART_VERSION) || CUDART_VERSION > 10010 \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) TEST(spvv_bad_arg, spvv_float) { testing_spvv_bad_arg(); } TEST_P(parameterized_spvv_real, spvv_i32_float) { Arguments arg = setup_spvv_arguments(GetParam()); hipsparseStatus_t status = testing_spvv(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spvv_real, spvv_i64_double) { Arguments arg = setup_spvv_arguments(GetParam()); hipsparseStatus_t status = testing_spvv(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spvv_complex, spvv_i32_float_complex) { Arguments arg = setup_spvv_arguments(GetParam()); hipsparseStatus_t status = testing_spvv(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spvv_complex, spvv_i64_double_complex) { Arguments arg = setup_spvv_arguments(GetParam()); hipsparseStatus_t status = testing_spvv(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(spvv, parameterized_spvv_real, testing::Combine(testing::ValuesIn(spvv_N_range), testing::ValuesIn(spvv_nnz_range), testing::ValuesIn(spvv_trans_real_range), testing::ValuesIn(spvv_idxbase_range))); INSTANTIATE_TEST_SUITE_P(spvv, parameterized_spvv_complex, testing::Combine(testing::ValuesIn(spvv_N_range), testing::ValuesIn(spvv_nnz_range), testing::ValuesIn(spvv_trans_complex_range), testing::ValuesIn(spvv_idxbase_range))); #endif hipSPARSE-rocm-6.4.3/cmake/000077500000000000000000000000001501764003400152405ustar00rootroot00000000000000hipSPARSE-rocm-6.4.3/cmake/ClientMatrices.cmake000066400000000000000000000142571501764003400211610ustar00rootroot00000000000000# ######################################################################## # Copyright (C) 2018-2023 Advanced Micro Devices, Inc. All rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # # ######################################################################## set(TEST_MATRICES SNAP/amazon0312 Muite/Chebyshev4 FEMLAB/sme3Dc Williams/webbase-1M Bova/rma10 JGD_BIBD/bibd_22_8 Williams/mac_econ_fwd500 Williams/mc2depi Hamm/scircuit Sandia/ASIC_320k GHS_psdef/bmwcra_1 HB/nos1 HB/nos2 HB/nos3 HB/nos4 HB/nos5 HB/nos6 HB/nos7 DNVS/shipsec1 ) set(TEST_MD5HASH f567e5f5029d052e3004bc69bb3f13f5 e39879103dafab21f4cf942e0fe42a85 a95eee14d980a9cfbbaf5df4a3c64713 2d4c239daad6f12d66a1e6a2af44cbdb a899a0c48b9a58d081c52ffd88a84955 455d5b699ea10232bbab5bc002219ae6 f1b0e56fbb75d1d6862874e3d7d33060 8c8633eada6455c1784269b213c85ea6 3e62f7ea83914f7e20019aefb2a5176f fcfaf8a25c8f49b8d29f138f3c65c08f 8a3cf5448a4fe73dcbdb5a16b326715f b203f7605cb1f20f83280061068f7ec7 b0f812ffcc9469f0bf9be701205522c4 f185514062a0eeabe86d2909275fe1dc 04b781415202db404733ca0c159acbef c98e35f1cfd1ee8177f37bdae155a6e7 c39375226aa5c495293003a5f637598f 9a6481268847e6cf0d70671f2ff1ddcd 73372e7d6a0848f8b19d64a924fab73e ) if(NOT CMAKE_MATRICES_DIR) message(FATAL_ERROR "Unspecified CMAKE_MATRICES_DIR") endif() if(NOT CONVERT_SOURCE) set(CONVERT_SOURCE ${CMAKE_SOURCE_DIR}/deps/convert.cpp) endif() # convert relative path to absolute get_filename_component(PROJECT_BINARY_DIR "${PROJECT_BINARY_DIR}" ABSOLUTE BASE_DIR "${CMAKE_SOURCE_DIR}") get_filename_component(CMAKE_MATRICES_DIR "${CMAKE_MATRICES_DIR}" ABSOLUTE BASE_DIR "${CMAKE_SOURCE_DIR}") file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}) if(BUILD_ADDRESS_SANITIZER) execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CONVERT_SOURCE} -O3 -fsanitize=address -shared-libasan -o ${PROJECT_BINARY_DIR}/mtx2csr.exe RESULT_VARIABLE STATUS) else() execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CONVERT_SOURCE} -O3 -o ${PROJECT_BINARY_DIR}/mtx2csr.exe RESULT_VARIABLE STATUS) endif() if(STATUS AND NOT STATUS EQUAL 0) message(FATAL_ERROR "mtx2csr.exe failed to build, aborting.") endif() list(LENGTH TEST_MATRICES len) math(EXPR len1 "${len} - 1") foreach(i RANGE 0 ${len1}) list(GET TEST_MATRICES ${i} m) list(GET TEST_MD5HASH ${i} md5) string(REPLACE "/" ";" sep_m ${m}) list(GET sep_m 0 dir) list(GET sep_m 1 mat) # Download test matrices if not already downloaded if(NOT EXISTS "${CMAKE_MATRICES_DIR}/${mat}.bin") if(NOT HIPSPARSE_MTX_DIR) # First try user specified mirror, if available if(DEFINED ENV{HIPSPARSE_TEST_MIRROR} AND NOT $ENV{HIPSPARSE_TEST_MIRROR} STREQUAL "") message("-- Downloading and extracting test matrix ${m}.tar.gz from user specified test mirror: $ENV{HIPSPARSE_TEST_MIRROR}") file(DOWNLOAD $ENV{HIPSPARSE_TEST_MIRROR}/${mat}.tar.gz ${CMAKE_MATRICES_DIR}/${mat}.tar.gz INACTIVITY_TIMEOUT 3 STATUS DL) list(GET DL 0 stat) list(GET DL 1 msg) if(NOT stat EQUAL 0) message(FATAL_ERROR "-- Timeout has been reached, specified test mirror is not reachable: ${msg}") endif() else() message("-- Downloading and extracting test matrix ${m}.tar.gz") file(DOWNLOAD https://sparse.tamu.edu/MM/${m}.tar.gz ${CMAKE_MATRICES_DIR}/${mat}.tar.gz INACTIVITY_TIMEOUT 3 STATUS DL) list(GET DL 0 stat) list(GET DL 1 msg) if(NOT stat EQUAL 0) message("-- Timeout has been reached, trying mirror ...") # Try again using ufl links file(DOWNLOAD https://www.cise.ufl.edu/research/sparse/MM/${m}.tar.gz ${CMAKE_MATRICES_DIR}/${mat}.tar.gz INACTIVITY_TIMEOUT 3 STATUS DL) list(GET DL 0 stat) list(GET DL 1 msg) if(NOT stat EQUAL 0) message(FATAL_ERROR "${msg}") endif() endif() endif() # Check MD5 hash before continuing file(MD5 ${CMAKE_MATRICES_DIR}/${mat}.tar.gz hash) # Compare hash if(NOT hash STREQUAL md5) message(FATAL_ERROR "${mat}.tar.gz is corrupted") endif() execute_process(COMMAND tar xf ${mat}.tar.gz RESULT_VARIABLE STATUS WORKING_DIRECTORY ${CMAKE_MATRICES_DIR}) if(STATUS AND NOT STATUS EQUAL 0) message(FATAL_ERROR "uncompressing failed, aborting.") endif() file(RENAME ${CMAKE_MATRICES_DIR}/${mat}/${mat}.mtx ${CMAKE_MATRICES_DIR}/${mat}.mtx) else() file(RENAME ${HIPSPARSE_MTX_DIR}/${mat}/${mat}.mtx ${CMAKE_MATRICES_DIR}/${mat}.mtx) endif() execute_process(COMMAND ${PROJECT_BINARY_DIR}/mtx2csr.exe ${mat}.mtx ${mat}.bin RESULT_VARIABLE STATUS WORKING_DIRECTORY ${CMAKE_MATRICES_DIR}) if(STATUS AND NOT STATUS EQUAL 0) message(FATAL_ERROR "mtx2csr.exe failed, aborting.") else() message(STATUS "${mat} success.") endif() # TODO: add 'COMMAND_ERROR_IS_FATAL ANY' once cmake supported version is 3.19 file(REMOVE_RECURSE ${CMAKE_MATRICES_DIR}/${mat}.tar.gz ${CMAKE_MATRICES_DIR}/${mat} ${CMAKE_MATRICES_DIR}/${mat}.mtx) endif() endforeach() hipSPARSE-rocm-6.4.3/cmake/Dependencies.cmake000066400000000000000000000074651501764003400206440ustar00rootroot00000000000000# ######################################################################## # 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}) if( CUSTOM_ROCSPARSE ) set ( ENV{rocsparse_DIR} ${CUSTOM_ROCSPARSE}) find_package( rocsparse REQUIRED CONFIG NO_CMAKE_PATH ) else() find_package( rocsparse REQUIRED CONFIG PATHS ${ROCSPARSE_PATH} ) endif() 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-6.4.3/cmake/Verbose.cmake000066400000000000000000000062521501764003400176540ustar00rootroot00000000000000# ######################################################################## # 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-6.4.3/cmake/get-cli-arguments.cmake000066400000000000000000000017771501764003400216050ustar00rootroot00000000000000# 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-6.4.3/cmake/hipsparse_clientmatrices.cmake000066400000000000000000000134561501764003400233370ustar00rootroot00000000000000# ######################################################################## # Copyright (C) 2023 Advanced Micro Devices, Inc. All rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # # ######################################################################## find_program(HIPSPARSE_MTX2CSR hipsparse_mtx2csr PATHS /opt/rocm/bin ${ROCM_PATH}/bin) set(TEST_MATRICES SNAP/amazon0312 Muite/Chebyshev4 FEMLAB/sme3Dc Williams/webbase-1M Bova/rma10 JGD_BIBD/bibd_22_8 Williams/mac_econ_fwd500 Williams/mc2depi Hamm/scircuit Sandia/ASIC_320k GHS_psdef/bmwcra_1 HB/nos1 HB/nos2 HB/nos3 HB/nos4 HB/nos5 HB/nos6 HB/nos7 DNVS/shipsec1 ) set(TEST_MD5HASH f567e5f5029d052e3004bc69bb3f13f5 e39879103dafab21f4cf942e0fe42a85 a95eee14d980a9cfbbaf5df4a3c64713 2d4c239daad6f12d66a1e6a2af44cbdb a899a0c48b9a58d081c52ffd88a84955 455d5b699ea10232bbab5bc002219ae6 f1b0e56fbb75d1d6862874e3d7d33060 8c8633eada6455c1784269b213c85ea6 3e62f7ea83914f7e20019aefb2a5176f fcfaf8a25c8f49b8d29f138f3c65c08f 8a3cf5448a4fe73dcbdb5a16b326715f b203f7605cb1f20f83280061068f7ec7 b0f812ffcc9469f0bf9be701205522c4 f185514062a0eeabe86d2909275fe1dc 04b781415202db404733ca0c159acbef c98e35f1cfd1ee8177f37bdae155a6e7 c39375226aa5c495293003a5f637598f 9a6481268847e6cf0d70671f2ff1ddcd 73372e7d6a0848f8b19d64a924fab73e ) if(NOT CMAKE_MATRICES_DIR) set(CMAKE_MATRICES_DIR "./") message(WARNING "Unspecified CMAKE_MATRICES_DIR, the default value of CMAKE_MATRICES_DIR is set to './'") endif() # convert relative path to absolute get_filename_component(PROJECT_BINARY_DIR "${PROJECT_BINARY_DIR}" ABSOLUTE BASE_DIR "${CMAKE_SOURCE_DIR}") get_filename_component(CMAKE_MATRICES_DIR "${CMAKE_MATRICES_DIR}" ABSOLUTE BASE_DIR "${CMAKE_SOURCE_DIR}") file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}) list(LENGTH TEST_MATRICES len) math(EXPR len1 "${len} - 1") foreach(i RANGE 0 ${len1}) list(GET TEST_MATRICES ${i} m) list(GET TEST_MD5HASH ${i} md5) string(REPLACE "/" ";" sep_m ${m}) list(GET sep_m 0 dir) list(GET sep_m 1 mat) # Download test matrices if not already downloaded if(NOT EXISTS "${CMAKE_MATRICES_DIR}/${mat}.bin") if(NOT HIPSPARSE_MTX_DIR) # First try user specified mirror, if available if(DEFINED ENV{HIPSPARSE_TEST_MIRROR} AND NOT $ENV{HIPSPARSE_TEST_MIRROR} STREQUAL "") message("-- Downloading and extracting test matrix ${m}.tar.gz from user specified test mirror: $ENV{HIPSPARSE_TEST_MIRROR}") file(DOWNLOAD $ENV{HIPSPARSE_TEST_MIRROR}/${mat}.tar.gz ${CMAKE_MATRICES_DIR}/${mat}.tar.gz INACTIVITY_TIMEOUT 3 STATUS DL) list(GET DL 0 stat) list(GET DL 1 msg) if(NOT stat EQUAL 0) message(FATAL_ERROR "-- Timeout has been reached, specified test mirror is not reachable: ${msg}") endif() else() message("-- Downloading and extracting test matrix ${m}.tar.gz") file(DOWNLOAD https://sparse.tamu.edu/MM/${m}.tar.gz ${CMAKE_MATRICES_DIR}/${mat}.tar.gz INACTIVITY_TIMEOUT 3 STATUS DL) list(GET DL 0 stat) list(GET DL 1 msg) if(NOT stat EQUAL 0) message("-- Timeout has been reached, trying mirror ...") # Try again using ufl links file(DOWNLOAD https://www.cise.ufl.edu/research/sparse/MM/${m}.tar.gz ${CMAKE_MATRICES_DIR}/${mat}.tar.gz INACTIVITY_TIMEOUT 3 STATUS DL) list(GET DL 0 stat) list(GET DL 1 msg) if(NOT stat EQUAL 0) message(FATAL_ERROR "${msg}") endif() endif() endif() # Check MD5 hash before continuing file(MD5 ${CMAKE_MATRICES_DIR}/${mat}.tar.gz hash) # Compare hash if(NOT hash STREQUAL md5) message(FATAL_ERROR "${mat}.tar.gz is corrupted") endif() execute_process(COMMAND tar xf ${mat}.tar.gz RESULT_VARIABLE STATUS WORKING_DIRECTORY ${CMAKE_MATRICES_DIR}) if(STATUS AND NOT STATUS EQUAL 0) message(FATAL_ERROR "uncompressing failed, aborting.") endif() file(RENAME ${CMAKE_MATRICES_DIR}/${mat}/${mat}.mtx ${CMAKE_MATRICES_DIR}/${mat}.mtx) else() file(RENAME ${HIPSPARSE_MTX_DIR}/${mat}/${mat}.mtx ${CMAKE_MATRICES_DIR}/${mat}.mtx) endif() execute_process(COMMAND ${HIPSPARSE_MTX2CSR} ${mat}.mtx ${mat}.bin RESULT_VARIABLE STATUS WORKING_DIRECTORY ${CMAKE_MATRICES_DIR}) if(STATUS AND NOT STATUS EQUAL 0) message(FATAL_ERROR "${HIPSPARSE_MTX2CSR} failed, aborting.") else() message(STATUS "${mat} success.") endif() # TODO: add 'COMMAND_ERROR_IS_FATAL ANY' once cmake supported version is 3.19 file(REMOVE_RECURSE ${CMAKE_MATRICES_DIR}/${mat}.tar.gz ${CMAKE_MATRICES_DIR}/${mat} ${CMAKE_MATRICES_DIR}/${mat}.mtx) endif() endforeach() hipSPARSE-rocm-6.4.3/deps/000077500000000000000000000000001501764003400151135ustar00rootroot00000000000000hipSPARSE-rocm-6.4.3/deps/CMakeLists.txt000066400000000000000000000065261501764003400176640ustar00rootroot00000000000000# ######################################################################## # 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-6.4.3/deps/convert.cpp000066400000000000000000000152401501764003400173010ustar00rootroot00000000000000/* ************************************************************************ * 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-6.4.3/deps/external-gtest.cmake000066400000000000000000000115011501764003400210610ustar00rootroot00000000000000# ######################################################################## # 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 hip-clang # 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 parameter 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-6.4.3/deps/to_hipSPARSE.sh000077500000000000000000000230241501764003400176530ustar00rootroot00000000000000# ######################################################################## # 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-6.4.3/docs/000077500000000000000000000000001501764003400151105ustar00rootroot00000000000000hipSPARSE-rocm-6.4.3/docs/.gitignore000066400000000000000000000001001501764003400170670ustar00rootroot00000000000000_build/ _doxygen/ doxygen/html doxygen/xml sphinx/_toc.yml hipSPARSE-rocm-6.4.3/docs/CMakeLists.txt000066400000000000000000000024771501764003400176620ustar00rootroot00000000000000# MIT License # # Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. include(ROCMDoxygenDoc) rocm_add_doxygen_doc( OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" ) install( DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/html" DESTINATION "${CMAKE_INSTALL_DOCDIR}") hipSPARSE-rocm-6.4.3/docs/conf.py000066400000000000000000000021671501764003400164150ustar00rootroot00000000000000# Configuration file for the Sphinx documentation builder. # # This file only contains a selection of the most common options. For a full # list see the documentation: # https://www.sphinx-doc.org/en/master/usage/configuration.html import re from rocm_docs import ROCmDocs with open('../CMakeLists.txt', encoding='utf-8') as f: match = re.search(r'.*\brocm_setup_version\(VERSION\s+\"?([0-9.]+)[^0-9.]+', f.read()) if not match: raise ValueError("VERSION not found!") version_number = match[1] left_nav_title = f"hipSPARSE {version_number} Documentation" # for PDF output on Read the Docs project = "hipSPARSE Documentation" author = "Advanced Micro Devices, Inc." copyright = "Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved." version = version_number release = version_number external_toc_path = "./sphinx/_toc.yml" docs_core = ROCmDocs(left_nav_title) docs_core.run_doxygen(doxygen_root="doxygen", doxygen_path="doxygen/xml") docs_core.setup() external_projects_current_project = "hipsparse" for sphinx_var in ROCmDocs.SPHINX_VARS: globals()[sphinx_var] = getattr(docs_core, sphinx_var) hipSPARSE-rocm-6.4.3/docs/doxygen/000077500000000000000000000000001501764003400165655ustar00rootroot00000000000000hipSPARSE-rocm-6.4.3/docs/doxygen/Doxyfile000066400000000000000000003305421501764003400203020ustar00rootroot00000000000000# 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 = . # 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 = # 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 = YES # 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 ../../README.md # 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 #--------------------------------------------------------------------------- # 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 # , /