././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.6203995 hipsparse/0000775000175100017510000000000015206065364013013 5ustar00jenkinsjenkins././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.546399 hipsparse/.azuredevops/0000775000175100017510000000000015206065364015440 5ustar00jenkinsjenkins././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.546399 hipsparse/.azuredevops/rocm-ci.yml0000664000175100017510000000124315206065364017514 0ustar00jenkinsjenkinsresources: 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 ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.546399 hipsparse/.clang-format0000664000175100017510000000654215206065364015375 0ustar00jenkinsjenkins# 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 --- ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.546399 hipsparse/.githooks/0000775000175100017510000000000015206065364014720 5ustar00jenkinsjenkins././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.546399 hipsparse/.githooks/install0000775000175100017510000000022215206065364016310 0ustar00jenkinsjenkins#!/usr/bin/env bash cd $(git rev-parse --git-dir) cd hooks echo "Installing hooks..." ln -fs ../../.githooks/pre-commit pre-commit echo "Done!" ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.546399 hipsparse/.githooks/pre-commit0000775000175100017510000000176615206065364016734 0ustar00jenkinsjenkins#!/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 ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.546399 hipsparse/.github/0000775000175100017510000000000015206065364014353 5ustar00jenkinsjenkins././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.546399 hipsparse/.github/CODEOWNERS0000775000175100017510000000043315206065364015751 0ustar00jenkinsjenkins* @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 ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.546399 hipsparse/.github/CONTRIBUTING.md0000664000175100017510000002064115206065364016607 0ustar00jenkinsjenkins # 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 file ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.546399 hipsparse/.github/dependabot.yml0000664000175100017510000000126015206065364017202 0ustar00jenkinsjenkins# 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" ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.546399 hipsparse/.gitignore0000664000175100017510000000057315206065364015010 0ustar00jenkinsjenkins# 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 ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.547399 hipsparse/.jenkins/0000775000175100017510000000000015206065364014532 5ustar00jenkinsjenkins././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.546399 hipsparse/.jenkins/codecov.groovy0000664000175100017510000000455715206065364017436 0ustar00jenkinsjenkins#!/usr/bin/env groovy // This shared library is available at https://github.com/ROCm/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', 'CodeCov') // customize for project prj.paths.build_command = './install.sh -kc --codecoverage' 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 = "**" commonGroovy.runCoverageCommand(platform, project, gfilter, "release-debug") } buildProject(prj, formatCheck, nodes.dockerArray, compileCommand, testCommand, null) } ci: { String urlJobName = auxiliary.getTopJobName(env.BUILD_URL) def propertyList = [:] propertyList = auxiliary.appendPropertyList(propertyList) def jobNameList = [:] 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) } // Set standardJobNameSet = ["compute-rocm-dkms-no-npi", "compute-rocm-dkms-no-npi-hipclang", "rocm-docker"] // 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([], urlJobName) } } ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.546399 hipsparse/.jenkins/common.groovy0000664000175100017510000000614315206065364017275 0ustar00jenkinsjenkins// 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) } def runCoverageCommand (platform, project, gfilter, String dirmode = "release") { String commitSha String repoUrl (commitSha, repoUrl) = util.getGitHubCommitInformation(project.paths.project_src_prefix) withCredentials([string(credentialsId: "mathlibs-codecov-token-rocm-libraries", variable: 'CODECOV_TOKEN')]) { def command = """#!/usr/bin/env bash set -x cd ${project.paths.project_build_prefix}/build/${dirmode} export LD_LIBRARY_PATH=/opt/rocm/lib/ GTEST_LISTENER=NO_PASS_LINE_IN_LOG make coverage_cleanup coverage GTEST_FILTER=${gfilter}-*known_bug* curl -Os https://uploader.codecov.io/latest/linux/codecov chmod +x codecov ./codecov -v -U \$http_proxy -t ${CODECOV_TOKEN} --file lcoverage/main_coverage.info --name rocm-libraries --flags hipSPARSE --sha ${commitSha} """ platform.runCommand(this, command) } publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: "${project.paths.project_build_prefix}/build/${dirmode}/lcoverage", reportFiles: "index.html", reportName: "Code coverage report", reportTitles: "Code coverage report"]) } 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 ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.546399 hipsparse/.jenkins/extended.groovy0000664000175100017510000000575215206065364017612 0ustar00jenkinsjenkins#!/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) } } ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.547399 hipsparse/.jenkins/precheckin-cuda.groovy0000664000175100017510000000442615206065364021034 0ustar00jenkinsjenkins#!/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) 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')])])) runCI(['ubuntu22-cuda12':['anycuda']], urlJobName) } } ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.547399 hipsparse/.jenkins/precheckin.groovy0000664000175100017510000000575315206065364020126 0ustar00jenkinsjenkins#!/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) } } ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.547399 hipsparse/.jenkins/static.groovy0000664000175100017510000000600615206065364017272 0ustar00jenkinsjenkins#!/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', '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) } } ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.547399 hipsparse/.jenkins/staticanalysis.groovy0000664000175100017510000000266215206065364021042 0ustar00jenkinsjenkins#!/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) runCI(nodeDetails, jobName) } } ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.547399 hipsparse/.readthedocs.yaml0000664000175100017510000000046715206065364016251 0ustar00jenkinsjenkins# 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" ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.547399 hipsparse/CHANGELOG.md0000664000175100017510000002445515206065364014636 0ustar00jenkinsjenkins# 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 4.2.0 for ROCm 7.2.0 ### Added * Added `--clients-only` option to the `install.sh` and `rmake.py` scripts to allow building only the clients while using an already installed version of hipSPARSE. ### Optimized * Improved the user documentation. ### Resolved issues * Fixed a memory leak in `hipsparseCreate` functions. ## hipSPARSE 4.1.0 for ROCm 7.1.0 ### Added * Added brain half float mixed precision to `hipsparseAxpby` where X and Y use bfloat16 and result and the compute type use float. * Added brain half float mixed precision to `hipsparseSpVV` where X and Y use bfloat16 and result and the compute type use float. * Added brain half float mixed precision to `hipsparseSpMV` where A and X use bfloat16 and Y and the compute type use float. * Added brain half float mixed precision to `hipsparseSpMM` where A and B use bfloat16 and C and the compute type use float. * Added brain half float mixed precision to `hipsparseSDDMM` where A and B use bfloat16 and C and the compute type use float. * Added brain half float mixed precision to `hipsparseSDDMM` where A and B and C use bfloat16 and the compute type use float. * Added half float mixed precision to `hipsparseSDDMM` where A and B and C use float16 and the compute type use float. * Added brain half float uniform precision to `hipsparseScatter` and `hipsparseGather` routines. * Added documentation for installing and building hipSPARSE on Microsoft Windows. ## hipSPARSE 4.0.1 for ROCm 7.0.0 ### Added * Add the `int8`, `int32`, and `float16` data types to `hipDataTypeToHCCDataType` so that sparse matrix descriptors can be used with them. * Added half float mixed precision to `hipsparseAxpby` where X and Y use float16 and result and the compute type use float. * Added half float mixed precision to `hipsparseSpVV` where X and Y use float16 and result and the compute type use float. * Added half float mixed precision to `hipsparseSpMM` where A and B use float16 and C and the compute type use float. * Added half float mixed precision to `hipsparseSDDMM` where A and B use float16 and C and the compute type use float. * Added half float uniform precision to `hipsparseScatter` and `hipsparseGather` routines. * Added half float uniform precision to `hipsparseSDDMM` routine. * Add `int8` precision to `hipsparseCsr2cscEx2` routine. * Add the `almalinux` OS name to correct the gfortran dependency. ### Changed * Switch to defaulting to C++17 when building hipSPARSE from source. Previously hipSPARSE was using C++14 by default. ### Resolved issues * Fixed a compilation [issue](https://github.com/ROCm/hipSPARSE/issues/555) related to using `std::filesystem` and C++14. * Fixed the empty clients-common package by moving the `hipsparse_clientmatrices.cmake` and `hipsparse_mtx2csr` files to it. ### 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 because it is unused internally by `hipsparseSpSM_solve()`. ## 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 ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.547399 hipsparse/CMakeLists.txt0000664000175100017510000002354615206065364015565 0ustar00jenkinsjenkins# ######################################################################## # 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 C ${fortran_language}) # Set CXX flags if (NOT DEFINED CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 17) endif() set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) # Set CXX standard if (CMAKE_CXX_STANDARD EQUAL 14) message( DEPRECATION "Builds using the C++14 standard will no longer be supported in the next major release" ) elseif(NOT CMAKE_CXX_STANDARD EQUAL 17) message(FATAL_ERROR "Only C++14 and C++17 are supported") endif() # 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_CLIENTS_ONLY "Build only clients" OFF) 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) # Setup version rocm_setup_version(VERSION 4.2.0) set(hipsparse_SOVERSION 4.2.0) # hipSPARSE library if (NOT BUILD_CLIENTS_ONLY) add_subdirectory(library) endif() if(BUILD_CLIENTS_ONLY OR 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" OR CLIENTS_OS STREQUAL "almalinux") 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_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 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 "4.0.1") 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") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "C:/hipSDK" CACHE PATH "Install path" FORCE) endif() 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 ) # # Generate coverage output. # add_custom_command(TARGET coverage_output COMMAND lcov --directory . --base-directory . --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() ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.547399 hipsparse/LICENSE.md0000664000175100017510000000207015206065364014416 0ustar00jenkinsjenkinsMIT License Copyright (C) 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. ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.547399 hipsparse/README.md0000664000175100017510000000732415206065364014300 0ustar00jenkinsjenkins# 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/ROCm/rocm-libraries/tree/develop/projects/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 `rocm-libraries/projects/hipsparse` 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 `rocm-libraries/projects/hipsparse` folder of the rocm-libraries 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.sh -h # shows help ./install.sh -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 installation guide](https://rocm.docs.amd.com/projects/hipSPARSE/en/latest/install/install.html) provides information on how to configure CMake and build hipSPARSE manually. ### Supported functions See the hipSPARSE documentation for a list of [exported functions](https://rocm.docs.amd.com/projects/hipSPARSE/en/latest/reference/api.html). ## 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. ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5803993 hipsparse/clients/0000775000175100017510000000000015206065364014454 5ustar00jenkinsjenkins././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.547399 hipsparse/clients/CMakeLists.txt0000664000175100017510000001521715206065364017222 0ustar00jenkinsjenkins# ######################################################################## # Copyright (C) 2018-2020 Advanced Micro Devices, Inc. All rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # # ######################################################################## # The ROCm platform requires Ubuntu 16.04 or Fedora 24, which has cmake 3.5 cmake_minimum_required(VERSION 3.5 FATAL_ERROR) # Consider removing this in the future # This should appear before the project command, because it does not use FORCE if(WIN32) set(CMAKE_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/package" CACHE PATH "Install path prefix, prepended onto install directories") else() set(CMAKE_INSTALL_PREFIX "/opt/rocm" CACHE PATH "Install path prefix, prepended onto install directories") endif() # This has to be initialized before the project() command appears # Set the default of CMAKE_BUILD_TYPE to be release, unless user specifies with -D. MSVC_IDE does not use CMAKE_BUILD_TYPE if(NOT DEFINED CMAKE_CONFIGURATION_TYPES AND NOT DEFINED CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel.") endif() # This project may compile dependencies for clients project(hipsparse-clients LANGUAGES CXX) if (BUILD_CLIENTS_ONLY) find_package(hipsparse 4.0.0 REQUIRED) endif() list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) # This option only works for make/nmake and the ninja generators, but no reason it shouldn't be on all the time # This tells cmake to create a compile_commands.json file that can be used with clang tooling or vim set(CMAKE_EXPORT_COMPILE_COMMANDS ON) if(NOT TARGET hipsparse) find_package(hipsparse REQUIRED CONFIG PATHS /opt/rocm/hipsparse) option(BUILD_CLIENTS_TESTS "Build tests (requires googletest)" OFF) option(BUILD_CLIENTS_SAMPLES "Build examples" ON) option(BUILD_CLIENTS_BENCHMARKS "Build benchmarks" ON) endif() # Set CXX flags if (NOT DEFINED CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 17) endif() set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) # Set CXX standard if (CMAKE_CXX_STANDARD EQUAL 14) message( DEPRECATION "Builds using the C++14 standard will no longer be supported in the next major release" ) elseif(NOT CMAKE_CXX_STANDARD EQUAL 17) message(FATAL_ERROR "Only C++14 and C++17 are supported") endif() # If OpenMP is available, we can use it to speed up some tests find_package(OpenMP QUIET) find_package(Threads QUIET) if(OPENMP_FOUND AND THREADS_FOUND) if(NOT TARGET OpenMP::OpenMP_CXX) # OpenMP cmake fix for cmake <= 3.9 add_library(OpenMP::OpenMP_CXX IMPORTED INTERFACE) set_property(TARGET OpenMP::OpenMP_CXX PROPERTY INTERFACE_COMPILE_OPTIONS ${OpenMP_CXX_FLAGS}) set_property(TARGET OpenMP::OpenMP_CXX PROPERTY INTERFACE_LINK_LIBRARIES ${OpenMP_CXX_FLAGS} Threads::Threads) endif() endif() if(BUILD_CLIENTS_SAMPLES) add_subdirectory(samples) endif() if(BUILD_CLIENTS_BENCHMARKS) add_subdirectory(benchmarks) endif() if(BUILD_CLIENTS_TESTS) enable_testing() add_subdirectory(tests) if(NOT CONVERT_SOURCE) set(CONVERT_SOURCE ${CMAKE_SOURCE_DIR}/deps/convert.cpp) endif() execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CONVERT_SOURCE} -Wl,--build-id=sha1 -O3 -o ${PROJECT_BINARY_DIR}/mtx2csr.exe RESULT_VARIABLE STATUS) if(STATUS AND NOT STATUS EQUAL 0) message(FATAL_ERROR "mtx2csr.exe failed to build, aborting.") endif() set(HIPSPARSE_CLIENTMATRICES "${CMAKE_SOURCE_DIR}/cmake/hipsparse_clientmatrices.cmake") set(HIPSPARSE_CONVERT "${PROJECT_BINARY_DIR}/hipsparse_mtx2csr") add_custom_command(OUTPUT "${HIPSPARSE_CONVERT}" COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_BINARY_DIR}/mtx2csr.exe" "${HIPSPARSE_CONVERT}" DEPENDS "${PROJECT_BINARY_DIR}/mtx2csr.exe" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") set(HIPSPARSE_COMMON "${PROJECT_BINARY_DIR}/staging/hipsparse_common.yaml") add_custom_command(OUTPUT "${HIPSPARSE_COMMON}" COMMAND ${CMAKE_COMMAND} -E copy include/hipsparse_common.yaml "${HIPSPARSE_COMMON}" DEPENDS include/hipsparse_common.yaml WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") set(HIPSPARSE_TEMPLATE "${PROJECT_BINARY_DIR}/staging/hipsparse_template.yaml") add_custom_command(OUTPUT "${HIPSPARSE_TEMPLATE}" COMMAND ${CMAKE_COMMAND} -E copy include/hipsparse_template.yaml "${HIPSPARSE_TEMPLATE}" DEPENDS include/hipsparse_template.yaml WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") set(HIPSPARSE_GENTEST "${PROJECT_BINARY_DIR}/staging/hipsparse_gentest.py") add_custom_command(OUTPUT "${HIPSPARSE_GENTEST}" COMMAND ${CMAKE_COMMAND} -E copy common/hipsparse_gentest.py "${HIPSPARSE_GENTEST}" DEPENDS common/hipsparse_gentest.py WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") add_custom_target(hipsparse-common DEPENDS "${HIPSPARSE_COMMON}" "${HIPSPARSE_TEMPLATE}" "${HIPSPARSE_CLIENTMATRICES}" "${HIPSPARSE_GENTEST}" "${HIPSPARSE_CONVERT}") rocm_install( FILES "${HIPSPARSE_COMMON}" "${HIPSPARSE_TEMPLATE}" COMPONENT clients-common DESTINATION "${CMAKE_INSTALL_DATADIR}/hipsparse/test" ) # rocm_install( PROGRAMS "${HIPSPARSE_GENTEST}" COMPONENT clients-common DESTINATION "${CMAKE_INSTALL_LIBEXECDIR}/hipsparse/test" ) rocm_install( PROGRAMS "${HIPSPARSE_CONVERT}" COMPONENT clients-common DESTINATION ${CMAKE_INSTALL_BINDIR} ) rocm_install( FILES "${HIPSPARSE_CLIENTMATRICES}" COMPONENT clients-common DESTINATION "${CMAKE_INSTALL_DATADIR}/hipsparse/test" ) endif() ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5493991 hipsparse/clients/benchmarks/0000775000175100017510000000000015206065364016571 5ustar00jenkinsjenkins././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.547399 hipsparse/clients/benchmarks/CMakeLists.txt0000664000175100017510000000544715206065364021343 0ustar00jenkinsjenkins# ######################################################################## # 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 $) if (BUILD_CLIENTS_ONLY) target_include_directories(hipsparse-bench PRIVATE ${hipsparse_INCLUDE_DIRS}/hipsparse) endif() # 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) ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.547399 hipsparse/clients/benchmarks/client.cpp0000664000175100017510000000761615206065364020565 0ustar00jenkinsjenkins/*! \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; } } } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5483992 hipsparse/clients/benchmarks/hipsparse_arguments_config.cpp0000664000175100017510000004401215206065364024706 0ustar00jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2024-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #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[0] = '\0'; this->function[0] = '\0'; this->category[0] = '\0'; this->index_type_I = HIPSPARSE_INDEX_32I; this->index_type_J = HIPSPARSE_INDEX_32I; this->compute_type = HIP_R_32F; this->alpha = 0.0; this->alphai = 0.0; this->beta = 0.0; this->betai = 0.0; this->threshold = 0.0; this->percentage = 0.0; this->c = 1.0; this->s = 1.0; this->transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; this->transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; this->baseA = HIPSPARSE_INDEX_BASE_ZERO; this->baseB = HIPSPARSE_INDEX_BASE_ZERO; this->baseC = HIPSPARSE_INDEX_BASE_ZERO; this->baseD = HIPSPARSE_INDEX_BASE_ZERO; this->action = HIPSPARSE_ACTION_NUMERIC; this->part = HIPSPARSE_HYB_PARTITION_AUTO; this->diag_type = HIPSPARSE_DIAG_TYPE_NON_UNIT; this->fill_mode = HIPSPARSE_FILL_MODE_LOWER; this->solve_policy = HIPSPARSE_SOLVE_POLICY_NO_LEVEL; this->dirA = HIPSPARSE_DIRECTION_ROW; this->orderA = HIPSPARSE_ORDER_COL; this->orderB = HIPSPARSE_ORDER_COL; this->orderC = HIPSPARSE_ORDER_COL; this->formatA = HIPSPARSE_FORMAT_COO; this->formatB = HIPSPARSE_FORMAT_COO; this->csr2csc_alg = csr2csc_alg_support::get_default_algorithm(); this->dense2sparse_alg = dense2sparse_alg_support::get_default_algorithm(); this->sparse2dense_alg = sparse2dense_alg_support::get_default_algorithm(); this->sddmm_alg = sddmm_alg_support::get_default_algorithm(); this->spgemm_alg = spgemm_alg_support::get_default_algorithm(); this->spmm_alg = spmm_alg_support::get_default_algorithm(); this->spmv_alg = spmv_alg_support::get_default_algorithm(); this->spsm_alg = spsm_alg_support::get_default_algorithm(); this->spsv_alg = spsv_alg_support::get_default_algorithm(); this->numericboost = 0; this->boosttol = 0.0; this->boostval = 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->b_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(&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->b_csr2csc_alg)->default_value(csr2csc_alg_support::get_default_algorithm()), csr2csc_alg_support::get_description()) ("dense2sparse_alg", value(&this->b_dense2sparse_alg)->default_value(dense2sparse_alg_support::get_default_algorithm()), dense2sparse_alg_support::get_description()) ("sparse2dense_alg", value(&this->b_sparse2dense_alg)->default_value(sparse2dense_alg_support::get_default_algorithm()), sparse2dense_alg_support::get_description()) ("sddmm_alg", value(&this->b_sddmm_alg)->default_value(sddmm_alg_support::get_default_algorithm()), sddmm_alg_support::get_description()) ("spgemm_alg", value(&this->b_spgemm_alg)->default_value(spgemm_alg_support::get_default_algorithm()), spgemm_alg_support::get_description()) ("spmm_alg", value(&this->b_spmm_alg)->default_value(spmm_alg_support::get_default_algorithm()), spmm_alg_support::get_description()) ("spmv_alg", value(&this->b_spmv_alg)->default_value(spmv_alg_support::get_default_algorithm()), spmv_alg_support::get_description()) ("spsm_alg", value(&this->b_spsm_alg)->default_value(spsm_alg_support::get_default_algorithm()), spsm_alg_support::get_description()) ("spsv_alg", value(&this->b_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; this->csr2csc_alg = (hipsparseCsr2CscAlg_t)this->b_csr2csc_alg; this->dense2sparse_alg = (hipsparseDenseToSparseAlg_t)this->b_dense2sparse_alg; this->sparse2dense_alg = (hipsparseSparseToDenseAlg_t)this->b_sparse2dense_alg; this->sddmm_alg = (hipsparseSDDMMAlg_t)this->b_sddmm_alg; this->spgemm_alg = (hipsparseSpGEMMAlg_t)this->b_spgemm_alg; this->spmm_alg = (hipsparseSpMMAlg_t)this->b_spmm_alg; this->spmv_alg = (hipsparseSpMVAlg_t)this->b_spmv_alg; this->spsm_alg = (hipsparseSpSMAlg_t)this->b_spsm_alg; this->spsv_alg = (hipsparseSpSVAlg_t)this->b_spsv_alg; strncpy(this->filename, this->b_filename.c_str(), this->b_filename.length()); this->filename[this->b_filename.length()] = '\0'; strncpy(this->function, this->function_name.c_str(), this->function_name.length()); this->function[this->function_name.length()] = '\0'; 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; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5483992 hipsparse/clients/benchmarks/hipsparse_arguments_config.hpp0000664000175100017510000000471615206065364024722 0ustar00jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2024-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #include "hipsparse_arguments.hpp" #include "program_options.hpp" struct hipsparse_arguments_config : Arguments { public: char precision{}; char indextype{}; int device_id{}; std::string function_name{}; private: std::string b_filename{}; 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{}; int b_csr2csc_alg{}; int b_dense2sparse_alg{}; int b_sparse2dense_alg{}; int b_sddmm_alg{}; int b_spgemm_alg{}; int b_spmm_alg{}; int b_spmv_alg{}; int b_spsm_alg{}; int b_spsv_alg{}; 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); }; ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5483992 hipsparse/clients/benchmarks/hipsparse_bench.cpp0000664000175100017510000001265715206065364022445 0ustar00jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2024-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse_bench.hpp" #include "hipsparse_bench_cmdlines.hpp" // Return version. std::string hipsparse_get_version() { int hipsparse_ver; char hipsparse_rev[256]; hipsparseStatus_t status; hipsparseHandle_t handle; status = hipsparseCreate(&handle); if(HIPSPARSE_STATUS_SUCCESS != status) { std::cerr << "The creation of the hipsparseHandle_t failed." << std::endl; throw(status); } status = hipsparseGetVersion(handle, &hipsparse_ver); if(HIPSPARSE_STATUS_SUCCESS != status) { std::cerr << "hipsparseGetVersion failed." << std::endl; throw(status); } status = hipsparseGetGitRevision(handle, hipsparse_rev); if(HIPSPARSE_STATUS_SUCCESS != status) { std::cerr << "hipsparseGetGitRevision failed." << std::endl; throw(status); } status = hipsparseDestroy(handle); if(HIPSPARSE_STATUS_SUCCESS != status) { std::cerr << "rocsparse_destroy_handle failed." << std::endl; throw(status); } 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 << "hipsparse_bench 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 << "hipsparse_bench 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 << "hipsparse_bench 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 << "hipsparse_bench 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; if(hipGetDeviceProperties(&prop, device_id) != hipSuccess) { std::cerr << "hipsparse_bench error: cannot get device properties" << std::endl; exit(1); } out_ << "Using device ID " << device_id << " (" << prop.name << ") for hipSPARSE" << std::endl << "-------------------------------------------------------------------------" << std::endl << "hipSPARSE version: " << hipsparse_get_version() << std::endl << std::endl; } } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5483992 hipsparse/clients/benchmarks/hipsparse_bench.hpp0000664000175100017510000001026415206065364022442 0ustar00jenkinsjenkins/*! \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(); ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5483992 hipsparse/clients/benchmarks/hipsparse_bench_app.cpp0000664000175100017510000003555115206065364023303 0ustar00jenkinsjenkins/*! \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 #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(size_t 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; std::ignore = 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; const 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(static_cast(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; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5483992 hipsparse/clients/benchmarks/hipsparse_bench_app.hpp0000664000175100017510000001576615206065364023316 0ustar00jenkinsjenkins/*! \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]); }; ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5483992 hipsparse/clients/benchmarks/hipsparse_bench_cmdlines.cpp0000664000175100017510000000564415206065364024321 0ustar00jenkinsjenkins#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; } } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5483992 hipsparse/clients/benchmarks/hipsparse_bench_cmdlines.hpp0000664000175100017510000004563315206065364024330 0ustar00jenkinsjenkins/*! \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; }; ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5493991 hipsparse/clients/benchmarks/hipsparse_routine.cpp0000664000175100017510000006140315206065364023044 0ustar00jenkinsjenkins/*! \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; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5493991 hipsparse/clients/benchmarks/hipsparse_routine.hpp0000664000175100017510000001145415206065364023052 0ustar00jenkinsjenkins/*! \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); }; ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5493991 hipsparse/clients/benchmarks/program_options.hpp0000664000175100017510000003036115206065364022527 0ustar00jenkinsjenkins/* ************************************************************************ * 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&) {} ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5513992 hipsparse/clients/common/0000775000175100017510000000000015206065364015744 5ustar00jenkinsjenkins././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5493991 hipsparse/clients/common/arg_check.cpp0000664000175100017510000001276215206065364020366 0ustar00jenkinsjenkins/* ************************************************************************ * 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 } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5493991 hipsparse/clients/common/hipsparse_gentest.py0000664000175100017510000004263515206065364022057 0ustar00jenkinsjenkins#!/usr/bin/env python3 # ######################################################################## # Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # # ######################################################################## """Expand hipSPARSE YAML test data file into binary Arguments records""" import re import sys import os import argparse import ctypes import glob from fnmatch import fnmatchcase try: # Import either the C or pure-Python YAML parser from yaml import CLoader as Loader except ImportError: from yaml import Loader import yaml # Regex for type names in the YAML file. Optional *nnn indicates array. TYPE_RE = re.compile(r'[a-z_A-Z]\w*(:?\s*\*\s*\d+)?$') # Regex for integer ranges A..B[..C] INT_RANGE_RE = re.compile(r'\s*(-?\d+)\s*\.\.\s*(-?\d+)\s*(?:\.\.\s*(-?\d+)\s*)?$') # Regex for include: YAML extension INCLUDE_RE = re.compile(r'include\s*:\s*(.*)') # Regex for complex types COMPLEX_RE = re.compile(r'f\d+_c$') args = {} testcases = set() datatypes = {} param = {} def main(): args.update(parse_args().__dict__) for doc in get_yaml_docs(): process_doc(doc) def process_doc(doc): """Process one document in the YAML file""" # Ignore empty documents if not doc or not doc.get('Tests'): return # Clear datatypes and params from previous documents datatypes.clear() param.clear() # Return dictionary of all known datatypes datatypes.update(get_datatypes(doc)) # Arguments structure corresponding to C/C++ structure param['Arguments'] = type('Arguments', (ctypes.Structure,), {'_fields_': get_arguments(doc)}) # Special names which get expanded as lists of arguments param['dict_lists_to_expand'] = doc.get('Dictionary lists to expand') or () # Lists which are not expanded param['lists_to_not_expand'] = doc.get('Lists to not expand') or () # Defaults defaults = doc.get('Defaults') or {} # Known Bugs param['known_bugs'] = doc.get('Known bugs') or [] # Functions param['Functions'] = doc.get('Functions') or {} # Instantiate all of the tests, starting with defaults for test in doc['Tests']: case = defaults.copy() case.update(test) generate(case, instantiate) def parse_args(): """Parse command-line arguments, returning input and output files""" parser = argparse.ArgumentParser(description=""" Expand hipSPARSE YAML test data file into binary Arguments records """) parser.add_argument('infile', nargs='?', type=argparse.FileType('r'), default=sys.stdin) parser.add_argument('-o', '--out', dest='outfile', type=argparse.FileType('wb'), default=sys.stdout) parser.add_argument('-I', help="Add include path", action='append', dest='includes', default=[]) parser.add_argument('-t', '--template', type=argparse.FileType('r')) parser.add_argument('-m', '--matrices-dir', dest='matrices-dir', default='./') return parser.parse_args() def read_yaml_file(file): """Read the YAML file, processing include: lines as an extension""" file_dir = os.path.dirname(file.name) or os.getcwd() source = [] for line_no, line in enumerate(file, start=1): # Keep track of file names and line numbers for each line of YAML match = line.startswith('include') and INCLUDE_RE.match(line) if not match: source.append([line, file.name, line_no]) else: include_file = match.group(1) include_dirs = [file_dir] + args['includes'] for path in include_dirs: path = os.path.join(path, include_file) if os.path.exists(path): source.extend(read_yaml_file(open(path, 'r'))) break else: sys.exit("In file " + file.name + ", line " + str(line_no) + ", column " + str(match.start(1)+1) + ":\n" + line.rstrip() + "\n" + " " * match.start(1) + "^\nCannot open " + include_file + "\n\nInclude paths:\n" + "\n".join(include_dirs)) file.close() return source def get_yaml_docs(): """Parse the YAML file""" source = read_yaml_file(args['infile']) if args.get('template'): source = read_yaml_file(args['template']) + source source_str = ''.join([line[0] for line in source]) def mark_str(mark): line = source[mark.line] return("In file " + line[1] + ", line " + str(line[2]) + ", column " + str(mark.column + 1) + ":\n" + line[0].rstrip() + "\n" + ' ' * mark.column + "^\n") # We iterate through all of the documents to properly diagnose errors, # because the load_all generator does not handle exceptions correctly. docs = [] load = Loader(source_str) while load.check_data(): try: doc = load.get_data() except yaml.YAMLError as err: sys.exit((mark_str(err.problem_mark) if err.problem_mark else "") + (err.problem + "\n" if err.problem else "") + (err.note + "\n" if err.note else "")) else: docs.append(doc) return docs def get_datatypes(doc): """ Get datatypes from YAML doc""" dt = ctypes.__dict__.copy() for declaration in doc.get('Datatypes') or (): for name, decl in declaration.items(): if isinstance(decl, dict): # Create derived class type based on bases and attr entries dt[name] = type(name, tuple([eval(t, dt) for t in decl.get('bases') or () if TYPE_RE.match(t)] ), decl.get('attr') or {}) # Import class' attributes into the datatype namespace for subtype in decl.get('attr') or {}: if TYPE_RE.match(subtype): dt[subtype] = eval(name+'.'+subtype, dt) elif isinstance(decl, str) and TYPE_RE.match(decl): dt[name] = dt[decl] else: sys.exit("Unrecognized data type "+name+": "+repr(decl)) return dt def get_arguments(doc): """The kernel argument list, with argument names and types""" return [(var, eval(decl[var], datatypes)) for decl in doc.get('Arguments') or () if len(decl) == 1 for var in decl if TYPE_RE.match(decl[var])] def setdefaults(test): """Set default values for parameters""" # Do not put constant defaults here -- use hipsparse_common.yaml for that. # These are only for dynamic defaults # TODO: This should be ideally moved to YAML file, with eval'd expressions. if test['transA'] == 111 or test['transB'] == 111: test.setdefault('lda', 0) test.setdefault('ldb', 0) test.setdefault('ldc', 0) test.setdefault('ldd', 0) else: test.setdefault('lda', test['M'] if test['transA'] == 111 else test['K']) test.setdefault('ldb', test['K'] if test['transB'] == 111 else test['N']) test.setdefault('ldc', test['M']) test.setdefault('ldd', test['M']) def write_signature(out): """Write the signature used to verify binary file compatibility""" if 'signature_written' not in args: sig = 0 byt = bytearray("hipSPARSE", 'utf_8') byt.append(0) last_ofs = 0 for (name, ctype) in param['Arguments']._fields_: member = getattr(param['Arguments'], name) for i in range(0, member.offset - last_ofs): byt.append(0) for i in range(0, member.size): byt.append(sig ^ i) sig = (sig + 89) % 256 last_ofs = member.offset + member.size for i in range(0, ctypes.sizeof(param['Arguments']) - last_ofs): byt.append(0) byt.extend(bytes("HIPsparse", 'utf_8')) byt.append(0) out.write(byt) args['signature_written'] = True def write_test(test): """Write the test case out to the binary file if not seen already""" # For each argument declared in arguments, we generate a positional # argument in the Arguments constructor. For strings, we pass the # value of the string directly. For arrays, we unpack their contents # into the ctype array constructor and pass the ctype array. For # scalars, we coerce the string/numeric value into ctype. arg = [] for name, ctype in param['Arguments']._fields_: try: if issubclass(ctype, ctypes.Array): if issubclass(ctype._type_, ctypes.c_char): arg.append(bytes(test[name], 'utf_8')) else: arg.append(ctype(*test[name])) elif issubclass(ctype, ctypes.c_char): arg.append(bytes(test[name], 'utf_8')) else: arg.append(ctype(test[name])) except TypeError as err: sys.exit("TypeError: " + str(err) + " for " + name + ", which has type " + str(type(test[name])) + "\n") byt = bytes(param['Arguments'](*arg)) if byt not in testcases: testcases.add(byt) write_signature(args['outfile']) args['outfile'].write(byt) def instantiate(test): """Instantiate a given test case""" test = test.copy() # Any Arguments fields declared as enums enum_args = [decl[0] for decl in param['Arguments']._fields_ if decl[1].__module__ == '__main__'] try: setdefaults(test) # If no enum arguments are complex, clear alphai and betai for typename in enum_args: if COMPLEX_RE.match(test[typename]): break else: for name in ('alphai', 'betai', 'boostvali'): if name in test: test[name] = 0.0 # For enum arguments, replace name with value for typename in enum_args: test[typename] = datatypes[test[typename]] # Match known bugs if test['category'] not in ('known_bug', 'disabled'): for bug in param['known_bugs']: for key, value in bug.items(): if key not in test: break if key == 'function': if not fnmatchcase(test[key], value): break # For keys declared as enums, compare resulting values elif test[key] != (datatypes.get(value) if key in enum_args else value): break else: # All values specified in known bug match test case test['category'] = 'known_bug' break write_test(test) except KeyError as err: sys.exit("Undefined value " + str(err) + "\n" + str(test)) def generate(test, function): """Generate test combinations by iterating across lists recursively""" test = test.copy() # For specially named lists, they are expanded and merged into the test # argument list. When the list name is a dictionary of length 1, its pairs # indicate that the argument named by its key takes on values paired with # the argument named by its value, which is another dictionary list. We # process the value dictionaries' keys in alphabetic order, to ensure # deterministic test ordering. for argname in param['dict_lists_to_expand']: if type(argname) == dict: if len(argname) == 1: arg, target = list(argname.items())[0] if arg in test and type(test[arg]) == dict: pairs = sorted(list(test[arg].items()), key=lambda x: x[0]) for test[arg], test[target] in pairs: generate(test, function) return elif argname in test and type(test[argname]) in (tuple, list, dict): # Pop the list and iterate across it ilist = test.pop(argname) # For a bare dictionary, wrap it in a list and apply it once for item in [ilist] if type(ilist) == dict else ilist: try: case = test.copy() case.update(item) # original test merged with each item generate(case, function) except TypeError as err: sys.exit("TypeError: " + str(err) + " for " + argname + ", which has type " + str(type(item)) + "\nA name listed in \"Dictionary lists to expand\" " "must be a defined as a dictionary.\n") return matrices_dir = str(args['matrices-dir']) if matrices_dir[-1] != "/": matrices_dir+="/" for key in sorted(list(test)): # Integer arguments which are ranges (A..B[..C]) are expanded if type(test[key]) == str: match = INT_RANGE_RE.match(str(test[key])) if match: for test[key] in range(int(match.group(1)), int(match.group(2))+1, int(match.group(3) or 1)): generate(test, function) return # For sequence arguments, they are expanded into scalars elif (type(test[key]) in (tuple, list) and key not in param['lists_to_not_expand']): if key == "filename" and test[key] != "*": cleanlist=[] for test[key] in test[key]: # # Get argument. # filename_arg = matrices_dir + str(test[key]) # # Check if this is a valid argument # if ((not os.path.isdir(filename_arg)) and (not glob.glob(filename_arg)) and (not glob.glob(filename_arg + ".bin"))): print("skip unrecognized filename, directory or filename glob expression: '" + test[key] + "'") else: cleanlist.append(test[key]) if not cleanlist: return; test[key] = cleanlist for test[key] in test[key]: # # Get argument. # filename_arg = matrices_dir + str(test[key]) # # It is a directory. # if os.path.isdir(filename_arg): # # List the files. # names = glob.glob(filename_arg + "/*") for name in names: subpath=os.path.splitext(name.replace(matrices_dir,""))[0] test[key]=[subpath] generate(test,function) else: # # Might be a glob expression # names = glob.glob(filename_arg) if not names: names = glob.glob(filename_arg + ".bin") generate(test,function) else: for name in names: subpath=os.path.splitext(name.replace(matrices_dir,""))[0] test[key]=[subpath] generate(test,function) else: for test[key] in test[key]: generate(test,function) return # Replace typed function names with generic functions and types if 'hipsparse_function' in test: func = test.pop('hipsparse_function') if func in param['Functions']: test.update(param['Functions'][func]) else: test['function'] = func generate(test, function) return function(test) if __name__ == '__main__': main()././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5493991 hipsparse/clients/common/hipsparse_parse_data.cpp0000664000175100017510000000311415206065364022630 0ustar00jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse_parse_data.hpp" #include "hipsparse_data.hpp" bool hipsparse_parse_data(int& argc, char** argv, const std::string& default_file) { std::cout << "default_file: " << default_file << std::endl; HipSPARSE_TestData::set_filename(default_file, false); return true; }././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5513992 hipsparse/clients/common/hipsparse_template_specialization.cpp0000664000175100017510000203526515206065364025454 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5513992 hipsparse/clients/common/unit.cpp0000664000175100017510000002052515206065364017433 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2019 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "unit.hpp" #include #include #include #include #ifdef GOOGLE_TEST #include #else #ifdef NDEBUG #undef NDEBUG #include #define NDEBUG #else #include #endif #endif /* ========================================Gtest Unit Check * ==================================================== */ /*! \brief Template: gtest unit compare two matrices float/double/complex */ // Do not put a wrapper over ASSERT_FLOAT_EQ, sincer assert exit the current function NOT the test // case // a wrapper will cause the loop keep going template <> void unit_check_general(int64_t M, int64_t N, int64_t lda, int8_t* hCPU, int8_t* hGPU) { for(int64_t j = 0; j < N; j++) { for(int64_t i = 0; i < M; i++) { #ifdef GOOGLE_TEST ASSERT_FLOAT_EQ(hCPU[i + j * lda], hGPU[i + j * lda]); #else assert(hCPU[i + j * lda] == hGPU[i + j * lda]); #endif } } } template <> void unit_check_general(int64_t M, int64_t N, int64_t lda, float* hCPU, float* hGPU) { for(int64_t j = 0; j < N; j++) { for(int64_t i = 0; i < M; i++) { #ifdef GOOGLE_TEST ASSERT_FLOAT_EQ(hCPU[i + j * lda], hGPU[i + j * lda]); #else assert(hCPU[i + j * lda] == hGPU[i + j * lda]); #endif } } } template <> void unit_check_general(int64_t M, int64_t N, int64_t lda, double* hCPU, double* hGPU) { for(int64_t j = 0; j < N; j++) { for(int64_t i = 0; i < M; i++) { #ifdef GOOGLE_TEST ASSERT_DOUBLE_EQ(hCPU[i + j * lda], hGPU[i + j * lda]); #else assert(hCPU[i + j * lda] == hGPU[i + j * lda]); #endif } } } template <> void unit_check_general(int64_t M, int64_t N, int64_t lda, hipComplex* hCPU, hipComplex* hGPU) { for(int64_t j = 0; j < N; j++) { for(int64_t i = 0; i < M; i++) { #ifdef GOOGLE_TEST ASSERT_FLOAT_EQ(hCPU[i + j * lda].x, hGPU[i + j * lda].x); ASSERT_FLOAT_EQ(hCPU[i + j * lda].y, hGPU[i + j * lda].y); #else assert(hCPU[i + j * lda].x == hGPU[i + j * lda].x); assert(hCPU[i + j * lda].y == hGPU[i + j * lda].y); #endif } } } template <> void unit_check_general( int64_t M, int64_t N, int64_t lda, hipDoubleComplex* hCPU, hipDoubleComplex* hGPU) { for(int64_t j = 0; j < N; j++) { for(int64_t i = 0; i < M; i++) { #ifdef GOOGLE_TEST ASSERT_DOUBLE_EQ(hCPU[i + j * lda].x, hGPU[i + j * lda].x); ASSERT_DOUBLE_EQ(hCPU[i + j * lda].y, hGPU[i + j * lda].y); #else assert(hCPU[i + j * lda].x == hGPU[i + j * lda].x); assert(hCPU[i + j * lda].y == hGPU[i + j * lda].y); #endif } } } template <> void unit_check_general(int64_t M, int64_t N, int64_t lda, int* hCPU, int* hGPU) { for(int64_t j = 0; j < N; j++) { for(int64_t i = 0; i < M; i++) { #ifdef GOOGLE_TEST ASSERT_EQ(hCPU[i + j * lda], hGPU[i + j * lda]); #else assert(hCPU[i + j * lda] == hGPU[i + j * lda]); #endif } } } template <> void unit_check_general(int64_t M, int64_t N, int64_t lda, int64_t* hCPU, int64_t* hGPU) { for(int64_t j = 0; j < N; j++) { for(int64_t i = 0; i < M; i++) { #ifdef GOOGLE_TEST ASSERT_EQ(hCPU[i + j * lda], hGPU[i + j * lda]); #else assert(hCPU[i + j * lda] == hGPU[i + j * lda]); #endif } } } template <> void unit_check_general(int64_t M, int64_t N, int64_t lda, size_t* hCPU, size_t* hGPU) { for(int64_t j = 0; j < N; j++) { for(int64_t i = 0; i < M; i++) { #ifdef GOOGLE_TEST ASSERT_EQ(hCPU[i + j * lda], hGPU[i + j * lda]); #else assert(hCPU[i + j * lda] == hGPU[i + j * lda]); #endif } } } /*! \brief Template: gtest unit compare two matrices float/double/complex */ // Do not put a wrapper over ASSERT_FLOAT_EQ, since assert exit the current function NOT the test // case // a wrapper will cause the loop keep going template <> void unit_check_near(int64_t M, int64_t N, int64_t lda, float* hCPU, float* hGPU) { for(int64_t j = 0; j < N; j++) { for(int64_t i = 0; i < M; i++) { float compare_val = std::max(std::abs(hCPU[i + j * lda] * 1e-3f), 10 * std::numeric_limits::epsilon()); #ifdef GOOGLE_TEST ASSERT_NEAR(hCPU[i + j * lda], hGPU[i + j * lda], compare_val); #else assert(std::abs(hCPU[i + j * lda] - hGPU[i + j * lda]) < compare_val); #endif } } } template <> void unit_check_near(int64_t M, int64_t N, int64_t lda, double* hCPU, double* hGPU) { for(int64_t j = 0; j < N; j++) { for(int64_t i = 0; i < M; i++) { double compare_val = std::max(std::abs(hCPU[i + j * lda] * 1e-10), 10 * std::numeric_limits::epsilon()); #ifdef GOOGLE_TEST ASSERT_NEAR(hCPU[i + j * lda], hGPU[i + j * lda], compare_val); #else assert(std::abs(hCPU[i + j * lda] - hGPU[i + j * lda]) < compare_val); #endif } } } template <> void unit_check_near(int64_t M, int64_t N, int64_t lda, hipComplex* hCPU, hipComplex* hGPU) { for(int64_t j = 0; j < N; j++) { for(int64_t i = 0; i < M; i++) { hipComplex compare_val = make_hipFloatComplex(std::max(std::abs(hCPU[i + j * lda].x * 1e-3f), 10 * std::numeric_limits::epsilon()), std::max(std::abs(hCPU[i + j * lda].y * 1e-3f), 10 * std::numeric_limits::epsilon())); #ifdef GOOGLE_TEST ASSERT_NEAR(hCPU[i + j * lda].x, hGPU[i + j * lda].x, compare_val.x); ASSERT_NEAR(hCPU[i + j * lda].y, hGPU[i + j * lda].y, compare_val.y); #else assert(std::abs(hCPU[i + j * lda].x - hGPU[i + j * lda].x) < compare_val.x); assert(std::abs(hCPU[i + j * lda].y - hGPU[i + j * lda].y) < compare_val.y); #endif } } } template <> void unit_check_near( int64_t M, int64_t N, int64_t lda, hipDoubleComplex* hCPU, hipDoubleComplex* hGPU) { for(int64_t j = 0; j < N; j++) { for(int64_t i = 0; i < M; i++) { hipDoubleComplex compare_val = make_hipDoubleComplex(std::max(std::abs(hCPU[i + j * lda].x * 1e-10), 10 * std::numeric_limits::epsilon()), std::max(std::abs(hCPU[i + j * lda].y * 1e-10), 10 * std::numeric_limits::epsilon())); #ifdef GOOGLE_TEST ASSERT_NEAR(hCPU[i + j * lda].x, hGPU[i + j * lda].x, compare_val.x); ASSERT_NEAR(hCPU[i + j * lda].y, hGPU[i + j * lda].y, compare_val.y); #else assert(std::abs(hCPU[i + j * lda].x - hGPU[i + j * lda].x) < compare_val.x); assert(std::abs(hCPU[i + j * lda].y - hGPU[i + j * lda].y) < compare_val.y); #endif } } } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5513992 hipsparse/clients/common/utility.cpp0000664000175100017510000002050115206065364020151 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include #ifdef WIN32 #include #endif #include "utility.hpp" #include #include #ifdef WIN32 #define strSUITEcmp(A, B) _stricmp(A, B) #endif #ifdef __cpp_lib_filesystem #include namespace fs = std::filesystem; #else #include namespace fs = std::experimental::filesystem; #endif /* ============================================================================================ */ // Return path of this executable std::string hipsparse_exepath() { #ifdef WIN32 std::vector result(MAX_PATH + 1); // Ensure result is large enough to accomodate the path DWORD length = 0; for(;;) { length = GetModuleFileNameA(nullptr, result.data(), result.size()); if(length < result.size() - 1) { result.resize(length + 1); break; } result.resize(result.size() * 2); } fs::path exepath(result.begin(), result.end()); exepath = exepath.remove_filename(); exepath += exepath.empty() ? "" : "/"; return exepath.string(); #else std::string pathstr; char* path = realpath("/proc/self/exe", 0); if(path) { char* p = strrchr(path, '/'); if(p) { p[1] = 0; pathstr = path; } free(path); } return pathstr; #endif } /* ==================================================================================== */ // Return path where the test data file (hipsparse_test.data) is located std::string hipsparse_datapath() { #ifdef WIN32 fs::path share_path = fs::path(hipsparse_exepath() + "../share/hipsparse/test"); std::error_code ec; fs::path path = fs::canonical(share_path, ec); if(!ec) { if(fs::exists(path, ec) && !ec) { path += path.empty() ? "" : "/"; return path.string(); } } #else std::string pathstr; std::string share_path = hipsparse_exepath() + "../share/hipsparse/test"; char* path = realpath(share_path.c_str(), 0); if(path != NULL) { pathstr = path; pathstr += "/"; free(path); return pathstr; } #endif return hipsparse_exepath(); } #ifdef __cplusplus extern "C" { #endif /* ============================================================================================ */ /* query for hipsparse version and git commit SHA-1. */ void query_version(char* version) { int hipsparse_ver; char hipsparse_rev[256]; hipsparseStatus_t status; hipsparseHandle_t handle; status = hipsparseCreate(&handle); if(HIPSPARSE_STATUS_SUCCESS != status) { std::cerr << "The creation of the hipsparseHandle_t failed." << std::endl; throw(status); } status = hipsparseGetVersion(handle, &hipsparse_ver); if(HIPSPARSE_STATUS_SUCCESS != status) { std::cerr << "hipsparseGetVersion failed." << std::endl; throw(status); } status = hipsparseGetGitRevision(handle, hipsparse_rev); if(HIPSPARSE_STATUS_SUCCESS != status) { std::cerr << "hipsparseGetGitRevision failed." << std::endl; throw(status); } status = hipsparseDestroy(handle); if(HIPSPARSE_STATUS_SUCCESS != status) { std::cerr << "rocsparse_destroy_handle failed." << std::endl; throw(status); } snprintf(version, 512, "v%d.%d.%d-%.256s", hipsparse_ver / 100000, hipsparse_ver / 100 % 1000, hipsparse_ver % 100, hipsparse_rev); } /* ============================================================================================ */ /* device query and print out their ID and name; return number of compute-capable devices. */ int query_device_property() { int device_count; { hipsparseStatus_t status = (hipsparseStatus_t)hipGetDeviceCount(&device_count); if(status != HIPSPARSE_STATUS_SUCCESS) { printf("Query device error: cannot get device count.\n"); return -1; } else { printf("Query device success: there are %d devices\n", device_count); } } for(int i = 0; i < device_count; i++) { hipDeviceProp_t props; hipsparseStatus_t status = (hipsparseStatus_t)hipGetDeviceProperties(&props, i); if(status != HIPSPARSE_STATUS_SUCCESS) { printf("Query device error: cannot get device ID %d's property\n", i); } else { printf("Device ID %d : %s\n", i, props.name); printf("-------------------------------------------------------------------------\n"); printf("with %ldMB memory, clock rate %dMHz @ computing capability %d.%d \n", props.totalGlobalMem >> 20, (int)(props.clockRate / 1000), props.major, props.minor); printf("maxGridDimX %d, sharedMemPerBlock %ldKB, maxThreadsPerBlock %d, warpSize %d\n", props.maxGridSize[0], props.sharedMemPerBlock >> 10, props.maxThreadsPerBlock, props.warpSize); printf("-------------------------------------------------------------------------\n"); } } return device_count; } /* set current device to device_id */ void set_device(int device_id) { hipsparseStatus_t status = (hipsparseStatus_t)hipSetDevice(device_id); if(status != HIPSPARSE_STATUS_SUCCESS) { printf("Set device error: cannot set device ID %d, there may not be such device ID\n", (int)device_id); } } /* ============================================================================================ */ /* timing:*/ /*! \brief CPU Timer(in microsecond): synchronize with the default device and return wall time */ double get_time_us(void) { std::ignore = hipDeviceSynchronize(); auto now = std::chrono::steady_clock::now(); // struct timeval tv; // gettimeofday(&tv, NULL); // return (tv.tv_sec * 1000 * 1000) + tv.tv_usec; auto duration = std::chrono::duration_cast(now.time_since_epoch()).count(); return (static_cast(duration)); // hipDeviceSynchronize(); //struct timeval tv; //gettimeofday(&tv, NULL); //return (tv.tv_sec * 1000 * 1000) + tv.tv_usec; }; /*! \brief CPU Timer(in microsecond): synchronize with given queue/stream and return wall time */ double get_time_us_sync(hipStream_t stream) { std::ignore = hipStreamSynchronize(stream); auto now = std::chrono::steady_clock::now(); // struct timeval tv; // gettimeofday(&tv, NULL); // return (tv.tv_sec * 1000 * 1000) + tv.tv_usec; auto duration = std::chrono::duration_cast(now.time_since_epoch()).count(); return (static_cast(duration)); // hipStreamSynchronize(stream); // struct timeval tv; // gettimeofday(&tv, NULL); // return (tv.tv_sec * 1000 * 1000) + tv.tv_usec; }; #ifdef __cplusplus } #endif ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5733993 hipsparse/clients/include/0000775000175100017510000000000015206065364016077 5ustar00jenkinsjenkins././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5513992 hipsparse/clients/include/arg_check.hpp0000664000175100017510000000437715206065364020531 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5513992 hipsparse/clients/include/display.hpp0000664000175100017510000004135615206065364020266 0ustar00jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2024 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ /*! \file * \brief display.hpp provides common testing utilities. */ #pragma once #ifndef DISPLAY_HPP #define DISPLAY_HPP #include #include #include #include #include #include #include #include static constexpr const char* s_timing_info_perf = "GFlop/s"; static constexpr const char* s_timing_info_bandwidth = "GB/s"; static constexpr const char* s_timing_info_time = "msec"; static constexpr const char* s_analysis_timing_info_time = "analysis msec"; hipsparseStatus_t hipsparse_record_output_legend(const std::string& s); hipsparseStatus_t hipsparse_record_output(const std::string& s); hipsparseStatus_t hipsparse_record_timing(double msec, double gflops, double gbs); bool display_timing_info_is_stdout_disabled(); inline auto& operator<<(std::ostream& out, const hipComplex& z) { std::stringstream ss; ss << '(' << z.x << ',' << z.y << ')'; return out << ss.str(); } inline auto& operator<<(std::ostream& out, const hipDoubleComplex& z) { std::stringstream ss; ss << '(' << z.x << ',' << z.y << ')'; return out << ss.str(); } struct display_key_t { // // Enumerate keys. // typedef enum enum_ { gflops = 0, bandwidth, time_ms, iters, function, ctype, itype, jtype, size, M, N, K, LD, Mb, MbA, MbC, Nb, NbA, NbC, Kb, nrhs, ell_width, ell_nnz, coo_nnz, nnz, nnzA, nnzB, nnzC, nnzb, nnzbA, nnzbC, block_dim, row_block_dim, row_block_dimA, row_block_dimC, col_block_dim, col_block_dimA, col_block_dimC, batch_count, batch_countA, batch_countB, batch_countC, batch_stride, alpha, beta, percentage, threshold, trans, transA, transB, transC, transX, direction, order, format, fill_mode, diag_type, solve_policy, action, partition, algorithm, permute } key_t; static const char* to_str(key_t key_) { switch(key_) { case gflops: { return s_timing_info_perf; } case bandwidth: { return s_timing_info_bandwidth; } case time_ms: { return s_timing_info_time; } case iters: { return "iters"; } case function: { return "function"; } case ctype: { return "ctype"; } case itype: { return "itype"; } case jtype: { return "jtype"; } case size: { return "size"; } case M: { return "M"; } case N: { return "N"; } case K: { return "K"; } case LD: { return "LD"; } case Mb: { return "Mb"; } case MbA: { return "MbA"; } case MbC: { return "MbC"; } case Nb: { return "Nb"; } case NbA: { return "NbA"; } case NbC: { return "NbC"; } case Kb: { return "Kb"; } case nrhs: { return "nrhs"; } case ell_width: { return "ell_width"; } case ell_nnz: { return "ell_nnz"; } case coo_nnz: { return "coo_nnz"; } case nnz: { return "nnz"; } case nnzA: { return "nnzA"; } case nnzB: { return "nnzB"; } case nnzC: { return "nnzC"; } case nnzb: { return "nnzb"; } case nnzbA: { return "nnzbA"; } case nnzbC: { return "nnzbC"; } case block_dim: { return "block_dim"; } case row_block_dim: { return "row_block_dim"; } case row_block_dimA: { return "row_block_dimA"; } case row_block_dimC: { return "row_block_dimC"; } case col_block_dim: { return "col_block_dim"; } case col_block_dimA: { return "col_block_dimA"; } case col_block_dimC: { return "col_block_dimC"; } case batch_count: { return "batch_count"; } case batch_countA: { return "batch_countA"; } case batch_countB: { return "batch_countB"; } case batch_countC: { return "batch_countC"; } case batch_stride: { return "batch_stride"; } case alpha: { return "alpha"; } case beta: { return "beta"; } case percentage: { return "percentage"; } case threshold: { return "threshold"; } case trans: { return "trans"; } case transA: { return "transA"; } case transB: { return "transB"; } case transC: { return "transC"; } case transX: { return "transX"; } case direction: { return "dir"; } case order: { return "order"; } case format: { return "format"; } case fill_mode: { return "uplo"; } case diag_type: { return "diag"; } case solve_policy: { return "solve_policy"; } case action: { return "action"; } case partition: { return "partition"; } case algorithm: { return "algorithm"; } case permute: { return "permute"; } default: { return nullptr; } } } }; template inline const char* display_to_string(S s) { return s; }; template <> inline const char* display_to_string(display_key_t::key_t s) { return display_key_t::to_str(s); }; // // Template to display timing information. // template inline void display_timing_info_legend(std::ostream& out, int n, S name, T t) { out << std::setw(n) << display_to_string(name); } template inline void display_timing_info_legend(std::ostream& out, int n, S name, T t, Ts... ts) { out << std::setw(n) << display_to_string(name); display_timing_info_legend(out, n, ts...); } template inline void display_timing_info_values(std::ostream& out, int n, S name, T t) { out << std::setw(n) << t; } template inline void display_timing_info_values(std::ostream& out, int n, S name, T t, Ts... ts) { out << std::setw(n) << t; display_timing_info_values(out, n, ts...); } template inline void display_timing_info_legend_noresults(std::ostream& out, int n, S name_, T t) { const char* name = display_to_string(name_); if(strcmp(name, s_timing_info_perf) && strcmp(name, s_timing_info_bandwidth) && strcmp(name, s_timing_info_time)) { out << " " << name; } } template inline void display_timing_info_legend_noresults(std::ostream& out, int n, S name_, T t, Ts... ts) { const char* name = display_to_string(name_); if(strcmp(name, s_timing_info_perf) && strcmp(name, s_timing_info_bandwidth) && strcmp(name, s_timing_info_time)) { out << " " << name; } display_timing_info_legend_noresults(out, n, ts...); } template inline void display_timing_info_values_noresults(std::ostream& out, int n, S name_, T t) { const char* name = display_to_string(name_); if(strcmp(name, s_timing_info_perf) && strcmp(name, s_timing_info_bandwidth) && strcmp(name, s_timing_info_time)) { out << " " << t; } } template inline void display_timing_info_values_noresults(std::ostream& out, int n, S name_, T t, Ts... ts) { const char* name = display_to_string(name_); if(strcmp(name, s_timing_info_perf) && strcmp(name, s_timing_info_bandwidth) && strcmp(name, s_timing_info_time)) { out << " " << t; } display_timing_info_values_noresults(out, n, ts...); } template inline void grab_results(double values[3], display_key_t::key_t key, T t) { } template <> inline void grab_results(double values[3], display_key_t::key_t key, double t) { const char* name = display_to_string(key); if(!strcmp(name, s_timing_info_perf)) { values[1] = t; } else if(!strcmp(name, s_timing_info_bandwidth)) { values[2] = t; } else if(!strcmp(name, s_timing_info_time)) { values[0] = t; } } template inline void grab_results(double values[3], const char* name, T t) { } template <> inline void grab_results(double values[3], const char* name, double t) { if(!strcmp(name, s_timing_info_perf)) { values[1] = t; } else if(!strcmp(name, s_timing_info_bandwidth)) { values[2] = t; } else if(!strcmp(name, s_timing_info_time)) { values[0] = t; } } template inline void display_timing_info_grab_results(double values[3], S name, T t) { grab_results(values, name, t); } template inline void display_timing_info_grab_results(double values[3], S name, T t, Ts... ts) { grab_results(values, name, t); display_timing_info_grab_results(values, ts...); } //bool display_timing_info_is_stdout_disabled(); template inline void display_timing_info_generate(std::ostream& out, int n, S name, T t, Ts... ts) { double values[3]{}; display_timing_info_grab_results(values, name, t, ts...); hipsparse_record_timing(values[0], values[1], values[2]); display_timing_info_values(out, n, name, t, ts...); } template inline void display_timing_info_generate_params(std::ostream& out, int n, S name, T t, Ts... ts) { double values[3]{}; display_timing_info_grab_results(values, name, t, ts...); hipsparse_record_timing(values[0], values[1], values[2]); display_timing_info_values_noresults(out, n, name, t, ts...); } template inline void display_timing_info_max_size_strings(int mx[1], S name_, T t) { const char* name = display_to_string(name_); int len = strlen(name); mx[0] = std::max(len, mx[0]); } template inline void display_timing_info_max_size_strings(int mx[1], S name_, T t, Ts... ts) { const char* name = display_to_string(name_); int len = strlen(name); mx[0] = std::max(len, mx[0]); display_timing_info_max_size_strings(mx, ts...); } template inline void display_timing_info_main(S name, Ts... ts) { // // To configure the size of std::setw. // int n = 0; display_timing_info_max_size_strings(&n, name, ts...); // // // n += 4; // // Legend // { std::ostringstream out_legend; out_legend.precision(2); out_legend.setf(std::ios::fixed); out_legend.setf(std::ios::left); if(!display_timing_info_is_stdout_disabled()) { display_timing_info_legend(out_legend, n, name, ts...); std::cout << out_legend.str() << std::endl; } else { // store the string. display_timing_info_legend_noresults(out_legend, n, name, ts...); hipsparse_record_output_legend(out_legend.str()); } } std::ostringstream out; out.precision(2); out.setf(std::ios::fixed); out.setf(std::ios::left); if(!display_timing_info_is_stdout_disabled()) { display_timing_info_generate(out, n, name, ts...); std::cout << out.str() << std::endl; } else { display_timing_info_generate_params(out, n, name, ts...); // store the string. hipsparse_record_output(out.str()); } } inline void hipsparse_get_matrixname(const char* f, char* name) { int n = 0; while(f[n] != '\0') ++n; int cdir = 0; for(int i = 0; i < n; ++i) { if(f[i] == '/' || f[i] == '\\') { cdir = i + 1; } } int ddir = cdir; for(int i = cdir; i < n; ++i) { if(f[i] == '.') { ddir = i; } } if(ddir == cdir) { ddir = n; } for(int i = cdir; i < ddir; ++i) { name[i - cdir] = f[i]; } name[ddir - cdir] = '\0'; } #define display_timing_info(...) \ do \ { \ const char* ctypename = hipsparse_datatype2string(argus.compute_type); \ const char* itypename = hipsparse_indextype2string(argus.index_type_I); \ const char* jtypename = hipsparse_indextype2string(argus.index_type_J); \ \ display_timing_info_main(__VA_ARGS__, \ display_key_t::iters, \ argus.iters, \ "verified", \ (argus.unit_check ? "yes" : "no"), \ display_key_t::function, \ &argus.function[0], \ display_key_t::ctype, \ ctypename, \ display_key_t::itype, \ itypename, \ display_key_t::jtype, \ jtypename); \ } while(false) #endif // DISPLAY_HPP ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5513992 hipsparse/clients/include/flops.hpp0000664000175100017510000001434315206065364017740 0ustar00jenkinsjenkins/*! \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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5523992 hipsparse/clients/include/gbyte.hpp0000664000175100017510000005076715206065364017741 0ustar00jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2024 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ /*! \file * \brief gbyte.hpp provides data transfer counts of Sparse Linear Algebra Subprograms * of Level 1, 2 and 3. */ #pragma once #ifndef GBYTE_HPP #define GBYTE_HPP // Compute gbytes inline double get_gpu_gbyte(double gpu_time_used, double gbyte_count) { return gbyte_count / gpu_time_used * 1e6; } template inline double get_gpu_gbyte(double gpu_time_used, F count, Ts... ts) { return get_gpu_gbyte(gpu_time_used, count(ts...)); } inline double get_gpu_time_msec(double gpu_time_used) { return gpu_time_used / 1e3; } /* * =========================================================================== * level 1 SPARSE * =========================================================================== */ template constexpr double axpby_gbyte_count(I nnz) { return (nnz * sizeof(I) + (3.0 * nnz) * sizeof(T)) / 1e9; } template constexpr double doti_gbyte_count(I nnz) { return (nnz * sizeof(I) + nnz * (sizeof(X) + sizeof(Y))) / 1e9; } template constexpr double gthr_gbyte_count(I nnz) { return (nnz * sizeof(I) + (2.0 * nnz) * sizeof(T)) / 1e9; } template constexpr double gthrz_gbyte_count(I nnz) { return (nnz * sizeof(I) + (2.0 * nnz) * sizeof(T)) / 1e9; } template constexpr double roti_gbyte_count(I nnz) { return (nnz * sizeof(I) + (3.0 * nnz) * sizeof(T)) / 1e9; } template constexpr double sctr_gbyte_count(I nnz) { return (nnz * sizeof(I) + (2.0 * nnz) * sizeof(T)) / 1e9; } /* * =========================================================================== * level 2 SPARSE * =========================================================================== */ template constexpr double bsrmv_gbyte_count(J mb, J nb, I nnzb, J block_dim, bool beta = false) { return (sizeof(I) * (mb + 1) + sizeof(J) * nnzb + sizeof(A) * nnzb * block_dim * block_dim + sizeof(Y) * (mb * block_dim + (beta ? mb * block_dim : 0)) + sizeof(X) * (nb * block_dim)) / 1e9; } template constexpr double bsrmv_gbyte_count(J mb, J nb, I nnzb, J block_dim, bool beta = false) { return bsrmv_gbyte_count(mb, nb, nnzb, block_dim, beta); } template constexpr double bsrsv_gbyte_count(int mb, int nnzb, int bsr_dim) { return ((mb + 1 + nnzb) * sizeof(int) + (bsr_dim * (mb + mb + nnzb * bsr_dim)) * sizeof(T)) / 1e9; } template constexpr double coomv_gbyte_count(I M, I N, int64_t nnz, bool beta = false) { return (sizeof(I) * 2.0 * nnz + sizeof(A) * nnz + sizeof(Y) * (M + (beta ? M : 0)) + sizeof(X) * N) / 1e9; } template constexpr double coomv_gbyte_count(I M, I N, int64_t nnz, bool beta = false) { return coomv_gbyte_count(M, N, nnz, beta); } template constexpr double csrsv_gbyte_count(J M, I nnz) { return ((M + 1) * sizeof(I) + nnz * sizeof(J) + (M + M + nnz) * sizeof(T)) / 1e9; } template constexpr double coosv_gbyte_count(I M, int64_t nnz) { return (2 * nnz * sizeof(I) + (M + M + nnz) * sizeof(T)) / 1e9; } template constexpr double csrmv_gbyte_count(J M, J N, I nnz, bool beta = false) { return (sizeof(I) * (M + 1) + sizeof(J) * nnz + sizeof(A) * nnz + sizeof(Y) * (M + (beta ? M : 0)) + sizeof(X) * N) / 1e9; } template constexpr double csrmv_gbyte_count(J M, J N, I nnz, bool beta = false) { return csrmv_gbyte_count(M, N, nnz, beta); } template constexpr double gemvi_gbyte_count(I m, I nnz, bool beta = false) { return ((nnz) * sizeof(I) + (m * nnz + nnz + m + (beta ? m : 0)) * sizeof(T)) / 1e9; } /* * =========================================================================== * level 3 SPARSE * =========================================================================== */ template constexpr double bsrmm_gbyte_count(int Mb, int nnzb, int block_dim, int nnz_B, int nnz_C, bool beta = false) { //reads size_t reads = (Mb + 1 + nnzb) * sizeof(int) + (block_dim * block_dim * nnzb + nnz_B + (beta ? nnz_C : 0)) * sizeof(T); //writes size_t writes = nnz_C * sizeof(T); return (reads + writes) / 1e9; } template constexpr double csrmm_gbyte_count(J M, I nnz_A, I nnz_B, I nnz_C, bool beta = false) { return ((M + 1) * sizeof(I) + nnz_A * sizeof(J) + (nnz_A + nnz_B + nnz_C + (beta ? nnz_C : 0)) * sizeof(T)) / 1e9; } template constexpr double cscmm_gbyte_count(J N, I nnz_A, I nnz_B, I nnz_C, bool beta = false) { return csrmm_gbyte_count(N, nnz_A, nnz_B, nnz_C, beta); } template constexpr double coomm_gbyte_count(int64_t nnz_A, int64_t nnz_B, int64_t nnz_C, bool beta = false) { return (2.0 * nnz_A * sizeof(I) + (nnz_A + nnz_B + nnz_C + (beta ? nnz_C : 0)) * sizeof(T)) / 1e9; } template constexpr double csrmm_batched_gbyte_count(J M, I nnz_A, I nnz_B, I nnz_C, J batch_count_A, J batch_count_B, J batch_count_C, bool beta = false) { // read A matrix size_t readA = batch_count_A * ((M + 1) * sizeof(I) + nnz_A * sizeof(J) + nnz_A * sizeof(T)); // read B matrix size_t readB = batch_count_B * nnz_B * sizeof(T); // read C matrix size_t readC = batch_count_C * (beta ? nnz_C : 0) * sizeof(T); // write C matrix size_t writeC = batch_count_C * nnz_C * sizeof(T); return (readA + readB + readC + writeC) / 1e9; } template constexpr double cscmm_batched_gbyte_count(J N, I nnz_A, I nnz_B, I nnz_C, J batch_count_A, J batch_count_B, J batch_count_C, bool beta = false) { // read A matrix size_t readA = batch_count_A * ((N + 1) * sizeof(I) + nnz_A * sizeof(J) + nnz_A * sizeof(T)); // read B matrix size_t readB = batch_count_B * nnz_B * sizeof(T); // read C matrix size_t readC = batch_count_C * (beta ? nnz_C : 0) * sizeof(T); // write C matrix size_t writeC = batch_count_C * nnz_C * sizeof(T); return (readA + readB + readC + writeC) / 1e9; } template constexpr double coomm_batched_gbyte_count(I M, int64_t nnz_A, int64_t nnz_B, int64_t nnz_C, I batch_count_A, I batch_count_B, I batch_count_C, bool beta = false) { // read A matrix size_t readA = batch_count_A * (nnz_A * sizeof(I) + nnz_A * sizeof(I) + nnz_A * sizeof(T)); // read B matrix size_t readB = batch_count_B * nnz_B * sizeof(T); // read C matrix size_t readC = batch_count_C * (beta ? nnz_C : 0) * sizeof(T); // write C matrix size_t writeC = batch_count_C * nnz_C * sizeof(T); return (readA + readB + readC + writeC) / 1e9; } template constexpr double gemmi_gbyte_count(J N, I nnz_B, I nnz_A, I nnz_C, bool beta = false) { return ((N + 1) * sizeof(I) + nnz_B * sizeof(J) + (nnz_B + nnz_A + nnz_C + (beta ? nnz_C : 0)) * sizeof(T)) / 1e9; } template constexpr double sddmm_csr_gbyte_count(J M, J N, J K, I nnz, bool beta = false) { return ((size_t(M) + 1) * sizeof(I) + size_t(nnz) * sizeof(J) + (size_t(nnz) * (K * 2 + ((beta) ? 1 : 0)) * sizeof(T))) / 1e9; } template constexpr double sddmm_csc_gbyte_count(J M, J N, J K, I nnz, bool beta = false) { return ((size_t(N) + 1) * sizeof(I) + size_t(nnz) * sizeof(J) + (size_t(nnz) * (K * 2 + ((beta) ? 1 : 0)) * sizeof(T))) / 1e9; } template constexpr double sddmm_coo_gbyte_count(J M, J N, J K, I nnz, bool beta = false) { return (size_t(nnz) * 2 * sizeof(I) + size_t(nnz) * (K * 2 + ((beta) ? 1 : 0)) * sizeof(T)) / 1e9; } template constexpr double sddmm_coo_aos_gbyte_count(J M, J N, J K, I nnz, bool beta = false) { return (size_t(nnz) * 2 * sizeof(I) + (size_t(nnz) * (K * 2 + ((beta) ? 1 : 0)) * sizeof(T))) / 1e9; } /* * =========================================================================== * precond SPARSE * =========================================================================== */ template constexpr double bsric0_gbyte_count(int Mb, int block_dim, int nnzb) { return ((Mb + 1 + nnzb) * sizeof(int) + 2.0 * block_dim * block_dim * nnzb * sizeof(T)) / 1e9; } template constexpr double bsrilu0_gbyte_count(int Mb, int block_dim, int nnzb) { return ((Mb + 1 + nnzb) * sizeof(int) + 2.0 * block_dim * block_dim * nnzb * sizeof(T)) / 1e9; } template constexpr double csric0_gbyte_count(int M, int nnz) { return ((M + 1 + nnz) * sizeof(int) + 2.0 * nnz * sizeof(T)) / 1e9; } template constexpr double csrilu0_gbyte_count(int M, int nnz) { return ((M + 1 + nnz) * sizeof(int) + 2.0 * nnz * sizeof(T)) / 1e9; } template constexpr double gtsv_gbyte_count(int M, int N) { return ((3 * M + 2 * M * N) * sizeof(T)) / 1e9; } template constexpr double gtsv_strided_batch_gbyte_count(int M, int N) { return ((3 * M * N + 2 * M * N) * sizeof(T)) / 1e9; } template constexpr double gtsv_interleaved_batch_gbyte_count(int M, int N) { return ((3 * M * N + 2 * M * N) * sizeof(T)) / 1e9; } template constexpr double gpsv_interleaved_batch_gbyte_count(int M, int N) { return ((5 * M * N + 2 * M * N) * sizeof(T)) / 1e9; } /* * =========================================================================== * conversion SPARSE * =========================================================================== */ template constexpr double nnz_gbyte_count(int M, int N, hipsparseDirection_t dir) { return ((M * N) * sizeof(T) + ((dir == HIPSPARSE_DIRECTION_ROW) ? M : N) * sizeof(int)) / 1e9; } template constexpr double bsr2csr_gbyte_count(int Mb, int block_dim, int nnzb) { // reads size_t reads = nnzb * block_dim * block_dim * sizeof(T) + (Mb + 1 + nnzb) * sizeof(int); // writes size_t writes = nnzb * block_dim * block_dim * sizeof(T) + (Mb * block_dim + 1 + nnzb * block_dim * block_dim) * sizeof(int); return (reads + writes) / 1e9; } template constexpr double csr2coo_gbyte_count(int M, int nnz) { return (M + 1 + nnz) * sizeof(int) / 1e9; } template constexpr double coo2csr_gbyte_count(int M, int nnz) { return (M + 1 + nnz) * sizeof(int) / 1e9; } template constexpr double csr2csc_gbyte_count(int M, int N, int nnz, hipsparseAction_t action) { return ((M + N + 2 + 2.0 * nnz) * sizeof(int) + (action == HIPSPARSE_ACTION_NUMERIC ? (2.0 * nnz) * sizeof(T) : 0.0)) / 1e9; } template constexpr double csr2hyb_gbyte_count(int M, int nnz, int ell_nnz, int coo_nnz) { return ((M + 1.0 + ell_nnz + 2.0 * coo_nnz) * sizeof(int) + (nnz + ell_nnz + coo_nnz) * sizeof(T)) / 1e9; } template constexpr double hyb2csr_gbyte_count(int M, int csr_nnz, int ell_nnz, int coo_nnz) { return ((M + 1.0 + csr_nnz + ell_nnz + 2.0 * coo_nnz) * sizeof(int) + (csr_nnz + ell_nnz + coo_nnz) * sizeof(T)) / 1e9; } template constexpr double csr2bsr_gbyte_count(int M, int Mb, int nnz, int nnzb, int block_dim) { // reads size_t reads = (M + 1 + nnz) * sizeof(int) + nnz * sizeof(T); // writes size_t writes = (Mb + 1 + nnzb * block_dim * block_dim) * sizeof(int) + (nnzb * block_dim * block_dim) * sizeof(T); return (reads + writes) / 1e9; } template constexpr double csr2gebsr_gbyte_count(int M, int Mb, int nnz, int nnzb, int row_block_dim, int col_block_dim) { // reads size_t reads = (M + 1 + nnz) * sizeof(int) + nnz * sizeof(T); // writes size_t writes = (Mb + 1 + nnzb * row_block_dim * col_block_dim) * sizeof(int) + (nnzb * row_block_dim * col_block_dim) * sizeof(T); return (reads + writes) / 1e9; } template constexpr double csr2csr_compress_gbyte_count(int M, int nnz_A, int nnz_C) { size_t reads = (M + 1 + nnz_A) * sizeof(int) + nnz_A * sizeof(T); size_t writes = (M + 1 + nnz_C) * sizeof(int) + nnz_C * sizeof(T); return (reads + writes) / 1e9; } template constexpr double csx2dense_gbyte_count(J M, J N, I nnz) { J L = (DIRA == HIPSPARSE_DIRECTION_ROW) ? M : N; size_t read_csx = nnz * sizeof(T) + nnz * sizeof(J) + (L + 1) * sizeof(I); size_t write_dense = M * N * sizeof(T) + nnz * sizeof(T); return (read_csx + write_dense) / 1e9; } template constexpr double dense2csx_gbyte_count(J M, J N, I nnz) { J L = (DIRA == HIPSPARSE_DIRECTION_ROW) ? M : N; size_t write_csx_ptr = (L + 1) * sizeof(I); size_t read_csx_ptr = (L + 1) * sizeof(I); size_t build_csx_ptr = write_csx_ptr + read_csx_ptr; size_t write_csx = nnz * sizeof(T) + nnz * sizeof(J) + (L + 1) * sizeof(I); size_t read_dense = M * N * sizeof(T); return (read_dense + build_csx_ptr + write_csx) / 1e9; } template constexpr double dense2coo_gbyte_count(I M, I N, I nnz) { size_t reads = (M * N) * sizeof(T); size_t writes = 2 * nnz * sizeof(I) + nnz * sizeof(T); return (reads + writes) / 1e9; } template constexpr double coo2dense_gbyte_count(I M, I N, I nnz) { size_t reads = 2 * nnz * sizeof(I) + nnz * sizeof(T); size_t writes = (M * N) * sizeof(T); return (reads + writes) / 1e9; } constexpr double csrsort_gbyte_count(int M, int nnz, bool permute) { return ((2.0 * M + 2.0 + 2.0 * nnz + (permute ? 2.0 * nnz : 0.0)) * sizeof(int)) / 1e9; } constexpr double cscsort_gbyte_count(int N, int nnz, bool permute) { return ((2.0 * N + 2.0 + 2.0 * nnz + (permute ? 2.0 * nnz : 0.0)) * sizeof(int)) / 1e9; } constexpr double coosort_gbyte_count(int nnz, bool permute) { return ((4.0 * nnz + (permute ? 2.0 * nnz : 0.0)) * sizeof(int)) / 1e9; } template constexpr double gebsr2csr_gbyte_count(int Mb, int row_block_dim, int col_block_dim, int nnzb) { // reads size_t reads = nnzb * row_block_dim * col_block_dim * sizeof(T) + (Mb + 1 + nnzb) * sizeof(int); // writes size_t writes = nnzb * row_block_dim * col_block_dim * sizeof(T) + (Mb * row_block_dim + 1 + nnzb * row_block_dim * col_block_dim) * sizeof(int); return (reads + writes) / 1e9; } template constexpr double gebsr2gebsc_gbyte_count( int Mb, int Nb, int nnzb, int row_block_dim, int col_block_dim, hipsparseAction_t action) { return ((Mb + Nb + 2 + 2.0 * nnzb) * sizeof(int) + (action == HIPSPARSE_ACTION_NUMERIC ? (2.0 * nnzb * row_block_dim * col_block_dim) * sizeof(T) : 0.0)) / 1e9; } template constexpr double gebsr2gebsr_gbyte_count(int Mb_A, int Mb_C, int row_block_dim_A, int col_block_dim_A, int row_block_dim_C, int col_block_dim_C, int nnzb_A, int nnzb_C) { // reads size_t reads = nnzb_A * row_block_dim_A * col_block_dim_A * sizeof(T) + (Mb_A + 1 + nnzb_A) * sizeof(int); // writes size_t writes = nnzb_C * row_block_dim_C * col_block_dim_C * sizeof(T) + (Mb_C + 1 + nnzb_C) * sizeof(int); return (reads + writes) / 1e9; } constexpr double identity_gbyte_count(int N) { return N * sizeof(int) / 1e9; } template constexpr double prune_csr2csr_gbyte_count(int M, int nnz_A, int nnz_C) { // reads size_t reads = (M + 1 + nnz_A) * sizeof(int) + nnz_A * sizeof(T); // writes size_t writes = (M + 1 + nnz_C) * sizeof(int) + nnz_C * sizeof(T); return (reads + writes) / 1e9; } template constexpr double prune_csr2csr_by_percentage_gbyte_count(int M, int nnz_A, int nnz_C) { // reads size_t reads = (M + 1 + nnz_A) * sizeof(int) + nnz_A * sizeof(T); // writes size_t writes = (M + 1 + nnz_C) * sizeof(int) + nnz_C * sizeof(T); return (reads + writes) / 1e9; } template constexpr double prune_dense2csr_gbyte_count(int M, int N, int nnz) { size_t reads = M * N * sizeof(T); size_t writes = (M + 1 + nnz) * sizeof(int) + nnz * sizeof(T); return (reads + writes) / 1e9; } template constexpr double prune_dense2csr_by_percentage_gbyte_count(int M, int N, int nnz) { size_t reads = M * N * sizeof(T); size_t writes = (M + 1 + nnz) * sizeof(int) + nnz * sizeof(T); return (reads + writes) / 1e9; } /* * =========================================================================== * extra SPARSE * =========================================================================== */ template constexpr double csrgeam_gbyte_count(int M, int nnz_A, int nnz_B, int nnz_C, const T* alpha, const T* beta) { double size_A = alpha ? (M + 1.0 + nnz_A) * sizeof(int) + nnz_A * sizeof(T) : 0.0; double size_B = beta ? (M + 1.0 + nnz_B) * sizeof(int) + nnz_B * sizeof(T) : 0.0; double size_C = (M + 1.0 + nnz_C) * sizeof(int) + nnz_C * sizeof(T); return (size_A + size_B + size_C) / 1e9; } template constexpr double csrgemm_gbyte_count(J M, J N, J K, I nnz_A, I nnz_B, I nnz_C) { double size_A = (M + 1.0) * sizeof(I) + nnz_A * sizeof(J) + nnz_A * sizeof(T); double size_B = (K + 1.0) * sizeof(I) + nnz_B * sizeof(J) + nnz_B * sizeof(T); double size_C = (M + 1.0) * sizeof(I) + nnz_C * sizeof(J) + nnz_C * sizeof(T); return (size_A + size_B + size_C) / 1e9; } #endif // GBYTE_HPP ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5573993 hipsparse/clients/include/hipsparse.hpp0000664000175100017510000031721515206065364020617 0ustar00jenkinsjenkins/* ************************************************************************ * 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_ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5583992 hipsparse/clients/include/hipsparse_arguments.hpp0000664000175100017510000004107515206065364022702 0ustar00jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2024-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ /*! \file * \brief hipsparse_arguments.hpp provides a class to parse command arguments in both, * clients and gtest. */ #pragma once #include #include #include #include #include "hipsparse_arguments_support.hpp" #include "hipsparse_datatype2string.hpp" template static T convert_alpha_beta(double r, double i) { return static_cast(r); } struct Arguments { int M; int N; int K; int nnz; int block_dim; int row_block_dimA; int col_block_dimA; int row_block_dimB; int col_block_dimB; int lda; int ldb; int ldc; int batch_count; hipsparseIndexType_t index_type_I; hipsparseIndexType_t index_type_J; hipDataType compute_type; double alpha; double alphai; double beta; double betai; double threshold; double percentage; double c; double s; hipsparseOperation_t transA; hipsparseOperation_t transB; hipsparseIndexBase_t baseA; hipsparseIndexBase_t baseB; hipsparseIndexBase_t baseC; hipsparseIndexBase_t baseD; hipsparseAction_t action; hipsparseHybPartition_t part; hipsparseDiagType_t diag_type; hipsparseFillMode_t fill_mode; hipsparseSolvePolicy_t solve_policy; hipsparseDirection_t dirA; hipsparseOrder_t orderA; hipsparseOrder_t orderB; hipsparseOrder_t orderC; hipsparseFormat_t formatA; hipsparseFormat_t formatB; hipsparseCsr2CscAlg_t csr2csc_alg; hipsparseDenseToSparseAlg_t dense2sparse_alg; hipsparseSparseToDenseAlg_t sparse2dense_alg; hipsparseSDDMMAlg_t sddmm_alg; hipsparseSpGEMMAlg_t spgemm_alg; hipsparseSpMMAlg_t spmm_alg; hipsparseSpMVAlg_t spmv_alg; hipsparseSpSMAlg_t spsm_alg; hipsparseSpSVAlg_t spsv_alg; int numericboost; double boosttol; double boostval; double boostvali; int ell_width; int permute; int gtsv_alg; int gpsv_alg; int unit_check; int timing; int iters; char filename[192]; // nos2.bin, bmwcra_1.bin, etc char function[64]; // axpby, spmv_csr, etc char category[32]; // quick, pre_checkin, etc Arguments() { this->M = -1; this->N = -1; this->K = -1; this->nnz = -1; this->block_dim = 2; this->row_block_dimA = 2; this->col_block_dimA = 2; this->row_block_dimB = 2; this->col_block_dimB = 2; this->lda = -1; this->ldb = -1; this->ldc = -1; this->batch_count = -1; this->index_type_I = HIPSPARSE_INDEX_32I; this->index_type_J = HIPSPARSE_INDEX_32I; this->compute_type = HIP_R_32F; this->alpha = 0.0; this->alphai = 0.0; this->beta = 0.0; this->betai = 0.0; this->threshold = 0.0; this->percentage = 0.0; this->c = 1.0; this->s = 1.0; this->transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; this->transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; this->baseA = HIPSPARSE_INDEX_BASE_ZERO; this->baseB = HIPSPARSE_INDEX_BASE_ZERO; this->baseC = HIPSPARSE_INDEX_BASE_ZERO; this->baseD = HIPSPARSE_INDEX_BASE_ZERO; this->action = HIPSPARSE_ACTION_NUMERIC; this->part = HIPSPARSE_HYB_PARTITION_AUTO; this->diag_type = HIPSPARSE_DIAG_TYPE_NON_UNIT; this->fill_mode = HIPSPARSE_FILL_MODE_LOWER; this->solve_policy = HIPSPARSE_SOLVE_POLICY_NO_LEVEL; this->dirA = HIPSPARSE_DIRECTION_ROW; this->orderA = HIPSPARSE_ORDER_COL; this->orderB = HIPSPARSE_ORDER_COL; this->orderC = HIPSPARSE_ORDER_COL; this->formatA = HIPSPARSE_FORMAT_COO; this->formatB = HIPSPARSE_FORMAT_COO; this->csr2csc_alg = csr2csc_alg_support::get_default_algorithm(); this->dense2sparse_alg = dense2sparse_alg_support::get_default_algorithm(); this->sparse2dense_alg = sparse2dense_alg_support::get_default_algorithm(); this->sddmm_alg = sddmm_alg_support::get_default_algorithm(); this->spgemm_alg = spgemm_alg_support::get_default_algorithm(); this->spmm_alg = spmm_alg_support::get_default_algorithm(); this->spmv_alg = spmv_alg_support::get_default_algorithm(); this->spsm_alg = spsm_alg_support::get_default_algorithm(); this->spsv_alg = spsv_alg_support::get_default_algorithm(); this->numericboost = 0; this->boosttol = 0.0; this->boostval = 1.0; this->boostvali = 0.0; this->ell_width = 0; this->permute = 0; this->gtsv_alg = 0; this->gpsv_alg = 0; this->unit_check = 1; this->timing = 0; this->iters = 10; this->filename[0] = '\0'; this->function[0] = '\0'; this->category[0] = '\0'; } template T get_alpha() const { return convert_alpha_beta(alpha, alphai); } template T get_beta() const { return convert_alpha_beta(beta, betai); } template T get_threshold() const { return threshold; } template T get_percentage() const { return percentage; } // Validate input format. // hipsparse_gentest.py is expected to conform to this format. // hipsparse_gentest.py uses hipsparse_common.yaml to generate this format. static void validate(std::istream& ifs) { auto error = [](auto name) { std::cerr << "Arguments field " << name << " does not match format.\n\n" << "Fatal error: Binary test data does match input format.\n" "Ensure that hipsparse_arguments.hpp and hipsparse_common.yaml\n" "define exactly the same Arguments, that hipsparse_gentest.py\n" "generates the data correctly, and that endianness is the same.\n"; abort(); }; char header[10]{}, trailer[10]{}; Arguments arg{}; ifs.read(header, sizeof(header)); ifs >> arg; ifs.read(trailer, sizeof(trailer)); if(strcmp(header, "hipSPARSE")) error("header"); else if(strcmp(trailer, "HIPsparse")) error("trailer"); auto check_func = [&, sig = (uint8_t)0](const auto& elem, auto name) mutable { static_assert(sizeof(elem) <= 255, "One of the fields of Arguments is too large (> 255 bytes)"); for(uint8_t i = 0; i < sizeof(elem); ++i) if(reinterpret_cast(&elem)[i] ^ sig ^ i) error(name); sig += 89; }; #define HIPSPARSE_FORMAT_CHECK(x) check_func(arg.x, #x) // Order is important HIPSPARSE_FORMAT_CHECK(M); HIPSPARSE_FORMAT_CHECK(N); HIPSPARSE_FORMAT_CHECK(K); HIPSPARSE_FORMAT_CHECK(nnz); HIPSPARSE_FORMAT_CHECK(block_dim); HIPSPARSE_FORMAT_CHECK(row_block_dimA); HIPSPARSE_FORMAT_CHECK(col_block_dimA); HIPSPARSE_FORMAT_CHECK(row_block_dimB); HIPSPARSE_FORMAT_CHECK(col_block_dimB); HIPSPARSE_FORMAT_CHECK(lda); HIPSPARSE_FORMAT_CHECK(ldb); HIPSPARSE_FORMAT_CHECK(ldc); HIPSPARSE_FORMAT_CHECK(batch_count); HIPSPARSE_FORMAT_CHECK(index_type_I); HIPSPARSE_FORMAT_CHECK(index_type_J); HIPSPARSE_FORMAT_CHECK(compute_type); HIPSPARSE_FORMAT_CHECK(alpha); HIPSPARSE_FORMAT_CHECK(alphai); HIPSPARSE_FORMAT_CHECK(beta); HIPSPARSE_FORMAT_CHECK(betai); HIPSPARSE_FORMAT_CHECK(threshold); HIPSPARSE_FORMAT_CHECK(percentage); HIPSPARSE_FORMAT_CHECK(c); HIPSPARSE_FORMAT_CHECK(s); HIPSPARSE_FORMAT_CHECK(transA); HIPSPARSE_FORMAT_CHECK(transB); HIPSPARSE_FORMAT_CHECK(baseA); HIPSPARSE_FORMAT_CHECK(baseB); HIPSPARSE_FORMAT_CHECK(baseC); HIPSPARSE_FORMAT_CHECK(baseD); HIPSPARSE_FORMAT_CHECK(action); HIPSPARSE_FORMAT_CHECK(part); HIPSPARSE_FORMAT_CHECK(diag_type); HIPSPARSE_FORMAT_CHECK(fill_mode); HIPSPARSE_FORMAT_CHECK(solve_policy); HIPSPARSE_FORMAT_CHECK(dirA); HIPSPARSE_FORMAT_CHECK(orderA); HIPSPARSE_FORMAT_CHECK(orderB); HIPSPARSE_FORMAT_CHECK(orderC); HIPSPARSE_FORMAT_CHECK(formatA); HIPSPARSE_FORMAT_CHECK(formatB); HIPSPARSE_FORMAT_CHECK(csr2csc_alg); HIPSPARSE_FORMAT_CHECK(dense2sparse_alg); HIPSPARSE_FORMAT_CHECK(sparse2dense_alg); HIPSPARSE_FORMAT_CHECK(sddmm_alg); HIPSPARSE_FORMAT_CHECK(spgemm_alg); HIPSPARSE_FORMAT_CHECK(spmm_alg); HIPSPARSE_FORMAT_CHECK(spmv_alg); HIPSPARSE_FORMAT_CHECK(spsm_alg); HIPSPARSE_FORMAT_CHECK(spsv_alg); HIPSPARSE_FORMAT_CHECK(numericboost); HIPSPARSE_FORMAT_CHECK(boosttol); HIPSPARSE_FORMAT_CHECK(boostval); HIPSPARSE_FORMAT_CHECK(boostvali); HIPSPARSE_FORMAT_CHECK(ell_width); HIPSPARSE_FORMAT_CHECK(permute); HIPSPARSE_FORMAT_CHECK(gtsv_alg); HIPSPARSE_FORMAT_CHECK(gpsv_alg); HIPSPARSE_FORMAT_CHECK(unit_check); HIPSPARSE_FORMAT_CHECK(timing); HIPSPARSE_FORMAT_CHECK(iters); HIPSPARSE_FORMAT_CHECK(filename); HIPSPARSE_FORMAT_CHECK(function); HIPSPARSE_FORMAT_CHECK(category); } void set_filename(const std::string& bin_file) { strncpy(this->filename, bin_file.c_str(), bin_file.length()); this->filename[bin_file.length()] = '\0'; } private: // Function to read Structures data from stream friend std::istream& operator>>(std::istream& str, Arguments& arg) { str.read(reinterpret_cast(&arg), sizeof(arg)); return str; } // print_value is for formatting different data types // Default output template static void print_value(std::ostream& str, const T& x) { str << x; } // Floating-point output static void print_value(std::ostream& str, double x) { if(std::isnan(x)) str << ".nan"; else if(std::isinf(x)) str << (x < 0 ? "-.inf" : ".inf"); else { char s[32]; snprintf(s, sizeof(s) - 2, "%.17g", x); // If no decimal point or exponent, append .0 char* end = s + strcspn(s, ".eE"); if(!*end) strcat(end, ".0"); str << s; } } // Character output static void print_value(std::ostream& str, char c) { char s[]{c, 0}; str << std::quoted(s, '\''); } // bool output static void print_value(std::ostream& str, bool b) { str << (b ? "true" : "false"); } // string output static void print_value(std::ostream& str, const char* s) { str << std::quoted(s); } // Function to print Arguments out to stream in YAML format // Google Tests uses this automatically to dump parameters friend std::ostream& operator<<(std::ostream& str, const Arguments& arg) { // delim starts as '{' opening brace and becomes ',' afterwards auto print = [&, delim = '{'](const char* name, auto x) mutable { str << delim << " " << name << ": "; print_value(str, x); delim = ','; }; print("filename", arg.filename); print("function", arg.function); print("category", arg.category); print("M", arg.M); print("N", arg.N); print("K", arg.K); print("nnz", arg.nnz); print("block_dim", arg.block_dim); print("row_block_dimA", arg.row_block_dimA); print("col_block_dimA", arg.col_block_dimA); print("row_block_dimB", arg.row_block_dimB); print("col_block_dimB", arg.col_block_dimB); print("lda", arg.lda); print("ldb", arg.ldb); print("ldc", arg.ldc); print("batch_count", arg.batch_count); print("index_type_I", hipsparse_indextype2string(arg.index_type_I)); print("index_type_J", hipsparse_indextype2string(arg.index_type_J)); print("compute_type", hipsparse_datatype2string(arg.compute_type)); print("alpha", arg.alpha); print("alphai", arg.alphai); print("beta", arg.beta); print("betai", arg.betai); print("threshold", arg.threshold); print("percentage", arg.percentage); print("c", arg.c); print("s", arg.s); print("transA", hipsparse_operation2string(arg.transA)); print("transB", hipsparse_operation2string(arg.transB)); print("baseA", hipsparse_indexbase2string(arg.baseA)); print("baseB", hipsparse_indexbase2string(arg.baseB)); print("baseC", hipsparse_indexbase2string(arg.baseC)); print("baseD", hipsparse_indexbase2string(arg.baseD)); print("action", hipsparse_action2string(arg.action)); print("part", hipsparse_partition2string(arg.part)); print("diag_type", hipsparse_diagtype2string(arg.diag_type)); print("fill_mode", hipsparse_fillmode2string(arg.fill_mode)); print("solve_policy", hipsparse_solvepolicy2string(arg.solve_policy)); print("dirA", hipsparse_direction2string(arg.dirA)); print("orderA", hipsparse_order2string(arg.orderA)); print("orderB", hipsparse_order2string(arg.orderB)); print("orderC", hipsparse_order2string(arg.orderC)); print("formatA", hipsparse_format2string(arg.formatA)); print("formatB", hipsparse_format2string(arg.formatB)); print("csr2csc_alg", hipsparse_csr2cscalg2string(arg.csr2csc_alg)); print("dense2sparse_alg", hipsparse_densetosparsealg2string(arg.dense2sparse_alg)); print("sparse2dense_alg", hipsparse_sparsetodensealg2string(arg.sparse2dense_alg)); print("sddmm_alg", hipsparse_sddmmalg2string(arg.sddmm_alg)); print("spgemm_alg", hipsparse_spgemmalg2string(arg.spgemm_alg)); print("spmm_alg", hipsparse_spmmalg2string(arg.spmm_alg)); print("spmv_alg", hipsparse_spmvalg2string(arg.spmv_alg)); print("spsm_alg", hipsparse_spsmalg2string(arg.spsm_alg)); print("spsv_alg", hipsparse_spsvalg2string(arg.spsv_alg)); print("csr2csc_alg", arg.csr2csc_alg); print("dense2sparse_alg", arg.dense2sparse_alg); print("sparse2dense_alg", arg.sparse2dense_alg); print("sddmm_alg", arg.sddmm_alg); print("spgemm_alg", arg.spgemm_alg); print("spmm_alg", arg.spmm_alg); print("spmv_alg", arg.spmv_alg); print("spsm_alg", arg.spsm_alg); print("spsv_alg", arg.spsv_alg); print("numeric_boost", arg.numericboost); print("boosttol", arg.boosttol); print("boostval", arg.boostval); print("boostvali", arg.boostvali); print("ell_width", arg.ell_width); print("permute", arg.permute); print("gtsv_alg", arg.gtsv_alg); print("gpsv_alg", arg.gpsv_alg); print("unit_check", arg.unit_check); print("timing", arg.timing); print("iters", arg.iters); return str << " }\n"; } }; ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5583992 hipsparse/clients/include/hipsparse_arguments_support.hpp0000664000175100017510000006754015206065364024503 0ustar00jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2024-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #include #include #if(defined(CUDART_VERSION)) #define STRINGIFY(x) #x #define TOSTRING(x) STRINGIFY(x) static void print_cuda_12_0_0_to_12_5_1_support_string() { std::cout << "Warning: You are using CUDA version: " << TOSTRING(CUDART_VERSION) << " but this routine is not supported. See CUDA support table for this" << " routine below: " << std::endl; std::string table = " CUDA Version \n" "|11.7.1|11.8.0|12.0.0|12.0.1|...|12.4.1|12.5.0|12.5.1|\n" " |<--------------supported------------->| "; std::cout << table << std::endl; } static void print_cuda_11_3_1_to_12_5_1_support_string() { std::cout << "Warning: You are using CUDA version: " << TOSTRING(CUDART_VERSION) << " but this routine is not supported. See CUDA support table for this" << " routine below: " << std::endl; std::string table = " CUDA Version \n" "|11.2.2|11.3.0|11.3.1|11.4.0|...|12.4.1|12.5.0|12.5.1|\n" " |<--------------supported------------->| "; std::cout << table << std::endl; } static void print_cuda_11_2_0_to_12_5_1_support_string() { std::cout << "Warning: You are using CUDA version: " << TOSTRING(CUDART_VERSION) << " but this routine is not supported. See CUDA support table for this" << " routine below: " << std::endl; std::string table = " CUDA Version \n" "|11.1.0|11.1.1|11.2.0|11.2.1|...|12.4.1|12.5.0|12.5.1|\n" " |<--------------supported------------->| "; std::cout << table << std::endl; } static void print_cuda_10_0_0_to_12_5_1_support_string() { std::cout << "Warning: You are using CUDA version: " << TOSTRING(CUDART_VERSION) << " but this routine is not supported. See CUDA support table for this" << " routine below: " << std::endl; std::string table = " CUDA Version \n" "|10.0|10.1|10.2|....|12.4.1|12.5.0|12.5.1|...\n" "|<---------------supported-------------->| "; std::cout << table << std::endl; } static void print_cuda_10_0_0_to_11_8_0_support_string() { std::cout << "Warning: You are using CUDA version: " << TOSTRING(CUDART_VERSION) << " but this routine is not supported. See CUDA support table for this" << " routine below: " << std::endl; std::string table = " CUDA Version \n" "|10.0|10.1|10.2|....|11.7.0|11.7.1|11.8.0|12.0.0|12.0.1|...\n" "|<--------------supported--------------->| "; std::cout << table << std::endl; } static void print_cuda_10_0_0_to_10_2_0_support_string() { std::cout << "Warning: You are using CUDA version: " << TOSTRING(CUDART_VERSION) << " but this routine is not supported. See CUDA support table for this" << " routine below: " << std::endl; std::string table = " CUDA Version \n" "|10.0|10.1|10.1.1|10.1.2|10.2.0|11.0.1|11.0.2|...\n" "|<---------supported---------->| "; std::cout << table << std::endl; } #undef STRINGIFY #undef TOSTRING #endif struct routine_support { // Level 1 static bool is_axpyi_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) return true; #else return false; #endif } static bool is_doti_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) return true; #else return false; #endif } static bool is_dotci_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) return true; #else return false; #endif } static bool is_gthr_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) return true; #else return false; #endif } static bool is_gthrz_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) return true; #else return false; #endif } static bool is_roti_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) return true; #else return false; #endif } static bool is_sctr_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) return true; #else return false; #endif } // Level2 static bool is_bsrsv2_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) return true; #else return false; #endif } static bool is_coomv_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION > 10010 \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) return true; #else return false; #endif } static bool is_csrmv_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION > 10010 \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) return true; #else return false; #endif } static bool is_csrsv_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11030) return true; #else return false; #endif } static bool is_gemvi_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) return true; #else return false; #endif } static bool is_hybmv_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) return true; #else return false; #endif } // Level3 static bool is_bsrmm_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) return true; #else return false; #endif } static bool is_bsrsm2_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) return true; #else return false; #endif } static bool is_coomm_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) return true; #else return false; #endif } static bool is_cscmm_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) return true; #else return false; #endif } static bool is_csrmm_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) return true; #else return false; #endif } static bool is_coosm_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11031) return true; #else return false; #endif } static bool is_csrsm_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11031) return true; #else return false; #endif } static bool is_gemmi_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) return true; #else return false; #endif } // Extra static bool is_csrgeam_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) return true; #else return false; #endif } static bool is_csrgemm_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) return true; #else return false; #endif } // Precond static bool is_bsric02_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) return true; #else return false; #endif } static bool is_bsrilu02_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) return true; #else return false; #endif } static bool is_csric02_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) return true; #else return false; #endif } static bool is_csrilu02_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) return true; #else return false; #endif } static bool is_gtsv2_supported() { return true; } static bool is_gtsv2_nopivot_supported() { return true; } static bool is_gtsv2_strided_batch_supported() { return true; } static bool is_gtsv_interleaved_batch_supported() { return true; } static bool is_gpsv_interleaved_batch_supported() { return true; } // Conversion static bool is_bsr2csr_supported() { return true; } static bool is_csr2coo_supported() { return true; } static bool is_csr2csc_supported() { return true; } static bool is_csr2hyb_supported() { return true; } static bool is_csr2bsr_supported() { return true; } static bool is_csr2gebsr_supported() { return true; } static bool is_csr2csr_compress_supported() { return true; } static bool is_coo2csr_supported() { return true; } static bool is_hyb2csr_supported() { return true; } static bool is_csr2dense_supported() { return true; } static bool is_csc2dense_supported() { return true; } static bool is_coo2dense_supported() { return true; } static bool is_dense2csr_supported() { return true; } static bool is_dense2csc_supported() { return true; } static bool is_dense2coo_supported() { return true; } static bool is_gebsr2csr_supported() { return true; } static bool is_gebsr2gebsc_supported() { return true; } static bool is_gebsr2gebsr_supported() { return true; } // Level 1 static void print_axpyi_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_11_8_0_support_string(); #endif } static void print_doti_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_10_2_0_support_string(); #endif } static void print_dotci_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_10_2_0_support_string(); #endif } static void print_gthr_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_11_8_0_support_string(); #endif } static void print_gthrz_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_11_8_0_support_string(); #endif } static void print_roti_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_11_8_0_support_string(); #endif } static void print_sctr_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_11_8_0_support_string(); #endif } // Level 2 static void print_bsrsv2_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_coomv_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_csrmv_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_csrsv_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_11_8_0_support_string(); #endif } static void print_gemvi_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_11_8_0_support_string(); #endif } static void print_hybmv_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_10_2_0_support_string(); #endif } // Level 3 static void print_bsrmm_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_bsrsm2_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_coomm_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_cscmm_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_csrmm_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_coosm_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_11_3_1_to_12_5_1_support_string(); #endif } static void print_csrsm_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_11_3_1_to_12_5_1_support_string(); #endif } static void print_gemmi_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_11_8_0_support_string(); #endif } // Extra static void print_csrgeam_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_10_2_0_support_string(); #endif } static void print_csrgemm_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_10_2_0_support_string(); #endif } // Precond static void print_bsric02_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_bsrilu02_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_csric02_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_csrilu02_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_gtsv2_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_gtsv2_nopivot_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_gtsv2_strided_batch_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_gtsv_interleaved_batch_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_gpsv_interleaved_batch_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } // Conversion static void print_bsr2csr_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_csr2coo_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_csr2csc_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_csr2hyb_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_csr2bsr_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_csr2gebsr_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_csr2csr_compress_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_coo2csr_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_hyb2csr_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_csr2dense_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_11_2_0_to_12_5_1_support_string(); #endif } static void print_csc2dense_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_11_2_0_to_12_5_1_support_string(); #endif } static void print_coo2dense_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_11_2_0_to_12_5_1_support_string(); #endif } static void print_dense2csr_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_11_2_0_to_12_5_1_support_string(); #endif } static void print_dense2csc_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_11_2_0_to_12_5_1_support_string(); #endif } static void print_dense2coo_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_11_2_0_to_12_5_1_support_string(); #endif } static void print_gebsr2csr_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_gebsr2gebsc_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_gebsr2gebsr_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } }; struct csr2csc_alg_support { static hipsparseCsr2CscAlg_t get_default_algorithm() { #if(!defined(CUDART_VERSION)) return HIPSPARSE_CSR2CSC_ALG_DEFAULT; #else #if(CUDART_VERSION >= 12000) return HIPSPARSE_CSR2CSC_ALG_DEFAULT; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 12000) return HIPSPARSE_CSR2CSC_ALG1; #else return -1; #endif #endif } static std::string get_description() { #if(!defined(CUDART_VERSION)) return "Indicates what algorithm to use when running csr2csc. Possible choices are " "default: 0, Alg1: 1, Alg2: 2 (default:0)"; #else #if(CUDART_VERSION >= 12000) return "Indicates what algorithm to use when running csr2csc. Possible choices are " "default: 0, Alg1: 1 (default:0)"; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 12000) return "Indicates what algorithm to use when running csr2csc. Possible choices are " "default: 1, Alg1: 1, Alg2: 2 (default:1)"; #else return "No algorithm supported in selected cusparse version"; #endif #endif } static std::vector get_supported_algorithms() { #if(!defined(CUDART_VERSION)) return std::vector( {HIPSPARSE_CSR2CSC_ALG_DEFAULT, HIPSPARSE_CSR2CSC_ALG1, HIPSPARSE_CSR2CSC_ALG2}); #else #if(CUDART_VERSION >= 12000) return std::vector({HIPSPARSE_CSR2CSC_ALG_DEFAULT, HIPSPARSE_CSR2CSC_ALG1}); #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 12000) return std::vector({HIPSPARSE_CSR2CSC_ALG1, HIPSPARSE_CSR2CSC_ALG2}); #endif #endif return std::vector(); } }; struct dense2sparse_alg_support { static hipsparseDenseToSparseAlg_t get_default_algorithm() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) return HIPSPARSE_DENSETOSPARSE_ALG_DEFAULT; #else return -1; #endif } static std::string get_description() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) return "Indicates what algorithm to use when running dense2sparse. Possible choices are " "default: 0 (default:0)"; #else return "No algorithm supported in selected cusparse version"; #endif } }; struct sparse2dense_alg_support { static hipsparseSparseToDenseAlg_t get_default_algorithm() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) return HIPSPARSE_SPARSETODENSE_ALG_DEFAULT; #else return -1; #endif } static std::string get_description() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) return "Indicates what algorithm to use when running sparse2dense. Possible choices are " "default: 0 (default:0)"; #else return "No algorithm supported in selected cusparse version"; #endif } }; struct sddmm_alg_support { static hipsparseSDDMMAlg_t get_default_algorithm() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11022) return HIPSPARSE_SDDMM_ALG_DEFAULT; #else return -1; #endif } static std::string get_description() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11022) return "Indicates what algorithm to use when running sddmm. Possible choices are default: " "0 (default:0)"; #else return "No algorithm supported in selected cusparse version"; #endif } }; struct spgemm_alg_support { static hipsparseSpGEMMAlg_t get_default_algorithm() { #if(!defined(CUDART_VERSION)) return HIPSPARSE_SPGEMM_DEFAULT; #else #if(CUDART_VERSION >= 12000) return HIPSPARSE_SPGEMM_DEFAULT; #elif(CUDART_VERSION >= 11031 && CUDART_VERSION < 12000) return HIPSPARSE_SPGEMM_DEFAULT; #elif(CUDART_VERSION >= 11000) return HIPSPARSE_SPGEMM_DEFAULT; #else return -1; #endif #endif } static std::string get_description() { #if(!defined(CUDART_VERSION)) return "Indicates what algorithm to use when running spgemm. Possible choices are default: " "0, Deterministic: 1, Non-Deterministic: 2, Alg1: 3, Alg2: 4, Alg3: 5 (default:0)"; #else #if(CUDART_VERSION >= 12000) return "Indicates what algorithm to use when running spgemm. Possible choices are default: " "0, Deterministic: 1, Non-Deterministic: 2, Alg1: 3, Alg2: 4, Alg3: 5 (default:0)"; #elif(CUDART_VERSION >= 11031 && CUDART_VERSION < 12000) return "Indicates what algorithm to use when running spgemm. Possible choices are default: " "0, Deterministic: 1, Non-Deterministic: 2 (default:0)"; #elif(CUDART_VERSION >= 11000) return "Indicates what algorithm to use when running spgemm. Possible choices are default: " "0 (default:0)"; #else return "No algorithm supported in selected cusparse version"; #endif #endif } }; struct spmm_alg_support { static hipsparseSpMMAlg_t get_default_algorithm() { #if(!defined(CUDART_VERSION)) return HIPSPARSE_SPMM_ALG_DEFAULT; #else #if(CUDART_VERSION >= 12000) return HIPSPARSE_SPMM_ALG_DEFAULT; #elif(CUDART_VERSION >= 11021 && CUDART_VERSION < 12000) return HIPSPARSE_SPMM_ALG_DEFAULT; #elif(CUDART_VERSION >= 11003 && CUDART_VERSION < 11021) return HIPSPARSE_SPMM_ALG_DEFAULT; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 11003) return HIPSPARSE_MM_ALG_DEFAULT; #else return -1; #endif #endif } static std::string get_description() { #if(!defined(CUDART_VERSION)) return "Indicates what algorithm to use when running spmm. Possible choices are default: " "0, COO Alg1: 1, COO Alg2: 2, COO Alg3: 3, CSR Alg1: 4, COO Alg4: 5, CSR Alg2: 6, " "CSR Alg3: 12, Blocked ELL Alg1: 13 (default:0)"; #else #if(CUDART_VERSION >= 12000) return "Indicates what algorithm to use when running spmm. Possible choices are default: " "0, COO Alg1: 1, COO Alg2: 2, COO Alg3: 3, CSR Alg1: 4, COO Alg4: 5 CSR Alg2: 6, " "CSR Alg3: 12, Blocked ELL Alg1: 13 (default:0)"; #elif(CUDART_VERSION >= 11021 && CUDART_VERSION < 12000) return "Indicates what algorithm to use when running spmm. Possible choices are default: " "0, COO Alg1: 1, COO Alg2: 2, COO Alg3: 3, CSR Alg1: 4, COO Alg4: 5, CSR Alg2: 6, " "CSR Alg3: 12, Blocked ELL Alg1: 13 (default:0)"; #elif(CUDART_VERSION >= 11003 && CUDART_VERSION < 11021) return "Indicates what algorithm to use when running spmm. Possible choices are default: " "0, COO Alg1: 1, COO Alg2: 2, COO Alg3: 3, CSR Alg1: 4, COO Alg4: 5, CSR Alg2: 6, " "Blocked ELL Alg1: 13 (default:0)"; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 11003) return "Indicates what algorithm to use when running spmm. Possible choices are default: " "0, COO Alg1: 1, COO Alg2: 2, COO Alg3: 3, CSR Alg1: 4 (default:0)"; #else return "No algorithm supported in selected cusparse version"; #endif #endif } }; struct spmv_alg_support { static hipsparseSpMVAlg_t get_default_algorithm() { #if(!defined(CUDART_VERSION)) return HIPSPARSE_SPMV_ALG_DEFAULT; #else #if(CUDART_VERSION >= 12000) return HIPSPARSE_SPMV_ALG_DEFAULT; #elif(CUDART_VERSION >= 11021 && CUDART_VERSION < 12000) return HIPSPARSE_SPMV_ALG_DEFAULT; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 11021) return HIPSPARSE_MV_ALG_DEFAULT; #else return -1; #endif #endif } static std::string get_description() { #if(!defined(CUDART_VERSION)) return "Indicates what algorithm to use when running spmv. Possible choices are default: " "0, COO Alg1: 1, CSR Alg1: 2, CSR Alg2: 3, COO Alg2: 4 (default:0)"; #else #if(CUDART_VERSION >= 12000) return "Indicates what algorithm to use when running spmv. Possible choices are default: " "0, COO Alg1: 1, CSR Alg1: 2, CSR Alg2: 3, COO Alg2: 4 (default:0)"; #elif(CUDART_VERSION >= 11021 && CUDART_VERSION < 12000) return "Indicates what algorithm to use when running spmv. Possible choices are default: " "0, COO Alg1: 1, CSR Alg1: 2, CSR Alg2: 3, COO Alg2: 4 (default:0)"; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 11021) return "Indicates what algorithm to use when running spmv. Possible choices are default: " "0, COO Alg: 1, CSR Alg1: 2, CSR Alg2: 3 (default:0)"; #else return "No algorithm supported in selected cusparse version"; #endif #endif } }; struct spsm_alg_support { static hipsparseSpSMAlg_t get_default_algorithm() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11031) return HIPSPARSE_SPSM_ALG_DEFAULT; #else return -1; #endif } static std::string get_description() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11031) return "Indicates what algorithm to use when running spsm. Possible choices are default: 0 " "(default:0)"; #else return "No algorithm supported in selected cusparse version"; #endif } }; struct spsv_alg_support { static hipsparseSpSVAlg_t get_default_algorithm() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11030) return HIPSPARSE_SPSV_ALG_DEFAULT; #else return -1; #endif } static std::string get_description() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11030) return "Indicates what algorithm to use when running spsv. Possible choices are default: 0 " "(default:0)"; #else return "No algorithm supported in selected cusparse version"; #endif } }; ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5583992 hipsparse/clients/include/hipsparse_common.yaml0000664000175100017510000003212115206065364022330 0ustar00jenkinsjenkins# ######################################################################## # Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # # ######################################################################## # Data types are defined as either aliases to Python-recognized ctypes, # or enums defined with c_int base clases and attributes. Datatypes: - hipsparseIndexType_t: bases: [ c_int ] attr: u16: 1 i32: 2 i64: 3 - hipDataType: bases: [ c_int ] attr: f32_r: 0 f64_r: 1 f16_r: 2 i8_r: 3 f32_c: 4 f64_c: 5 u8_r: 8 i32_r: 10 u32_r: 12 - { single: f32_r, double: f64_r } - { single complex: f32_c, double complex: f64_c } - hipsparseOperation_t: bases: [ c_int ] attr: HIPSPARSE_OPERATION_NON_TRANSPOSE: 0 HIPSPARSE_OPERATION_TRANSPOSE: 1 HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE: 2 - hipsparseIndexBase_t: bases: [ c_int ] attr: HIPSPARSE_INDEX_BASE_ZERO: 0 HIPSPARSE_INDEX_BASE_ONE: 1 - hipsparseDiagType_t: bases: [ c_int ] attr: HIPSPARSE_DIAG_TYPE_NON_UNIT: 0 HIPSPARSE_DIAG_TYPE_UNIT: 1 - hipsparseFillMode_t: bases: [ c_int ] attr: HIPSPARSE_FILL_MODE_LOWER: 0 HIPSPARSE_FILL_MODE_UPPER: 1 - hipsparseAction_t: bases: [ c_int ] attr: HIPSPARSE_ACTION_SYMBOLIC: 0 HIPSPARSE_ACTION_NUMERIC: 1 - hipsparseHybPartition_t: bases: [ c_int ] attr: HIPSPARSE_HYB_PARTITION_AUTO: 0 HIPSPARSE_HYB_PARTITION_USER: 1 HIPSPARSE_HYB_PARTITION_MAX: 2 - hipsparseSolvePolicy_t: bases: [ c_int ] attr: HIPSPARSE_SOLVE_POLICY_NO_LEVEL: 0 HIPSPARSE_SOLVE_POLICY_USE_LEVEL: 1 - hipsparseDirection_t: bases: [ c_int ] attr: HIPSPARSE_DIRECTION_ROW: 0 HIPSPARSE_DIRECTION_COLUMN: 1 - hipsparseOrder_t: bases: [c_int ] attr: HIPSPARSE_ORDER_COL: 1 HIPSPARSE_ORDER_ROW: 2 - hipsparseFormat_t: bases: [c_int ] attr: HIPSPARSE_FORMAT_CSR: 1 HIPSPARSE_FORMAT_CSC: 2 HIPSPARSE_FORMAT_COO: 3 HIPSPARSE_FORMAT_COO_AOS: 4 HIPSPARSE_FORMAT_BLOCKED_ELL: 5 - hipsparseCsr2CscAlg_t: bases: [c_int ] attr: HIPSPARSE_CSR2CSC_ALG_DEFAULT: 0 HIPSPARSE_CSR2CSC_ALG1: 1 HIPSPARSE_CSR2CSC_ALG2: 2 - hipsparseDenseToSparseAlg_t: bases: [c_int ] attr: HIPSPARSE_DENSETOSPARSE_ALG_DEFAULT: 0 - hipsparseSparseToDenseAlg_t: bases: [c_int ] attr: HIPSPARSE_SPARSETODENSE_ALG_DEFAULT: 0 - hipsparseSDDMMAlg_t: bases: [c_int ] attr: HIPSPARSE_SDDMM_ALG_DEFAULT: 0 - hipsparseSpGEMMAlg_t: bases: [c_int ] attr: HIPSPARSE_SPGEMM_DEFAULT: 0 - hipsparseSpMVAlg_t: bases: [c_int ] attr: HIPSPARSE_SPMV_ALG_DEFAULT: 0 HIPSPARSE_SPMV_COO_ALG1: 1 HIPSPARSE_SPMV_CSR_ALG1: 2 HIPSPARSE_SPMV_CSR_ALG2: 3 HIPSPARSE_SPMV_COO_ALG2: 4 - hipsparseSpSVAlg_t: bases: [c_int ] attr: HIPSPARSE_SPSV_ALG_DEFAULT: 0 - hipsparseSpSMAlg_t: bases: [c_int ] attr: HIPSPARSE_SPSM_ALG_DEFAULT: 0 - hipsparseSpMMAlg_t: bases: [c_int ] attr: HIPSPARSE_SPMM_ALG_DEFAULT: 0 HIPSPARSE_SPMM_COO_ALG1: 1 HIPSPARSE_SPMM_COO_ALG2: 2 HIPSPARSE_SPMM_COO_ALG3: 3 HIPSPARSE_SPMM_COO_ALG4: 5 HIPSPARSE_SPMM_CSR_ALG1: 4 HIPSPARSE_SPMM_CSR_ALG2: 6 HIPSPARSE_SPMM_CSR_ALG3: 12 HIPSPARSE_SPMM_BLOCKED_ELL_ALG1: 13 - hipsparseSPGEMMAlg_t: bases: [c_int ] attr: HIPSPARSE_SPGEMM_DEFAULT: 0 HIPSPARSE_SPGEMM_CSR_ALG_DETERMINISTIC: 1 HIPSPARSE_SPGEMM_CSR_ALG_NONDETERMINISTIC: 2 HIPSPARSE_SPGEMM_ALG1: 3 HIPSPARSE_SPGEMM_ALG2: 4 HIPSPARSE_SPGEMM_ALG3: 5 indextype i32: &i32 - index_type_I: i32 index_type_J: i32 indextype i64i32 mixture: &i64i32 - index_type_I: i64 index_type_J: i32 indextype i64: &i64 - index_type_I: i64 index_type_J: i64 indextype i32 and i64: &i32_i64 - index_type_I: i32 index_type_J: i32 - index_type_I: i64 index_type_J: i64 indextype i32 i64i32 mixture and i64: &i32i32_i64i32_i64i64 - index_type_I: i32 index_type_J: i32 - index_type_I: i64 index_type_J: i32 - index_type_I: i64 index_type_J: i64 Real precisions: &real_precisions - &int8_int8_int32_xyt_precision { x_type: i8_r, y_type: i8_r, compute_type: i32_r } - &int8_int8_float32_xyt_precision { x_type: i8_r, y_type: i8_r, compute_type: f32_r } - &float16_float16_float32_xyt_precision { x_type: f16_r, y_type: f16_r, compute_type: f32_r } - &int8_int8_int32_int32_axyt_precision { a_type: i8_r, x_type: i8_r, y_type: i32_r, compute_type: i32_r } - &int8_int8_float32_float32_axyt_precision { a_type: i8_r, x_type: i8_r, y_type: f32_r, compute_type: f32_r } - &int8_int8_int32_int32_abct_precision { a_type: i8_r, b_type: i8_r, c_type: i32_r, compute_type: i32_r } - &int8_int8_float32_float32_abct_precision { a_type: i8_r, b_type: i8_r, c_type: f32_r, compute_type: f32_r } - &float16_float16_float32_float32_abct_precision { a_type: f16_r, b_type: f16_r, c_type: f32_r, compute_type: f32_r } - &int8_precision { a_type: i8_r, b_type: i8_r, c_type: i8_r, x_type: i8_r, y_type: i8_r, compute_type: i8_r } - &half_precision { a_type: f16_r, b_type: f16_r, c_type: f16_r, x_type: f16_r, y_type: f16_r, compute_type: f16_r } - &single_precision { a_type: f32_r, b_type: f32_r, c_type: f32_r, x_type: f32_r, y_type: f32_r, compute_type: f32_r } - &double_precision { a_type: f64_r, b_type: f64_r, c_type: f64_r, x_type: f64_r, y_type: f64_r, compute_type: f64_r } - &float32_float64_float64_float64 { a_type: f32_r, x_type: f64_r, y_type: f64_r, compute_type: f64_r } Complex precisions: &complex_precisions - &float32_cmplx32_cmplx32_cmplx32_axyt_precision { a_type: f32_r, x_type: f32_c, y_type: f32_c, compute_type: f32_c } - &float64_cmplx64_cmplx64_cmplx64_axyt_precision { a_type: f64_r, x_type: f64_c, y_type: f64_c, compute_type: f64_c } - &single_precision_complex { a_type: f32_c, b_type: f32_c, c_type: f32_c, x_type: f32_c, y_type: f32_c, compute_type: f32_c } - &double_precision_complex { a_type: f64_c, b_type: f64_c, c_type: f64_c, x_type: f64_c, y_type: f64_c, compute_type: f64_c } - &cmplx32_cmplx64_cmplx64_cmplx64 { a_type: f32_c, x_type: f64_c, y_type: f64_c, compute_type: f64_c } C precisions real: &single_only_precisions - *single_precision C precisions real: &double_only_precisions - *double_precision C precisions real: &single_double_precisions - *single_precision - *double_precision C precisions complex: &single_only_precisions_complex - *single_precision_complex C precisions complex: &double_only_precisions_complex - *double_precision_complex C precisions complex: &single_double_precisions_complex - *single_precision_complex - *double_precision_complex C precisions complex and real: &single_double_precisions_complex_real - *single_precision - *double_precision - *single_precision_complex - *double_precision_complex C precisions complex and real: &single_only_precisions_complex_real - *single_precision - *single_precision_complex C precisions complex and real: &double_only_precisions_complex_real - *double_precision - *double_precision_complex # The Arguments struct passed directly to C++. See hipsparse_arguments.hpp. # The order of the entries is significant, so it can't simply be a dictionary. # The types on the RHS are eval'd for Python-recognized types including ctypes # and datatypes defined in Datatypes above. T*n represents array of length n. Arguments: - M: c_int - N: c_int - K: c_int - nnz: c_int - block_dim: c_int - row_block_dimA: c_int - col_block_dimA: c_int - row_block_dimB: c_int - col_block_dimB: c_int - lda: c_int - ldb: c_int - ldc: c_int - batch_count: c_int - index_type_I: hipsparseIndexType_t - index_type_J: hipsparseIndexType_t - compute_type: hipDataType - alpha: c_double - alphai: c_double - beta: c_double - betai: c_double - threshold: c_double - percentage: c_double - c: c_double - s: c_double - transA: hipsparseOperation_t - transB: hipsparseOperation_t - baseA: hipsparseIndexBase_t - baseB: hipsparseIndexBase_t - baseC: hipsparseIndexBase_t - baseD: hipsparseIndexBase_t - action: hipsparseAction_t - part: hipsparseHybPartition_t - diag_type: hipsparseDiagType_t - fill_mode: hipsparseFillMode_t - solve_policy: hipsparseSolvePolicy_t - dirA: hipsparseDirection_t - orderA: hipsparseOrder_t - orderB: hipsparseOrder_t - orderC: hipsparseOrder_t - formatA: hipsparseFormat_t - formatB: hipsparseFormat_t - csr2csc_alg: hipsparseCsr2CscAlg_t - dense2sparse_alg: hipsparseDenseToSparseAlg_t - sparse2dense_alg: hipsparseSparseToDenseAlg_t - sddmm_alg: hipsparseSDDMMAlg_t - spgemm_alg: hipsparseSpGEMMAlg_t - spmm_alg: hipsparseSpMMAlg_t - spmv_alg: hipsparseSpMVAlg_t - spsm_alg: hipsparseSpSMAlg_t - spsv_alg: hipsparseSpSVAlg_t - numericboost: c_int - boosttol: c_double - boostval: c_double - boostvali: c_double - ell_width: c_int - permute: c_int - gtsv_alg: c_int - gpsv_alg: c_int - unit_check: c_int - timing: c_int - iters: c_int - filename: c_char*192 - function: c_char*64 - category: c_char*32 # These named dictionary lists [ {dict1}, {dict2}, etc. ] supply subsets of # test arguments in a structured way. The dictionaries are applied to the test # one at a time, to generate combinations. If one of this table's entries is # a dictionary of size one, it means that the argument named by its key takes # on values paired with argument named by its value. For example: # # - function: precision # # when used with the code: # # function: # func1: prec1 # func2: prec2 # func3: prec3 # # causes (function, precision) to take on the values (func1, prec1), # (func2, prec2), (func3, prec3), etc. Dictionary lists to expand: - arguments - M_N - M_N_K - transA_transB - alpha_beta - alpha_alphai - beta_betai - alphai_betai - boostval_boostvali - indextype - precision - function: precision # In case an array argument needs to be passed directly to C as an array, # it needs to be listed here to avoid being expanded into multiple test # cases with each of its elements. Lists to not expand: - e.g., an array argument not to be expanded # Defaults Defaults: M: -1 N: -1 K: -1 nnz: -1 block_dim: 2 row_block_dimA: 2 col_block_dimA: 2 row_block_dimB: 2 col_block_dimB: 2 lda: 1 ldb: 1 ldc: 1 batch_count: -1 index_type_I: i32 index_type_J: i32 compute_type: f32_r alpha: 1.0 alphai: 0.0 beta: 0.0 betai: 0.0 threshold: 1.0 percentage: 0.0 c: 1.0 s: 1.0 transA: HIPSPARSE_OPERATION_NON_TRANSPOSE transB: HIPSPARSE_OPERATION_NON_TRANSPOSE baseA: HIPSPARSE_INDEX_BASE_ZERO baseB: HIPSPARSE_INDEX_BASE_ZERO baseC: HIPSPARSE_INDEX_BASE_ZERO baseD: HIPSPARSE_INDEX_BASE_ZERO action: HIPSPARSE_ACTION_NUMERIC part: HIPSPARSE_HYB_PARTITION_AUTO diag_type: HIPSPARSE_DIAG_TYPE_NON_UNIT fill_mode: HIPSPARSE_FILL_MODE_LOWER solve_policy: HIPSPARSE_SOLVE_POLICY_USE_LEVEL dirA: HIPSPARSE_DIRECTION_ROW orderA: HIPSPARSE_ORDER_COL orderB: HIPSPARSE_ORDER_COL orderC: HIPSPARSE_ORDER_COL formatA: HIPSPARSE_FORMAT_CSR formatB: HIPSPARSE_FORMAT_CSR csr2csc_alg: HIPSPARSE_CSR2CSC_ALG_DEFAULT dense2sparse_alg: HIPSPARSE_DENSETOSPARSE_ALG_DEFAULT sparse2dense_alg: HIPSPARSE_SPARSETODENSE_ALG_DEFAULT sddmm_alg: HIPSPARSE_SDDMM_ALG_DEFAULT spgemm_alg: HIPSPARSE_SPGEMM_DEFAULT spmm_alg: HIPSPARSE_SPMM_ALG_DEFAULT spmv_alg: HIPSPARSE_SPMV_ALG_DEFAULT spsm_alg: HIPSPARSE_SPSM_ALG_DEFAULT spsv_alg: HIPSPARSE_SPSV_ALG_DEFAULT numericboost: 0 boosttol: 0.0 boostval: 1.0 boostvali: 0.0 ell_width: 0 permute: 0 gtsv_alg: 0 gpsv_alg: 0 unit_check: 1 timing: 0 iters: 10 filename: '*' function: '*' category: '*'././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5583992 hipsparse/clients/include/hipsparse_data.hpp0000664000175100017510000001131715206065364021602 0ustar00jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef HIPSPARSE_DATA_HPP #define HIPSPARSE_DATA_HPP #include "hipsparse_arguments.hpp" #include "hipsparse_test_cleanup.hpp" #include #include #include #include #include #include // Class used to read Arguments data into the tests class HipSPARSE_TestData { // data filename static auto& filename() { static std::string filename = "(Uninitialized data. HipSPARSE_TestData::set_filename needs to be called first.)"; return filename; } // filter iterator class iterator : public std::istream_iterator { bool (*const filter)(const Arguments&) = nullptr; // Skip entries for which filter is false void skip_filter() { if(filter) while(*this != std::istream_iterator{} && !filter(**this)) ++*static_cast*>(this); } public: // Constructor takes a filter and iterator explicit iterator(bool filter_(const Arguments&), std::istream_iterator iter) : std::istream_iterator(iter) , filter(filter_) { skip_filter(); } // Default end iterator and nullptr filter iterator() = default; // Preincrement iterator operator with filtering iterator& operator++() { ++*static_cast*>(this); skip_filter(); return *this; } // We do not need a postincrement iterator operator // We delete it here so that the base class's isn't silently called // To implement it, use "auto old = *this; ++*this; return old;" iterator operator++(int) = delete; }; public: // Initialize filename, optionally removing it at exit static void set_filename(std::string name, bool remove_atexit = false) { filename() = std::move(name); if(remove_atexit) { auto cleanup = [] { remove(filename().c_str()); }; atexit(cleanup); auto err = at_quick_exit(cleanup); if(err) { } } } // begin() iterator which accepts an optional filter. static iterator begin(bool filter(const Arguments&) = nullptr) { static std::ifstream* ifs; // If this is the first time, or after test_cleanup::cleanup() has been called if(!ifs) { // Allocate a std::ifstream and register it to be deleted during cleanup ifs = test_cleanup::allocate(&ifs, filename(), std::ifstream::binary); if(!ifs || ifs->fail()) { std::cerr << "Cannot open " << filename() << ": " << strerror(errno) << std::endl; exit(EXIT_FAILURE); } } // We re-seek the file back to position 0 ifs->clear(); ifs->seekg(0); // Validate the data file format Arguments::validate(*ifs); // We create a filter iterator which will choose only the test cases we want right now. // This is to preserve Gtest structure while not creating no-op tests which "always pass". return iterator(filter, std::istream_iterator(*ifs)); } // end() iterator static iterator end() { return {}; } }; #endif // HIPSPARSE_DATA_HPP././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5583992 hipsparse/clients/include/hipsparse_datatype2string.hpp0000664000175100017510000003625215206065364024022 0ustar00jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2019-2024 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #include #include constexpr auto hipsparse_indextype2string(hipsparseIndexType_t type) { switch(type) { case HIPSPARSE_INDEX_16U: return "u16"; case HIPSPARSE_INDEX_32I: return "i32"; case HIPSPARSE_INDEX_64I: return "i64"; } return "invalid"; } constexpr auto hipsparse_datatype2string(hipDataType type) { switch(type) { case HIP_R_32F: return "f32_r"; case HIP_R_64F: return "f64_r"; case HIP_C_32F: return "f32_c"; case HIP_C_64F: return "f64_c"; default: return "invalid"; } } constexpr auto hipsparse_indexbase2string(hipsparseIndexBase_t base) { switch(base) { case HIPSPARSE_INDEX_BASE_ZERO: return "0b"; case HIPSPARSE_INDEX_BASE_ONE: return "1b"; } return "invalid"; } constexpr auto hipsparse_operation2string(hipsparseOperation_t trans) { switch(trans) { case HIPSPARSE_OPERATION_NON_TRANSPOSE: return "NT"; case HIPSPARSE_OPERATION_TRANSPOSE: return "T"; case HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE: return "CT"; } return "invalid"; } constexpr auto hipsparse_direction2string(hipsparseDirection_t direction) { switch(direction) { case HIPSPARSE_DIRECTION_ROW: return "row"; case HIPSPARSE_DIRECTION_COLUMN: return "column"; } return "invalid"; } #if(!defined(CUDART_VERSION)) constexpr auto hipsparse_order2string(hipsparseOrder_t order) { switch(order) { case HIPSPARSE_ORDER_ROW: return "row"; case HIPSPARSE_ORDER_COL: return "col"; } return "invalid"; } #else #if(CUDART_VERSION >= 11000) constexpr auto hipsparse_order2string(hipsparseOrder_t order) { switch(order) { case HIPSPARSE_ORDER_ROW: return "row"; case HIPSPARSE_ORDER_COL: return "col"; } return "invalid"; } #elif(CUDART_VERSION >= 10010) constexpr auto hipsparse_order2string(hipsparseOrder_t order) { switch(order) { case HIPSPARSE_ORDER_COL: return "col"; } return "invalid"; } #endif #endif #if(!defined(CUDART_VERSION)) constexpr auto hipsparse_format2string(hipsparseFormat_t format) { switch(format) { case HIPSPARSE_FORMAT_COO: return "coo"; case HIPSPARSE_FORMAT_COO_AOS: return "coo_aos"; case HIPSPARSE_FORMAT_CSR: return "csr"; case HIPSPARSE_FORMAT_CSC: return "csc"; case HIPSPARSE_FORMAT_BLOCKED_ELL: return "bell"; } return "invalid"; } #else #if(CUDART_VERSION >= 12000) constexpr auto hipsparse_format2string(hipsparseFormat_t format) { switch(format) { case HIPSPARSE_FORMAT_COO: return "coo"; case HIPSPARSE_FORMAT_CSR: return "csr"; case HIPSPARSE_FORMAT_CSC: return "csc"; case HIPSPARSE_FORMAT_BLOCKED_ELL: return "bell"; } return "invalid"; } #elif(CUDART_VERSION >= 11021 && CUDART_VERSION < 12000) constexpr auto hipsparse_format2string(hipsparseFormat_t format) { switch(format) { case HIPSPARSE_FORMAT_COO: return "coo"; case HIPSPARSE_FORMAT_COO_AOS: return "coo_aos"; case HIPSPARSE_FORMAT_CSR: return "csr"; case HIPSPARSE_FORMAT_CSC: return "csc"; case HIPSPARSE_FORMAT_BLOCKED_ELL: return "bell"; } return "invalid"; } #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 11021) constexpr auto hipsparse_format2string(hipsparseFormat_t format) { switch(format) { case HIPSPARSE_FORMAT_COO: return "coo"; case HIPSPARSE_FORMAT_COO_AOS: return "coo_aos"; case HIPSPARSE_FORMAT_CSR: return "csr"; } return "invalid"; } #endif #endif constexpr auto hipsparse_action2string(hipsparseAction_t action) { switch(action) { case HIPSPARSE_ACTION_SYMBOLIC: return "sym"; case HIPSPARSE_ACTION_NUMERIC: return "num"; } return "invalid"; } constexpr auto hipsparse_partition2string(hipsparseHybPartition_t part) { switch(part) { case HIPSPARSE_HYB_PARTITION_AUTO: return "auto"; case HIPSPARSE_HYB_PARTITION_USER: return "user"; case HIPSPARSE_HYB_PARTITION_MAX: return "max"; } return "invalid"; } constexpr auto hipsparse_diagtype2string(hipsparseDiagType_t diag_type) { switch(diag_type) { case HIPSPARSE_DIAG_TYPE_NON_UNIT: return "ND"; case HIPSPARSE_DIAG_TYPE_UNIT: return "UD"; } return "invalid"; } constexpr auto hipsparse_fillmode2string(hipsparseFillMode_t fill_mode) { switch(fill_mode) { case HIPSPARSE_FILL_MODE_LOWER: return "L"; case HIPSPARSE_FILL_MODE_UPPER: return "U"; } return "invalid"; } constexpr auto hipsparse_solvepolicy2string(hipsparseSolvePolicy_t policy) { switch(policy) { case HIPSPARSE_SOLVE_POLICY_NO_LEVEL: return "no_level"; case HIPSPARSE_SOLVE_POLICY_USE_LEVEL: return "use_level"; } return "invalid"; } #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11022) constexpr auto hipsparse_sddmmalg2string(hipsparseSDDMMAlg_t alg) { switch(alg) { case HIPSPARSE_SDDMM_ALG_DEFAULT: return "default"; } return "invalid"; } #endif #if(!defined(CUDART_VERSION)) constexpr auto hipsparse_spgemmalg2string(hipsparseSpGEMMAlg_t alg) { switch(alg) { case HIPSPARSE_SPGEMM_DEFAULT: return "default"; case HIPSPARSE_SPGEMM_CSR_ALG_DETERMINISTIC: return "deterministic"; case HIPSPARSE_SPGEMM_CSR_ALG_NONDETERMINISTIC: return "nondeterministic"; case HIPSPARSE_SPGEMM_ALG1: return "alg1"; case HIPSPARSE_SPGEMM_ALG2: return "alg2"; case HIPSPARSE_SPGEMM_ALG3: return "alg3"; } return "invalid"; } #else #if(CUDART_VERSION >= 12000) constexpr auto hipsparse_spgemmalg2string(hipsparseSpGEMMAlg_t alg) { switch(alg) { case HIPSPARSE_SPGEMM_DEFAULT: return "default"; case HIPSPARSE_SPGEMM_CSR_ALG_DETERMINISTIC: return "deterministic"; case HIPSPARSE_SPGEMM_CSR_ALG_NONDETERMINISTIC: return "nondeterministic"; case HIPSPARSE_SPGEMM_ALG1: return "alg1"; case HIPSPARSE_SPGEMM_ALG2: return "alg2"; case HIPSPARSE_SPGEMM_ALG3: return "alg3"; } return "invalid"; } #elif(CUDART_VERSION >= 11031 && CUDART_VERSION < 12000) constexpr auto hipsparse_spmmalg2string(hipsparseSpGEMMAlg_t alg) { switch(alg) { case HIPSPARSE_SPGEMM_DEFAULT: return "default"; case HIPSPARSE_SPGEMM_CSR_ALG_DETERMINISTIC: return "deterministic"; case HIPSPARSE_SPGEMM_CSR_ALG_NONDETERMINISTIC: return "nondeterministic"; } return "invalid"; } #elif(CUDART_VERSION >= 11000) constexpr auto hipsparse_spmmalg2string(hipsparseSpGEMMAlg_t alg) { switch(alg) { case HIPSPARSE_SPGEMM_DEFAULT: return "default"; } return "invalid"; } #endif #endif #if(!defined(CUDART_VERSION)) constexpr auto hipsparse_spmmalg2string(hipsparseSpMMAlg_t alg) { switch(alg) { case HIPSPARSE_SPMM_ALG_DEFAULT: return "default"; case HIPSPARSE_SPMM_COO_ALG1: return "coo_alg1"; case HIPSPARSE_SPMM_COO_ALG2: return "coo_alg2"; case HIPSPARSE_SPMM_COO_ALG3: return "coo_alg3"; case HIPSPARSE_SPMM_COO_ALG4: return "coo_alg4"; case HIPSPARSE_SPMM_CSR_ALG1: return "csr_alg1"; case HIPSPARSE_SPMM_CSR_ALG2: return "csr_alg2"; case HIPSPARSE_SPMM_CSR_ALG3: return "csr_alg3"; case HIPSPARSE_SPMM_BLOCKED_ELL_ALG1: return "bell_alg1"; } return "invalid"; } #else #if(CUDART_VERSION >= 12000) constexpr auto hipsparse_spmmalg2string(hipsparseSpMMAlg_t alg) { switch(alg) { case HIPSPARSE_SPMM_ALG_DEFAULT: return "default"; case HIPSPARSE_SPMM_COO_ALG1: return "coo_alg1"; case HIPSPARSE_SPMM_COO_ALG2: return "coo_alg2"; case HIPSPARSE_SPMM_COO_ALG3: return "coo_alg3"; case HIPSPARSE_SPMM_COO_ALG4: return "coo_alg4"; case HIPSPARSE_SPMM_CSR_ALG1: return "csr_alg1"; case HIPSPARSE_SPMM_CSR_ALG2: return "csr_alg2"; case HIPSPARSE_SPMM_CSR_ALG3: return "csr_alg3"; case HIPSPARSE_SPMM_BLOCKED_ELL_ALG1: return "bell_alg1"; } return "invalid"; } #elif(CUDART_VERSION >= 11021 && CUDART_VERSION < 12000) constexpr auto hipsparse_spmmalg2string(hipsparseSpMMAlg_t alg) { switch(alg) { case HIPSPARSE_SPMM_ALG_DEFAULT: return "default"; case HIPSPARSE_SPMM_COO_ALG1: return "coo_alg1"; case HIPSPARSE_SPMM_COO_ALG2: return "coo_alg2"; case HIPSPARSE_SPMM_COO_ALG3: return "coo_alg3"; case HIPSPARSE_SPMM_COO_ALG4: return "coo_alg4"; case HIPSPARSE_SPMM_CSR_ALG1: return "csr_alg1"; case HIPSPARSE_SPMM_CSR_ALG2: return "csr_alg2"; case HIPSPARSE_SPMM_CSR_ALG3: return "csr_alg3"; case HIPSPARSE_SPMM_BLOCKED_ELL_ALG1: return "bell_alg1"; } return "invalid"; } #elif(CUDART_VERSION >= 11003 && CUDART_VERSION < 11021) constexpr auto hipsparse_spmmalg2string(hipsparseSpMMAlg_t alg) { switch(alg) { case HIPSPARSE_SPMM_ALG_DEFAULT: return "default"; case HIPSPARSE_SPMM_COO_ALG1: return "coo_alg1"; case HIPSPARSE_SPMM_COO_ALG2: return "coo_alg2"; case HIPSPARSE_SPMM_COO_ALG3: return "coo_alg3"; case HIPSPARSE_SPMM_COO_ALG4: return "coo_alg4"; case HIPSPARSE_SPMM_CSR_ALG1: return "csr_alg1"; case HIPSPARSE_SPMM_CSR_ALG2: return "csr_alg2"; case HIPSPARSE_SPMM_BLOCKED_ELL_ALG1: return "bell_alg1"; } return "invalid"; } #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 11003) constexpr auto hipsparse_spmmalg2string(hipsparseSpMMAlg_t alg) { switch(alg) { case HIPSPARSE_MM_ALG_DEFAULT: return "default"; case HIPSPARSE_COOMM_ALG1: return "coo_alg1"; case HIPSPARSE_COOMM_ALG2: return "coo_alg2"; case HIPSPARSE_COOMM_ALG3: return "coo_alg3"; case HIPSPARSE_CSRMM_ALG1: return "csr_alg1"; } return "invalid"; } #endif #endif #if(!defined(CUDART_VERSION)) constexpr auto hipsparse_spmvalg2string(hipsparseSpMVAlg_t alg) { switch(alg) { case HIPSPARSE_SPMV_ALG_DEFAULT: return "default"; case HIPSPARSE_SPMV_COO_ALG1: return "coo_alg1"; case HIPSPARSE_SPMV_COO_ALG2: return "coo_alg2"; case HIPSPARSE_SPMV_CSR_ALG1: return "csr_alg1"; case HIPSPARSE_SPMV_CSR_ALG2: return "csr_alg2"; } return "invalid"; } #else #if(CUDART_VERSION >= 12000) constexpr auto hipsparse_spmvalg2string(hipsparseSpMVAlg_t alg) { switch(alg) { case HIPSPARSE_SPMV_ALG_DEFAULT: return "default"; case HIPSPARSE_SPMV_COO_ALG1: return "coo_alg1"; case HIPSPARSE_SPMV_COO_ALG2: return "coo_alg2"; case HIPSPARSE_SPMV_CSR_ALG1: return "csr_alg1"; case HIPSPARSE_SPMV_CSR_ALG2: return "csr_alg2"; } return "invalid"; } #elif(CUDART_VERSION >= 11021 && CUDART_VERSION < 12000) constexpr auto hipsparse_spmvalg2string(hipsparseSpMVAlg_t alg) { switch(alg) { case HIPSPARSE_SPMV_ALG_DEFAULT: return "default"; case HIPSPARSE_SPMV_COO_ALG1: return "coo_alg1"; case HIPSPARSE_SPMV_COO_ALG2: return "coo_alg2"; case HIPSPARSE_SPMV_CSR_ALG1: return "csr_alg1"; case HIPSPARSE_SPMV_CSR_ALG2: return "csr_alg2"; } return "invalid"; } #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 11021) constexpr auto hipsparse_spmvalg2string(hipsparseSpMVAlg_t alg) { switch(alg) { case HIPSPARSE_MV_ALG_DEFAULT: return "default"; case HIPSPARSE_COOMV_ALG: return "coo_alg1"; case HIPSPARSE_CSRMV_ALG1: return "csr_alg1"; case HIPSPARSE_CSRMV_ALG2: return "csr_alg2"; } return "invalid"; } #endif #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11031) constexpr auto hipsparse_spsmalg2string(hipsparseSpSMAlg_t alg) { switch(alg) { case HIPSPARSE_SPSM_ALG_DEFAULT: return "default"; } return "invalid"; } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11030) constexpr auto hipsparse_spsvalg2string(hipsparseSpSVAlg_t alg) { switch(alg) { case HIPSPARSE_SPSV_ALG_DEFAULT: return "default"; } return "invalid"; } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) constexpr auto hipsparse_sparsetodensealg2string(hipsparseSparseToDenseAlg_t alg) { switch(alg) { case HIPSPARSE_SPARSETODENSE_ALG_DEFAULT: return "default"; } return "invalid"; } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) constexpr auto hipsparse_densetosparsealg2string(hipsparseDenseToSparseAlg_t alg) { switch(alg) { case HIPSPARSE_DENSETOSPARSE_ALG_DEFAULT: return "default"; } return "invalid"; } #endif #if(!defined(CUDART_VERSION)) constexpr auto hipsparse_csr2cscalg2string(hipsparseCsr2CscAlg_t alg) { switch(alg) { case HIPSPARSE_CSR2CSC_ALG_DEFAULT: return "default"; case HIPSPARSE_CSR2CSC_ALG1: return "alg1"; case HIPSPARSE_CSR2CSC_ALG2: return "alg2"; } return "invalid"; } #else #if(CUDART_VERSION >= 12000) constexpr auto hipsparse_csr2cscalg2string(hipsparseCsr2CscAlg_t alg) { switch(alg) { case HIPSPARSE_CSR2CSC_ALG_DEFAULT: return "default"; case HIPSPARSE_CSR2CSC_ALG1: return "alg1"; } return "invalid"; } #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 12000) constexpr auto hipsparse_csr2cscalg2string(hipsparseCsr2CscAlg_t alg) { switch(alg) { case HIPSPARSE_CSR2CSC_ALG1: return "alg1"; case HIPSPARSE_CSR2CSC_ALG2: return "alg2"; } return "invalid"; } #endif #endif ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5583992 hipsparse/clients/include/hipsparse_parse_data.hpp0000664000175100017510000000300615206065364022770 0ustar00jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef HIPSPARSE_PARSE_DATA_HPP #define HIPSPARSE_PARSE_DATA_HPP #include bool hipsparse_parse_data(int& argc, char** argv, const std::string& default_file = ""); #endif // HIPSPARSE_PARSE_DATA_HPP././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5583992 hipsparse/clients/include/hipsparse_template.yaml0000664000175100017510000000254615206065364022663 0ustar00jenkinsjenkins# ######################################################################## # Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # # ######################################################################## # Template used to process YAML from log files --- include: hipsparse_common.yaml Functions: Tests:././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5583992 hipsparse/clients/include/hipsparse_test.hpp0000664000175100017510000002025415206065364021650 0ustar00jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef HIPSPARSE_TEST_HPP #define HIPSPARSE_TEST_HPP #include "hipsparse_arguments.hpp" #include "hipsparse_test_cleanup.hpp" #include #include #include #include #include #include #include #ifdef GOOGLE_TEST #include // The tests are instantiated by filtering through the HipSPARSE_Data stream // The filter is by category and by the type_filter() and function_filter() // functions in the testclass #define INSTANTIATE_TEST_CATEGORY(testclass, categ0ry) \ INSTANTIATE_TEST_SUITE_P( \ categ0ry, \ testclass, \ testing::ValuesIn(HipSPARSE_TestData::begin([](const Arguments& arg) { \ return !strcmp(arg.category, #categ0ry) \ && testclass::type_filter(arg) \ && testclass::function_filter(arg); \ }), \ HipSPARSE_TestData::end()), \ testclass::PrintToStringParamName()); #if defined(GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST) #define HIPSPARSE_ALLOW_UNINSTANTIATED_GTEST(testclass) \ GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(testclass); #else #define HIPSPARSE_ALLOW_UNINSTANTIATED_GTEST(testclass) #endif // Instantiate all test categories #define INSTANTIATE_TEST_CATEGORIES(testclass) \ HIPSPARSE_ALLOW_UNINSTANTIATED_GTEST(testclass) \ INSTANTIATE_TEST_CATEGORY(testclass, quick) \ INSTANTIATE_TEST_CATEGORY(testclass, pre_checkin) \ INSTANTIATE_TEST_CATEGORY(testclass, nightly) \ INSTANTIATE_TEST_CATEGORY(testclass, stress) \ INSTANTIATE_TEST_CATEGORY(testclass, known_bug) /* ============================================================================================ */ /*! \brief Normalized test name to conform to Google Tests */ // Template parameter is used to generate multiple instantiations template class HipSPARSE_TestName { std::ostringstream str; static auto& get_table() { // Placed inside function to avoid dependency on initialization order static std::unordered_map* table = test_cleanup::allocate(&table); return *table; } public: // Convert stream to normalized Google Test name // rvalue reference qualified so that it can only be called once // The name should only be generated once before the stream is destroyed operator std::string() && { // This table is private to each instantation of HipSPARSE_TestName auto& table = get_table(); std::string name(str.str()); if(name == "") name = "1"; // Warn about unset letter parameters if(name.find('*') != name.npos) fputs("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" "Warning: Character * found in name." " This means a required letter parameter\n" "(e.g., transA, diag, etc.) has not been set in the YAML file." " Check the YAML file.\n" "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n", stderr); // Replace non-alphanumeric characters with letters std::replace(name.begin(), name.end(), '-', 'n'); // minus std::replace(name.begin(), name.end(), '.', 'p'); // decimal point // Complex (A,B) is replaced with ArBi name.erase(std::remove(name.begin(), name.end(), '('), name.end()); std::replace(name.begin(), name.end(), ',', 'r'); std::replace(name.begin(), name.end(), ')', 'i'); // If parameters are repeated, append an incrementing suffix auto p = table.find(name); if(p != table.end()) name += "_t" + std::to_string(++p->second); else table[name] = 1; return name; } // Stream output operations template // Lvalue LHS friend HipSPARSE_TestName& operator<<(HipSPARSE_TestName& name, U&& obj) { name.str << std::forward(obj); return name; } template // Rvalue LHS friend HipSPARSE_TestName&& operator<<(HipSPARSE_TestName&& name, U&& obj) { name.str << std::forward(obj); return std::move(name); } HipSPARSE_TestName() = default; HipSPARSE_TestName(const HipSPARSE_TestName&) = delete; HipSPARSE_TestName& operator=(const HipSPARSE_TestName&) = delete; }; // ---------------------------------------------------------------------------- // HipSPARSE_Test base class. All non-legacy hipSPARSE Google tests derive from it. // It defines a type_filter_functor() and a PrintToStringParamName class // which calls name_suffix() in the derived class to form the test name suffix. // ---------------------------------------------------------------------------- template class FILTER> class HipSPARSE_Test : public testing::TestWithParam { protected: // This template functor returns true if the type arguments are valid. // It converts a FILTER specialization to bool to test type matching. template struct type_filter_functor { bool operator()(const Arguments&) { return static_cast(FILTER{}); } }; public: // Wrapper functor class which calls name_suffix() struct PrintToStringParamName { std::string operator()(const testing::TestParamInfo& info) const { return TEST::name_suffix(info.param); } }; }; #endif // GOOGLE_TEST // ---------------------------------------------------------------------------- // Error case which returns false when converted to bool. A void specialization // of the FILTER class template above, should be derived from this class, in // order to indicate that the type combination is invalid. // ---------------------------------------------------------------------------- struct hipsparse_test_invalid { // Return false to indicate the type combination is invalid, for filtering explicit operator bool() { return false; } // If this specialization is actually called, print fatal error message void operator()(const Arguments&) { static constexpr char msg[] = "Internal error: Test called with invalid types\n"; #ifdef GOOGLE_TEST FAIL() << msg; #else fputs(msg, stderr); exit(EXIT_FAILURE); #endif } }; #endif // HIPSPARSE_TEST_HPP././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5593991 hipsparse/clients/include/hipsparse_test_cleanup.hpp0000664000175100017510000000445515206065364023364 0ustar00jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef HIPSPARSE_TEST_CLEANUP_HPP #define HIPSPARSE_TEST_CLEANUP_HPP #include #include /*! \brief Test cleanup handler. Frees memory or performs other cleanup at specified points in program. */ class test_cleanup { static auto& stack() { // Placed inside function to avoid dependency on initialization order static std::stack> stack; return stack; } public: // Run all cleanup handlers pushed so far, in LIFO order static void cleanup() { while(!stack().empty()) { stack().top()(); stack().pop(); } } // Create an object and register a cleanup handler template static T* allocate(T** ptr, Args&&... args) { *ptr = nullptr; stack().push([=] { delete *ptr; *ptr = nullptr; }); return new T(std::forward(args)...); } }; #endif // HIPSPARSE_TEST_CLEANUP_HPP././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5593991 hipsparse/clients/include/hipsparse_test_unique_ptr.hpp0000664000175100017510000002413015206065364024120 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef GUARD_HIPSPARSE_MANAGE_PTR #define GUARD_HIPSPARSE_MANAGE_PTR #include "arg_check.hpp" #include #include #include #include #define PRINT_IF_HIP_ERROR(INPUT_STATUS_FOR_CHECK) \ { \ hipError_t TMP_STATUS_FOR_CHECK = INPUT_STATUS_FOR_CHECK; \ if(TMP_STATUS_FOR_CHECK != hipSuccess) \ { \ fprintf(stderr, \ "hip error code: %d at %s:%d\n", \ TMP_STATUS_FOR_CHECK, \ __FILE__, \ __LINE__); \ } \ } namespace hipsparse_test { // device_malloc wraps hipMalloc and provides same API as malloc static void* device_malloc(size_t byte_size) { void* pointer; PRINT_IF_HIP_ERROR(hipMalloc(&pointer, byte_size)); return pointer; } // device_free wraps hipFree and provides same API as free static void device_free(void* ptr) { PRINT_IF_HIP_ERROR(hipFree(ptr)); } struct handle_struct { hipsparseHandle_t handle; handle_struct() { hipsparseStatus_t status = hipsparseCreate(&handle); verify_hipsparse_status_success(status, "ERROR: handle_struct constructor"); } ~handle_struct() { hipsparseStatus_t status = hipsparseDestroy(handle); verify_hipsparse_status_success(status, "ERROR: handle_struct destructor"); } }; struct descr_struct { hipsparseMatDescr_t descr; descr_struct() { hipsparseStatus_t status = hipsparseCreateMatDescr(&descr); verify_hipsparse_status_success(status, "ERROR: descr_struct constructor"); } ~descr_struct() { hipsparseStatus_t status = hipsparseDestroyMatDescr(descr); verify_hipsparse_status_success(status, "ERROR: descr_struct destructor"); } }; #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) struct hyb_struct { hipsparseHybMat_t hyb; hyb_struct() { hipsparseStatus_t status = hipsparseCreateHybMat(&hyb); verify_hipsparse_status_success(status, "ERROR: hyb_struct constructor"); } ~hyb_struct() { hipsparseStatus_t status = hipsparseDestroyHybMat(hyb); verify_hipsparse_status_success(status, "ERROR: hyb_struct destructor"); } }; #endif struct bsrsv2_struct { bsrsv2Info_t info; bsrsv2_struct() { hipsparseStatus_t status = hipsparseCreateBsrsv2Info(&info); verify_hipsparse_status_success(status, "ERROR: bsrsv2_struct constructor"); } ~bsrsv2_struct() { hipsparseStatus_t status = hipsparseDestroyBsrsv2Info(info); verify_hipsparse_status_success(status, "ERROR: bsrsv2_struct destructor"); } }; struct bsrsm2_struct { bsrsm2Info_t info; bsrsm2_struct() { hipsparseStatus_t status = hipsparseCreateBsrsm2Info(&info); verify_hipsparse_status_success(status, "ERROR: bsrsm2_struct constructor"); } ~bsrsm2_struct() { hipsparseStatus_t status = hipsparseDestroyBsrsm2Info(info); verify_hipsparse_status_success(status, "ERROR: bsrsm2_struct destructor"); } }; #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) struct csrsv2_struct { csrsv2Info_t info; csrsv2_struct() { hipsparseStatus_t status = hipsparseCreateCsrsv2Info(&info); verify_hipsparse_status_success(status, "ERROR: csrsv2_struct constructor"); } ~csrsv2_struct() { hipsparseStatus_t status = hipsparseDestroyCsrsv2Info(info); verify_hipsparse_status_success(status, "ERROR: csrsv2_struct destructor"); } }; struct csrsm2_struct { csrsm2Info_t info; csrsm2_struct() { hipsparseStatus_t status = hipsparseCreateCsrsm2Info(&info); verify_hipsparse_status_success(status, "ERROR: csrsm2_struct constructor"); } ~csrsm2_struct() { hipsparseStatus_t status = hipsparseDestroyCsrsm2Info(info); verify_hipsparse_status_success(status, "ERROR: csrsm2_struct destructor"); } }; #endif struct bsrilu02_struct { bsrilu02Info_t info; bsrilu02_struct() { hipsparseStatus_t status = hipsparseCreateBsrilu02Info(&info); verify_hipsparse_status_success(status, "ERROR: bsrilu02_struct constructor"); } ~bsrilu02_struct() { hipsparseStatus_t status = hipsparseDestroyBsrilu02Info(info); verify_hipsparse_status_success(status, "ERROR: bsrilu02_struct destructor"); } }; struct csrilu02_struct { csrilu02Info_t info; csrilu02_struct() { hipsparseStatus_t status = hipsparseCreateCsrilu02Info(&info); verify_hipsparse_status_success(status, "ERROR: csrilu02_struct constructor"); } ~csrilu02_struct() { hipsparseStatus_t status = hipsparseDestroyCsrilu02Info(info); verify_hipsparse_status_success(status, "ERROR: csrilu02_struct destructor"); } }; struct bsric02_struct { bsric02Info_t info; bsric02_struct() { hipsparseStatus_t status = hipsparseCreateBsric02Info(&info); verify_hipsparse_status_success(status, "ERROR: bsric02_struct constructor"); } ~bsric02_struct() { hipsparseStatus_t status = hipsparseDestroyBsric02Info(info); verify_hipsparse_status_success(status, "ERROR: bsric02_struct destructor"); } }; struct csric02_struct { csric02Info_t info; csric02_struct() { hipsparseStatus_t status = hipsparseCreateCsric02Info(&info); verify_hipsparse_status_success(status, "ERROR: csric02_struct constructor"); } ~csric02_struct() { hipsparseStatus_t status = hipsparseDestroyCsric02Info(info); verify_hipsparse_status_success(status, "ERROR: csric02_struct destructor"); } }; #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) struct csrgemm2_struct { csrgemm2Info_t info; csrgemm2_struct() { hipsparseStatus_t status = hipsparseCreateCsrgemm2Info(&info); verify_hipsparse_status_success(status, "ERROR: csrgemm2_struct constructor"); } ~csrgemm2_struct() { hipsparseStatus_t status = hipsparseDestroyCsrgemm2Info(info); verify_hipsparse_status_success(status, "ERROR: csrgemm2_struct destructor"); } }; #endif struct prune_struct { pruneInfo_t info; prune_struct() { hipsparseStatus_t status = hipsparseCreatePruneInfo(&info); verify_hipsparse_status_success(status, "ERROR: prune_struct constructor"); } ~prune_struct() { hipsparseStatus_t status = hipsparseDestroyPruneInfo(info); verify_hipsparse_status_success(status, "ERROR: prune_struct destructor"); } }; struct csru2csr_struct { csru2csrInfo_t info; csru2csr_struct() { hipsparseStatus_t status = hipsparseCreateCsru2csrInfo(&info); verify_hipsparse_status_success(status, "ERROR: csru2csr_struct constructor"); } ~csru2csr_struct() { hipsparseStatus_t status = hipsparseDestroyCsru2csrInfo(info); verify_hipsparse_status_success(status, "ERROR: csru2csr_struct destructor"); } }; #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) struct spgemm_struct { hipsparseSpGEMMDescr_t descr; spgemm_struct() { hipsparseStatus_t status = hipsparseSpGEMM_createDescr(&descr); verify_hipsparse_status_success(status, "ERROR: spgemm_struct constructor"); } ~spgemm_struct() { hipsparseStatus_t status = hipsparseSpGEMM_destroyDescr(descr); verify_hipsparse_status_success(status, "ERROR: spgemm_struct destructor"); } }; #endif } // namespace hipsparse_test using hipsparse_unique_ptr = std::unique_ptr; #endif // GUARD_HIPSPARSE_MANAGE_PTR ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5593991 hipsparse/clients/include/testing_axpby.hpp0000664000175100017510000001776615206065364021511 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5593991 hipsparse/clients/include/testing_axpyi.hpp0000664000175100017510000002003415206065364021476 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_AXPYI_HPP #define TESTING_AXPYI_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include using namespace hipsparse; using namespace hipsparse_test; template void testing_axpyi_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int nnz = 100; int safe_size = 100; T alpha = make_DataType(0.6); hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dxVal_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dxInd_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; T* dxVal = (T*)dxVal_managed.get(); int* dxInd = (int*)dxInd_managed.get(); T* dy = (T*)dy_managed.get(); verify_hipsparse_status_invalid_pointer( hipsparseXaxpyi(handle, nnz, &alpha, dxVal, (int*)nullptr, dy, idx_base), "Error: xInd is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXaxpyi(handle, nnz, &alpha, (T*)nullptr, dxInd, dy, idx_base), "Error: xVal is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXaxpyi(handle, nnz, &alpha, dxVal, dxInd, (T*)nullptr, idx_base), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXaxpyi(handle, nnz, (T*)nullptr, dxVal, dxInd, dy, idx_base), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXaxpyi((hipsparseHandle_t) nullptr, nnz, &alpha, dxVal, dxInd, dy, idx_base)); #endif } template hipsparseStatus_t testing_axpyi(const Arguments& argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int N = argus.N; int nnz = argus.nnz; T h_alpha = make_DataType(argus.alpha); hipsparseIndexBase_t idx_base = argus.baseA; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hxInd(nnz); std::vector hxVal(nnz); std::vector hy_1(N); std::vector hy_2(N); std::vector hy_gold(N); // Initial Data on CPU srand(12345ULL); hipsparseInitIndex(hxInd.data(), nnz, 1, N); hipsparseInit(hxVal, 1, nnz); hipsparseInit(hy_1, 1, N); // copy vector is easy in STL; hy_gold = hx: save a copy in hy_gold which will be output of CPU hy_2 = hy_1; hy_gold = hy_1; // allocate memory on device auto dxInd_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dxVal_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * N), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * N), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dxInd = (int*)dxInd_managed.get(); T* dxVal = (T*)dxVal_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dxInd, hxInd.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dxVal, hxVal.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_1, hy_1.data(), sizeof(T) * N, hipMemcpyHostToDevice)); if(argus.unit_check) { CHECK_HIP_ERROR(hipMemcpy(dy_2, hy_2.data(), sizeof(T) * N, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXaxpyi(handle, nnz, &h_alpha, dxVal, dxInd, dy_1, idx_base)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXaxpyi(handle, nnz, d_alpha, dxVal, dxInd, dy_2, idx_base)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hy_1.data(), dy_1, sizeof(T) * N, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_2.data(), dy_2, sizeof(T) * N, hipMemcpyDeviceToHost)); // CPU for(int i = 0; i < nnz; ++i) { hy_gold[hxInd[i] - idx_base] = hy_gold[hxInd[i] - idx_base] + testing_mult(h_alpha, hxVal[i]); } unit_check_general(1, N, 1, hy_gold.data(), hy_1.data()); unit_check_general(1, N, 1, hy_gold.data(), hy_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXaxpyi(handle, nnz, &h_alpha, dxVal, dxInd, dy_1, idx_base)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXaxpyi(handle, nnz, &h_alpha, dxVal, dxInd, dy_1, idx_base)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = axpyi_gflop_count(nnz); double gbyte_count = axpby_gbyte_count(nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); display_timing_info(display_key_t::size, N, display_key_t::nnz, nnz, display_key_t::alpha, h_alpha, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_AXPYI_HPP ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5593991 hipsparse/clients/include/testing_bsr2csr.hpp0000664000175100017510000006215615206065364021737 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_BSR2CSR_HPP #define TESTING_BSR2CSR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_bsr2csr_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int m = 1; int n = 1; int safe_size = 1; int block_dim = 2; hipsparseIndexBase_t csr_idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexBase_t bsr_idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseDirection_t dir = HIPSPARSE_DIRECTION_ROW; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_csr_descr(new descr_struct); hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; std::unique_ptr unique_ptr_bsr_descr(new descr_struct); hipsparseMatDescr_t bsr_descr = unique_ptr_bsr_descr->descr; hipsparseSetMatIndexBase(csr_descr, csr_idx_base); hipsparseSetMatIndexBase(bsr_descr, bsr_idx_base); auto bsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto bsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto bsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto csr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* bsr_row_ptr = (int*)bsr_row_ptr_managed.get(); int* bsr_col_ind = (int*)bsr_col_ind_managed.get(); T* bsr_val = (T*)bsr_val_managed.get(); int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* csr_col_ind = (int*)csr_col_ind_managed.get(); T* csr_val = (T*)csr_val_managed.get(); int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(bsr_row_ptr, local_ptr, sizeof(int) * (1 + 1), hipMemcpyHostToDevice)); verify_hipsparse_status_invalid_handle(hipsparseXbsr2csr((hipsparseHandle_t) nullptr, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind)); verify_hipsparse_status_invalid_pointer(hipsparseXbsr2csr(handle, dir, m, n, (hipsparseMatDescr_t) nullptr, bsr_val, bsr_row_ptr, bsr_col_ind, block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: bsr_descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsr2csr(handle, dir, m, n, bsr_descr, (T*)nullptr, bsr_row_ptr, bsr_col_ind, block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: bsr_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsr2csr(handle, dir, m, n, bsr_descr, bsr_val, (int*)nullptr, bsr_col_ind, block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: bsr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, (int*)nullptr, block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: bsr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, block_dim, (hipsparseMatDescr_t) nullptr, csr_val, csr_row_ptr, csr_col_ind), "Error: csr_descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, block_dim, csr_descr, (T*)nullptr, csr_row_ptr, csr_col_ind), "Error: csr_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, block_dim, csr_descr, csr_val, (int*)nullptr, csr_col_ind), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, block_dim, csr_descr, csr_val, csr_row_ptr, (int*)nullptr), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_size(hipsparseXbsr2csr(handle, dir, -1, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: m is invalid"); verify_hipsparse_status_invalid_size(hipsparseXbsr2csr(handle, dir, m, -1, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: n is invalid"); verify_hipsparse_status_invalid_size(hipsparseXbsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, -1, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: block_dim is invalid"); #endif } template hipsparseStatus_t testing_bsr2csr(Arguments argus) { int m = argus.M; int n = argus.N; int block_dim = argus.block_dim; hipsparseIndexBase_t bsr_idx_base = argus.baseA; hipsparseIndexBase_t csr_idx_base = argus.baseB; hipsparseDirection_t dir = argus.dirA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_csr_descr(new descr_struct); hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; std::unique_ptr unique_ptr_bsr_descr(new descr_struct); hipsparseMatDescr_t bsr_descr = unique_ptr_bsr_descr->descr; hipsparseSetMatIndexBase(csr_descr, csr_idx_base); hipsparseSetMatIndexBase(bsr_descr, bsr_idx_base); if(m == 0 || n == 0 || block_dim == 1) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse does not support m == 0 or n == 0 for bsr2csr // cusparse does not support asynchronous execution if block_dim == 1 return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector csr_row_ptr; std::vector csr_col_ind; std::vector csr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, n, nnz, csr_row_ptr, csr_col_ind, csr_val, csr_idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // m and n can be modifed if we read in a matrix from a file int mb = (m + block_dim - 1) / block_dim; int nb = (n + block_dim - 1) / block_dim; // Host BSR matrix std::vector hbsr_row_ptr; std::vector hbsr_col_ind; std::vector hbsr_val; // Convert CSR matrix to BSR int nnzb; host_csr_to_bsr(dir, m, n, block_dim, nnzb, csr_idx_base, csr_row_ptr, csr_col_ind, csr_val, bsr_idx_base, hbsr_row_ptr, hbsr_col_ind, hbsr_val); // Determine the size of the output CSR matrix based on the size of the input BSR matrix m = mb * block_dim; n = nb * block_dim; // Host CSR matrix std::vector hcsr_row_ptr(m + 1); std::vector hcsr_col_ind(nnzb * block_dim * block_dim); std::vector hcsr_val(nnzb * block_dim * block_dim); // Allocate memory on the device auto dbsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb + 1)), device_free}; auto dbsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnzb), device_free}; auto dbsr_val_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * nnzb * block_dim * block_dim), device_free}; auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{ device_malloc(sizeof(int) * nnzb * block_dim * block_dim), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * nnzb * block_dim * block_dim), device_free}; int* dbsr_row_ptr = (int*)dbsr_row_ptr_managed.get(); int* dbsr_col_ind = (int*)dbsr_col_ind_managed.get(); T* dbsr_val = (T*)dbsr_val_managed.get(); int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); // Copy data from host to device CHECK_HIP_ERROR(hipMemcpy( dbsr_row_ptr, hbsr_row_ptr.data(), sizeof(int) * (mb + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dbsr_col_ind, hbsr_col_ind.data(), sizeof(int) * nnzb, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dbsr_val, hbsr_val.data(), sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyHostToDevice)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseXbsr2csr(handle, dir, mb, nb, bsr_descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind)); // Copy output from device to host CHECK_HIP_ERROR(hipMemcpy( hcsr_row_ptr.data(), dcsr_row_ptr, sizeof(int) * (m + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hcsr_col_ind.data(), dcsr_col_ind, sizeof(int) * nnzb * block_dim * block_dim, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hcsr_val.data(), dcsr_val, sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyDeviceToHost)); // Host computed bsr2csr conversion std::vector hcsr_row_ptr_gold(m + 1); std::vector hcsr_col_ind_gold(nnzb * block_dim * block_dim, 0); std::vector hcsr_val_gold(nnzb * block_dim * block_dim); // Host bsr2csr host_bsr_to_csr(dir, mb, nb, block_dim, bsr_idx_base, hbsr_row_ptr, hbsr_col_ind, hbsr_val, csr_idx_base, hcsr_row_ptr_gold, hcsr_col_ind_gold, hcsr_val_gold); // Unit check unit_check_general(1, m + 1, 1, hcsr_row_ptr_gold.data(), hcsr_row_ptr.data()); unit_check_general( 1, nnzb * block_dim * block_dim, 1, hcsr_col_ind_gold.data(), hcsr_col_ind.data()); unit_check_general( 1, nnzb * block_dim * block_dim, 1, hcsr_val_gold.data(), hcsr_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXbsr2csr(handle, dir, mb, nb, bsr_descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXbsr2csr(handle, dir, mb, nb, bsr_descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = bsr2csr_gbyte_count(mb, block_dim, nnzb); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::Mb, mb, display_key_t::Nb, nb, display_key_t::block_dim, block_dim, display_key_t::nnzb, nnzb, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_BSR2CSR_HPP ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5613992 hipsparse/clients/include/testing_bsric02.hpp0000664000175100017510000011371515206065364021621 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5613992 hipsparse/clients/include/testing_bsrilu02.hpp0000664000175100017510000011616315206065364022017 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5623991 hipsparse/clients/include/testing_bsrmm.hpp0000664000175100017510000011617015206065364021473 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_BSRMM_HPP #define TESTING_BSRMM_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_bsrmm_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int mb = 100; int n = 100; int kb = 100; int nnzb = 100; int block_dim = 100; int ldb = 100; int ldc = 100; int safe_size = 100; T alpha = make_DataType(0.6); T beta = make_DataType(0.2); hipsparseDirection_t dirA = HIPSPARSE_DIRECTION_ROW; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; auto dbsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dbsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dbsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dC_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* dbsr_row_ptr = (int*)dbsr_row_ptr_managed.get(); int* dbsr_col_ind = (int*)dbsr_col_ind_managed.get(); T* dbsr_val = (T*)dbsr_val_managed.get(); T* dB = (T*)dB_managed.get(); T* dC = (T*)dC_managed.get(); verify_hipsparse_status_invalid_handle(hipsparseXbsrmm((hipsparseHandle_t) nullptr, dirA, transA, transB, mb, n, kb, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, &beta, dC, ldc)); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, (T*)nullptr, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, &beta, dC, ldc), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, &alpha, (hipsparseMatDescr_t) nullptr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, &beta, dC, ldc), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, &alpha, descr, (T*)nullptr, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, &beta, dC, ldc), "Error: dbsr_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, &alpha, descr, dbsr_val, (int*)nullptr, dbsr_col_ind, block_dim, dB, ldb, &beta, dC, ldc), "Error: dbsr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, (int*)nullptr, block_dim, dB, ldb, &beta, dC, ldc), "Error: dbsr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, (T*)nullptr, ldb, &beta, dC, ldc), "Error: dB is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, (T*)nullptr, dC, ldc), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, &beta, (T*)nullptr, ldc), "Error: dC is nullptr"); verify_hipsparse_status_invalid_size(hipsparseXbsrmm(handle, dirA, transA, transB, -1, n, kb, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, &beta, dC, ldc), "Error: mb is invalid"); verify_hipsparse_status_invalid_size(hipsparseXbsrmm(handle, dirA, transA, transB, mb, -1, kb, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, &beta, dC, ldc), "Error: n is invalid"); verify_hipsparse_status_invalid_size(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, -1, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, &beta, dC, ldc), "Error: kb is invalid"); verify_hipsparse_status_invalid_size(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, 0, dB, ldb, &beta, dC, ldc), "Error: block_dim is invalid"); // Test not implemented (mapped to hiparse internal error) verify_hipsparse_status_not_supported(hipsparseXbsrmm(handle, dirA, HIPSPARSE_OPERATION_TRANSPOSE, transB, mb, n, kb, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, &beta, dC, ldc), "Error: Passed value for transA is not supported"); verify_hipsparse_status_not_supported(hipsparseXbsrmm(handle, dirA, HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE, transB, mb, n, kb, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, &beta, dC, ldc), "Error: Passed value for transA is not supported"); verify_hipsparse_status_not_supported(hipsparseXbsrmm(handle, dirA, transA, HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE, mb, n, kb, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, &beta, dC, ldc), "Error: Passed value for transB is not supported"); #endif } template hipsparseStatus_t testing_bsrmm(const Arguments& argus) { int m = argus.M; int n = argus.N; int k = argus.K; int block_dim = argus.block_dim; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseDirection_t dirA = argus.dirA; hipsparseOperation_t transA = argus.transA; hipsparseOperation_t transB = argus.transB; hipsparseIndexBase_t idx_base = argus.baseA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); if(m == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse does not support m == 0 for csr2bsr return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector csr_row_ptr; std::vector csr_col_ind; std::vector csr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, k, nnz, csr_row_ptr, csr_col_ind, csr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // m and k can be modifed if we read in a matrix from a file int mb = (m + block_dim - 1) / block_dim; int kb = (k + block_dim - 1) / block_dim; // Allocate memory on device for CSR matrix and BSR row pointer array auto dcsr_row_ptrA_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_indA_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_valA_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dbsr_row_ptrA_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb + 1)), device_free}; int* dcsr_row_ptrA = (int*)dcsr_row_ptrA_managed.get(); int* dcsr_col_indA = (int*)dcsr_col_indA_managed.get(); T* dcsr_valA = (T*)dcsr_valA_managed.get(); int* dbsr_row_ptrA = (int*)dbsr_row_ptrA_managed.get(); // Copy CSR from host to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptrA, csr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_indA, csr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_valA, csr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); // Convert CSR to BSR int nnzb; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsrNnz(handle, dirA, m, k, descr, dcsr_row_ptrA, dcsr_col_indA, block_dim, descr, dbsr_row_ptrA, &nnzb)); auto dbsr_col_indA_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnzb), device_free}; auto dbsr_valA_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * nnzb * block_dim * block_dim), device_free}; int* dbsr_col_indA = (int*)dbsr_col_indA_managed.get(); T* dbsr_valA = (T*)dbsr_valA_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsr(handle, dirA, m, k, descr, dcsr_valA, dcsr_row_ptrA, dcsr_col_indA, block_dim, descr, dbsr_valA, dbsr_row_ptrA, dbsr_col_indA)); // Host BSR matrix std::vector hbsr_row_ptrA(mb + 1); std::vector hbsr_col_indA(nnzb); std::vector hbsr_valA(nnzb * block_dim * block_dim); // Copy BSR matrix to host CHECK_HIP_ERROR(hipMemcpy( hbsr_row_ptrA.data(), dbsr_row_ptrA, sizeof(int) * (mb + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hbsr_col_indA.data(), dbsr_col_indA, sizeof(int) * nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsr_valA.data(), dbsr_valA, sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyDeviceToHost)); m = mb * block_dim; k = kb * block_dim; // Some matrix properties int ldb = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : n; int ldc = m; int ncol_B = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE ? n : k); int nnz_B = ldb * ncol_B; int nnz_C = ldc * n; // Allocate host memory for dense matrices std::vector hB(nnz_B); std::vector hC_1(nnz_C); std::vector hC_2(nnz_C); std::vector hC_gold(nnz_C); hipsparseInit(hB, ldb, ncol_B); hipsparseInit(hC_1, ldc, n); // copy vector is easy in STL; hC_gold = hC_1: save a copy in hy_gold which will be output of // CPU hC_gold = hC_1; hC_2 = hC_1; // allocate memory on device auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_B), device_free}; auto dC_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_C), device_free}; auto dC_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_C), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; T* dB = (T*)dB_managed.get(); T* dC_1 = (T*)dC_1_managed.get(); T* dC_2 = (T*)dC_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // Copy data from host to device CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_1, hC_1.data(), sizeof(T) * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_2, hC_2.data(), sizeof(T) * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); if(argus.unit_check) { // Testing using host pointer mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, &h_alpha, descr, dbsr_valA, dbsr_row_ptrA, dbsr_col_indA, block_dim, dB, ldb, &h_beta, dC_1, ldc)); // Testing using device pointer mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, d_alpha, descr, dbsr_valA, dbsr_row_ptrA, dbsr_col_indA, block_dim, dB, ldb, d_beta, dC_2, ldc)); // Copy output from device to host CHECK_HIP_ERROR(hipMemcpy(hC_1.data(), dC_1, sizeof(T) * nnz_C, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hC_2.data(), dC_2, sizeof(T) * nnz_C, hipMemcpyDeviceToHost)); // Host bsrmm host_bsrmm(mb, n, kb, block_dim, dirA, transA, transB, h_alpha, hbsr_row_ptrA, hbsr_col_indA, hbsr_valA, hB, ldb, h_beta, hC_gold, ldc, idx_base); // Unit check unit_check_near(1, nnz_C, 1, hC_gold.data(), hC_1.data()); unit_check_near(1, nnz_C, 1, hC_gold.data(), hC_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, &h_alpha, descr, dbsr_valA, dbsr_row_ptrA, dbsr_col_indA, block_dim, dB, ldb, &h_beta, dC_1, ldc)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, &h_alpha, descr, dbsr_valA, dbsr_row_ptrA, dbsr_col_indA, block_dim, dB, ldb, &h_beta, dC_1, ldc)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = bsrmm_gflop_count(n, nnzb, block_dim, m * n, h_beta != make_DataType(0.0)); double gbyte_count = bsrmm_gbyte_count( mb, nnzb, block_dim, k * n, m * n, h_beta != make_DataType(0.0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::K, k, display_key_t::direction, dirA, display_key_t::transA, transA, display_key_t::transB, transB, display_key_t::nnzb, nnzb, display_key_t::block_dim, block_dim, display_key_t::nnzB, nnz_B, display_key_t::nnzC, nnz_C, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_BSRMM_HPP ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5623991 hipsparse/clients/include/testing_bsrmv.hpp0000664000175100017510000007261315206065364021507 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_BSRMV_HPP #define TESTING_BSRMV_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_bsrmv_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int safe_size = 100; int safe_dim = 2; T alpha = make_DataType(0.6); T beta = make_DataType(0.2); hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseDirection_t dirA = HIPSPARSE_DIRECTION_COLUMN; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dx = (T*)dx_managed.get(); T* dy = (T*)dy_managed.get(); // Test hipsparseXbsrmv verify_hipsparse_status_invalid_handle(hipsparseXbsrmv((hipsparseHandle_t) nullptr, dirA, transA, safe_size, safe_size, safe_size, &alpha, descr, dval, dptr, dcol, safe_dim, dx, &beta, dy)); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmv(handle, dirA, transA, safe_size, safe_size, safe_size, (T*)nullptr, descr, dval, dptr, dcol, safe_dim, dx, &beta, dy), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmv(handle, dirA, transA, safe_size, safe_size, safe_size, &alpha, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, safe_dim, dx, &beta, dy), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmv(handle, dirA, transA, safe_size, safe_size, safe_size, &alpha, descr, (T*)nullptr, dptr, dcol, safe_dim, dx, &beta, dy), "Error: bsr_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmv(handle, dirA, transA, safe_size, safe_size, safe_size, &alpha, descr, dval, (int*)nullptr, dcol, safe_dim, dx, &beta, dy), "Error: bsr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmv(handle, dirA, transA, safe_size, safe_size, safe_size, &alpha, descr, dval, dptr, (int*)nullptr, safe_dim, dx, &beta, dy), "Error: bsr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmv(handle, dirA, transA, safe_size, safe_size, safe_size, &alpha, descr, dval, dptr, dcol, safe_dim, (T*)nullptr, &beta, dy), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmv(handle, dirA, transA, safe_size, safe_size, safe_size, &alpha, descr, dval, dptr, dcol, safe_dim, dx, (T*)nullptr, dy), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmv(handle, dirA, transA, safe_size, safe_size, safe_size, &alpha, descr, dval, dptr, dcol, safe_dim, dx, &beta, (T*)nullptr), "Error: y is nullptr"); verify_hipsparse_status_invalid_size(hipsparseXbsrmv(handle, dirA, transA, -1, safe_size, safe_size, &alpha, descr, dval, dptr, dcol, safe_dim, dx, &beta, dy), "Error: mb is invalid"); verify_hipsparse_status_invalid_size(hipsparseXbsrmv(handle, dirA, transA, safe_size, -1, safe_size, &alpha, descr, dval, dptr, dcol, safe_dim, dx, &beta, dy), "Error: nb is invalid"); verify_hipsparse_status_invalid_size(hipsparseXbsrmv(handle, dirA, transA, safe_size, safe_size, -1, &alpha, descr, dval, dptr, dcol, safe_dim, dx, &beta, dy), "Error: nnzb is invalid"); verify_hipsparse_status_invalid_size(hipsparseXbsrmv(handle, dirA, transA, safe_size, safe_size, safe_size, &alpha, descr, dval, dptr, dcol, -1, dx, &beta, dy), "Error: block_dim is invalid"); #endif } template hipsparseStatus_t testing_bsrmv(Arguments argus) { int m = argus.M; int n = argus.N; int block_dim = argus.block_dim; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseDirection_t dir = argus.dirA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); int mb = (m + block_dim - 1) / block_dim; int nb = (n + block_dim - 1) / block_dim; if(block_dim == 1 || mb == 0 || nb == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse only accepts block_dim > 1 return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } mb = (m + block_dim - 1) / block_dim; nb = (n + block_dim - 1) / block_dim; std::vector hx(nb * block_dim); std::vector hy_1(mb * block_dim); std::vector hy_2(mb * block_dim); std::vector hy_gold(mb * block_dim); hipsparseInit(hx, 1, nb * block_dim); hipsparseInit(hy_1, 1, mb * block_dim); // copy vector is easy in STL; hy_gold = hx: save a copy in hy_gold which will be output of CPU hy_2 = hy_1; hy_gold = hy_1; // allocate memory on device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dbsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb + 1)), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nb * block_dim), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * mb * block_dim), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * mb * block_dim), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); int* dbsr_row_ptr = (int*)dbsr_row_ptr_managed.get(); T* dx = (T*)dx_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_val, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx, hx.data(), sizeof(T) * n, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_1, hy_1.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // Convert to BSR int nnzb; CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsrNnz(handle, dir, m, n, descr, dcsr_row_ptr, dcsr_col_ind, block_dim, descr, dbsr_row_ptr, &nnzb)); auto dbsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnzb), device_free}; auto dbsr_val_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * nnzb * block_dim * block_dim), device_free}; int* dbsr_col_ind = (int*)dbsr_col_ind_managed.get(); T* dbsr_val = (T*)dbsr_val_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsr(handle, dir, m, n, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, block_dim, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind)); if(argus.unit_check) { CHECK_HIP_ERROR(hipMemcpy(dy_2, hy_2.data(), sizeof(T) * m, hipMemcpyHostToDevice)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXbsrmv(handle, dir, transA, mb, nb, nnzb, &h_alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dx, &h_beta, dy_1)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXbsrmv(handle, dir, transA, mb, nb, nnzb, d_alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dx, d_beta, dy_2)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hy_1.data(), dy_1, sizeof(T) * m, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_2.data(), dy_2, sizeof(T) * m, hipMemcpyDeviceToHost)); // Host bsrmv std::vector hbsr_row_ptr(mb + 1); std::vector hbsr_col_ind(nnzb); std::vector hbsr_val(nnzb * block_dim * block_dim); CHECK_HIP_ERROR(hipMemcpy( hbsr_row_ptr.data(), dbsr_row_ptr, sizeof(int) * (mb + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hbsr_col_ind.data(), dbsr_col_ind, sizeof(int) * nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsr_val.data(), dbsr_val, sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyDeviceToHost)); host_bsrmv(dir, transA, mb, nb, nnzb, h_alpha, hbsr_row_ptr.data(), hbsr_col_ind.data(), hbsr_val.data(), block_dim, hx.data(), h_beta, hy_gold.data(), idx_base); unit_check_near(1, m, 1, hy_gold.data(), hy_1.data()); unit_check_near(1, m, 1, hy_gold.data(), hy_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXbsrmv(handle, dir, transA, mb, nb, nnzb, &h_alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dx, &h_beta, dy_1)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXbsrmv(handle, dir, transA, mb, nb, nnzb, &h_alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dx, &h_beta, dy_1)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = spmv_gflop_count(m, nnzb * block_dim * block_dim, h_beta != make_DataType(0.0)); double gbyte_count = bsrmv_gbyte_count(mb, nb, nnzb, block_dim, h_beta != make_DataType(0.0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::block_dim, block_dim, display_key_t::direction, hipsparse_direction2string(dir), display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_BSRMV_HPP ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5623991 hipsparse/clients/include/testing_bsrsm2.hpp0000664000175100017510000015310615206065364021563 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_BSRSM2_HPP #define TESTING_BSRSM2_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include using namespace hipsparse; using namespace hipsparse_test; template void testing_bsrsm2_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int mb = 100; int nrhs = 100; int nnzb = 100; int block_dim = 100; int safe_size = 100; float alpha = 0.6; int ldb = 100; int ldx = 100; hipsparseDirection_t dirA = HIPSPARSE_DIRECTION_ROW; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transX = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseSolvePolicy_t policy = HIPSPARSE_SOLVE_POLICY_USE_LEVEL; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_info(new bsrsm2_struct); bsrsm2Info_t info = unique_ptr_info->info; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dX_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); float* dval = (float*)dval_managed.get(); float* dB = (float*)dB_managed.get(); float* dX = (float*)dX_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // testing hipsparseXbsrsm2_bufferSize int size; verify_hipsparse_status_invalid_handle(hipsparseXbsrsm2_bufferSize(nullptr, dirA, transA, transX, mb, nrhs, nnzb, descr, dval, dptr, dcol, block_dim, info, &size)); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_bufferSize(handle, dirA, transA, transX, mb, nrhs, nnzb, nullptr, dval, dptr, dcol, block_dim, info, &size), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_bufferSize(handle, dirA, transA, transX, mb, nrhs, nnzb, descr, (float*)nullptr, dptr, dcol, block_dim, info, &size), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_bufferSize(handle, dirA, transA, transX, mb, nrhs, nnzb, descr, dval, nullptr, dcol, block_dim, info, &size), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_bufferSize(handle, dirA, transA, transX, mb, nrhs, nnzb, descr, dval, dptr, nullptr, block_dim, info, &size), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_bufferSize(handle, dirA, transA, transX, mb, nrhs, nnzb, descr, dval, dptr, dcol, block_dim, nullptr, &size), "Error: info is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_bufferSize(handle, dirA, transA, transX, mb, nrhs, nnzb, descr, dval, dptr, dcol, block_dim, info, nullptr), "Error: size is nullptr"); // testing hipsparseXbsrsm2_analysis verify_hipsparse_status_invalid_handle(hipsparseXbsrsm2_analysis(nullptr, dirA, transA, transX, mb, nrhs, nnzb, descr, dval, dptr, dcol, block_dim, info, policy, dbuf)); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_analysis(handle, dirA, transA, transX, mb, nrhs, nnzb, nullptr, dval, dptr, dcol, block_dim, info, policy, dbuf), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_analysis(handle, dirA, transA, transX, mb, nrhs, nnzb, descr, (const float*)nullptr, dptr, dcol, block_dim, info, policy, dbuf), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_analysis(handle, dirA, transA, transX, mb, nrhs, nnzb, descr, dval, nullptr, dcol, block_dim, info, policy, dbuf), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_analysis(handle, dirA, transA, transX, mb, nrhs, nnzb, descr, dval, dptr, nullptr, block_dim, info, policy, dbuf), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_analysis(handle, dirA, transA, transX, mb, nrhs, nnzb, descr, dval, dptr, dcol, block_dim, nullptr, policy, dbuf), "Error: info is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_analysis(handle, dirA, transA, transX, mb, nrhs, nnzb, descr, dval, dptr, dcol, block_dim, info, policy, nullptr), "Error: dbuf is nullptr"); // testing hipsparseXbsrsm2_solve verify_hipsparse_status_invalid_handle(hipsparseXbsrsm2_solve(nullptr, dirA, transA, transX, mb, nrhs, nnzb, &alpha, descr, dval, dptr, dcol, block_dim, info, dB, ldb, dX, ldx, policy, dbuf)); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_solve(handle, dirA, transA, transX, mb, nrhs, nnzb, (const float*)nullptr, descr, dval, dptr, dcol, block_dim, info, dB, ldb, dX, ldx, policy, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_solve(handle, dirA, transA, transX, mb, nrhs, nnzb, &alpha, nullptr, dval, dptr, dcol, block_dim, info, dB, ldb, dX, ldx, policy, dbuf), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_solve(handle, dirA, transA, transX, mb, nrhs, nnzb, &alpha, descr, (const float*)nullptr, dptr, dcol, block_dim, info, dB, ldb, dX, ldx, policy, dbuf), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_solve(handle, dirA, transA, transX, mb, nrhs, nnzb, &alpha, descr, dval, nullptr, dcol, block_dim, info, dB, ldb, dX, ldx, policy, dbuf), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_solve(handle, dirA, transA, transX, mb, nrhs, nnzb, &alpha, descr, dval, dptr, nullptr, block_dim, info, dB, ldb, dX, ldx, policy, dbuf), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_solve(handle, dirA, transA, transX, mb, nrhs, nnzb, &alpha, descr, dval, dptr, dcol, block_dim, nullptr, dB, ldb, dX, ldx, policy, dbuf), "Error: info is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_solve(handle, dirA, transA, transX, mb, nrhs, nnzb, &alpha, descr, dval, dptr, dcol, block_dim, info, (const float*)nullptr, ldb, dX, ldx, policy, dbuf), "Error: dB is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_solve(handle, dirA, transA, transX, mb, nrhs, nnzb, &alpha, descr, dval, dptr, dcol, block_dim, info, dB, ldb, (float*)nullptr, ldx, policy, dbuf), "Error: dX is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_solve(handle, dirA, transA, transX, mb, nrhs, nnzb, &alpha, descr, dval, dptr, dcol, block_dim, info, dB, ldb, dX, ldx, policy, nullptr), "Error: dbuf is nullptr"); #endif } template hipsparseStatus_t testing_bsrsm2(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) int m = argus.M; int nrhs = argus.N; int block_dim = argus.block_dim; T h_alpha = make_DataType(argus.alpha); hipsparseDirection_t dir = argus.dirA; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseOperation_t transA = argus.transA; hipsparseOperation_t transX = argus.transB; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_bsrsm2_info(new bsrsm2_struct); bsrsm2Info_t info = unique_ptr_bsrsm2_info->info; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); if(m == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse does not support m == 0 for csr2bsr return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, m, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } int mb = (m + block_dim - 1) / block_dim; int ldb = (transX == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? mb * block_dim : nrhs; int ldx = (transX == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? mb * block_dim : nrhs; int64_t nrowB = (transX == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? mb * block_dim : nrhs; int64_t ncolB = (transX == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? nrhs : mb * block_dim; int64_t nrowX = nrowB; int64_t ncolX = ncolB; std::vector hB(nrowB * ncolB); std::vector hX_1(nrowX * ncolX); std::vector hX_2(nrowX * ncolX); std::vector hX_gold(nrowX * ncolX); hipsparseInit(hB, nrowB, ncolB); // Allocate memory on device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dbsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb + 1)), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nrowB * ncolB), device_free}; auto dX_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nrowX * ncolX), device_free}; auto dX_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nrowX * ncolX), device_free}; auto dalpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto dpos_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); int* dbsr_row_ptr = (int*)dbsr_row_ptr_managed.get(); T* dB = (T*)dB_managed.get(); T* dX_1 = (T*)dX_1_managed.get(); T* dX_2 = (T*)dX_2_managed.get(); T* dalpha = (T*)dalpha_managed.get(); int* dposition = (int*)dpos_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_val, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * nrowB * ncolB, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dalpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); // Convert to BSR int nnzb; CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsrNnz(handle, dir, m, m, descr, dcsr_row_ptr, dcsr_col_ind, block_dim, descr, dbsr_row_ptr, &nnzb)); auto dbsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnzb), device_free}; auto dbsr_val_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * nnzb * block_dim * block_dim), device_free}; int* dbsr_col_ind = (int*)dbsr_col_ind_managed.get(); T* dbsr_val = (T*)dbsr_val_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsr(handle, dir, m, m, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, block_dim, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind)); // Obtain bsrsm2 buffer size int bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseXbsrsm2_bufferSize(handle, dir, transA, transX, mb, nrhs, nnzb, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, &bufferSize)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * bufferSize), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); // bsrsm2 analysis CHECK_HIPSPARSE_ERROR(hipsparseXbsrsm2_analysis(handle, dir, transA, transX, mb, nrhs, nnzb, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer)); int pos_analysis; hipsparseXbsrsm2_zeroPivot(handle, info, &pos_analysis); if(argus.unit_check) { // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXbsrsm2_solve(handle, dir, transA, transX, mb, nrhs, nnzb, &h_alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, dB, ldb, dX_1, ldx, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer)); int hposition_1; hipsparseStatus_t pivot_status_1 = hipsparseXbsrsm2_zeroPivot(handle, info, &hposition_1); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXbsrsm2_solve(handle, dir, transA, transX, mb, nrhs, nnzb, dalpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, dB, ldb, dX_2, ldx, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer)); hipsparseStatus_t pivot_status_2 = hipsparseXbsrsm2_zeroPivot(handle, info, dposition); // Copy output from device to CPU int hposition_2; CHECK_HIP_ERROR( hipMemcpy(hX_1.data(), dX_1, sizeof(T) * nrowX * ncolX, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hX_2.data(), dX_2, sizeof(T) * nrowX * ncolX, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(&hposition_2, dposition, sizeof(int), hipMemcpyDeviceToHost)); // Host bsrsm2 std::vector hbsr_row_ptr(mb + 1); std::vector hbsr_col_ind(nnzb); std::vector hbsr_val(nnzb * block_dim * block_dim); CHECK_HIP_ERROR(hipMemcpy( hbsr_row_ptr.data(), dbsr_row_ptr, sizeof(int) * (mb + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hbsr_col_ind.data(), dbsr_col_ind, sizeof(int) * nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsr_val.data(), dbsr_val, sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyDeviceToHost)); int struct_position_gold; int numeric_position_gold; CHECK_HIP_ERROR(hipDeviceSynchronize()); host_bsrsm(mb, nrhs, nnzb, dir, transA, transX, h_alpha, hbsr_row_ptr.data(), hbsr_col_ind.data(), hbsr_val.data(), block_dim, hB.data(), ldb, hX_gold.data(), ldx, HIPSPARSE_DIAG_TYPE_NON_UNIT, HIPSPARSE_FILL_MODE_LOWER, idx_base, &struct_position_gold, &numeric_position_gold); unit_check_general(1, 1, 1, &struct_position_gold, &pos_analysis); unit_check_general(1, 1, 1, &numeric_position_gold, &hposition_1); unit_check_general(1, 1, 1, &numeric_position_gold, &hposition_2); if(hposition_1 != -1) { verify_hipsparse_status_zero_pivot(pivot_status_1, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); return HIPSPARSE_STATUS_SUCCESS; } if(hposition_2 != -1) { verify_hipsparse_status_zero_pivot(pivot_status_2, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); return HIPSPARSE_STATUS_SUCCESS; } unit_check_near(nrowX, ncolX, ldx, hX_gold.data(), hX_1.data()); unit_check_near(nrowX, ncolX, ldx, hX_gold.data(), hX_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXbsrsm2_solve(handle, dir, transA, transX, mb, nrhs, nnzb, &h_alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, dB, ldb, dX_1, ldx, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXbsrsm2_solve(handle, dir, transA, transX, mb, nrhs, nnzb, &h_alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, dB, ldb, dX_1, ldx, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = csrsv_gflop_count(m, size_t(nnzb) * block_dim * block_dim, HIPSPARSE_DIAG_TYPE_NON_UNIT) * nrhs; double gbyte_count = bsrsv_gbyte_count(mb, nnzb, block_dim) * nrhs; double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::nnz, nnzb * block_dim * block_dim, display_key_t::nrhs, nrhs, display_key_t::block_dim, block_dim, display_key_t::alpha, h_alpha, display_key_t::transA, hipsparse_operation2string(transA), display_key_t::transX, hipsparse_operation2string(transX), display_key_t::diag_type, hipsparse_diagtype2string(HIPSPARSE_DIAG_TYPE_NON_UNIT), display_key_t::fill_mode, hipsparse_fillmode2string(HIPSPARSE_FILL_MODE_LOWER), display_key_t::solve_policy, hipsparse_solvepolicy2string(HIPSPARSE_SOLVE_POLICY_USE_LEVEL), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_BSRSV2_HPP ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5623991 hipsparse/clients/include/testing_bsrsv2.hpp0000664000175100017510000012730115206065364021572 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_BSRSV2_HPP #define TESTING_BSRSV2_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_bsrsv2_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int m = 100; int nnz = 100; int block_dim = 2; int safe_size = 100; T h_alpha = make_DataType(0.6); hipsparseDirection_t dirA = HIPSPARSE_DIRECTION_COLUMN; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseSolvePolicy_t policy = HIPSPARSE_SOLVE_POLICY_USE_LEVEL; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_bsrsv2_info(new bsrsv2_struct); bsrsv2Info_t info = unique_ptr_bsrsv2_info->info; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dx = (T*)dx_managed.get(); T* dy = (T*)dy_managed.get(); void* dbuffer = (void*)dbuffer_managed.get(); int size; int position; verify_hipsparse_status_invalid_pointer( hipsparseXbsrsv2_bufferSize( handle, dirA, transA, m, nnz, descr, dval, (int*)nullptr, dcol, block_dim, info, &size), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsrsv2_bufferSize( handle, dirA, transA, m, nnz, descr, dval, dptr, (int*)nullptr, block_dim, info, &size), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsrsv2_bufferSize( handle, dirA, transA, m, nnz, descr, (T*)nullptr, dptr, dcol, block_dim, info, &size), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsrsv2_bufferSize( handle, dirA, transA, m, nnz, descr, dval, dptr, dcol, block_dim, info, (int*)nullptr), "Error: size is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsrsv2_bufferSize(handle, dirA, transA, m, nnz, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, block_dim, info, &size), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_bufferSize(handle, dirA, transA, m, nnz, descr, dval, dptr, dcol, block_dim, (bsrsv2Info_t) nullptr, &size), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXbsrsv2_bufferSize((hipsparseHandle_t) nullptr, dirA, transA, m, nnz, descr, dval, dptr, dcol, block_dim, info, &size)); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_analysis(handle, dirA, transA, m, nnz, descr, dval, (int*)nullptr, dcol, block_dim, info, policy, dbuffer), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_analysis(handle, dirA, transA, m, nnz, descr, dval, dptr, (int*)nullptr, block_dim, info, policy, dbuffer), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_analysis(handle, dirA, transA, m, nnz, descr, (T*)nullptr, dptr, dcol, block_dim, info, policy, dbuffer), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_analysis(handle, dirA, transA, m, nnz, descr, dval, dptr, dcol, block_dim, info, policy, (void*)nullptr), "Error: dbuffer is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_analysis(handle, dirA, transA, m, nnz, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, block_dim, info, policy, dbuffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_analysis(handle, dirA, transA, m, nnz, descr, dval, dptr, dcol, block_dim, (bsrsv2Info_t) nullptr, policy, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXbsrsv2_analysis((hipsparseHandle_t) nullptr, dirA, transA, m, nnz, descr, dval, dptr, dcol, block_dim, info, policy, dbuffer)); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_solve(handle, dirA, transA, m, nnz, &h_alpha, descr, dval, (int*)nullptr, dcol, block_dim, info, dx, dy, policy, dbuffer), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_solve(handle, dirA, transA, m, nnz, &h_alpha, descr, dval, dptr, (int*)nullptr, block_dim, info, dx, dy, policy, dbuffer), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_solve(handle, dirA, transA, m, nnz, &h_alpha, descr, (T*)nullptr, dptr, dcol, block_dim, info, dx, dy, policy, dbuffer), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_solve(handle, dirA, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, block_dim, info, (T*)nullptr, dy, policy, dbuffer), "Error: dx is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_solve(handle, dirA, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, block_dim, info, dx, (T*)nullptr, policy, dbuffer), "Error: dy is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_solve(handle, dirA, transA, m, nnz, (T*)nullptr, descr, dval, dptr, dcol, block_dim, info, dx, dy, policy, dbuffer), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_solve(handle, dirA, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, block_dim, info, dx, dy, policy, (void*)nullptr), "Error: dbuffer is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_solve(handle, dirA, transA, m, nnz, &h_alpha, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, block_dim, info, dx, dy, policy, dbuffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_solve(handle, dirA, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, block_dim, (bsrsv2Info_t) nullptr, dx, dy, policy, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXbsrsv2_solve((hipsparseHandle_t) nullptr, dirA, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, block_dim, info, dx, dy, policy, dbuffer)); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_zeroPivot(handle, info, (int*)nullptr), "Error: position is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsrsv2_zeroPivot(handle, (bsrsv2Info_t) nullptr, &position), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXbsrsv2_zeroPivot((hipsparseHandle_t) nullptr, info, &position)); #endif } template hipsparseStatus_t testing_bsrsv2(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) int m = argus.M; int block_dim = argus.block_dim; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseDirection_t dir = argus.dirA; hipsparseOperation_t trans = argus.transA; hipsparseDiagType_t diag_type = argus.diag_type; hipsparseFillMode_t fill_mode = argus.fill_mode; hipsparseSolvePolicy_t policy = argus.solve_policy; T h_alpha = make_DataType(argus.alpha); std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_bsrsv2_info(new bsrsv2_struct); bsrsv2Info_t info = unique_ptr_bsrsv2_info->info; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); // Set matrix diag type CHECK_HIPSPARSE_ERROR(hipsparseSetMatDiagType(descr, diag_type)); // Set matrix fill mode CHECK_HIPSPARSE_ERROR(hipsparseSetMatFillMode(descr, fill_mode)); if(m == 0 || block_dim == 1) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse does not support m == 0 for csr2bsr // cusparse does not support asynchronous execution if block_dim == 1 return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, m, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } int mb = (m + block_dim - 1) / block_dim; std::vector hx(mb * block_dim); std::vector hy_1(mb * block_dim); std::vector hy_2(mb * block_dim); std::vector hy_gold(mb * block_dim); hipsparseInit(hx, 1, mb * block_dim); // Allocate memory on device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dbsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb + 1)), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * mb * block_dim), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * mb * block_dim), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * mb * block_dim), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_position_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); int* dbsr_row_ptr = (int*)dbsr_row_ptr_managed.get(); T* dx = (T*)dx_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); int* d_position = (int*)d_position_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_val, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx, hx.data(), sizeof(T) * mb * block_dim, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dy_1, hy_1.data(), sizeof(T) * mb * block_dim, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); // Convert to BSR int nnzb; CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsrNnz(handle, dir, m, m, descr, dcsr_row_ptr, dcsr_col_ind, block_dim, descr, dbsr_row_ptr, &nnzb)); auto dbsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnzb), device_free}; auto dbsr_val_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * nnzb * block_dim * block_dim), device_free}; int* dbsr_col_ind = (int*)dbsr_col_ind_managed.get(); T* dbsr_val = (T*)dbsr_val_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsr(handle, dir, m, m, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, block_dim, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind)); // Obtain bsrsv2 buffer size int bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseXbsrsv2_bufferSize(handle, dir, trans, mb, nnzb, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, &bufferSize)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * bufferSize), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); // bsrsv2 analysis CHECK_HIPSPARSE_ERROR(hipsparseXbsrsv2_analysis(handle, dir, trans, mb, nnzb, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, policy, dbuffer)); if(argus.unit_check) { CHECK_HIP_ERROR( hipMemcpy(dy_2, hy_2.data(), sizeof(T) * mb * block_dim, hipMemcpyHostToDevice)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXbsrsv2_solve(handle, dir, trans, mb, nnzb, &h_alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, dx, dy_1, policy, dbuffer)); int hposition_1; hipsparseStatus_t pivot_status_1; pivot_status_1 = hipsparseXbsrsv2_zeroPivot(handle, info, &hposition_1); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXbsrsv2_solve(handle, dir, trans, mb, nnzb, d_alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, dx, dy_2, policy, dbuffer)); hipsparseStatus_t pivot_status_2; pivot_status_2 = hipsparseXbsrsv2_zeroPivot(handle, info, d_position); // Copy output from device to CPU int hposition_2; CHECK_HIP_ERROR( hipMemcpy(hy_1.data(), dy_1, sizeof(T) * mb * block_dim, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hy_2.data(), dy_2, sizeof(T) * mb * block_dim, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(&hposition_2, d_position, sizeof(int), hipMemcpyDeviceToHost)); // Host bsrsv2 std::vector hbsr_row_ptr(mb + 1); std::vector hbsr_col_ind(nnzb); std::vector hbsr_val(nnzb * block_dim * block_dim); CHECK_HIP_ERROR(hipMemcpy( hbsr_row_ptr.data(), dbsr_row_ptr, sizeof(int) * (mb + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hbsr_col_ind.data(), dbsr_col_ind, sizeof(int) * nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsr_val.data(), dbsr_val, sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyDeviceToHost)); int struct_position_gold; int position_gold; bsrsv(trans, dir, mb, nnzb, h_alpha, hbsr_row_ptr.data(), hbsr_col_ind.data(), hbsr_val.data(), block_dim, hx.data(), hy_gold.data(), diag_type, fill_mode, idx_base, &struct_position_gold, &position_gold); unit_check_general(1, 1, 1, &position_gold, &hposition_1); unit_check_general(1, 1, 1, &position_gold, &hposition_2); if(hposition_1 != -1) { verify_hipsparse_status_zero_pivot(pivot_status_1, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); return HIPSPARSE_STATUS_SUCCESS; } if(hposition_2 != -1) { verify_hipsparse_status_zero_pivot(pivot_status_2, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); return HIPSPARSE_STATUS_SUCCESS; } unit_check_near(1, mb * block_dim, 1, hy_gold.data(), hy_1.data()); unit_check_near(1, mb * block_dim, 1, hy_gold.data(), hy_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXbsrsv2_solve(handle, dir, trans, mb, nnzb, &h_alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, dx, dy_1, policy, dbuffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXbsrsv2_solve(handle, dir, trans, mb, nnzb, &h_alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, dx, dy_1, policy, dbuffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = csrsv_gflop_count(mb * block_dim, size_t(nnzb) * block_dim * block_dim, diag_type); double gbyte_count = bsrsv_gbyte_count(mb, nnzb, block_dim); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::nnz, nnzb * block_dim * block_dim, display_key_t::alpha, h_alpha, display_key_t::trans, hipsparse_operation2string(trans), display_key_t::diag_type, hipsparse_diagtype2string(diag_type), display_key_t::fill_mode, hipsparse_fillmode2string(fill_mode), display_key_t::solve_policy, hipsparse_solvepolicy2string(policy), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_BSRSV2_HPP ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5623991 hipsparse/clients/include/testing_bsrxmv.hpp0000664000175100017510000007260415206065364021677 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5623991 hipsparse/clients/include/testing_const_dnmat_descr.hpp0000664000175100017510000001251215206065364024037 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5623991 hipsparse/clients/include/testing_const_dnvec_descr.hpp0000664000175100017510000000753615206065364024045 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.563399 hipsparse/clients/include/testing_const_spmat_descr.hpp0000664000175100017510000013616515206065364024073 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.563399 hipsparse/clients/include/testing_const_spvec_descr.hpp0000664000175100017510000001325515206065364024061 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.563399 hipsparse/clients/include/testing_coo2csr.hpp0000664000175100017510000001502415206065364021721 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_COO2CSR_HPP #define TESTING_COO2CSR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_coo2csr_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int m = 100; int nnz = 100; int safe_size = 100; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto coo_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; int* coo_row_ind = (int*)coo_row_ind_managed.get(); int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); verify_hipsparse_status_invalid_pointer( hipsparseXcoo2csr(handle, (int*)nullptr, nnz, m, csr_row_ptr, idx_base), "Error: coo_row_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcoo2csr(handle, coo_row_ind, nnz, m, (int*)nullptr, idx_base), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXcoo2csr((hipsparseHandle_t) nullptr, coo_row_ind, nnz, m, csr_row_ptr, idx_base)); #endif } template hipsparseStatus_t testing_coo2csr(Arguments argus) { int m = argus.M; int n = argus.N; hipsparseIndexBase_t idx_base = argus.baseA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; if(m == 0 || n == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcoo_row_ind; std::vector hcoo_col_ind; std::vector hcoo_val; // Read or construct CSR matrix int nnz = 0; if(!generate_coo_matrix(filename, m, n, nnz, hcoo_row_ind, hcoo_col_ind, hcoo_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hcsr_row_ptr(m + 1); std::vector hcsr_row_ptr_gold(m + 1, 0); // Allocate memory on the device auto dcoo_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; int* dcoo_row_ind = (int*)dcoo_row_ind_managed.get(); int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); // Copy data from host to device CHECK_HIP_ERROR( hipMemcpy(dcoo_row_ind, hcoo_row_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR( hipsparseXcoo2csr(handle, dcoo_row_ind, nnz, m, dcsr_row_ptr, idx_base)); // Copy output from device to host CHECK_HIP_ERROR(hipMemcpy( hcsr_row_ptr.data(), dcsr_row_ptr, sizeof(int) * (m + 1), hipMemcpyDeviceToHost)); // CPU // coo2csr on host for(int i = 0; i < nnz; ++i) { ++hcsr_row_ptr_gold[hcoo_row_ind[i] + 1 - idx_base]; } hcsr_row_ptr_gold[0] = idx_base; for(int i = 0; i < m; ++i) { hcsr_row_ptr_gold[i + 1] += hcsr_row_ptr_gold[i]; } // Unit check unit_check_general(1, m + 1, 1, hcsr_row_ptr_gold.data(), hcsr_row_ptr.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXcoo2csr(handle, dcoo_row_ind, nnz, m, dcsr_row_ptr, idx_base)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXcoo2csr(handle, dcoo_row_ind, nnz, m, dcsr_row_ptr, idx_base)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = coo2csr_gbyte_count(m, nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_COO2CSR_HPP ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.563399 hipsparse/clients/include/testing_coosort.hpp0000664000175100017510000003206015206065364022036 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.563399 hipsparse/clients/include/testing_csc2dense.hpp0000664000175100017510000000405115206065364022216 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSC2DENSE_HPP #define TESTING_CSC2DENSE_HPP #include "testing_csx2dense.hpp" template void testing_csc2dense_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_COLUMN; testing_csx2dense_bad_arg(hipsparseXcsc2dense); #endif } template hipsparseStatus_t testing_csc2dense(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_COLUMN; return testing_csx2dense(argus, hipsparseXcsc2dense, hipsparseXdense2csc); #else return HIPSPARSE_STATUS_SUCCESS; #endif } #endif // TESTING_CSC2DENSE ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.563399 hipsparse/clients/include/testing_cscsort.hpp0000664000175100017510000002712715206065364022036 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5643992 hipsparse/clients/include/testing_csr2bsr.hpp0000664000175100017510000010366715206065364021742 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSR2BSR_HPP #define TESTING_CSR2BSR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csr2bsr_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int m = 1; int n = 1; int safe_size = 1; int block_dim = 2; hipsparseIndexBase_t csr_idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexBase_t bsr_idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseDirection_t dir = HIPSPARSE_DIRECTION_ROW; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_csr_descr(new descr_struct); hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; std::unique_ptr unique_ptr_bsr_descr(new descr_struct); hipsparseMatDescr_t bsr_descr = unique_ptr_bsr_descr->descr; hipsparseSetMatIndexBase(csr_descr, csr_idx_base); hipsparseSetMatIndexBase(bsr_descr, bsr_idx_base); auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto csr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto bsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto bsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto bsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* csr_col_ind = (int*)csr_col_ind_managed.get(); T* csr_val = (T*)csr_val_managed.get(); int* bsr_row_ptr = (int*)bsr_row_ptr_managed.get(); int* bsr_col_ind = (int*)bsr_col_ind_managed.get(); T* bsr_val = (T*)bsr_val_managed.get(); int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(csr_row_ptr, local_ptr, sizeof(int) * (1 + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(bsr_row_ptr, local_ptr, sizeof(int) * (1 + 1), hipMemcpyHostToDevice)); int bsr_nnzb; verify_hipsparse_status_invalid_handle(hipsparseXcsr2bsrNnz(nullptr, dir, m, n, csr_descr, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_row_ptr, &bsr_nnzb)); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsrNnz(handle, dir, m, n, nullptr, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_row_ptr, &bsr_nnzb), "Error: csr_descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsrNnz(handle, dir, m, n, csr_descr, nullptr, csr_col_ind, block_dim, bsr_descr, bsr_row_ptr, &bsr_nnzb), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsrNnz(handle, dir, m, n, csr_descr, csr_row_ptr, csr_col_ind, block_dim, nullptr, bsr_row_ptr, &bsr_nnzb), "Error: bsr_descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsrNnz(handle, dir, m, n, csr_descr, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, nullptr, &bsr_nnzb), "Error: bsr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsrNnz(handle, dir, m, n, csr_descr, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_row_ptr, nullptr), "Error: bsr_nnzb is nullptr"); verify_hipsparse_status_invalid_size(hipsparseXcsr2bsrNnz(handle, dir, -1, n, csr_descr, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_row_ptr, &bsr_nnzb), "Error: m is invalid"); verify_hipsparse_status_invalid_size(hipsparseXcsr2bsrNnz(handle, dir, m, -1, csr_descr, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_row_ptr, &bsr_nnzb), "Error: n is invalid"); verify_hipsparse_status_invalid_size(hipsparseXcsr2bsrNnz(handle, dir, m, n, csr_descr, csr_row_ptr, csr_col_ind, -1, bsr_descr, bsr_row_ptr, &bsr_nnzb), "Error: block_dim is invalid"); verify_hipsparse_status_invalid_handle(hipsparseXcsr2bsr(nullptr, dir, m, n, csr_descr, csr_val, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind)); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsr(handle, dir, m, n, nullptr, csr_val, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind), "Error: csr_descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsr(handle, dir, m, n, csr_descr, (T*)nullptr, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind), "Error: csr_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsr(handle, dir, m, n, csr_descr, csr_val, nullptr, csr_col_ind, block_dim, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsr(handle, dir, m, n, csr_descr, csr_val, csr_row_ptr, nullptr, block_dim, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsr(handle, dir, m, n, csr_descr, csr_val, csr_row_ptr, csr_col_ind, block_dim, nullptr, bsr_val, bsr_row_ptr, bsr_col_ind), "Error: bsr_descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsr(handle, dir, m, n, csr_descr, csr_val, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, (T*)nullptr, bsr_row_ptr, bsr_col_ind), "Error: bsr_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsr(handle, dir, m, n, csr_descr, csr_val, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_val, nullptr, bsr_col_ind), "Error: bsr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsr(handle, dir, m, n, csr_descr, csr_val, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_val, bsr_row_ptr, nullptr), "Error: bsr_col_ind is nullptr"); verify_hipsparse_status_invalid_size(hipsparseXcsr2bsr(handle, dir, -1, n, csr_descr, csr_val, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind), "Error: m is invalid"); verify_hipsparse_status_invalid_size(hipsparseXcsr2bsr(handle, dir, m, -1, csr_descr, csr_val, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind), "Error: n is invalid"); verify_hipsparse_status_invalid_size(hipsparseXcsr2bsr(handle, dir, m, n, csr_descr, csr_val, csr_row_ptr, csr_col_ind, -1, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind), "Error: block_dim is invalid"); #endif } template hipsparseStatus_t testing_csr2bsr(Arguments argus) { int m = argus.M; int n = argus.N; int block_dim = argus.block_dim; hipsparseIndexBase_t csr_idx_base = argus.baseA; hipsparseIndexBase_t bsr_idx_base = argus.baseB; hipsparseDirection_t dir = argus.dirA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_csr_descr(new descr_struct); hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; std::unique_ptr unique_ptr_bsr_descr(new descr_struct); hipsparseMatDescr_t bsr_descr = unique_ptr_bsr_descr->descr; hipsparseSetMatIndexBase(csr_descr, csr_idx_base); hipsparseSetMatIndexBase(bsr_descr, bsr_idx_base); if(m == 0 || n == 0 || block_dim == 1) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse does not support m == 0 or n == 0 for csr2bsr // cusparse does not support asynchronous execution if block_dim == 1 return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix( filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, csr_idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } int mb = (m + block_dim - 1) / block_dim; int nb = (n + block_dim - 1) / block_dim; // Allocate memory on the device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dbsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb + 1)), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); int* dbsr_row_ptr = (int*)dbsr_row_ptr_managed.get(); // Copy data from host to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_val, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); // Obtain BSR nnzb first on the host and then using the device and ensure they give the same results CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); int hbsr_nnzb; CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsrNnz(handle, dir, m, n, csr_descr, dcsr_row_ptr, dcsr_col_ind, block_dim, bsr_descr, dbsr_row_ptr, &hbsr_nnzb)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); auto dbsr_nnzb_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dbsr_nnzb = (int*)dbsr_nnzb_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsrNnz(handle, dir, m, n, csr_descr, dcsr_row_ptr, dcsr_col_ind, block_dim, bsr_descr, dbsr_row_ptr, dbsr_nnzb)); int hbsr_nnzb_copied_from_device; CHECK_HIP_ERROR( hipMemcpy(&hbsr_nnzb_copied_from_device, dbsr_nnzb, sizeof(int), hipMemcpyDeviceToHost)); // Check that using host and device pointer mode gives the same result unit_check_general(1, 1, 1, &hbsr_nnzb_copied_from_device, &hbsr_nnzb); // Allocate memory on the device auto dbsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * hbsr_nnzb), device_free}; auto dbsr_val_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * hbsr_nnzb * block_dim * block_dim), device_free}; int* dbsr_col_ind = (int*)dbsr_col_ind_managed.get(); T* dbsr_val = (T*)dbsr_val_managed.get(); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsr(handle, dir, m, n, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, block_dim, bsr_descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind)); // Copy output from device to host std::vector hbsr_row_ptr(mb + 1); std::vector hbsr_col_ind(hbsr_nnzb); std::vector hbsr_val(hbsr_nnzb * block_dim * block_dim); CHECK_HIP_ERROR(hipMemcpy( hbsr_row_ptr.data(), dbsr_row_ptr, sizeof(int) * (mb + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hbsr_col_ind.data(), dbsr_col_ind, sizeof(int) * hbsr_nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsr_val.data(), dbsr_val, sizeof(T) * hbsr_nnzb * block_dim * block_dim, hipMemcpyDeviceToHost)); // Host csr2bsr conversion std::vector hbsr_row_ptr_gold(mb + 1); std::vector hbsr_col_ind_gold(hbsr_nnzb, 0); std::vector hbsr_val_gold(hbsr_nnzb * block_dim * block_dim); // call host csr2bsr here int bsr_nnzb_gold; host_csr_to_bsr(dir, m, n, block_dim, bsr_nnzb_gold, csr_idx_base, hcsr_row_ptr, hcsr_col_ind, hcsr_val, bsr_idx_base, hbsr_row_ptr_gold, hbsr_col_ind_gold, hbsr_val_gold); // Unit check unit_check_general(1, 1, 1, &bsr_nnzb_gold, &hbsr_nnzb); unit_check_general(1, mb + 1, 1, hbsr_row_ptr_gold.data(), hbsr_row_ptr.data()); unit_check_general(1, hbsr_nnzb, 1, hbsr_col_ind_gold.data(), hbsr_col_ind.data()); unit_check_general( 1, hbsr_nnzb * block_dim * block_dim, 1, hbsr_val_gold.data(), hbsr_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsr(handle, dir, m, n, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, block_dim, bsr_descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsr(handle, dir, m, n, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, block_dim, bsr_descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = csr2bsr_gbyte_count(m, mb, nnz, hbsr_nnzb, block_dim); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::Mb, mb, display_key_t::Nb, nb, display_key_t::block_dim, block_dim, display_key_t::nnzb, hbsr_nnzb, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSR2BSR_HPP ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5643992 hipsparse/clients/include/testing_csr2coo.hpp0000664000175100017510000001466315206065364021731 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSR2COO_HPP #define TESTING_CSR2COO_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csr2coo_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int m = 100; int nnz = 100; int safe_size = 100; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto coo_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* coo_row_ind = (int*)coo_row_ind_managed.get(); verify_hipsparse_status_invalid_pointer( hipsparseXcsr2coo(handle, (int*)nullptr, nnz, m, coo_row_ind, idx_base), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsr2coo(handle, csr_row_ptr, nnz, m, (int*)nullptr, idx_base), "Error: coo_row_ind is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXcsr2coo((hipsparseHandle_t) nullptr, csr_row_ptr, nnz, m, coo_row_ind, idx_base)); #endif } template hipsparseStatus_t testing_csr2coo(Arguments argus) { int m = argus.M; int n = argus.N; hipsparseIndexBase_t idx_base = argus.baseA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Allocate memory on the device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcoo_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcoo_row_ind = (int*)dcoo_row_ind_managed.get(); // Copy data from host to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR( hipsparseXcsr2coo(handle, dcsr_row_ptr, nnz, m, dcoo_row_ind, idx_base)); // Copy output from device to host std::vector hcoo_row_ind(nnz); CHECK_HIP_ERROR( hipMemcpy(hcoo_row_ind.data(), dcoo_row_ind, sizeof(int) * nnz, hipMemcpyDeviceToHost)); // CPU conversion to COO std::vector hcoo_row_ind_gold(nnz); for(int i = 0; i < m; ++i) { int row_begin = hcsr_row_ptr[i] - idx_base; int row_end = hcsr_row_ptr[i + 1] - idx_base; for(int j = row_begin; j < row_end; ++j) { hcoo_row_ind_gold[j] = i + idx_base; } } // Unit check unit_check_general(1, nnz, 1, hcoo_row_ind_gold.data(), hcoo_row_ind.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXcsr2coo(handle, dcsr_row_ptr, nnz, m, dcoo_row_ind, idx_base)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXcsr2coo(handle, dcsr_row_ptr, nnz, m, dcoo_row_ind, idx_base)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = csr2coo_gbyte_count(m, nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSR2COO_HPP ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5643992 hipsparse/clients/include/testing_csr2csc.hpp0000664000175100017510000004267615206065364021726 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSR2CSC_HPP #define TESTING_CSR2CSC_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csr2csc_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int m = 100; int n = 100; int nnz = 100; int safe_size = 100; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto csc_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csc_col_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csc_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* csr_col_ind = (int*)csr_col_ind_managed.get(); T* csr_val = (T*)csr_val_managed.get(); int* csc_row_ind = (int*)csc_row_ind_managed.get(); int* csc_col_ptr = (int*)csc_col_ptr_managed.get(); T* csc_val = (T*)csc_val_managed.get(); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csc(handle, m, n, nnz, csr_val, (int*)nullptr, csr_col_ind, csc_val, csc_row_ind, csc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csc(handle, m, n, nnz, csr_val, csr_row_ptr, (int*)nullptr, csc_val, csc_row_ind, csc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csc(handle, m, n, nnz, (T*)nullptr, csr_row_ptr, csr_col_ind, csc_val, csc_row_ind, csc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO), "Error: csr_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csc(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, (int*)nullptr, csc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO), "Error: csc_row_ind is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csc(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, csc_row_ind, (int*)nullptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO), "Error: csc_col_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csc(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, (T*)nullptr, csc_row_ind, csc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO), "Error: csc_val is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsr2csc((hipsparseHandle_t) nullptr, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, csc_row_ind, csc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO)); #endif } template hipsparseStatus_t testing_csr2csc(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) int m = argus.M; int n = argus.N; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseAction_t action = argus.action; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Allocate memory on the device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dcsc_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsc_col_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (n + 1)), device_free}; auto dcsc_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); int* dcsc_row_ind = (int*)dcsc_row_ind_managed.get(); int* dcsc_col_ptr = (int*)dcsc_col_ptr_managed.get(); T* dcsc_val = (T*)dcsc_val_managed.get(); // Reset CSC arrays CHECK_HIP_ERROR(hipMemset(dcsc_row_ind, 0, sizeof(int) * nnz)); CHECK_HIP_ERROR(hipMemset(dcsc_col_ptr, 0, sizeof(int) * (n + 1))); CHECK_HIP_ERROR(hipMemset(dcsc_val, 0, sizeof(T) * nnz)); // Copy data from host to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_val, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2csc(handle, m, n, nnz, dcsr_val, dcsr_row_ptr, dcsr_col_ind, dcsc_val, dcsc_row_ind, dcsc_col_ptr, action, idx_base)); // Copy output from device to host std::vector hcsc_row_ind(nnz); std::vector hcsc_col_ptr(n + 1); std::vector hcsc_val(nnz); CHECK_HIP_ERROR( hipMemcpy(hcsc_row_ind.data(), dcsc_row_ind, sizeof(int) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcsc_col_ptr.data(), dcsc_col_ptr, sizeof(int) * (n + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsc_val.data(), dcsc_val, sizeof(T) * nnz, hipMemcpyDeviceToHost)); // Host csr2csc conversion std::vector hcsc_row_ind_gold(nnz); std::vector hcsc_col_ptr_gold(n + 1, 0); std::vector hcsc_val_gold(nnz); // Determine nnz per column for(int i = 0; i < nnz; ++i) { ++hcsc_col_ptr_gold[hcsr_col_ind[i] + 1 - idx_base]; } // Scan for(int i = 0; i < n; ++i) { hcsc_col_ptr_gold[i + 1] += hcsc_col_ptr_gold[i]; } // Fill row indices and values for(int i = 0; i < m; ++i) { for(int j = hcsr_row_ptr[i]; j < hcsr_row_ptr[i + 1]; ++j) { int col = hcsr_col_ind[j - idx_base] - idx_base; int idx = hcsc_col_ptr_gold[col]; hcsc_row_ind_gold[idx] = i + idx_base; hcsc_val_gold[idx] = hcsr_val[j - idx_base]; ++hcsc_col_ptr_gold[col]; } } // Shift column pointer array for(int i = n; i > 0; --i) { hcsc_col_ptr_gold[i] = hcsc_col_ptr_gold[i - 1] + idx_base; } hcsc_col_ptr_gold[0] = idx_base; // Unit check unit_check_general(1, nnz, 1, hcsc_row_ind_gold.data(), hcsc_row_ind.data()); unit_check_general(1, n + 1, 1, hcsc_col_ptr_gold.data(), hcsc_col_ptr.data()); // If action == HIPSPARSE_ACTION_NUMERIC also check values if(action == HIPSPARSE_ACTION_NUMERIC) { unit_check_general(1, nnz, 1, hcsc_val_gold.data(), hcsc_val.data()); } } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2csc(handle, m, n, nnz, dcsr_val, dcsr_row_ptr, dcsr_col_ind, dcsc_val, dcsc_row_ind, dcsc_col_ptr, action, idx_base)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2csc(handle, m, n, nnz, dcsr_val, dcsr_row_ptr, dcsr_col_ind, dcsc_val, dcsc_row_ind, dcsc_col_ptr, action, idx_base)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = csr2csc_gbyte_count(m, n, nnz, action); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::action, hipsparse_action2string(action), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSR2CSC_HPP ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5643992 hipsparse/clients/include/testing_csr2csc_ex2.hpp0000664000175100017510000006367215206065364022503 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2022-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSR2CSC_EX2_HPP #define TESTING_CSR2CSC_EX2_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csr2csc_ex2_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int m = 100; int n = 100; int nnz = 100; int safe_size = 100; size_t buffer_size = 0; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto csc_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csc_col_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csc_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto buffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* csr_col_ind = (int*)csr_col_ind_managed.get(); T* csr_val = (T*)csr_val_managed.get(); int* csc_row_ind = (int*)csc_row_ind_managed.get(); int* csc_col_ptr = (int*)csc_col_ptr_managed.get(); T* csc_val = (T*)csc_val_managed.get(); void* buffer = (void*)buffer_managed.get(); verify_hipsparse_status_invalid_handle( hipsparseCsr2cscEx2_bufferSize((hipsparseHandle_t) nullptr, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, csc_col_ptr, csc_row_ind, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, &buffer_size)); verify_hipsparse_status_invalid_pointer( hipsparseCsr2cscEx2_bufferSize(handle, m, n, nnz, csr_val, (int*)nullptr, csr_col_ind, csc_val, csc_col_ptr, csc_row_ind, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, &buffer_size), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCsr2cscEx2_bufferSize(handle, m, n, nnz, csr_val, csr_row_ptr, (int*)nullptr, csc_val, csc_col_ptr, csc_row_ind, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, &buffer_size), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCsr2cscEx2_bufferSize(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, csc_col_ptr, csc_row_ind, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, (size_t*)nullptr), "Error: buffer_size is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseCsr2cscEx2((hipsparseHandle_t) nullptr, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, csc_col_ptr, csc_row_ind, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, buffer)); verify_hipsparse_status_invalid_pointer(hipsparseCsr2cscEx2(handle, m, n, nnz, csr_val, (int*)nullptr, csr_col_ind, csc_val, csc_col_ptr, csc_row_ind, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, buffer), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsr2cscEx2(handle, m, n, nnz, csr_val, csr_row_ptr, (int*)nullptr, csc_val, csc_col_ptr, csc_row_ind, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, buffer), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsr2cscEx2(handle, m, n, nnz, (T*)nullptr, csr_row_ptr, csr_col_ind, csc_val, csc_col_ptr, csc_row_ind, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, buffer), "Error: csr_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsr2cscEx2(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, (int*)nullptr, csc_row_ind, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, buffer), "Error: csc_col_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsr2cscEx2(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, csc_col_ptr, (int*)nullptr, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, buffer), "Error: csc_row_ind is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsr2cscEx2(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, (T*)nullptr, csc_col_ptr, csc_row_ind, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, buffer), "Error: csc_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsr2cscEx2(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, csc_col_ptr, csc_row_ind, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, (T*)nullptr), "Error: buffer is nullptr"); #endif } template hipsparseStatus_t testing_csr2csc_ex2(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) int m = argus.M; int n = argus.N; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseAction_t action = argus.action; hipsparseCsr2CscAlg_t alg = static_cast(argus.csr2csc_alg); std::string filename = argus.filename; hipDataType dataType = getDataType(); std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Allocate memory on the device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dcsc_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsc_col_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (n + 1)), device_free}; auto dcsc_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); int* dcsc_row_ind = (int*)dcsc_row_ind_managed.get(); int* dcsc_col_ptr = (int*)dcsc_col_ptr_managed.get(); T* dcsc_val = (T*)dcsc_val_managed.get(); // Reset CSC arrays CHECK_HIP_ERROR(hipMemset(dcsc_row_ind, 0, sizeof(int) * nnz)); CHECK_HIP_ERROR(hipMemset(dcsc_col_ptr, 0, sizeof(int) * (n + 1))); CHECK_HIP_ERROR(hipMemset(dcsc_val, 0, sizeof(T) * nnz)); // Copy data from host to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_val, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseCsr2cscEx2_bufferSize(handle, m, n, nnz, dcsr_val, dcsr_row_ptr, dcsr_col_ind, dcsc_val, dcsc_col_ptr, dcsc_row_ind, dataType, action, idx_base, alg, &bufferSize)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * bufferSize), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseCsr2cscEx2(handle, m, n, nnz, dcsr_val, dcsr_row_ptr, dcsr_col_ind, dcsc_val, dcsc_col_ptr, dcsc_row_ind, dataType, action, idx_base, alg, dbuffer)); // Copy output from device to host std::vector hcsc_row_ind(nnz); std::vector hcsc_col_ptr(n + 1); std::vector hcsc_val(nnz); CHECK_HIP_ERROR( hipMemcpy(hcsc_row_ind.data(), dcsc_row_ind, sizeof(int) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcsc_col_ptr.data(), dcsc_col_ptr, sizeof(int) * (n + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsc_val.data(), dcsc_val, sizeof(T) * nnz, hipMemcpyDeviceToHost)); // Host csr2csc conversion std::vector hcsc_row_ind_gold(nnz); std::vector hcsc_col_ptr_gold(n + 1, 0); std::vector hcsc_val_gold(nnz); // Determine nnz per column for(int i = 0; i < nnz; ++i) { ++hcsc_col_ptr_gold[hcsr_col_ind[i] + 1 - idx_base]; } // Scan for(int i = 0; i < n; ++i) { hcsc_col_ptr_gold[i + 1] += hcsc_col_ptr_gold[i]; } // Fill row indices and values for(int i = 0; i < m; ++i) { for(int j = hcsr_row_ptr[i]; j < hcsr_row_ptr[i + 1]; ++j) { int col = hcsr_col_ind[j - idx_base] - idx_base; int idx = hcsc_col_ptr_gold[col]; hcsc_row_ind_gold[idx] = i + idx_base; hcsc_val_gold[idx] = hcsr_val[j - idx_base]; ++hcsc_col_ptr_gold[col]; } } // Shift column pointer array for(int i = n; i > 0; --i) { hcsc_col_ptr_gold[i] = hcsc_col_ptr_gold[i - 1] + idx_base; } hcsc_col_ptr_gold[0] = idx_base; // Unit check unit_check_general(1, nnz, 1, hcsc_row_ind_gold.data(), hcsc_row_ind.data()); unit_check_general(1, n + 1, 1, hcsc_col_ptr_gold.data(), hcsc_col_ptr.data()); // If action == HIPSPARSE_ACTION_NUMERIC also check values if(action == HIPSPARSE_ACTION_NUMERIC) { unit_check_general(1, nnz, 1, hcsc_val_gold.data(), hcsc_val.data()); } } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseCsr2cscEx2(handle, m, n, nnz, dcsr_val, dcsr_row_ptr, dcsr_col_ind, dcsc_val, dcsc_col_ptr, dcsc_row_ind, dataType, action, idx_base, alg, dbuffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseCsr2cscEx2(handle, m, n, nnz, dcsr_val, dcsr_row_ptr, dcsr_col_ind, dcsc_val, dcsc_col_ptr, dcsc_row_ind, dataType, action, idx_base, alg, dbuffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = csr2csc_gbyte_count(m, n, nnz, action); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::action, hipsparse_action2string(action), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSR2CSC_EX2_HPP ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5643992 hipsparse/clients/include/testing_csr2csr_compress.hpp0000664000175100017510000007451415206065364023654 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSR2CSR_COMPRESS_HPP #define TESTING_CSR2CSR_COMPRESS_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csr2csr_compress_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int m = 1; int n = 1; int nnz_A = 1; int safe_size = 1; T tol = make_DataType(0); hipsparseIndexBase_t csr_idx_base = HIPSPARSE_INDEX_BASE_ZERO; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_csr_descr(new descr_struct); hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; hipsparseSetMatIndexBase(csr_descr, csr_idx_base); auto csr_row_ptr_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto csr_col_ind_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto csr_row_ptr_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto csr_col_ind_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto nnz_per_row_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto nnz_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* csr_row_ptr_A = (int*)csr_row_ptr_A_managed.get(); int* csr_col_ind_A = (int*)csr_col_ind_A_managed.get(); T* csr_val_A = (T*)csr_val_A_managed.get(); int* csr_row_ptr_C = (int*)csr_row_ptr_C_managed.get(); int* csr_col_ind_C = (int*)csr_col_ind_C_managed.get(); T* csr_val_C = (T*)csr_val_C_managed.get(); int* nnz_per_row = (int*)nnz_per_row_managed.get(); int* nnz_C = (int*)nnz_C_managed.get(); int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(csr_row_ptr_A, local_ptr, sizeof(int) * (1 + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(csr_row_ptr_C, local_ptr, sizeof(int) * (1 + 1), hipMemcpyHostToDevice)); int local_nnz[1] = {1}; CHECK_HIP_ERROR(hipMemcpy(nnz_per_row, local_nnz, sizeof(int), hipMemcpyHostToDevice)); verify_hipsparse_status_invalid_handle(hipsparseXnnz_compress( nullptr, m, csr_descr, csr_val_A, csr_row_ptr_A, nnz_per_row, nnz_C, tol)); verify_hipsparse_status_invalid_pointer( hipsparseXnnz_compress( handle, m, nullptr, csr_val_A, csr_row_ptr_A, nnz_per_row, nnz_C, tol), "Error: Matrix descriptor is invalid"); verify_hipsparse_status_invalid_pointer( hipsparseXnnz_compress(handle, m, csr_descr, csr_val_A, nullptr, nnz_per_row, nnz_C, tol), "Error: CSR row pointer array is invalid"); verify_hipsparse_status_invalid_pointer( hipsparseXnnz_compress(handle, m, csr_descr, csr_val_A, csr_row_ptr_A, nullptr, nnz_C, tol), "Error: Number of elements per row array is invalid"); verify_hipsparse_status_invalid_pointer( hipsparseXnnz_compress( handle, m, csr_descr, csr_val_A, csr_row_ptr_A, nnz_per_row, nullptr, tol), "Error: Total number of elements pointer is invalid"); verify_hipsparse_status_invalid_size( hipsparseXnnz_compress( handle, -1, csr_descr, csr_val_A, csr_row_ptr_A, nnz_per_row, nnz_C, tol), "Error: Matrix size is invalid"); verify_hipsparse_status_invalid_size(hipsparseXnnz_compress(handle, m, csr_descr, csr_val_A, csr_row_ptr_A, nnz_per_row, nnz_C, make_DataType(-1)), "Error: Tolerance is invalid"); verify_hipsparse_status_invalid_handle(hipsparseXcsr2csr_compress(nullptr, m, n, csr_descr, csr_val_A, csr_col_ind_A, csr_row_ptr_A, nnz_A, nnz_per_row, csr_val_C, csr_col_ind_C, csr_row_ptr_C, tol)); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csr_compress(handle, m, n, nullptr, csr_val_A, csr_col_ind_A, csr_row_ptr_A, nnz_A, nnz_per_row, csr_val_C, csr_col_ind_C, csr_row_ptr_C, tol), "Error: Matrix descriptor is invalid"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csr_compress(handle, m, n, csr_descr, (const T*)nullptr, csr_col_ind_A, csr_row_ptr_A, nnz_A, nnz_per_row, csr_val_C, csr_col_ind_C, csr_row_ptr_C, tol), "Error: CSR matrix values array is invalid"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csr_compress(handle, m, n, csr_descr, csr_val_A, nullptr, csr_row_ptr_A, nnz_A, nnz_per_row, csr_val_C, csr_col_ind_C, csr_row_ptr_C, tol), "Error: CSR matrix column indices array is invalid"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csr_compress(handle, m, n, csr_descr, csr_val_A, csr_col_ind_A, nullptr, nnz_A, nnz_per_row, csr_val_C, csr_col_ind_C, csr_row_ptr_C, tol), "Error: CSR matrix row pointer array is invalid"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csr_compress(handle, m, n, csr_descr, csr_val_A, csr_col_ind_A, csr_row_ptr_A, nnz_A, nullptr, csr_val_C, csr_col_ind_C, csr_row_ptr_C, tol), "Error: Number of elements per row array is invalid"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csr_compress(handle, m, n, csr_descr, csr_val_A, csr_col_ind_A, csr_row_ptr_A, nnz_A, nnz_per_row, (T*)nullptr, csr_col_ind_C, csr_row_ptr_C, tol), "Error: CSR matrix values array is invalid"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csr_compress(handle, m, n, csr_descr, csr_val_A, csr_col_ind_A, csr_row_ptr_A, nnz_A, nnz_per_row, csr_val_C, nullptr, csr_row_ptr_C, tol), "Error: CSR matrix column indices array is invalid"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csr_compress(handle, m, n, csr_descr, csr_val_A, csr_col_ind_A, csr_row_ptr_A, nnz_A, nnz_per_row, csr_val_C, csr_col_ind_C, nullptr, tol), "Error: CSR matrix row pointer array is invalid"); verify_hipsparse_status_invalid_size(hipsparseXcsr2csr_compress(handle, -1, n, csr_descr, csr_val_A, csr_col_ind_A, csr_row_ptr_A, nnz_A, nnz_per_row, csr_val_C, csr_col_ind_C, csr_row_ptr_C, tol), "Error: Matrix size is invalid"); verify_hipsparse_status_invalid_size(hipsparseXcsr2csr_compress(handle, m, -1, csr_descr, csr_val_A, csr_col_ind_A, csr_row_ptr_A, nnz_A, nnz_per_row, csr_val_C, csr_col_ind_C, csr_row_ptr_C, tol), "Error: Matrix size is invalid"); verify_hipsparse_status_invalid_size(hipsparseXcsr2csr_compress(handle, m, n, csr_descr, csr_val_A, csr_col_ind_A, csr_row_ptr_A, -1, nnz_per_row, csr_val_C, csr_col_ind_C, csr_row_ptr_C, tol), "Error: Matrix size is invalid"); verify_hipsparse_status_invalid_value(hipsparseXcsr2csr_compress(handle, m, n, csr_descr, csr_val_A, csr_col_ind_A, csr_row_ptr_A, nnz_A, nnz_per_row, csr_val_C, csr_col_ind_C, csr_row_ptr_C, static_cast(-1)), "Error: Tolerance is invalid"); #endif } template hipsparseStatus_t testing_csr2csr_compress(Arguments argus) { int m = argus.M; int n = argus.N; T tol = make_DataType(argus.alpha); hipsparseIndexBase_t idx_base = argus.baseA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_csr_descr(new descr_struct); hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; hipsparseSetMatIndexBase(csr_descr, idx_base); hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE); srand(12345ULL); // Host structures std::vector hcsr_row_ptr_A; std::vector hcsr_col_ind_A; std::vector hcsr_val_A; // Read or construct CSR matrix int hnnz_A = 0; if(!generate_csr_matrix( filename, m, n, hnnz_A, hcsr_row_ptr_A, hcsr_col_ind_A, hcsr_val_A, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Allocate memory on the device auto dcsr_row_ptr_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * hnnz_A), device_free}; auto dcsr_val_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * hnnz_A), device_free}; auto dcsr_row_ptr_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dnnz_per_row_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * m), device_free}; int* dcsr_row_ptr_A = (int*)dcsr_row_ptr_A_managed.get(); int* dcsr_col_ind_A = (int*)dcsr_col_ind_A_managed.get(); T* dcsr_val_A = (T*)dcsr_val_A_managed.get(); int* dcsr_row_ptr_C = (int*)dcsr_row_ptr_C_managed.get(); int* dnnz_per_row = (int*)dnnz_per_row_managed.get(); // Copy data from host to device CHECK_HIP_ERROR(hipMemcpy( dcsr_row_ptr_A, hcsr_row_ptr_A.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy( dcsr_col_ind_A, hcsr_col_ind_A.data(), sizeof(int) * hnnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_val_A, hcsr_val_A.data(), sizeof(T) * hnnz_A, hipMemcpyHostToDevice)); if(argus.unit_check) { // Use both host and device pointers for nnz_C and confirm they give the same answer CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); int hnnz_C; CHECK_HIPSPARSE_ERROR(hipsparseXnnz_compress( handle, m, csr_descr, dcsr_val_A, dcsr_row_ptr_A, dnnz_per_row, &hnnz_C, tol)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); auto dnnz_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dnnz_C = (int*)dnnz_C_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseXnnz_compress( handle, m, csr_descr, dcsr_val_A, dcsr_row_ptr_A, dnnz_per_row, dnnz_C, tol)); int hnnz_C_copied_from_device; CHECK_HIP_ERROR( hipMemcpy(&hnnz_C_copied_from_device, dnnz_C, sizeof(int), hipMemcpyDeviceToHost)); unit_check_general(1, 1, 1, &hnnz_C_copied_from_device, &hnnz_C); if(hnnz_C == 0) { return HIPSPARSE_STATUS_SUCCESS; } // Allocate device memory for compressed CSR columns indices and values auto dcsr_col_ind_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * hnnz_C), device_free}; auto dcsr_val_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * hnnz_C), device_free}; int* dcsr_col_ind_C = (int*)dcsr_col_ind_C_managed.get(); T* dcsr_val_C = (T*)dcsr_val_C_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseXcsr2csr_compress(handle, m, n, csr_descr, dcsr_val_A, dcsr_col_ind_A, dcsr_row_ptr_A, hnnz_A, dnnz_per_row, dcsr_val_C, dcsr_col_ind_C, dcsr_row_ptr_C, tol)); // Copy output from device to host std::vector hcsr_row_ptr_C(m + 1); std::vector hcsr_col_ind_C(hnnz_C); std::vector hcsr_val_C(hnnz_C); CHECK_HIP_ERROR(hipMemcpy( hcsr_row_ptr_C.data(), dcsr_row_ptr_C, sizeof(int) * (m + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcsr_col_ind_C.data(), dcsr_col_ind_C, sizeof(int) * hnnz_C, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val_C.data(), dcsr_val_C, sizeof(T) * hnnz_C, hipMemcpyDeviceToHost)); // Host csr2csc conversion std::vector hcsr_row_ptr_C_gold; std::vector hcsr_col_ind_C_gold; std::vector hcsr_val_gold; // Call host conversion here host_csr_to_csr_compress(m, n, hcsr_row_ptr_A, hcsr_col_ind_A, hcsr_val_A, hcsr_row_ptr_C_gold, hcsr_col_ind_C_gold, hcsr_val_gold, idx_base, tol); // Unit check unit_check_general(1, m + 1, 1, hcsr_row_ptr_C_gold.data(), hcsr_row_ptr_C.data()); unit_check_general(1, hnnz_C, 1, hcsr_col_ind_C_gold.data(), hcsr_col_ind_C.data()); unit_check_general(1, hnnz_C, 1, hcsr_val_gold.data(), hcsr_val_C.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); int hnnz_C; CHECK_HIPSPARSE_ERROR(hipsparseXnnz_compress( handle, m, csr_descr, dcsr_val_A, dcsr_row_ptr_A, dnnz_per_row, &hnnz_C, tol)); // Allocate device memory for compressed CSR columns indices and values auto dcsr_col_ind_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * hnnz_C), device_free}; auto dcsr_val_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * hnnz_C), device_free}; int* dcsr_col_ind_C = (int*)dcsr_col_ind_C_managed.get(); T* dcsr_val_C = (T*)dcsr_val_C_managed.get(); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2csr_compress(handle, m, n, csr_descr, dcsr_val_A, dcsr_col_ind_A, dcsr_row_ptr_A, hnnz_A, dnnz_per_row, dcsr_val_C, dcsr_col_ind_C, dcsr_row_ptr_C, tol)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2csr_compress(handle, m, n, csr_descr, dcsr_val_A, dcsr_col_ind_A, dcsr_row_ptr_A, hnnz_A, dnnz_per_row, dcsr_val_C, dcsr_col_ind_C, dcsr_row_ptr_C, tol)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = csr2csr_compress_gbyte_count(m, hnnz_A, hnnz_C); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnzA, hnnz_A, display_key_t::nnzC, hnnz_C, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSR2CSR_COMPRESS_HPP ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5643992 hipsparse/clients/include/testing_csr2dense.hpp0000664000175100017510000000404315206065364022236 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSR2DENSE_HPP #define TESTING_CSR2DENSE_HPP #include "testing_csx2dense.hpp" template void testing_csr2dense_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_ROW; testing_csx2dense_bad_arg(hipsparseXcsr2dense); #endif } template hipsparseStatus_t testing_csr2dense(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_ROW; return testing_csx2dense(argus, hipsparseXcsr2dense, hipsparseXdense2csr); #else return HIPSPARSE_STATUS_SUCCESS; #endif } #endif // TESTING_CSR2DENSE ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5643992 hipsparse/clients/include/testing_csr2gebsr.hpp0000664000175100017510000006123215206065364022245 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSR2GEBSR_HPP #define TESTING_CSR2GEBSR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csr2gebsr_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) hipsparseStatus_t status; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; hipsparseIndexBase_t csr_idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexBase_t bsr_idx_base = HIPSPARSE_INDEX_BASE_ZERO; static const size_t safe_size = 1; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto csr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* csr_col_ind = (int*)csr_col_ind_managed.get(); T* csr_val = (T*)csr_val_managed.get(); auto bsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto bsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto bsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto buffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; void* buffer = buffer_managed.get(); int* bsr_row_ptr = (int*)bsr_row_ptr_managed.get(); int* bsr_col_ind = (int*)bsr_col_ind_managed.get(); T* bsr_val = (T*)bsr_val_managed.get(); { // int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(csr_row_ptr, local_ptr, sizeof(int) * (1 + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(bsr_row_ptr, local_ptr, sizeof(int) * (1 + 1), hipMemcpyHostToDevice)); } // std::unique_ptr unique_ptr_csr_descr(new descr_struct); hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; std::unique_ptr unique_ptr_bsr_descr(new descr_struct); hipsparseMatDescr_t bsr_descr = unique_ptr_bsr_descr->descr; hipsparseSetMatIndexBase(csr_descr, csr_idx_base); hipsparseSetMatIndexBase(bsr_descr, bsr_idx_base); // // Declaration of arguments. // hipsparseDirection_t arg_direction; int arg_m; int arg_n; hipsparseMatDescr_t arg_csr_descr; const T* arg_csr_val; const int* arg_csr_row_ptr; const int* arg_csr_col_ind; hipsparseMatDescr_t arg_bsr_descr; T* arg_bsr_val; int* arg_bsr_row_ptr; int* arg_bsr_col_ind; int arg_row_block_dim; int arg_col_block_dim; void* arg_p_buffer; int* arg_bsr_nnz_devhost; size_t* arg_p_buffer_size; int hbsr_nnzb; size_t buffer_size; // // Macro to set arguments. // #define ARGSET \ arg_direction = HIPSPARSE_DIRECTION_ROW; \ arg_m = safe_size; \ arg_n = safe_size; \ arg_csr_descr = csr_descr; \ arg_csr_val = (T*)csr_val; \ arg_csr_row_ptr = csr_row_ptr; \ arg_csr_col_ind = csr_col_ind; \ arg_bsr_descr = bsr_descr; \ arg_bsr_val = (T*)bsr_val; \ arg_bsr_row_ptr = bsr_row_ptr; \ arg_bsr_col_ind = bsr_col_ind; \ arg_row_block_dim = safe_size; \ arg_col_block_dim = safe_size; \ arg_p_buffer = (void*)((T*)buffer); \ arg_bsr_nnz_devhost = &hbsr_nnzb; \ arg_p_buffer_size = &buffer_size // // BUFFER_SIZE ############ // #define CALL_ARG_BUFFER_SIZE \ arg_direction, arg_m, arg_n, arg_csr_descr, arg_csr_val, arg_csr_row_ptr, arg_csr_col_ind, \ arg_row_block_dim, arg_col_block_dim, arg_p_buffer_size #define CALL_BUFFER_SIZE hipsparseXcsr2gebsr_bufferSize(handle, CALL_ARG_BUFFER_SIZE) { ARGSET; status = hipsparseXcsr2gebsr_bufferSize(nullptr, CALL_ARG_BUFFER_SIZE); verify_hipsparse_status_invalid_handle(status); } { ARGSET; arg_m = -1; status = CALL_BUFFER_SIZE; verify_hipsparse_status_invalid_size(status, "Error: m is invalid"); } { ARGSET; arg_n = -1; status = CALL_BUFFER_SIZE; verify_hipsparse_status_invalid_size(status, "Error: n is invalid"); } { ARGSET; arg_csr_descr = nullptr; status = CALL_BUFFER_SIZE; verify_hipsparse_status_invalid_pointer(status, "Error: csr_descr is nullptr"); } { ARGSET; arg_csr_val = nullptr; status = CALL_BUFFER_SIZE; verify_hipsparse_status_invalid_pointer(status, "Error: csr_val is nullptr"); } { ARGSET; arg_csr_row_ptr = nullptr; status = CALL_BUFFER_SIZE; verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr is nullptr"); } { ARGSET; arg_csr_col_ind = nullptr; status = CALL_BUFFER_SIZE; verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind is nullptr"); } { ARGSET; arg_row_block_dim = -1; status = CALL_BUFFER_SIZE; verify_hipsparse_status_invalid_size(status, "Error: row_block_dim is invalid"); } { ARGSET; arg_col_block_dim = -1; status = CALL_BUFFER_SIZE; verify_hipsparse_status_invalid_size(status, "Error: col_block_dim is invalid"); } { ARGSET; arg_p_buffer_size = nullptr; status = CALL_BUFFER_SIZE; verify_hipsparse_status_invalid_pointer(status, "Error: p_buffer_size is nullptr"); } #undef CALL_ARG_BUFFER_SIZE #undef CALL_BUFFER_SIZE // // NNZ ############ // #define CALL_ARG_NNZ \ arg_direction, arg_m, arg_n, arg_csr_descr, arg_csr_row_ptr, arg_csr_col_ind, arg_bsr_descr, \ arg_bsr_row_ptr, arg_row_block_dim, arg_col_block_dim, arg_bsr_nnz_devhost, arg_p_buffer #define CALL_NNZ hipsparseXcsr2gebsrNnz(handle, CALL_ARG_NNZ) { ARGSET; status = hipsparseXcsr2gebsrNnz(nullptr, CALL_ARG_NNZ); verify_hipsparse_status_invalid_handle(status); } { ARGSET; arg_m = -1; status = CALL_NNZ; verify_hipsparse_status_invalid_size(status, "Error: m is invalid"); } { ARGSET; arg_n = -1; status = CALL_NNZ; verify_hipsparse_status_invalid_size(status, "Error: n is invalid"); } { ARGSET; arg_csr_descr = nullptr; status = CALL_NNZ; verify_hipsparse_status_invalid_pointer(status, "Error: csr_descr is nullptr"); } { ARGSET; arg_csr_row_ptr = nullptr; status = CALL_NNZ; verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr is nullptr"); } { ARGSET; arg_bsr_descr = nullptr; status = CALL_NNZ; verify_hipsparse_status_invalid_pointer(status, "Error: bsr_descr is nullptr"); } { ARGSET; arg_bsr_row_ptr = nullptr; status = CALL_NNZ; verify_hipsparse_status_invalid_pointer(status, "Error: bsr_row_ptr is nullptr"); } { ARGSET; arg_row_block_dim = -1; status = CALL_NNZ; verify_hipsparse_status_invalid_size(status, "Error: row_block_dim is invalid"); } { ARGSET; arg_col_block_dim = -1; status = CALL_NNZ; verify_hipsparse_status_invalid_size(status, "Error: col_block_dim is invalid"); } { ARGSET; arg_bsr_nnz_devhost = nullptr; status = CALL_NNZ; verify_hipsparse_status_invalid_pointer(status, "Error: bsr_nnz_devhost is nullptr"); } #undef CALL_NNZ #undef CALL_ARG_NNZ #undef ARGSET #define ARGSET \ arg_direction = HIPSPARSE_DIRECTION_ROW; \ arg_m = safe_size; \ arg_n = safe_size; \ arg_csr_descr = csr_descr; \ arg_csr_val = (T*)csr_val; \ arg_csr_row_ptr = csr_row_ptr; \ arg_csr_col_ind = csr_col_ind; \ arg_bsr_descr = bsr_descr; \ arg_bsr_val = (T*)bsr_val; \ arg_bsr_row_ptr = bsr_row_ptr; \ arg_bsr_col_ind = bsr_col_ind; \ arg_row_block_dim = safe_size; \ arg_col_block_dim = safe_size; \ arg_p_buffer = (void*)((T*)buffer); \ arg_p_buffer_size = &buffer_size #define CALL_ARG_FUNC \ arg_direction, arg_m, arg_n, arg_csr_descr, arg_csr_val, arg_csr_row_ptr, arg_csr_col_ind, \ arg_bsr_descr, arg_bsr_val, arg_bsr_row_ptr, arg_bsr_col_ind, arg_row_block_dim, \ arg_col_block_dim, arg_p_buffer #define CALL_FUNC hipsparseXcsr2gebsr(handle, CALL_ARG_FUNC) { ARGSET; status = hipsparseXcsr2gebsr(nullptr, CALL_ARG_FUNC); verify_hipsparse_status_invalid_handle(status); } { ARGSET; arg_m = -1; status = CALL_FUNC; verify_hipsparse_status_invalid_size(status, "Error: m is invalid"); } { ARGSET; arg_n = -1; status = CALL_FUNC; verify_hipsparse_status_invalid_size(status, "Error: n is invalid"); } { ARGSET; arg_csr_descr = nullptr; status = CALL_FUNC; verify_hipsparse_status_invalid_pointer(status, "Error: csr_descr is nullptr"); } { ARGSET; arg_csr_val = nullptr; status = CALL_FUNC; verify_hipsparse_status_invalid_pointer(status, "Error: csr_val is nullptr"); } { ARGSET; arg_csr_row_ptr = nullptr; status = CALL_FUNC; verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr is nullptr"); } { ARGSET; arg_csr_col_ind = nullptr; status = CALL_FUNC; verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind is nullptr"); } { ARGSET; arg_bsr_descr = nullptr; status = CALL_FUNC; verify_hipsparse_status_invalid_pointer(status, "Error: bsr_descr is nullptr"); } { ARGSET; arg_bsr_val = nullptr; status = CALL_FUNC; verify_hipsparse_status_invalid_pointer(status, "Error: bsr_val is nullptr"); } { ARGSET; arg_bsr_row_ptr = nullptr; status = CALL_FUNC; verify_hipsparse_status_invalid_pointer(status, "Error: bsr_row_ptr is nullptr"); } { ARGSET; arg_bsr_col_ind = nullptr; status = CALL_FUNC; verify_hipsparse_status_invalid_pointer(status, "Error: bsr_col_ind is nullptr"); } { ARGSET; arg_row_block_dim = -1; status = CALL_FUNC; verify_hipsparse_status_invalid_size(status, "Error: row_block_dim is invalid"); } { ARGSET; arg_col_block_dim = -1; status = CALL_FUNC; verify_hipsparse_status_invalid_size(status, "Error: col_block_dim is invalid"); } #undef CALL_FUNC #undef CALL_ARG_FUNC #undef ARGSET #endif } template hipsparseStatus_t testing_csr2gebsr(Arguments argus) { int m = argus.M; int n = argus.N; hipsparseIndexBase_t csr_idx_base = argus.baseA; hipsparseIndexBase_t bsr_idx_base = argus.baseB; hipsparseDirection_t dir = argus.dirA; int row_block_dim = argus.row_block_dimA; int col_block_dim = argus.col_block_dimA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_csr_descr(new descr_struct); hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; std::unique_ptr unique_ptr_bsr_descr(new descr_struct); hipsparseMatDescr_t bsr_descr = unique_ptr_bsr_descr->descr; hipsparseSetMatIndexBase(csr_descr, csr_idx_base); hipsparseSetMatIndexBase(bsr_descr, bsr_idx_base); if(row_block_dim == 1 || m == 0 || n == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // Do not test cusparse with block dim 1 return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix( filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, csr_idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } int mb = (m + row_block_dim - 1) / row_block_dim; int nb = (n + col_block_dim - 1) / col_block_dim; // Allocate memory on the device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dbsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb + 1)), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); int* dbsr_row_ptr = (int*)dbsr_row_ptr_managed.get(); // Copy data from host to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_val, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); size_t buffer_size; CHECK_HIPSPARSE_ERROR(hipsparseXcsr2gebsr_bufferSize(handle, dir, m, n, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, row_block_dim, col_block_dim, &buffer_size)); auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(buffer_size), device_free}; void* dbuffer = dbuffer_managed.get(); int hbsr_nnzb; CHECK_HIPSPARSE_ERROR(hipsparseXcsr2gebsrNnz(handle, dir, m, n, csr_descr, dcsr_row_ptr, dcsr_col_ind, bsr_descr, dbsr_row_ptr, row_block_dim, col_block_dim, &hbsr_nnzb, dbuffer)); // Allocate memory on the device auto dbsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * hbsr_nnzb), device_free}; auto dbsr_val_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * hbsr_nnzb * row_block_dim * col_block_dim), device_free}; int* dbsr_col_ind = (int*)dbsr_col_ind_managed.get(); T* dbsr_val = (T*)dbsr_val_managed.get(); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2gebsr(handle, dir, m, n, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, bsr_descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, row_block_dim, col_block_dim, dbuffer)); // Copy output from device to host std::vector hbsr_row_ptr(mb + 1); std::vector hbsr_col_ind(hbsr_nnzb); std::vector hbsr_val(hbsr_nnzb * row_block_dim * col_block_dim); CHECK_HIP_ERROR(hipMemcpy( hbsr_row_ptr.data(), dbsr_row_ptr, sizeof(int) * (mb + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hbsr_col_ind.data(), dbsr_col_ind, sizeof(int) * hbsr_nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsr_val.data(), dbsr_val, sizeof(T) * hbsr_nnzb * row_block_dim * col_block_dim, hipMemcpyDeviceToHost)); // Host csr2gebsr conversion std::vector hbsr_row_ptr_gold(mb + 1); std::vector hbsr_col_ind_gold(hbsr_nnzb, 0); std::vector hbsr_val_gold(hbsr_nnzb * row_block_dim * col_block_dim); // call host csr2gebsr here int bsr_nnzb_gold; host_csr_to_gebsr(dir, m, n, row_block_dim, col_block_dim, bsr_nnzb_gold, csr_idx_base, hcsr_row_ptr, hcsr_col_ind, hcsr_val, bsr_idx_base, hbsr_row_ptr_gold, hbsr_col_ind_gold, hbsr_val_gold); // Unit check unit_check_general(1, 1, 1, &bsr_nnzb_gold, &hbsr_nnzb); unit_check_general(1, mb + 1, 1, hbsr_row_ptr_gold.data(), hbsr_row_ptr.data()); unit_check_general(1, hbsr_nnzb, 1, hbsr_col_ind_gold.data(), hbsr_col_ind.data()); unit_check_general( 1, hbsr_nnzb * row_block_dim * col_block_dim, 1, hbsr_val_gold.data(), hbsr_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2gebsr(handle, dir, m, n, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, bsr_descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, row_block_dim, col_block_dim, dbuffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2gebsr(handle, dir, m, n, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, bsr_descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, row_block_dim, col_block_dim, dbuffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = csr2gebsr_gbyte_count(m, mb, nnz, hbsr_nnzb, row_block_dim, col_block_dim); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::Mb, mb, display_key_t::Nb, nb, display_key_t::row_block_dim, row_block_dim, display_key_t::col_block_dim, col_block_dim, display_key_t::nnzb, hbsr_nnzb, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSR2GEBSR_HPP ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5643992 hipsparse/clients/include/testing_csr2hyb.hpp0000664000175100017510000004314415206065364021727 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSR2HYB_HPP #define TESTING_CSR2HYB_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; #define ELL_IND_ROW(i, el, m, width) (el) * (m) + (i) #define ELL_IND_EL(i, el, m, width) (el) + (width) * (i) #define ELL_IND(i, el, m, width) ELL_IND_ROW(i, el, m, width) template void testing_csr2hyb_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) int m = 100; int n = 100; int safe_size = 100; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_hyb(new hyb_struct); hipsparseHybMat_t hyb = unique_ptr_hyb->hyb; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* csr_col_ind = (int*)csr_col_ind_managed.get(); T* csr_val = (T*)csr_val_managed.get(); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2hyb(handle, m, n, descr, csr_val, (int*)nullptr, csr_col_ind, hyb, 0, HIPSPARSE_HYB_PARTITION_AUTO), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2hyb(handle, m, n, descr, csr_val, csr_row_ptr, (int*)nullptr, hyb, 0, HIPSPARSE_HYB_PARTITION_AUTO), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2hyb(handle, m, n, descr, (T*)nullptr, csr_row_ptr, csr_col_ind, hyb, 0, HIPSPARSE_HYB_PARTITION_AUTO), "Error: csr_val is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsr2hyb((hipsparseHandle_t) nullptr, m, n, descr, csr_val, csr_row_ptr, csr_col_ind, hyb, 0, HIPSPARSE_HYB_PARTITION_AUTO)); #endif } template hipsparseStatus_t testing_csr2hyb(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) int m = argus.M; int n = argus.N; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseHybPartition_t part = argus.part; int user_ell_width = argus.ell_width; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); std::unique_ptr unique_ptr_hyb(new hyb_struct); hipsparseHybMat_t hyb = unique_ptr_hyb->hyb; srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } if(m == 0 || n == 0) { return HIPSPARSE_STATUS_SUCCESS; } // Allocate memory on the device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); // Copy data from host to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_val, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); // User given ELL width check hipsparseStatus_t status; if(part == HIPSPARSE_HYB_PARTITION_USER) { // ELL width -33 means we take a reasonable pre-computed width if(user_ell_width == -33) { user_ell_width = nnz / m; } // Test invalid user_ell_width int max_allowed_ell_nnz_per_row = (2 * nnz - 1) / m + 1; if(user_ell_width < 0 || user_ell_width > max_allowed_ell_nnz_per_row) { status = hipsparseXcsr2hyb(handle, m, n, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, hyb, user_ell_width, part); verify_hipsparse_status_invalid_value( status, "Error: user_ell_width < 0 || user_ell_width > max_ell_width"); return HIPSPARSE_STATUS_SUCCESS; } } // Max width check if(part == HIPSPARSE_HYB_PARTITION_MAX) { // Compute max ELL width int ell_max_width = 0; for(int i = 0; i < m; ++i) { ell_max_width = std::max(hcsr_row_ptr[i + 1] - hcsr_row_ptr[i], ell_max_width); } int width_limit = (2 * nnz - 1) / m + 1; if(ell_max_width > width_limit) { status = hipsparseXcsr2hyb(handle, m, n, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, hyb, user_ell_width, part); verify_hipsparse_status_invalid_value(status, "ell_max_width > width_limit"); return HIPSPARSE_STATUS_SUCCESS; } } // Host structures for verification std::vector hhyb_ell_col_ind_gold; std::vector hhyb_ell_val_gold; std::vector hhyb_coo_row_ind_gold; std::vector hhyb_coo_col_ind_gold; std::vector hhyb_coo_val_gold; // Host csr2hyb conversion int ell_width = 0; int ell_nnz = 0; int coo_nnz = 0; if(part == HIPSPARSE_HYB_PARTITION_AUTO || part == HIPSPARSE_HYB_PARTITION_USER) { if(part == HIPSPARSE_HYB_PARTITION_AUTO) { // ELL width is average nnz per row ell_width = (nnz - 1) / m + 1; } else { // User given ELL width ell_width = user_ell_width; } ell_nnz = ell_width * m; // Determine COO nnz for(int i = 0; i < m; ++i) { int row_nnz = hcsr_row_ptr[i + 1] - hcsr_row_ptr[i]; if(row_nnz > ell_width) { coo_nnz += row_nnz - ell_width; } } } else if(part == HIPSPARSE_HYB_PARTITION_MAX) { // Determine max nnz per row for(int i = 0; i < m; ++i) { int row_nnz = hcsr_row_ptr[i + 1] - hcsr_row_ptr[i]; ell_width = (row_nnz > ell_width) ? row_nnz : ell_width; } ell_nnz = ell_width * m; } // Allocate host memory // ELL hhyb_ell_col_ind_gold.resize(ell_nnz); hhyb_ell_val_gold.resize(ell_nnz); // COO hhyb_coo_row_ind_gold.resize(coo_nnz); hhyb_coo_col_ind_gold.resize(coo_nnz); hhyb_coo_val_gold.resize(coo_nnz); // Fill HYB int coo_idx = 0; for(int i = 0; i < m; ++i) { int p = 0; for(int j = hcsr_row_ptr[i] - idx_base; j < hcsr_row_ptr[i + 1] - idx_base; ++j) { if(p < ell_width) { int idx = ELL_IND(i, p++, m, ell_width); hhyb_ell_col_ind_gold[idx] = hcsr_col_ind[j]; hhyb_ell_val_gold[idx] = hcsr_val[j]; } else { hhyb_coo_row_ind_gold[coo_idx] = i + idx_base; hhyb_coo_col_ind_gold[coo_idx] = hcsr_col_ind[j]; hhyb_coo_val_gold[coo_idx] = hcsr_val[j]; ++coo_idx; } } for(int j = hcsr_row_ptr[i + 1] - hcsr_row_ptr[i]; j < ell_width; ++j) { int idx = ELL_IND(i, p++, m, ell_width); hhyb_ell_col_ind_gold[idx] = -1; hhyb_ell_val_gold[idx] = make_DataType(0.0); } } // Allocate verification structures std::vector hhyb_ell_col_ind(ell_nnz); std::vector hhyb_ell_val(ell_nnz); std::vector hhyb_coo_row_ind(coo_nnz); std::vector hhyb_coo_col_ind(coo_nnz); std::vector hhyb_coo_val(coo_nnz); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2hyb( handle, m, n, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, hyb, user_ell_width, part)); // Copy output from device to host testhyb* dhyb = (testhyb*)hyb; // Check if sizes match unit_check_general(1, 1, 1, &m, &dhyb->m); unit_check_general(1, 1, 1, &n, &dhyb->n); unit_check_general(1, 1, 1, &ell_width, &dhyb->ell_width); unit_check_general(1, 1, 1, &ell_nnz, &dhyb->ell_nnz); unit_check_general(1, 1, 1, &coo_nnz, &dhyb->coo_nnz); CHECK_HIP_ERROR(hipMemcpy(hhyb_ell_col_ind.data(), dhyb->ell_col_ind, sizeof(int) * ell_nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hhyb_ell_val.data(), dhyb->ell_val, sizeof(T) * ell_nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hhyb_coo_row_ind.data(), dhyb->coo_row_ind, sizeof(int) * coo_nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hhyb_coo_col_ind.data(), dhyb->coo_col_ind, sizeof(int) * coo_nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hhyb_coo_val.data(), dhyb->coo_val, sizeof(T) * coo_nnz, hipMemcpyDeviceToHost)); // Unit check unit_check_general(1, ell_nnz, 1, hhyb_ell_col_ind_gold.data(), hhyb_ell_col_ind.data()); unit_check_general(1, ell_nnz, 1, hhyb_ell_val_gold.data(), hhyb_ell_val.data()); unit_check_general(1, coo_nnz, 1, hhyb_coo_row_ind_gold.data(), hhyb_coo_row_ind.data()); unit_check_general(1, coo_nnz, 1, hhyb_coo_col_ind_gold.data(), hhyb_coo_col_ind.data()); unit_check_general(1, coo_nnz, 1, hhyb_coo_val_gold.data(), hhyb_coo_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2hyb(handle, m, n, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, hyb, user_ell_width, part)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2hyb(handle, m, n, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, hyb, user_ell_width, part)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = csr2hyb_gbyte_count(m, nnz, ell_nnz, coo_nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::ell_nnz, ell_nnz, display_key_t::coo_nnz, coo_nnz, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSR2HYB_HPP ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5643992 hipsparse/clients/include/testing_csrcolor.hpp0000664000175100017510000003173015206065364022177 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSRCOLOR_HPP #define TESTING_CSRCOLOR_HPP #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csrcolor_bad_arg(void) { #if(!defined(CUDART_VERSION)) static constexpr int M = 10; static constexpr int NNZ = 10; floating_data_t fractionToColor = make_DataType>(1.0); hipsparseStatus_t status; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; auto m_coloring = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; auto m_reordering = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; auto m_csr_val = hipsparse_unique_ptr{device_malloc(sizeof(T) * 1), device_free}; auto m_csr_row_ptr = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; auto m_csr_col_ind = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; T* d_csr_val = (T*)m_csr_val.get(); int* d_coloring = (int*)m_coloring.get(); int* d_reordering = (int*)m_reordering.get(); int* d_csr_row_ptr = (int*)m_csr_row_ptr.get(); int* d_csr_col_ind = (int*)m_csr_col_ind.get(); int ncolors; hipsparseColorInfo_t colorInfo = (hipsparseColorInfo_t)0x4; status = hipsparseXcsrcolor(handle, M, NNZ, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, &fractionToColor, &ncolors, d_coloring, d_reordering, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected.u"); status = hipsparseXcsrcolor(handle, M, NNZ, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, &fractionToColor, &ncolors, nullptr, d_reordering, colorInfo); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected.u"); status = hipsparseXcsrcolor(handle, M, NNZ, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, &fractionToColor, nullptr, d_coloring, d_reordering, colorInfo); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected.u"); status = hipsparseXcsrcolor(handle, M, NNZ, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, nullptr, &ncolors, d_coloring, d_reordering, colorInfo); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected.u"); status = hipsparseXcsrcolor(handle, M, NNZ, descr, d_csr_val, d_csr_row_ptr, nullptr, &fractionToColor, &ncolors, d_coloring, d_reordering, colorInfo); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected.u"); status = hipsparseXcsrcolor(handle, M, NNZ, descr, d_csr_val, nullptr, d_csr_col_ind, &fractionToColor, &ncolors, d_coloring, d_reordering, colorInfo); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected.u"); status = hipsparseXcsrcolor(handle, M, NNZ, descr, nullptr, d_csr_row_ptr, d_csr_col_ind, &fractionToColor, &ncolors, d_coloring, d_reordering, colorInfo); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected.u"); status = hipsparseXcsrcolor(handle, M, NNZ, nullptr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, &fractionToColor, &ncolors, d_coloring, d_reordering, colorInfo); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected.u"); status = hipsparseXcsrcolor(nullptr, M, NNZ, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, &fractionToColor, &ncolors, d_coloring, d_reordering, colorInfo); verify_hipsparse_status_invalid_handle(status); status = hipsparseXcsrcolor(handle, -1, NNZ, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, &fractionToColor, &ncolors, d_coloring, d_reordering, colorInfo); verify_hipsparse_status_invalid_value(status, "Error: an invalid value must be detected.u"); status = hipsparseXcsrcolor(handle, M, -1, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, &fractionToColor, &ncolors, d_coloring, d_reordering, colorInfo); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid value must be detected.u"); #endif } template hipsparseStatus_t testing_csrcolor() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) // Determine absolute path of test matrix // Matrices are stored at the same path in matrices directory std::string filename = "nos3.bin"; // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; // Host structures std::vector hrow_ptr; std::vector hcol_ind; std::vector hval; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; // Initial Data on CPU srand(12345ULL); floating_data_t fractionToColor = make_DataType>(1.0); int m; int k; int nnz; if(!generate_csr_matrix(filename, m, k, nnz, hrow_ptr, hcol_ind, hval, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } hipsparseColorInfo_t colorInfo; hipsparseCreateColorInfo(&colorInfo); // allocate memory on device auto drow_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcol_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dcoloring_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * m), device_free}; auto dreordering_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * m), device_free}; int* drow_ptr = (int*)drow_ptr_managed.get(); int* dcol_ind = (int*)dcol_ind_managed.get(); T* dval = (T*)dval_managed.get(); int* dcoloring = (int*)dcoloring_managed.get(); int* dreordering = (int*)dreordering_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(drow_ptr, hrow_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol_ind, hcol_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hval.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); int ncolors; CHECK_HIPSPARSE_ERROR(hipsparseXcsrcolor(handle, m, nnz, descr, dval, drow_ptr, dcol_ind, &fractionToColor, &ncolors, dcoloring, dreordering, colorInfo)); hipsparseDestroyColorInfo(colorInfo); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRCOLOR_HPP ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5653992 hipsparse/clients/include/testing_csrgeam.hpp0000664000175100017510000017311315206065364021774 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5653992 hipsparse/clients/include/testing_csrgeam2.hpp0000664000175100017510000020542415206065364022057 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5653992 hipsparse/clients/include/testing_csrgemm.hpp0000664000175100017510000015570115206065364022013 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5653992 hipsparse/clients/include/testing_csrgemm2_a.hpp0000664000175100017510000024436715206065364022404 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5653992 hipsparse/clients/include/testing_csrgemm2_b.hpp0000664000175100017510000014501215206065364022370 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5653992 hipsparse/clients/include/testing_csric02.hpp0000664000175100017510000004057715206065364021627 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.566399 hipsparse/clients/include/testing_csrilu02.hpp0000664000175100017510000004205615206065364022017 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.566399 hipsparse/clients/include/testing_csrilusv.hpp0000664000175100017510000005027215206065364022225 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2019 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSRILUSV_HPP #define TESTING_CSRILUSV_HPP #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include #include #include using namespace hipsparse; using namespace hipsparse_test; template hipsparseStatus_t testing_csrilusv(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) hipsparseIndexBase_t idx_base = argus.baseA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_M(new descr_struct); hipsparseMatDescr_t descr_M = unique_ptr_descr_M->descr; std::unique_ptr unique_ptr_csrilu02_info(new csrilu02_struct); csrilu02Info_t info_M = unique_ptr_csrilu02_info->info; // Initialize the matrix descriptor CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_M, idx_base)); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Initial Data on CPU int m; int n; int nnz; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto d_position_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); int* d_position = (int*)d_position_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); // Obtain csrilu02 buffer size int size; CHECK_HIPSPARSE_ERROR( hipsparseXcsrilu02_bufferSize(handle, m, nnz, descr_M, dval, dptr, dcol, info_M, &size)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * size), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); // csrilu02 analysis CHECK_HIPSPARSE_ERROR(hipsparseXcsrilu02_analysis(handle, m, nnz, descr_M, dval, dptr, dcol, info_M, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer)); // Compute incomplete LU factorization CHECK_HIPSPARSE_ERROR(hipsparseXcsrilu02(handle, m, nnz, descr_M, dval, dptr, dcol, info_M, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer)); // Check for zero pivot int hposition_1, hposition_2; hipsparseStatus_t pivot_status_1, pivot_status_2; // Host pointer mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); pivot_status_1 = hipsparseXcsrilu02_zeroPivot(handle, info_M, &hposition_1); // device pointer mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); pivot_status_2 = hipsparseXcsrilu02_zeroPivot(handle, info_M, d_position); // Copy output to CPU std::vector iluresult(nnz); CHECK_HIP_ERROR(hipMemcpy(iluresult.data(), dval, sizeof(T) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(&hposition_2, d_position, sizeof(int), hipMemcpyDeviceToHost)); // Compute host reference csrilu0 int position_gold = csrilu0(m, hcsr_row_ptr.data(), hcsr_col_ind.data(), hcsr_val.data(), idx_base, false, 0.0, make_DataType(0.0, 0.0)); // Check zero pivot results unit_check_general(1, 1, 1, &position_gold, &hposition_1); unit_check_general(1, 1, 1, &position_gold, &hposition_2); // If zero pivot was found, do not go further if(hposition_1 != -1) { verify_hipsparse_status_zero_pivot(pivot_status_1, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); return HIPSPARSE_STATUS_SUCCESS; } if(hposition_2 != -1) { verify_hipsparse_status_zero_pivot(pivot_status_2, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); return HIPSPARSE_STATUS_SUCCESS; } // Check csrilu0 factorization #if defined(__HIP_PLATFORM_AMD__) unit_check_general(1, nnz, 1, hcsr_val.data(), iluresult.data()); #elif defined(__HIP_PLATFORM_NVIDIA__) unit_check_near(1, nnz, 1, hcsr_val.data(), iluresult.data()); #endif // Create info structs for lower and upper part std::unique_ptr unique_ptr_csrsv2_lower(new csrsv2_struct); std::unique_ptr unique_ptr_csrsv2_upper(new csrsv2_struct); csrsv2Info_t info_L = unique_ptr_csrsv2_lower->info; csrsv2Info_t info_U = unique_ptr_csrsv2_upper->info; // Create matrix descriptors for csrsv std::unique_ptr unique_ptr_descr_L(new descr_struct); hipsparseMatDescr_t descr_L = unique_ptr_descr_L->descr; CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_L, idx_base)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatFillMode(descr_L, HIPSPARSE_FILL_MODE_LOWER)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatDiagType(descr_L, HIPSPARSE_DIAG_TYPE_UNIT)); std::unique_ptr unique_ptr_descr_U(new descr_struct); hipsparseMatDescr_t descr_U = unique_ptr_descr_U->descr; CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_U, idx_base)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatFillMode(descr_U, HIPSPARSE_FILL_MODE_UPPER)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatDiagType(descr_U, HIPSPARSE_DIAG_TYPE_NON_UNIT)); // Obtain csrsv buffer sizes int size_lower, size_upper; CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_bufferSize(handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, m, nnz, descr_L, dval, dptr, dcol, info_L, &size_lower)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_bufferSize(handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, m, nnz, descr_U, dval, dptr, dcol, info_U, &size_upper)); // Pick maximum size so that we need only one buffer size = std::max(size_lower, size_upper); // Allocate buffer on the device auto dbuffer_sv_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * size), device_free}; void* dbuffer_sv = (void*)dbuffer_sv_managed.get(); // csrsv analysis CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_analysis(handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, m, nnz, descr_L, dval, dptr, dcol, info_L, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer_sv)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_analysis(handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, m, nnz, descr_U, dval, dptr, dcol, info_U, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer_sv)); // Initialize some more structures required for Lz = x T h_alpha = static_cast(1); std::vector hx(m, static_cast(1)); std::vector hy_gold(m); std::vector hz_gold(m); // Allocate device memory auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dz_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dz_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; T* dx = (T*)dx_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* dz_1 = (T*)dz_1_managed.get(); T* dz_2 = (T*)dz_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); // Copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dx, hx.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); // Solve Lz = x // host pointer mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_solve(handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, m, nnz, &h_alpha, descr_L, dval, dptr, dcol, info_L, dx, dz_1, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer_sv)); // Check for zero pivot pivot_status_1 = hipsparseXcsrsv2_zeroPivot(handle, info_L, &hposition_1); // device pointer mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_solve(handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, m, nnz, d_alpha, descr_L, dval, dptr, dcol, info_L, dx, dz_2, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer_sv)); // Check for zero pivot pivot_status_2 = hipsparseXcsrsv2_zeroPivot(handle, info_L, d_position); // Host csrsv hipDeviceProp_t prop; CHECK_HIP_ERROR(hipGetDeviceProperties(&prop, 0)); position_gold = csr_lsolve(HIPSPARSE_OPERATION_NON_TRANSPOSE, m, hcsr_row_ptr.data(), hcsr_col_ind.data(), hcsr_val.data(), h_alpha, hx.data(), hz_gold.data(), idx_base, HIPSPARSE_DIAG_TYPE_UNIT, prop.warpSize); // Check zero pivot results unit_check_general(1, 1, 1, &position_gold, &hposition_1); unit_check_general(1, 1, 1, &position_gold, &hposition_2); // If zero pivot was found, do not go further if(hposition_1 != -1) { verify_hipsparse_status_zero_pivot(pivot_status_1, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); return HIPSPARSE_STATUS_SUCCESS; } if(hposition_2 != -1) { verify_hipsparse_status_zero_pivot(pivot_status_2, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); return HIPSPARSE_STATUS_SUCCESS; } // Copy output from device to CPU std::vector hz_1(m); std::vector hz_2(m); CHECK_HIP_ERROR(hipMemcpy(hz_1.data(), dz_1, sizeof(T) * m, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hz_2.data(), dz_2, sizeof(T) * m, hipMemcpyDeviceToHost)); // Check z #if defined(__HIP_PLATFORM_AMD__) unit_check_general(1, m, 1, hz_gold.data(), hz_1.data()); unit_check_general(1, m, 1, hz_gold.data(), hz_2.data()); #elif defined(__HIP_PLATFORM_NVIDIA__) unit_check_near(1, m, 1, hz_gold.data(), hz_1.data()); unit_check_near(1, m, 1, hz_gold.data(), hz_2.data()); #endif // Solve Uy = z // host pointer mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_solve(handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, m, nnz, &h_alpha, descr_U, dval, dptr, dcol, info_U, dz_1, dy_1, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer_sv)); // Check for zero pivot pivot_status_1 = hipsparseXcsrsv2_zeroPivot(handle, info_U, &hposition_1); // device pointer mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_solve(handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, m, nnz, d_alpha, descr_U, dval, dptr, dcol, info_U, dz_2, dy_2, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer_sv)); // Check for zero pivot pivot_status_2 = hipsparseXcsrsv2_zeroPivot(handle, info_U, d_position); // Host csrsv position_gold = csr_usolve(HIPSPARSE_OPERATION_NON_TRANSPOSE, m, hcsr_row_ptr.data(), hcsr_col_ind.data(), hcsr_val.data(), h_alpha, hz_gold.data(), hy_gold.data(), idx_base, HIPSPARSE_DIAG_TYPE_NON_UNIT, prop.warpSize); // Check zero pivot results unit_check_general(1, 1, 1, &position_gold, &hposition_1); unit_check_general(1, 1, 1, &position_gold, &hposition_2); // If zero pivot was found, do not go further if(hposition_1 != -1) { verify_hipsparse_status_zero_pivot(pivot_status_1, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); return HIPSPARSE_STATUS_SUCCESS; } if(hposition_2 != -1) { verify_hipsparse_status_zero_pivot(pivot_status_2, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); return HIPSPARSE_STATUS_SUCCESS; } // Copy output from device to CPU std::vector hy_1(m); std::vector hy_2(m); CHECK_HIP_ERROR(hipMemcpy(hy_1.data(), dy_1, sizeof(T) * m, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_2.data(), dy_2, sizeof(T) * m, hipMemcpyDeviceToHost)); // Check z unit_check_near(1, m, 1, hy_gold.data(), hy_1.data()); unit_check_near(1, m, 1, hy_gold.data(), hy_2.data()); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRILUSOLVE_HPP ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.566399 hipsparse/clients/include/testing_csrmm.hpp0000664000175100017510000007150515206065364021476 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2019 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSRMM_HPP #define TESTING_CSRMM_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csrmm_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int N = 100; int M = 100; int K = 100; int ldb = 100; int ldc = 100; int nnz = 100; int safe_size = 100; T alpha = make_DataType(0.6); T beta = make_DataType(0.2); hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dC_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dB = (T*)dB_managed.get(); T* dC = (T*)dC_managed.get(); verify_hipsparse_status_invalid_size(hipsparseXcsrmm2(handle, transA, transB, -1, N, K, nnz, &alpha, descr, dval, dptr, dcol, dB, ldb, &beta, dC, ldc), "Error: M < 0"); verify_hipsparse_status_invalid_size(hipsparseXcsrmm2(handle, transA, transB, M, -1, K, nnz, &alpha, descr, dval, dptr, dcol, dB, ldb, &beta, dC, ldc), "Error: N < 0"); verify_hipsparse_status_invalid_size(hipsparseXcsrmm2(handle, transA, transB, M, N, -1, nnz, &alpha, descr, dval, dptr, dcol, dB, ldb, &beta, dC, ldc), "Error: K < 0"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &alpha, descr, dval, (int*)nullptr, dcol, dB, ldb, &beta, dC, ldc), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &alpha, descr, dval, dptr, (int*)nullptr, dB, ldb, &beta, dC, ldc), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &alpha, descr, (T*)nullptr, dptr, dcol, dB, ldb, &beta, dC, ldc), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &alpha, descr, dval, dptr, dcol, (T*)nullptr, ldb, &beta, dC, ldc), "Error: dB is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &alpha, descr, dval, dptr, dcol, dB, ldb, &beta, (T*)nullptr, ldc), "Error: dC is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, (T*)nullptr, descr, dval, dptr, dcol, dB, ldb, &beta, dC, ldc), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &alpha, descr, dval, dptr, dcol, dB, ldb, (T*)nullptr, dC, ldc), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &alpha, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, dB, ldb, &beta, dC, ldc), "Error: descr is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrmm2((hipsparseHandle_t) nullptr, transA, transB, M, N, K, nnz, &alpha, descr, dval, dptr, dcol, dB, ldb, &beta, dC, ldc)); #endif } template hipsparseStatus_t testing_csrmm(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) int M = argus.M; int N = argus.N; int K = argus.K; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseOperation_t transB = argus.transB; hipsparseIndexBase_t idx_base = argus.baseA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); srand(12345ULL); // Host structures std::vector hcsr_row_ptrA; std::vector hcsr_col_indA; std::vector hcsr_valA; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, M, K, nnz, hcsr_row_ptrA, hcsr_col_indA, hcsr_valA, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Some matrix properties int A_m = M; int B_m = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE ? K : M) : N; int B_n = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? N : (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE ? K : M); int C_m = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE ? M : K); int C_n = N; int ldb = B_m; int ldc = C_m; int nrowB = ldb; int ncolB = B_n; int nrowC = ldc; int ncolC = C_n; int Bnnz = nrowB * ncolB; int Cnnz = nrowC * ncolC; // Host structures - Dense matrix B and C std::vector hB(Bnnz); std::vector hC_1(Cnnz); std::vector hC_2(Cnnz); std::vector hC_gold(Cnnz); hipsparseInit(hB, nrowB, ncolB); hipsparseInit(hC_1, nrowC, ncolC); // copy vector is easy in STL; hC_gold = hC_1: save a copy in hy_gold which will be output of // CPU hC_gold = hC_1; hC_2 = hC_1; // allocate memory on device auto dcsr_row_ptrA_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (A_m + 1)), device_free}; auto dcsr_col_indA_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_valA_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * Bnnz), device_free}; auto dC_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * Cnnz), device_free}; auto dC_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * Cnnz), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dcsr_row_ptrA = (int*)dcsr_row_ptrA_managed.get(); int* dcsr_col_indA = (int*)dcsr_col_indA_managed.get(); T* dcsr_valA = (T*)dcsr_valA_managed.get(); T* dB = (T*)dB_managed.get(); T* dC_1 = (T*)dC_1_managed.get(); T* dC_2 = (T*)dC_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy( dcsr_row_ptrA, hcsr_row_ptrA.data(), sizeof(int) * (A_m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_indA, hcsr_col_indA.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_valA, hcsr_valA.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * Bnnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_1, hC_1.data(), sizeof(T) * Cnnz, hipMemcpyHostToDevice)); if(argus.unit_check) { CHECK_HIP_ERROR(hipMemcpy(dC_2, hC_2.data(), sizeof(T) * Cnnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &h_alpha, descr, dcsr_valA, dcsr_row_ptrA, dcsr_col_indA, dB, ldb, &h_beta, dC_1, ldc)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, d_alpha, descr, dcsr_valA, dcsr_row_ptrA, dcsr_col_indA, dB, ldb, d_beta, dC_2, ldc)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hC_1.data(), dC_1, sizeof(T) * Cnnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hC_2.data(), dC_2, sizeof(T) * Cnnz, hipMemcpyDeviceToHost)); // CPU host_csrmm(M, N, K, transA, transB, h_alpha, hcsr_row_ptrA.data(), hcsr_col_indA.data(), hcsr_valA.data(), hB.data(), ldb, HIPSPARSE_ORDER_COL, h_beta, hC_gold.data(), ldc, HIPSPARSE_ORDER_COL, idx_base, false); unit_check_near(nrowC, ncolC, ldc, hC_gold.data(), hC_1.data()); unit_check_near(nrowC, ncolC, ldc, hC_gold.data(), hC_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &h_alpha, descr, dcsr_valA, dcsr_row_ptrA, dcsr_col_indA, dB, ldb, &h_beta, dC_1, ldc)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &h_alpha, descr, dcsr_valA, dcsr_row_ptrA, dcsr_col_indA, dB, ldb, &h_beta, dC_1, ldc)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = csrmm_gflop_count(B_m, nnz, C_m * C_n, h_beta != make_DataType(0.0)); double gbyte_count = csrmm_gbyte_count( A_m, nnz, B_m * B_n, C_m * C_n, h_beta != make_DataType(0.0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, M, display_key_t::N, N, display_key_t::K, K, display_key_t::transA, hipsparse_operation2string(transA), display_key_t::transB, hipsparse_operation2string(transB), display_key_t::nnzA, nnz, display_key_t::nnzB, B_m * B_n, display_key_t::nnzC, C_m * C_n, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRMM_HPP ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.566399 hipsparse/clients/include/testing_csrmv.hpp0000664000175100017510000003432315206065364021504 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2019 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSRMV_HPP #define TESTING_CSRMV_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csrmv_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int n = 100; int m = 100; int nnz = 100; int safe_size = 100; T alpha = make_DataType(0.6); T beta = make_DataType(0.2); hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dx = (T*)dx_managed.get(); T* dy = (T*)dy_managed.get(); verify_hipsparse_status_invalid_pointer( hipsparseXcsrmv( handle, transA, m, n, nnz, &alpha, descr, dval, (int*)nullptr, dcol, dx, &beta, dy), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrmv( handle, transA, m, n, nnz, &alpha, descr, dval, dptr, (int*)nullptr, dx, &beta, dy), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrmv( handle, transA, m, n, nnz, &alpha, descr, (T*)nullptr, dptr, dcol, dx, &beta, dy), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrmv( handle, transA, m, n, nnz, &alpha, descr, dval, dptr, dcol, (T*)nullptr, &beta, dy), "Error: dx is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrmv( handle, transA, m, n, nnz, &alpha, descr, dval, dptr, dcol, dx, &beta, (T*)nullptr), "Error: dy is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrmv( handle, transA, m, n, nnz, (T*)nullptr, descr, dval, dptr, dcol, dx, &beta, dy), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrmv( handle, transA, m, n, nnz, &alpha, descr, dval, dptr, dcol, dx, (T*)nullptr, dy), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrmv(handle, transA, m, n, nnz, &alpha, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, dx, &beta, dy), "Error: descr is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrmv((hipsparseHandle_t) nullptr, transA, m, n, nnz, &alpha, descr, dval, dptr, dcol, dx, &beta, dy)); #endif } template hipsparseStatus_t testing_csrmv(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) int nrow = argus.M; int ncol = argus.N; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseIndexBase_t idx_base = argus.baseA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix( filename, nrow, ncol, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } int m = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? nrow : ncol; int n = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? ncol : nrow; std::vector hx(n); std::vector hy_1(m); std::vector hy_2(m); std::vector hy_gold(m); hipsparseInit(hx, 1, n); hipsparseInit(hy_1, 1, m); // copy vector is easy in STL; hy_gold = hx: save a copy in hy_gold which will be output of CPU hy_2 = hy_1; hy_gold = hy_1; // allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (nrow + 1)), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * n), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dx = (T*)dx_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsr_row_ptr.data(), sizeof(int) * (nrow + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx, hx.data(), sizeof(T) * n, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_1, hy_1.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); if(argus.unit_check) { CHECK_HIP_ERROR(hipMemcpy(dy_2, hy_2.data(), sizeof(T) * m, hipMemcpyHostToDevice)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrmv( handle, transA, nrow, ncol, nnz, &h_alpha, descr, dval, dptr, dcol, dx, &h_beta, dy_1)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrmv( handle, transA, nrow, ncol, nnz, d_alpha, descr, dval, dptr, dcol, dx, d_beta, dy_2)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hy_1.data(), dy_1, sizeof(T) * m, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_2.data(), dy_2, sizeof(T) * m, hipMemcpyDeviceToHost)); host_csrmv(transA, nrow, ncol, nnz, h_alpha, hcsr_row_ptr.data(), hcsr_col_ind.data(), hcsr_val.data(), hx.data(), h_beta, hy_gold.data(), idx_base); unit_check_near(1, m, 1, hy_gold.data(), hy_1.data()); unit_check_near(1, m, 1, hy_gold.data(), hy_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrmv(handle, transA, nrow, ncol, nnz, &h_alpha, descr, dval, dptr, dcol, dx, &h_beta, dy_1)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrmv(handle, transA, nrow, ncol, nnz, &h_alpha, descr, dval, dptr, dcol, dx, &h_beta, dy_1)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = spmv_gflop_count(nrow, nnz, h_beta != make_DataType(0.0)); double gbyte_count = csrmv_gbyte_count(nrow, ncol, nnz, h_beta != make_DataType(0.0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, nrow, display_key_t::N, ncol, display_key_t::nnz, nnz, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRMV_HPP ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.566399 hipsparse/clients/include/testing_csrsm2.hpp0000664000175100017510000016060615206065364021567 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSRSM2_HPP #define TESTING_CSRSM2_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csrsm2_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int m = 100; int nrhs = 100; int nnz = 100; int safe_size = 100; T h_alpha = make_DataType(0.6); hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseSolvePolicy_t policy = HIPSPARSE_SOLVE_POLICY_USE_LEVEL; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_csrsm2_info(new csrsm2_struct); csrsm2Info_t info = unique_ptr_csrsm2_info->info; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dB = (T*)dB_managed.get(); void* dbuffer = (void*)dbuffer_managed.get(); size_t size; int position; verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, (T*)nullptr, descr, dval, dptr, dcol, dB, safe_size, info, policy, &size), "Error: dalpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, (int*)nullptr, dcol, dB, safe_size, info, policy, &size), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, (int*)nullptr, dB, safe_size, info, policy, &size), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, (T*)nullptr, dptr, dcol, dB, safe_size, info, policy, &size), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, info, policy, (size_t*)nullptr), "Error: size is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, dB, safe_size, info, policy, &size), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, (csrsm2Info_t) nullptr, policy, &size), "Error: info is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, (T*)nullptr, safe_size, info, policy, &size), "Error: dB is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXcsrsm2_bufferSizeExt((hipsparseHandle_t) nullptr, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, info, policy, &size)); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, (T*)nullptr, descr, dval, dptr, dcol, dB, safe_size, info, policy, dbuffer), "Error: dalpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, (int*)nullptr, dcol, dB, safe_size, info, policy, dbuffer), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, (int*)nullptr, dB, safe_size, info, policy, dbuffer), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, (T*)nullptr, dptr, dcol, dB, safe_size, info, policy, dbuffer), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, info, policy, (void*)nullptr), "Error: dbuffer is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, dB, safe_size, info, policy, dbuffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, (T*)nullptr, safe_size, info, policy, dbuffer), "Error: dB is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, (csrsm2Info_t) nullptr, policy, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrsm2_analysis((hipsparseHandle_t) nullptr, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, info, policy, dbuffer)); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, (int*)nullptr, dcol, dB, safe_size, info, policy, dbuffer), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, (int*)nullptr, dB, safe_size, info, policy, dbuffer), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, (T*)nullptr, dptr, dcol, dB, safe_size, info, policy, dbuffer), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, (T*)nullptr, safe_size, info, policy, dbuffer), "Error: dB is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, (T*)nullptr, descr, dval, dptr, dcol, dB, safe_size, info, policy, dbuffer), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, info, policy, (void*)nullptr), "Error: dbuffer is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, dB, safe_size, info, policy, dbuffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, (csrsm2Info_t) nullptr, policy, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrsm2_solve((hipsparseHandle_t) nullptr, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, info, policy, dbuffer)); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_zeroPivot(handle, info, (int*)nullptr), "Error: position is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsm2_zeroPivot(handle, (csrsm2Info_t) nullptr, &position), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXcsrsm2_zeroPivot((hipsparseHandle_t) nullptr, info, &position)); #endif } template hipsparseStatus_t testing_csrsm2(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int m = argus.M; int nrhs = argus.N; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseOperation_t transA = argus.transA; hipsparseOperation_t transB = argus.transB; hipsparseDiagType_t diag = argus.diag_type; hipsparseFillMode_t uplo = argus.fill_mode; hipsparseSolvePolicy_t policy = argus.solve_policy; T h_alpha = make_DataType(argus.alpha); std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_csrsm2_info(new csrsm2_struct); csrsm2Info_t info = unique_ptr_csrsm2_info->info; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); // Set matrix diag type CHECK_HIPSPARSE_ERROR(hipsparseSetMatDiagType(descr, diag)); // Set matrix fill mode CHECK_HIPSPARSE_ERROR(hipsparseSetMatFillMode(descr, uplo)); srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, m, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } int ldb = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : nrhs; std::vector hB_1(m * nrhs); std::vector hB_2(m * nrhs); std::vector hB_gold(m * nrhs); int h_analysis_pivot_gold; int h_analysis_pivot_1; int h_analysis_pivot_2; int h_solve_pivot_gold; int h_solve_pivot_1; int h_solve_pivot_2; hipsparseInit(hB_1, 1, m * nrhs); hB_2 = hB_1; hB_gold = hB_1; // Allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dB_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * nrhs), device_free}; auto dB_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * nrhs), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_analysis_pivot_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; auto d_solve_pivot_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dB_1 = (T*)dB_1_managed.get(); T* dB_2 = (T*)dB_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); int* d_analysis_pivot_2 = (int*)d_analysis_pivot_2_managed.get(); int* d_solve_pivot_2 = (int*)d_solve_pivot_2_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB_1, hB_1.data(), sizeof(T) * m * nrhs, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); // Obtain csrsm2 buffer size size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB_1, ldb, info, policy, &bufferSize)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * bufferSize), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); hipsparseStatus_t status_analysis_1; hipsparseStatus_t status_analysis_2; hipsparseStatus_t status_solve_1; hipsparseStatus_t status_solve_2; CHECK_HIP_ERROR(hipMemcpy(dB_2, hB_2.data(), sizeof(T) * m * nrhs, hipMemcpyHostToDevice)); // csrsm2 analysis - host mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB_1, ldb, info, policy, dbuffer)); // Get pivot status_analysis_1 = hipsparseXcsrsm2_zeroPivot(handle, info, &h_analysis_pivot_1); if(h_analysis_pivot_1 != -1) { verify_hipsparse_status_zero_pivot(status_analysis_1, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); } // csrsm2 analysis - device mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, d_alpha, descr, dval, dptr, dcol, dB_2, ldb, info, policy, dbuffer)); // Get pivot status_analysis_2 = hipsparseXcsrsm2_zeroPivot(handle, info, d_analysis_pivot_2); if(h_analysis_pivot_1 != -1) { verify_hipsparse_status_zero_pivot(status_analysis_2, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); } if(argus.unit_check) { // csrsm2 solve - host mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB_1, ldb, info, policy, dbuffer)); // Get pivot status_solve_1 = hipsparseXcsrsm2_zeroPivot(handle, info, &h_solve_pivot_1); if(h_solve_pivot_1 != -1) { verify_hipsparse_status_zero_pivot(status_solve_1, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); } // csrsm2 solve - device mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, d_alpha, descr, dval, dptr, dcol, dB_2, ldb, info, policy, dbuffer)); // Get pivot status_solve_2 = hipsparseXcsrsm2_zeroPivot(handle, info, d_solve_pivot_2); if(h_solve_pivot_1 != -1) { verify_hipsparse_status_zero_pivot(status_solve_2, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); } // Copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hB_1.data(), dB_1, sizeof(T) * m * nrhs, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hB_2.data(), dB_2, sizeof(T) * m * nrhs, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(&h_analysis_pivot_2, d_analysis_pivot_2, sizeof(int), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(&h_solve_pivot_2, d_solve_pivot_2, sizeof(int), hipMemcpyDeviceToHost)); // Host csrsm2 host_csrsm2(m, nrhs, nnz, transA, transB, h_alpha, hcsr_row_ptr, hcsr_col_ind, hcsr_val, hB_gold, ldb, HIPSPARSE_ORDER_COL, diag, uplo, idx_base, &h_analysis_pivot_gold, &h_solve_pivot_gold); // Check pivots unit_check_general(1, 1, 1, &h_analysis_pivot_gold, &h_analysis_pivot_1); unit_check_general(1, 1, 1, &h_analysis_pivot_gold, &h_analysis_pivot_2); unit_check_general(1, 1, 1, &h_solve_pivot_gold, &h_solve_pivot_1); unit_check_general(1, 1, 1, &h_solve_pivot_gold, &h_solve_pivot_2); // Check solution matrix if no pivot has been found if(h_analysis_pivot_gold == -1 && h_solve_pivot_gold == -1) { unit_check_near(1, m * nrhs, 1, hB_gold.data(), hB_1.data()); unit_check_near(1, m * nrhs, 1, hB_gold.data(), hB_2.data()); } } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB_1, ldb, info, policy, dbuffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB_1, ldb, info, policy, dbuffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = csrsv_gflop_count(m, nnz, diag) * nrhs; double gbyte_count = csrsv_gbyte_count(m, nnz) * nrhs; double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::nnz, nnz, display_key_t::nrhs, nrhs, display_key_t::alpha, h_alpha, display_key_t::transA, hipsparse_operation2string(transA), display_key_t::transB, hipsparse_operation2string(transB), display_key_t::diag_type, hipsparse_diagtype2string(diag), display_key_t::fill_mode, hipsparse_fillmode2string(uplo), display_key_t::solve_policy, hipsparse_solvepolicy2string(policy), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRSM2_HPP ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.566399 hipsparse/clients/include/testing_csrsort.hpp0000664000175100017510000002655015206065364022054 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.566399 hipsparse/clients/include/testing_csrsv2.hpp0000664000175100017510000010034015206065364021565 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2019 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSRSV2_HPP #define TESTING_CSRSV2_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csrsv2_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int m = 100; int nnz = 100; int safe_size = 100; T h_alpha = make_DataType(0.6); hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseSolvePolicy_t policy = HIPSPARSE_SOLVE_POLICY_USE_LEVEL; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_csrsv2_info(new csrsv2_struct); csrsv2Info_t info = unique_ptr_csrsv2_info->info; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dx = (T*)dx_managed.get(); T* dy = (T*)dy_managed.get(); void* dbuffer = (void*)dbuffer_managed.get(); int size; int position; verify_hipsparse_status_invalid_pointer( hipsparseXcsrsv2_bufferSize( handle, transA, m, nnz, descr, dval, (int*)nullptr, dcol, info, &size), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsv2_bufferSize( handle, transA, m, nnz, descr, dval, dptr, (int*)nullptr, info, &size), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsv2_bufferSize( handle, transA, m, nnz, descr, (T*)nullptr, dptr, dcol, info, &size), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsv2_bufferSize( handle, transA, m, nnz, descr, dval, dptr, dcol, info, (int*)nullptr), "Error: size is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsv2_bufferSize( handle, transA, m, nnz, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, info, &size), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsv2_bufferSize( handle, transA, m, nnz, descr, dval, dptr, dcol, (csrsv2Info_t) nullptr, &size), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrsv2_bufferSize( (hipsparseHandle_t) nullptr, transA, m, nnz, descr, dval, dptr, dcol, info, &size)); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsv2_analysis( handle, transA, m, nnz, descr, dval, (int*)nullptr, dcol, info, policy, dbuffer), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsv2_analysis( handle, transA, m, nnz, descr, dval, dptr, (int*)nullptr, info, policy, dbuffer), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsv2_analysis( handle, transA, m, nnz, descr, (T*)nullptr, dptr, dcol, info, policy, dbuffer), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsv2_analysis( handle, transA, m, nnz, descr, dval, dptr, dcol, info, policy, (void*)nullptr), "Error: dbuffer is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsv2_analysis(handle, transA, m, nnz, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, info, policy, dbuffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsv2_analysis(handle, transA, m, nnz, descr, dval, dptr, dcol, (csrsv2Info_t) nullptr, policy, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrsv2_analysis((hipsparseHandle_t) nullptr, transA, m, nnz, descr, dval, dptr, dcol, info, policy, dbuffer)); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr, dval, (int*)nullptr, dcol, info, dx, dy, policy, dbuffer), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr, dval, dptr, (int*)nullptr, info, dx, dy, policy, dbuffer), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr, (T*)nullptr, dptr, dcol, info, dx, dy, policy, dbuffer), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, info, (T*)nullptr, dy, policy, dbuffer), "Error: dx is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, info, dx, (T*)nullptr, policy, dbuffer), "Error: dy is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsv2_solve(handle, transA, m, nnz, (T*)nullptr, descr, dval, dptr, dcol, info, dx, dy, policy, dbuffer), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, info, dx, dy, policy, (void*)nullptr), "Error: dbuffer is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsv2_solve(handle, transA, m, nnz, &h_alpha, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, info, dx, dy, policy, dbuffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, (csrsv2Info_t) nullptr, dx, dy, policy, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrsv2_solve((hipsparseHandle_t) nullptr, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, info, dx, dy, policy, dbuffer)); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsv2_zeroPivot(handle, info, (int*)nullptr), "Error: position is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsv2_zeroPivot(handle, (csrsv2Info_t) nullptr, &position), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXcsrsv2_zeroPivot((hipsparseHandle_t) nullptr, info, &position)); #endif } template hipsparseStatus_t testing_csrsv2(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int m = argus.M; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseOperation_t trans = argus.transA; hipsparseDiagType_t diag_type = argus.diag_type; hipsparseFillMode_t fill_mode = argus.fill_mode; hipsparseSolvePolicy_t policy = argus.solve_policy; T h_alpha = make_DataType(argus.alpha); std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_csrsv2_info(new csrsv2_struct); csrsv2Info_t info = unique_ptr_csrsv2_info->info; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); // Set matrix diag type CHECK_HIPSPARSE_ERROR(hipsparseSetMatDiagType(descr, diag_type)); // Set matrix fill mode CHECK_HIPSPARSE_ERROR(hipsparseSetMatFillMode(descr, fill_mode)); if(m == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, m, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hx(m); std::vector hy_1(m); std::vector hy_2(m); std::vector hy_gold(m); hipsparseInit(hx, 1, m); // Allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_position_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dx = (T*)dx_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); int* d_position = (int*)d_position_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx, hx.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_1, hy_1.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); // Obtain csrsv2 buffer size int bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_bufferSize( handle, trans, m, nnz, descr, dval, dptr, dcol, info, &bufferSize)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * bufferSize), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); // csrsv2 analysis CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_analysis( handle, trans, m, nnz, descr, dval, dptr, dcol, info, policy, dbuffer)); if(argus.unit_check) { CHECK_HIP_ERROR(hipMemcpy(dy_2, hy_2.data(), sizeof(T) * m, hipMemcpyHostToDevice)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_solve(handle, trans, m, nnz, &h_alpha, descr, dval, dptr, dcol, info, dx, dy_1, policy, dbuffer)); int hposition_1; hipsparseStatus_t pivot_status_1; pivot_status_1 = hipsparseXcsrsv2_zeroPivot(handle, info, &hposition_1); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_solve(handle, trans, m, nnz, d_alpha, descr, dval, dptr, dcol, info, dx, dy_2, policy, dbuffer)); hipsparseStatus_t pivot_status_2; pivot_status_2 = hipsparseXcsrsv2_zeroPivot(handle, info, d_position); // Copy output from device to CPU int hposition_2; CHECK_HIP_ERROR(hipMemcpy(hy_1.data(), dy_1, sizeof(T) * m, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_2.data(), dy_2, sizeof(T) * m, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(&hposition_2, d_position, sizeof(int), hipMemcpyDeviceToHost)); // Host csrsv2 hipDeviceProp_t prop; CHECK_HIP_ERROR(hipGetDeviceProperties(&prop, 0)); int position_gold; if((fill_mode == HIPSPARSE_FILL_MODE_LOWER && trans == HIPSPARSE_OPERATION_NON_TRANSPOSE) || (fill_mode == HIPSPARSE_FILL_MODE_UPPER && trans == HIPSPARSE_OPERATION_TRANSPOSE)) { position_gold = csr_lsolve(trans, m, hcsr_row_ptr.data(), hcsr_col_ind.data(), hcsr_val.data(), h_alpha, hx.data(), hy_gold.data(), idx_base, diag_type, prop.warpSize); } else { position_gold = csr_usolve(trans, m, hcsr_row_ptr.data(), hcsr_col_ind.data(), hcsr_val.data(), h_alpha, hx.data(), hy_gold.data(), idx_base, diag_type, prop.warpSize); } unit_check_general(1, 1, 1, &position_gold, &hposition_1); unit_check_general(1, 1, 1, &position_gold, &hposition_2); if(hposition_1 != -1) { verify_hipsparse_status_zero_pivot(pivot_status_1, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); return HIPSPARSE_STATUS_SUCCESS; } if(hposition_2 != -1) { verify_hipsparse_status_zero_pivot(pivot_status_2, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); return HIPSPARSE_STATUS_SUCCESS; } unit_check_near(1, m, 1, hy_gold.data(), hy_1.data()); unit_check_near(1, m, 1, hy_gold.data(), hy_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_solve(handle, trans, m, nnz, &h_alpha, descr, dval, dptr, dcol, info, dx, dy_1, policy, dbuffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_solve(handle, trans, m, nnz, &h_alpha, descr, dval, dptr, dcol, info, dx, dy_1, policy, dbuffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = csrsv_gflop_count(m, nnz, diag_type); double gbyte_count = csrsv_gbyte_count(m, nnz); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::nnz, nnz, display_key_t::alpha, h_alpha, display_key_t::trans, hipsparse_operation2string(trans), display_key_t::diag_type, hipsparse_diagtype2string(diag_type), display_key_t::fill_mode, hipsparse_fillmode2string(fill_mode), display_key_t::solve_policy, hipsparse_solvepolicy2string(policy), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRSV2_HPP ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.566399 hipsparse/clients/include/testing_csru2csr.hpp0000664000175100017510000004027315206065364022121 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2021-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSRU2CSR_HPP #define TESTING_CSRU2CSR_HPP #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csru2csr_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) int m = 100; int n = 100; int nnz = 100; int safe_size = 100; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_csru2csr(new csru2csr_struct); csru2csrInfo_t info = unique_ptr_csru2csr->info; size_t bufferSize; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto buffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* csr_col_ind = (int*)csr_col_ind_managed.get(); float* csr_val = (float*)csr_val_managed.get(); void* buffer = (void*)buffer_managed.get(); // Testing csru2csr_bufferSizeExt for bad args #ifndef __HIP_PLATFORM_NVIDIA__ // cusparse seem to not have any error checking verify_hipsparse_status_invalid_handle(hipsparseXcsru2csr_bufferSizeExt( nullptr, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, info, &bufferSize)); verify_hipsparse_status_invalid_pointer( hipsparseXcsru2csr_bufferSizeExt( handle, m, n, nnz, (float*)nullptr, csr_row_ptr, csr_col_ind, info, &bufferSize), "Error: csr_val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsru2csr_bufferSizeExt( handle, m, n, nnz, csr_val, nullptr, csr_col_ind, info, &bufferSize), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsru2csr_bufferSizeExt( handle, m, n, nnz, csr_val, csr_row_ptr, nullptr, info, &bufferSize), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsru2csr_bufferSizeExt( handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, nullptr, &bufferSize), "Error: info is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsru2csr_bufferSizeExt( handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, info, nullptr), "Error: bufferSize is nullptr"); #endif verify_hipsparse_status_invalid_size( hipsparseXcsru2csr_bufferSizeExt( handle, -1, n, nnz, csr_val, csr_row_ptr, csr_col_ind, info, &bufferSize), "Error: m is invalid"); verify_hipsparse_status_invalid_size( hipsparseXcsru2csr_bufferSizeExt( handle, m, -1, nnz, csr_val, csr_row_ptr, csr_col_ind, info, &bufferSize), "Error: n is invalid"); verify_hipsparse_status_invalid_size( hipsparseXcsru2csr_bufferSizeExt( handle, m, n, -1, csr_val, csr_row_ptr, csr_col_ind, info, &bufferSize), "Error: nnz is invalid"); #ifndef __HIP_PLATFORM_NVIDIA__ // cusparse seem to not have any error checking for some parts verify_hipsparse_status_success( hipsparseXcsru2csr_bufferSizeExt( handle, 0, n, 0, (float*)nullptr, nullptr, nullptr, nullptr, &bufferSize), "Success"); verify_hipsparse_status_success( hipsparseXcsru2csr_bufferSizeExt( handle, m, 0, 0, (float*)nullptr, nullptr, nullptr, nullptr, &bufferSize), "Success"); verify_hipsparse_status_invalid_size( hipsparseXcsru2csr_bufferSizeExt( handle, 0, n, nnz, (float*)nullptr, nullptr, nullptr, nullptr, &bufferSize), "Error: nnz is invalid"); verify_hipsparse_status_invalid_pointer( hipsparseXcsru2csr_bufferSizeExt( handle, 0, n, 0, (float*)nullptr, nullptr, nullptr, nullptr, nullptr), "Error: bufferSize is invalid"); #endif // Testing csru2csr for bad args #ifndef __HIP_PLATFORM_NVIDIA__ // cusparse seem to not have any error checking for some parts verify_hipsparse_status_invalid_handle(hipsparseXcsru2csr( nullptr, m, n, nnz, descr, csr_val, csr_row_ptr, csr_col_ind, info, buffer)); verify_hipsparse_status_invalid_pointer( hipsparseXcsru2csr( handle, m, n, nnz, descr, csr_val, csr_row_ptr, csr_col_ind, nullptr, buffer), "Error: info is nullptr"); #endif verify_hipsparse_status_invalid_pointer( hipsparseXcsru2csr( handle, m, n, nnz, nullptr, csr_val, csr_row_ptr, csr_col_ind, info, buffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsru2csr( handle, m, n, nnz, descr, (float*)nullptr, csr_row_ptr, csr_col_ind, info, buffer), "Error: csr_val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsru2csr(handle, m, n, nnz, descr, csr_val, nullptr, csr_col_ind, info, buffer), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsru2csr(handle, m, n, nnz, descr, csr_val, csr_row_ptr, nullptr, info, buffer), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsru2csr( handle, m, n, nnz, descr, csr_val, csr_row_ptr, csr_col_ind, info, nullptr), "Error: buffer is nullptr"); verify_hipsparse_status_invalid_size( hipsparseXcsru2csr( handle, -1, n, nnz, descr, csr_val, csr_row_ptr, csr_col_ind, info, buffer), "Error: m is invalid"); verify_hipsparse_status_invalid_size( hipsparseXcsru2csr( handle, m, -1, nnz, descr, csr_val, csr_row_ptr, csr_col_ind, info, buffer), "Error: n is invalid"); verify_hipsparse_status_invalid_size( hipsparseXcsru2csr( handle, m, n, -1, descr, csr_val, csr_row_ptr, csr_col_ind, info, buffer), "Error: nnz is invalid"); #ifndef __HIP_PLATFORM_NVIDIA__ // cusparse seem to not have any error checking for some parts verify_hipsparse_status_success( hipsparseXcsru2csr( handle, 0, n, 0, nullptr, (float*)nullptr, nullptr, nullptr, nullptr, &bufferSize), "Success"); verify_hipsparse_status_success( hipsparseXcsru2csr( handle, m, 0, 0, nullptr, (float*)nullptr, nullptr, nullptr, nullptr, &bufferSize), "Success"); verify_hipsparse_status_invalid_size( hipsparseXcsru2csr( handle, 0, n, nnz, nullptr, (float*)nullptr, nullptr, nullptr, nullptr, &bufferSize), "Error: nnz is invalid"); #endif // Testing csr2csru for bad args #ifndef __HIP_PLATFORM_NVIDIA__ // cusparse seem to not have any error checking for some parts verify_hipsparse_status_invalid_handle(hipsparseXcsr2csru( nullptr, m, n, nnz, descr, csr_val, csr_row_ptr, csr_col_ind, info, buffer)); verify_hipsparse_status_invalid_pointer( hipsparseXcsr2csru( handle, m, n, nnz, descr, csr_val, csr_row_ptr, csr_col_ind, nullptr, buffer), "Error: info is nullptr"); #endif verify_hipsparse_status_invalid_pointer( hipsparseXcsr2csru( handle, m, n, nnz, nullptr, csr_val, csr_row_ptr, csr_col_ind, info, buffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsr2csru( handle, m, n, nnz, descr, (float*)nullptr, csr_row_ptr, csr_col_ind, info, buffer), "Error: csr_val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsr2csru(handle, m, n, nnz, descr, csr_val, nullptr, csr_col_ind, info, buffer), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsr2csru(handle, m, n, nnz, descr, csr_val, csr_row_ptr, nullptr, info, buffer), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsr2csru( handle, m, n, nnz, descr, csr_val, csr_row_ptr, csr_col_ind, info, nullptr), "Error: buffer is nullptr"); verify_hipsparse_status_invalid_size( hipsparseXcsr2csru( handle, -1, n, nnz, descr, csr_val, csr_row_ptr, csr_col_ind, info, buffer), "Error: m is invalid"); verify_hipsparse_status_invalid_size( hipsparseXcsr2csru( handle, m, -1, nnz, descr, csr_val, csr_row_ptr, csr_col_ind, info, buffer), "Error: n is invalid"); verify_hipsparse_status_invalid_size( hipsparseXcsr2csru( handle, m, n, -1, descr, csr_val, csr_row_ptr, csr_col_ind, info, buffer), "Error: nnz is invalid"); #ifndef __HIP_PLATFORM_NVIDIA__ // cusparse seem to not have any error checking for some parts verify_hipsparse_status_success( hipsparseXcsr2csru( handle, 0, n, 0, nullptr, (float*)nullptr, nullptr, nullptr, nullptr, &bufferSize), "Success"); verify_hipsparse_status_success( hipsparseXcsr2csru( handle, m, 0, 0, nullptr, (float*)nullptr, nullptr, nullptr, nullptr, &bufferSize), "Success"); verify_hipsparse_status_invalid_size( hipsparseXcsr2csru( handle, 0, n, nnz, nullptr, (float*)nullptr, nullptr, nullptr, nullptr, &bufferSize), "Error: nnz is invalid"); #endif #endif } template hipsparseStatus_t testing_csru2csr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) int m = argus.M; int n = argus.N; hipsparseIndexBase_t idx_base = argus.baseA; std::string filename = argus.filename; // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; hipsparseSetMatIndexBase(descr, idx_base); std::unique_ptr unique_ptr_info(new csru2csr_struct); csru2csrInfo_t info = unique_ptr_info->info; srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind_gold; std::vector hcsr_val_gold; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix( filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind_gold, hcsr_val_gold, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Unsort CSR columns std::vector hperm(nnz); std::vector hcsr_col_ind_unsorted_gold(nnz); std::vector hcsr_val_unsorted_gold(nnz); hcsr_col_ind_unsorted_gold = hcsr_col_ind_gold; hcsr_val_unsorted_gold = hcsr_val_gold; for(int i = 0; i < m; ++i) { int row_begin = hcsr_row_ptr[i] - idx_base; int row_end = hcsr_row_ptr[i + 1] - idx_base; int row_nnz = row_end - row_begin; for(int j = row_begin; j < row_end; ++j) { int rng = row_begin + rand() % row_nnz; int temp_col = hcsr_col_ind_unsorted_gold[j] - idx_base; T temp_val = hcsr_val_unsorted_gold[j]; hcsr_col_ind_unsorted_gold[j] = hcsr_col_ind_unsorted_gold[rng]; hcsr_val_unsorted_gold[j] = hcsr_val_unsorted_gold[rng]; hcsr_col_ind_unsorted_gold[rng] = temp_col + idx_base; hcsr_val_unsorted_gold[rng] = temp_val; } } // Allocate memory on the device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); // Copy data from host to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy( dcsr_col_ind, hcsr_col_ind_unsorted_gold.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_val, hcsr_val_unsorted_gold.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); // Obtain buffer size size_t buffer_size; CHECK_HIPSPARSE_ERROR(hipsparseXcsru2csr_bufferSizeExt( handle, m, n, nnz, dcsr_val, dcsr_row_ptr, dcsr_col_ind, info, &buffer_size)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * buffer_size), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); if(argus.unit_check) { // Sort CSR columns CHECK_HIPSPARSE_ERROR(hipsparseXcsru2csr( handle, m, n, nnz, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, info, dbuffer)); // Copy output from device to host std::vector hcsr_col_ind(nnz); std::vector hcsr_val(nnz); CHECK_HIP_ERROR( hipMemcpy(hcsr_col_ind.data(), dcsr_col_ind, sizeof(int) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val.data(), dcsr_val, sizeof(T) * nnz, hipMemcpyDeviceToHost)); // Unsort CSR columns back to original state CHECK_HIPSPARSE_ERROR(hipsparseXcsr2csru( handle, m, n, nnz, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, info, dbuffer)); // Copy output from device to host std::vector hcsr_col_ind_unsorted(nnz); std::vector hcsr_val_unsorted(nnz); CHECK_HIP_ERROR(hipMemcpy( hcsr_col_ind_unsorted.data(), dcsr_col_ind, sizeof(int) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val_unsorted.data(), dcsr_val, sizeof(T) * nnz, hipMemcpyDeviceToHost)); // Unit check unit_check_general(1, nnz, 1, hcsr_col_ind.data(), hcsr_col_ind_gold.data()); unit_check_general(1, nnz, 1, hcsr_val.data(), hcsr_val_gold.data()); unit_check_general( 1, nnz, 1, hcsr_col_ind_unsorted.data(), hcsr_col_ind_unsorted_gold.data()); unit_check_general(1, nnz, 1, hcsr_val_unsorted.data(), hcsr_val_unsorted_gold.data()); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRU2CSR_HPP ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5673993 hipsparse/clients/include/testing_csx2dense.hpp0000664000175100017510000003040215206065364022242 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5673993 hipsparse/clients/include/testing_dense2csc.hpp0000664000175100017510000000402115206065364022213 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_DENSE2CSC_HPP #define TESTING_DENSE2CSC_HPP #include "testing_dense2csx.hpp" template void testing_dense2csc_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_COLUMN; testing_dense2csx_bad_arg(hipsparseXdense2csc); #endif } template hipsparseStatus_t testing_dense2csc(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_COLUMN; return testing_dense2csx(argus, hipsparseXdense2csc); #else return HIPSPARSE_STATUS_SUCCESS; #endif } #endif // TESTING_DENSE2CSC ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5673993 hipsparse/clients/include/testing_dense2csr.hpp0000664000175100017510000000401315206065364022233 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_DENSE2CSR_HPP #define TESTING_DENSE2CSR_HPP #include "testing_dense2csx.hpp" template void testing_dense2csr_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_ROW; testing_dense2csx_bad_arg(hipsparseXdense2csr); #endif } template hipsparseStatus_t testing_dense2csr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_ROW; return testing_dense2csx(argus, hipsparseXdense2csr); #else return HIPSPARSE_STATUS_SUCCESS; #endif } #endif // TESTING_DENSE2CSR ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5673993 hipsparse/clients/include/testing_dense2csx.hpp0000664000175100017510000003746315206065364022260 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5673993 hipsparse/clients/include/testing_dense_to_sparse_coo.hpp0000664000175100017510000003060315206065364024364 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5673993 hipsparse/clients/include/testing_dense_to_sparse_csc.hpp0000664000175100017510000003357215206065364024364 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5673993 hipsparse/clients/include/testing_dense_to_sparse_csr.hpp0000664000175100017510000003360615206065364024401 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5673993 hipsparse/clients/include/testing_dnmat_descr.hpp0000664000175100017510000001377415206065364022644 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5673993 hipsparse/clients/include/testing_dnvec_descr.hpp0000664000175100017510000001014515206065364022625 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5673993 hipsparse/clients/include/testing_dotci.hpp0000664000175100017510000001740415206065364021455 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2019-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_DOTCI_HPP #define TESTING_DOTCI_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include using namespace hipsparse; using namespace hipsparse_test; template void testing_dotci_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int nnz = 100; int safe_size = 100; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; T* dx_val = (T*)dx_val_managed.get(); int* dx_ind = (int*)dx_ind_managed.get(); T* dy = (T*)dy_managed.get(); T result; verify_hipsparse_status_invalid_pointer( hipsparseXdotci(handle, nnz, (T*)nullptr, dx_ind, dy, &result, idx_base), "Error: x_val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXdotci(handle, nnz, dx_val, (int*)nullptr, dy, &result, idx_base), "Error: x_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXdotci(handle, nnz, dx_val, dx_ind, (T*)nullptr, &result, idx_base), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXdotci(handle, nnz, dx_val, dx_ind, dy, (T*)nullptr, idx_base), "Error: result is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXdotci((hipsparseHandle_t) nullptr, nnz, dx_val, dx_ind, dy, &result, idx_base)); #endif } template hipsparseStatus_t testing_dotci(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) int N = argus.N; int nnz = argus.nnz; hipsparseIndexBase_t idx_base = argus.baseA; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Grab stream used by handle hipStream_t stream; CHECK_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // Host structures std::vector hx_ind(nnz); std::vector hx_val(nnz); std::vector hy(N); T hresult_1; T hresult_2; T hresult_gold; // Initial Data on CPU srand(12345ULL); hipsparseInitIndex(hx_ind.data(), nnz, 1, N); hipsparseInit(hx_val, 1, nnz); hipsparseInit(hy, 1, N); // allocate memory on device auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * N), device_free}; auto dresult_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dx_ind = (int*)dx_ind_managed.get(); T* dx_val = (T*)dx_val_managed.get(); T* dy = (T*)dy_managed.get(); T* dresult_2 = (T*)dresult_2_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dx_ind, hx_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx_val, hx_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy, hy.data(), sizeof(T) * N, hipMemcpyHostToDevice)); if(argus.unit_check) { // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseXdotci(handle, nnz, dx_val, dx_ind, dy, &hresult_1, idx_base)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseXdotci(handle, nnz, dx_val, dx_ind, dy, dresult_2, idx_base)); // copy output from device to CPU^ CHECK_HIP_ERROR(hipMemcpy(&hresult_2, dresult_2, sizeof(T), hipMemcpyDeviceToHost)); // CPU hresult_gold = make_DataType(0.0); for(int i = 0; i < nnz; ++i) { hresult_gold = hresult_gold + testing_mult(testing_conj(hx_val[i]), hy[hx_ind[i] - idx_base]); } // enable unit check, notice unit check is not invasive, but norm check is, // unit check and norm check can not be interchanged their order unit_check_general(1, 1, 1, &hresult_gold, &hresult_1); unit_check_general(1, 1, 1, &hresult_gold, &hresult_2); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXdotci(handle, nnz, dx_val, dx_ind, dy, &hresult_1, idx_base)); CHECK_HIP_ERROR(hipStreamSynchronize(stream)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXdotci(handle, nnz, dx_val, dx_ind, dy, &hresult_1, idx_base)); CHECK_HIP_ERROR(hipStreamSynchronize(stream)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = doti_gflop_count(nnz); double gbyte_count = doti_gbyte_count(nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); display_timing_info(display_key_t::nnz, nnz, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_DOTCI_HPP ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5673993 hipsparse/clients/include/testing_doti.hpp0000664000175100017510000001731315206065364021311 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_DOTI_HPP #define TESTING_DOTI_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include using namespace hipsparse; using namespace hipsparse_test; template void testing_doti_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int nnz = 100; int safe_size = 100; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; T* dx_val = (T*)dx_val_managed.get(); int* dx_ind = (int*)dx_ind_managed.get(); T* dy = (T*)dy_managed.get(); T result; verify_hipsparse_status_invalid_pointer( hipsparseXdoti(handle, nnz, (T*)nullptr, dx_ind, dy, &result, idx_base), "Error: x_val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXdoti(handle, nnz, dx_val, (int*)nullptr, dy, &result, idx_base), "Error: x_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXdoti(handle, nnz, dx_val, dx_ind, (T*)nullptr, &result, idx_base), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXdoti(handle, nnz, dx_val, dx_ind, dy, (T*)nullptr, idx_base), "Error: result is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXdoti((hipsparseHandle_t) nullptr, nnz, dx_val, dx_ind, dy, &result, idx_base)); #endif } template hipsparseStatus_t testing_doti(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) int N = argus.N; int nnz = argus.nnz; hipsparseIndexBase_t idx_base = argus.baseA; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Grab stream used by handle hipStream_t stream; CHECK_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // Host structures std::vector hx_ind(nnz); std::vector hx_val(nnz); std::vector hy(N); T hresult_1; T hresult_2; T hresult_gold; // Initial Data on CPU srand(12345ULL); hipsparseInitIndex(hx_ind.data(), nnz, 1, N); hipsparseInit(hx_val, 1, nnz); hipsparseInit(hy, 1, N); // allocate memory on device auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * N), device_free}; auto dresult_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dx_ind = (int*)dx_ind_managed.get(); T* dx_val = (T*)dx_val_managed.get(); T* dy = (T*)dy_managed.get(); T* dresult_2 = (T*)dresult_2_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dx_ind, hx_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx_val, hx_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy, hy.data(), sizeof(T) * N, hipMemcpyHostToDevice)); if(argus.unit_check) { // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseXdoti(handle, nnz, dx_val, dx_ind, dy, &hresult_1, idx_base)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXdoti(handle, nnz, dx_val, dx_ind, dy, dresult_2, idx_base)); // copy output from device to CPU^ CHECK_HIP_ERROR(hipMemcpy(&hresult_2, dresult_2, sizeof(T), hipMemcpyDeviceToHost)); // CPU hresult_gold = make_DataType(0.0); for(int i = 0; i < nnz; ++i) { hresult_gold = hresult_gold + testing_mult(hy[hx_ind[i] - idx_base], hx_val[i]); } // enable unit check, notice unit check is not invasive, but norm check is, // unit check and norm check can not be interchanged their order unit_check_general(1, 1, 1, &hresult_gold, &hresult_1); unit_check_general(1, 1, 1, &hresult_gold, &hresult_2); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXdoti(handle, nnz, dx_val, dx_ind, dy, &hresult_1, idx_base)); CHECK_HIP_ERROR(hipStreamSynchronize(stream)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXdoti(handle, nnz, dx_val, dx_ind, dy, &hresult_1, idx_base)); CHECK_HIP_ERROR(hipStreamSynchronize(stream)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = doti_gflop_count(nnz); double gbyte_count = doti_gbyte_count(nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); display_timing_info(display_key_t::nnz, nnz, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_DOTI_HPP ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5683992 hipsparse/clients/include/testing_gather.hpp0000664000175100017510000001535615206065364021631 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5683992 hipsparse/clients/include/testing_gebsr2csr.hpp0000664000175100017510000006764315206065364022261 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_GEBSR2CSR_HPP #define TESTING_GEBSR2CSR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_gebsr2csr_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int m = 1; int n = 1; int safe_size = 1; int row_block_dim = 2; int col_block_dim = 2; hipsparseIndexBase_t csr_idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexBase_t bsr_idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseDirection_t dir = HIPSPARSE_DIRECTION_ROW; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_csr_descr(new descr_struct); hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; std::unique_ptr unique_ptr_bsr_descr(new descr_struct); hipsparseMatDescr_t bsr_descr = unique_ptr_bsr_descr->descr; hipsparseSetMatIndexBase(csr_descr, csr_idx_base); hipsparseSetMatIndexBase(bsr_descr, bsr_idx_base); auto bsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto bsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto bsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto csr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* bsr_row_ptr = (int*)bsr_row_ptr_managed.get(); int* bsr_col_ind = (int*)bsr_col_ind_managed.get(); T* bsr_val = (T*)bsr_val_managed.get(); int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* csr_col_ind = (int*)csr_col_ind_managed.get(); T* csr_val = (T*)csr_val_managed.get(); int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(bsr_row_ptr, local_ptr, sizeof(int) * (1 + 1), hipMemcpyHostToDevice)); verify_hipsparse_status_invalid_handle(hipsparseXgebsr2csr(nullptr, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, row_block_dim, col_block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind)); verify_hipsparse_status_invalid_pointer(hipsparseXgebsr2csr(handle, dir, m, n, nullptr, bsr_val, bsr_row_ptr, bsr_col_ind, row_block_dim, col_block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: bsr_descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgebsr2csr(handle, dir, m, n, bsr_descr, (T*)nullptr, bsr_row_ptr, bsr_col_ind, row_block_dim, col_block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: bsr_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgebsr2csr(handle, dir, m, n, bsr_descr, bsr_val, nullptr, bsr_col_ind, row_block_dim, col_block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: bsr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgebsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, nullptr, row_block_dim, col_block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: bsr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgebsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, row_block_dim, col_block_dim, nullptr, csr_val, csr_row_ptr, csr_col_ind), "Error: csr_descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgebsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, row_block_dim, col_block_dim, csr_descr, (T*)nullptr, csr_row_ptr, csr_col_ind), "Error: csr_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgebsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, row_block_dim, col_block_dim, csr_descr, csr_val, nullptr, csr_col_ind), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgebsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, row_block_dim, col_block_dim, csr_descr, csr_val, csr_row_ptr, nullptr), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_size(hipsparseXgebsr2csr(handle, dir, -1, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, row_block_dim, col_block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: m is invalid"); verify_hipsparse_status_invalid_size(hipsparseXgebsr2csr(handle, dir, m, -1, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, row_block_dim, col_block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: n is invalid"); verify_hipsparse_status_invalid_size(hipsparseXgebsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, -1, col_block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: row_block_dim is invalid"); verify_hipsparse_status_invalid_size(hipsparseXgebsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, row_block_dim, -1, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: col_block_dim is invalid"); #endif } template hipsparseStatus_t testing_gebsr2csr(Arguments argus) { int m = argus.M; int n = argus.N; int row_block_dim = argus.row_block_dimA; int col_block_dim = argus.col_block_dimA; hipsparseIndexBase_t csr_idx_base = argus.baseA; hipsparseIndexBase_t bsr_idx_base = argus.baseB; hipsparseDirection_t dir = argus.dirA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_csr_descr(new descr_struct); hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; std::unique_ptr unique_ptr_bsr_descr(new descr_struct); hipsparseMatDescr_t bsr_descr = unique_ptr_bsr_descr->descr; hipsparseSetMatIndexBase(csr_descr, csr_idx_base); hipsparseSetMatIndexBase(bsr_descr, bsr_idx_base); if(m == 0 || n == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse does not support m == 0 for csr2bsr return HIPSPARSE_STATUS_SUCCESS; #endif } int mb = m * row_block_dim; int nb = n * col_block_dim; srand(12345ULL); // Host structures std::vector bsr_row_ptr; std::vector bsr_col_ind; std::vector bsr_val; // Read or construct CSR matrix int nnzb = 0; if(!generate_csr_matrix( filename, mb, nb, nnzb, bsr_row_ptr, bsr_col_ind, bsr_val, bsr_idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } m = mb * row_block_dim; n = nb * col_block_dim; size_t nnz = nnzb * row_block_dim * col_block_dim; // Now use the csr matrix as the symbolic for the gebsr matrix. bsr_val.resize(nnz); int idx = 0; switch(dir) { case HIPSPARSE_DIRECTION_COLUMN: { for(int i = 0; i < mb; ++i) { for(int r = 0; r < row_block_dim; ++r) { for(int k = bsr_row_ptr[i] - bsr_idx_base; k < bsr_row_ptr[i + 1] - bsr_idx_base; ++k) { for(int c = 0; c < col_block_dim; ++c) { bsr_val[k * row_block_dim * col_block_dim + c * row_block_dim + r] = make_DataType(++idx); } } } } break; } case HIPSPARSE_DIRECTION_ROW: { for(int i = 0; i < mb; ++i) { for(int r = 0; r < row_block_dim; ++r) { for(int k = bsr_row_ptr[i] - bsr_idx_base; k < bsr_row_ptr[i + 1] - bsr_idx_base; ++k) { for(int c = 0; c < col_block_dim; ++c) { bsr_val[k * row_block_dim * col_block_dim + r * col_block_dim + c] = make_DataType(++idx); } } } } break; } } // Allocate memory on the device auto dbsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb + 1)), device_free}; auto dbsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnzb), device_free}; auto dbsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; int* dbsr_row_ptr = (int*)dbsr_row_ptr_managed.get(); int* dbsr_col_ind = (int*)dbsr_col_ind_managed.get(); T* dbsr_val = (T*)dbsr_val_managed.get(); int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); // Copy data from host to device CHECK_HIP_ERROR( hipMemcpy(dbsr_row_ptr, bsr_row_ptr.data(), sizeof(int) * (mb + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dbsr_col_ind, bsr_col_ind.data(), sizeof(int) * nnzb, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dbsr_val, bsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2csr(handle, dir, mb, nb, bsr_descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, row_block_dim, col_block_dim, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind)); // Host CSR matrix std::vector dh_csr_row_ptr(m + 1); std::vector dh_csr_col_ind(nnz); std::vector dh_csr_val(nnz); // Copy output from device to host CHECK_HIP_ERROR(hipMemcpy( dh_csr_row_ptr.data(), dcsr_row_ptr, sizeof(int) * (m + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( dh_csr_col_ind.data(), dcsr_col_ind, sizeof(int) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(dh_csr_val.data(), dcsr_val, sizeof(T) * nnz, hipMemcpyDeviceToHost)); // Host CSR matrix std::vector h_csr_row_ptr(m + 1); std::vector h_csr_col_ind(nnz); std::vector h_csr_val(nnz); // Host gebsr2csr host_gebsr_to_csr(dir, mb, nb, nnzb, bsr_val, bsr_row_ptr, bsr_col_ind, row_block_dim, col_block_dim, bsr_idx_base, h_csr_val, h_csr_row_ptr, h_csr_col_ind, csr_idx_base); // Unit check unit_check_general(1, m + 1, 1, dh_csr_row_ptr.data(), h_csr_row_ptr.data()); unit_check_general(1, nnz, 1, dh_csr_col_ind.data(), h_csr_col_ind.data()); unit_check_general(1, nnz, 1, dh_csr_val.data(), h_csr_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2csr(handle, dir, mb, nb, bsr_descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, row_block_dim, col_block_dim, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2csr(handle, dir, mb, nb, bsr_descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, row_block_dim, col_block_dim, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = gebsr2csr_gbyte_count(mb, row_block_dim, col_block_dim, nnzb); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::Mb, mb, display_key_t::Nb, nb, display_key_t::row_block_dim, row_block_dim, display_key_t::col_block_dim, col_block_dim, display_key_t::nnzb, nnzb, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GEBSR2CSR_HPP ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5683992 hipsparse/clients/include/testing_gebsr2gebsc.hpp0000664000175100017510000007570015206065364022546 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_GEBSR2GEBSC_HPP #define TESTING_GEBSR2GEBSC_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_gebsr2gebsc_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) hipsparseStatus_t status; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; static const size_t safe_size = 1; auto bsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto bsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto bsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* bsr_row_ptr = (int*)bsr_row_ptr_managed.get(); int* bsr_col_ind = (int*)bsr_col_ind_managed.get(); T* bsr_val = (T*)bsr_val_managed.get(); auto bsc_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto bsc_col_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto bsc_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto buffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; void* buffer = buffer_managed.get(); int* bsc_row_ind = (int*)bsc_row_ind_managed.get(); int* bsc_col_ptr = (int*)bsc_col_ptr_managed.get(); T* bsc_val = (T*)bsc_val_managed.get(); int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(bsr_row_ptr, local_ptr, sizeof(int) * (safe_size + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(bsc_col_ptr, local_ptr, sizeof(int) * (safe_size + 1), hipMemcpyHostToDevice)); size_t buffer_size; status = hipsparseXgebsr2gebsc_bufferSize(nullptr, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, &buffer_size); verify_hipsparse_status_invalid_handle(status); status = hipsparseXgebsr2gebsc_bufferSize(handle, -1, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, &buffer_size); verify_hipsparse_status_invalid_size(status, "Error: mb is invalid"); status = hipsparseXgebsr2gebsc_bufferSize(handle, safe_size, -1, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, &buffer_size); verify_hipsparse_status_invalid_size(status, "Error: nb is invalid"); status = hipsparseXgebsr2gebsc_bufferSize(handle, safe_size, safe_size, -1, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, &buffer_size); verify_hipsparse_status_invalid_size(status, "Error: nnzb is invalid"); status = hipsparseXgebsr2gebsc_bufferSize(handle, safe_size, safe_size, safe_size, nullptr, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, &buffer_size); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_val is nullptr"); status = hipsparseXgebsr2gebsc_bufferSize(handle, safe_size, safe_size, safe_size, bsr_val, nullptr, bsr_col_ind, safe_size, safe_size, &buffer_size); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_row_ptr is nullptr"); status = hipsparseXgebsr2gebsc_bufferSize(handle, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, nullptr, safe_size, safe_size, &buffer_size); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_col_ind is nullptr"); status = hipsparseXgebsr2gebsc_bufferSize(handle, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, -1, safe_size, &buffer_size); verify_hipsparse_status_invalid_size(status, "Error: row_block_dim is invalid"); status = hipsparseXgebsr2gebsc_bufferSize(handle, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, -1, &buffer_size); verify_hipsparse_status_invalid_size(status, "Error: col_block_dim is invalid"); status = hipsparseXgebsr2gebsc_bufferSize(handle, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer_size is nullptr"); // Test hipsparseXgebsr2gebsc() status = hipsparseXgebsr2gebsc(nullptr, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, bsc_val, bsc_row_ind, bsc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, buffer); verify_hipsparse_status_invalid_handle(status); status = hipsparseXgebsr2gebsc(handle, -1, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, bsc_val, bsc_row_ind, bsc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, buffer); verify_hipsparse_status_invalid_size(status, "Error: mb is invalid"); status = hipsparseXgebsr2gebsc(handle, safe_size, -1, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, bsc_val, bsc_row_ind, bsc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, buffer); verify_hipsparse_status_invalid_size(status, "Error: nb is invalid"); status = hipsparseXgebsr2gebsc(handle, safe_size, safe_size, -1, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, bsc_val, bsc_row_ind, bsc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, buffer); verify_hipsparse_status_invalid_size(status, "Error: nnzb is invalid"); status = hipsparseXgebsr2gebsc(handle, safe_size, safe_size, safe_size, nullptr, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, bsc_val, bsc_row_ind, bsc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, buffer); verify_hipsparse_status_invalid_size(status, "Error: bsr_val is nullptr"); status = hipsparseXgebsr2gebsc(handle, safe_size, safe_size, safe_size, bsr_val, nullptr, bsr_col_ind, safe_size, safe_size, bsc_val, bsc_row_ind, bsc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_row_ptr is nullptr"); status = hipsparseXgebsr2gebsc(handle, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, nullptr, safe_size, safe_size, bsc_val, bsc_row_ind, bsc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_col_ind is nullptr"); status = hipsparseXgebsr2gebsc(handle, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, -1, safe_size, bsc_val, bsc_row_ind, bsc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, buffer); verify_hipsparse_status_invalid_size(status, "Error: row_block_dim is invalid"); status = hipsparseXgebsr2gebsc(handle, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, -1, bsc_val, bsc_row_ind, bsc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, buffer); verify_hipsparse_status_invalid_size(status, "Error: col_block_dim is invalid"); status = hipsparseXgebsr2gebsc(handle, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, nullptr, bsc_row_ind, bsc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsc_val is nullptr"); status = hipsparseXgebsr2gebsc(handle, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, bsc_val, nullptr, bsc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsc_row_ind is nullptr"); status = hipsparseXgebsr2gebsc(handle, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, bsc_val, bsc_row_ind, nullptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsc_col_ptr is nullptr"); status = hipsparseXgebsr2gebsc(handle, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, bsc_val, bsc_row_ind, bsc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer is invalid"); #endif } #define DEVICE_ALLOC(TYPE, NAME, SIZE) \ auto NAME##_managed = hipsparse_unique_ptr{device_malloc(sizeof(TYPE) * SIZE), device_free}; \ TYPE* NAME = (TYPE*)NAME##_managed.get() template hipsparseStatus_t testing_gebsr2gebsc(Arguments argus) { int m = argus.M; int n = argus.N; int row_block_dim = argus.row_block_dimA; int col_block_dim = argus.col_block_dimA; hipsparseAction_t action = argus.action; hipsparseIndexBase_t base = argus.baseA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; if(m == 0 || n == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse does not support m == 0 for csr2bsr return HIPSPARSE_STATUS_SUCCESS; #endif } int mb = m * row_block_dim; int nb = n * col_block_dim; srand(12345ULL); // Host structures std::vector hbsr_row_ptr; std::vector hbsr_col_ind; std::vector hbsr_val; // Read or construct CSR matrix int nnzb = 0; if(!generate_csr_matrix(filename, mb, nb, nnzb, hbsr_row_ptr, hbsr_col_ind, hbsr_val, base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } m = mb * row_block_dim; n = nb * col_block_dim; size_t nnz = nnzb * row_block_dim * col_block_dim; // Now use the csr matrix as the symbolic for the gebsr matrix. hbsr_val.resize(nnz); for(size_t i = 0; i < nnz; ++i) { hbsr_val[i] = random_generator(); } DEVICE_ALLOC(int, dbsr_row_ptr, (mb + 1)); DEVICE_ALLOC(int, dbsr_col_ind, nnzb); DEVICE_ALLOC(T, dbsr_val, (nnzb * row_block_dim * col_block_dim)); // Copy data from host to device CHECK_HIP_ERROR(hipMemcpy( dbsr_row_ptr, hbsr_row_ptr.data(), sizeof(int) * (mb + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dbsr_col_ind, hbsr_col_ind.data(), sizeof(int) * nnzb, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dbsr_val, hbsr_val.data(), sizeof(T) * nnzb * row_block_dim * col_block_dim, hipMemcpyHostToDevice)); // Obtain required buffer size (from host) size_t buffer_size; CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2gebsc_bufferSize(handle, mb, nb, nnzb, dbsr_val, dbsr_row_ptr, dbsr_col_ind, row_block_dim, col_block_dim, &buffer_size)); // Allocate the buffer size. auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(buffer_size), device_free}; void* dbuffer = dbuffer_managed.get(); DEVICE_ALLOC(int, dbsc_row_ind, nnzb); DEVICE_ALLOC(int, dbsc_col_ptr, (nb + 1)); DEVICE_ALLOC(T, dbsc_val, (nnzb * row_block_dim * col_block_dim)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2gebsc(handle, mb, nb, nnzb, dbsr_val, dbsr_row_ptr, dbsr_col_ind, row_block_dim, col_block_dim, dbsc_val, dbsc_row_ind, dbsc_col_ptr, action, base, dbuffer)); // Transfer to host. std::vector hbsc_from_device_row_ind(nnzb); std::vector hbsc_from_device_col_ptr(nb + 1); std::vector hbsc_from_device_val(nnzb * row_block_dim * col_block_dim); CHECK_HIP_ERROR(hipMemcpy(hbsc_from_device_col_ptr.data(), dbsc_col_ptr, sizeof(int) * (nb + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsc_from_device_row_ind.data(), dbsc_row_ind, sizeof(int) * nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsc_from_device_val.data(), dbsc_val, sizeof(T) * nnzb * row_block_dim * col_block_dim, hipMemcpyDeviceToHost)); // Allocate host bsc matrix. std::vector hbsc_row_ind(nnzb); std::vector hbsc_col_ptr(nb + 1); std::vector hbsc_val(nnzb * row_block_dim * col_block_dim); host_gebsr_to_gebsc(mb, nb, nnzb, hbsr_row_ptr, hbsr_col_ind, hbsr_val, row_block_dim, col_block_dim, hbsc_row_ind, hbsc_col_ptr, hbsc_val, action, base); unit_check_general(1, nb + 1, 1, hbsc_from_device_col_ptr.data(), hbsc_col_ptr.data()); unit_check_general(1, nnzb, 1, hbsc_from_device_row_ind.data(), hbsc_row_ind.data()); if(action == HIPSPARSE_ACTION_NUMERIC) { unit_check_general(1, nnzb * row_block_dim * col_block_dim, 1, hbsc_from_device_val.data(), hbsc_val.data()); } } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2gebsc(handle, mb, nb, nnzb, dbsr_val, dbsr_row_ptr, dbsr_col_ind, row_block_dim, col_block_dim, dbsc_val, dbsc_row_ind, dbsc_col_ptr, action, base, dbuffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2gebsc(handle, mb, nb, nnzb, dbsr_val, dbsr_row_ptr, dbsr_col_ind, row_block_dim, col_block_dim, dbsc_val, dbsc_row_ind, dbsc_col_ptr, action, base, dbuffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = gebsr2gebsc_gbyte_count(mb, nb, nnzb, row_block_dim, col_block_dim, action); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::Mb, mb, display_key_t::Nb, nb, display_key_t::nnzb, nnzb, display_key_t::row_block_dim, row_block_dim, display_key_t::col_block_dim, col_block_dim, display_key_t::action, hipsparse_action2string(action), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GEBSR2GEBSC_HPP ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5683992 hipsparse/clients/include/testing_gebsr2gebsr.hpp0000664000175100017510000017403015206065364022561 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_GEBSR2GEBSR_HPP #define TESTING_GEBSR2GEBSR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" using namespace hipsparse; using namespace hipsparse_test; template void testing_gebsr2gebsr_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int mb = 1; int nb = 1; int nnzb = 1; int safe_size = 1; int row_block_dim_A = 2; int col_block_dim_A = 2; int row_block_dim_C = 2; int col_block_dim_C = 2; hipsparseIndexBase_t idx_base_A = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexBase_t idx_base_C = HIPSPARSE_INDEX_BASE_ZERO; hipsparseDirection_t dir = HIPSPARSE_DIRECTION_ROW; hipsparseStatus_t status; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = unique_ptr_descr_A->descr; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; hipsparseSetMatIndexBase(descr_A, idx_base_A); hipsparseSetMatIndexBase(descr_C, idx_base_C); auto bsr_row_ptr_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto bsr_col_ind_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto bsr_val_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto bsr_row_ptr_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto bsr_col_ind_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto bsr_val_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto temp_buffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* bsr_row_ptr_A = (int*)bsr_row_ptr_A_managed.get(); int* bsr_col_ind_A = (int*)bsr_col_ind_A_managed.get(); T* bsr_val_A = (T*)bsr_val_A_managed.get(); int* bsr_row_ptr_C = (int*)bsr_row_ptr_C_managed.get(); int* bsr_col_ind_C = (int*)bsr_col_ind_C_managed.get(); T* bsr_val_C = (T*)bsr_val_C_managed.get(); T* temp_buffer = (T*)temp_buffer_managed.get(); int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(bsr_row_ptr_A, local_ptr, sizeof(int) * (safe_size + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(bsr_row_ptr_C, local_ptr, sizeof(int) * (safe_size + 1), hipMemcpyHostToDevice)); // Testing hipsparseXgebsr2gebsr_bufferSize() int buffer_size; // Test invalid handle status = hipsparseXgebsr2gebsr_bufferSize(nullptr, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, row_block_dim_C, col_block_dim_C, &buffer_size); verify_hipsparse_status_invalid_handle(status); // Test invalid pointers status = hipsparseXgebsr2gebsr_bufferSize(handle, dir, mb, nb, nnzb, nullptr, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, row_block_dim_C, col_block_dim_C, &buffer_size); verify_hipsparse_status_invalid_pointer(status, "Error: descr_A is nullptr"); status = hipsparseXgebsr2gebsr_bufferSize(handle, dir, mb, nb, nnzb, descr_A, (const T*)nullptr, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, row_block_dim_C, col_block_dim_C, &buffer_size); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_val_A is nullptr"); status = hipsparseXgebsr2gebsr_bufferSize(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, nullptr, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, row_block_dim_C, col_block_dim_C, &buffer_size); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_row_ptr_A is nullptr"); status = hipsparseXgebsr2gebsr_bufferSize(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, nullptr, row_block_dim_A, col_block_dim_A, row_block_dim_C, col_block_dim_C, &buffer_size); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_col_ind_A is nullptr"); status = hipsparseXgebsr2gebsr_bufferSize(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, row_block_dim_C, col_block_dim_C, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer_size is nullptr"); // Test invalid sizes status = hipsparseXgebsr2gebsr_bufferSize(handle, dir, -1, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, row_block_dim_C, col_block_dim_C, &buffer_size); verify_hipsparse_status_invalid_size(status, "Error: mb is invalid"); status = hipsparseXgebsr2gebsr_bufferSize(handle, dir, mb, -1, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, row_block_dim_C, col_block_dim_C, &buffer_size); verify_hipsparse_status_invalid_size(status, "Error: nb is invalid"); status = hipsparseXgebsr2gebsr_bufferSize(handle, dir, mb, nb, -1, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, row_block_dim_C, col_block_dim_C, &buffer_size); verify_hipsparse_status_invalid_size(status, "Error: nnzb is invalid"); status = hipsparseXgebsr2gebsr_bufferSize(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, -1, col_block_dim_A, row_block_dim_C, col_block_dim_C, &buffer_size); verify_hipsparse_status_invalid_size(status, "Error: row_block_dim_A is invalid"); status = hipsparseXgebsr2gebsr_bufferSize(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, -1, row_block_dim_C, col_block_dim_C, &buffer_size); verify_hipsparse_status_invalid_size(status, "Error: col_block_dim_A is invalid"); status = hipsparseXgebsr2gebsr_bufferSize(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, -1, col_block_dim_C, &buffer_size); verify_hipsparse_status_invalid_size(status, "Error: row_block_dim_C is invalid"); status = hipsparseXgebsr2gebsr_bufferSize(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, row_block_dim_C, -1, &buffer_size); verify_hipsparse_status_invalid_size(status, "Error: col_block_dim_C is invalid"); // Testing hipsparseXgebsr2gebsrNnz() int nnz_total_dev_host_ptr; // Test invalid handle status = hipsparseXgebsr2gebsrNnz(nullptr, dir, mb, nb, nnzb, descr_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_row_ptr_C, row_block_dim_C, col_block_dim_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_handle(status); // Test invalid pointers status = hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, nnzb, nullptr, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_row_ptr_C, row_block_dim_C, col_block_dim_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_A is nullptr"); status = hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, nnzb, descr_A, nullptr, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_row_ptr_C, row_block_dim_C, col_block_dim_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_row_ptr_A is nullptr"); status = hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, nnzb, descr_A, bsr_row_ptr_A, nullptr, row_block_dim_A, col_block_dim_A, descr_C, bsr_row_ptr_C, row_block_dim_C, col_block_dim_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_col_ind_A is nullptr"); status = hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, nnzb, descr_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, nullptr, bsr_row_ptr_C, row_block_dim_C, col_block_dim_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_C is nullptr"); status = hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, nnzb, descr_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, nullptr, row_block_dim_C, col_block_dim_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_row_ptr_C is nullptr"); status = hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, nnzb, descr_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_row_ptr_C, row_block_dim_C, col_block_dim_C, nullptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: nnz_total_dev_host_ptr is nullptr"); // Test invalid sizes status = hipsparseXgebsr2gebsrNnz(handle, dir, -1, nb, nnzb, descr_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_row_ptr_C, row_block_dim_C, col_block_dim_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: mb is invalid"); status = hipsparseXgebsr2gebsrNnz(handle, dir, mb, -1, nnzb, descr_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_row_ptr_C, row_block_dim_C, col_block_dim_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: nb is invalid"); status = hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, -1, descr_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_row_ptr_C, row_block_dim_C, col_block_dim_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: nnzb is invalid"); status = hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, nnzb, descr_A, bsr_row_ptr_A, bsr_col_ind_A, -1, col_block_dim_A, descr_C, bsr_row_ptr_C, row_block_dim_C, col_block_dim_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: row_block_dim_A is invalid"); status = hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, nnzb, descr_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, -1, descr_C, bsr_row_ptr_C, row_block_dim_C, col_block_dim_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: col_block_dim_A is invalid"); status = hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, nnzb, descr_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_row_ptr_C, -1, col_block_dim_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: row_block_dim_C is invalid"); status = hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, nnzb, descr_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_row_ptr_C, row_block_dim_C, -1, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: col_block_dim_C is invalid"); // Test hipsparseXgebsr2gebsr() // Test invalid handle status = hipsparseXgebsr2gebsr(nullptr, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_handle(status); // Test invalid pointers status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, nullptr, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_A is nullptr"); status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, (const T*)nullptr, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_val_A is nullptr"); status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, nullptr, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_row_ptr_A is nullptr"); status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, nullptr, row_block_dim_A, col_block_dim_A, descr_C, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_col_ind_A is nullptr"); status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, nullptr, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_C is nullptr"); status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, (T*)nullptr, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_val_C is nullptr"); status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_val_C, nullptr, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_row_ptr_C is nullptr"); status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_val_C, bsr_row_ptr_C, nullptr, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_col_ind_C is nullptr"); // Test invalid sizes status = hipsparseXgebsr2gebsr(handle, dir, -1, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: mb is invalid"); status = hipsparseXgebsr2gebsr(handle, dir, mb, -1, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: nb is invalid"); status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, -1, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: nnzb is invalid"); status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, -1, col_block_dim_A, descr_C, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: row_block_dim_A is invalid"); status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, -1, descr_C, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: col_block_dim_A is invalid"); status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, -1, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: row_block_dim_C is invalid"); status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, -1, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: col_block_dim_C is invalid"); #endif } template hipsparseStatus_t testing_gebsr2gebsr(Arguments argus) { int m = argus.M; int n = argus.N; int row_block_dim_A = argus.row_block_dimA; int col_block_dim_A = argus.col_block_dimA; int row_block_dim_C = argus.row_block_dimB; int col_block_dim_C = argus.col_block_dimB; hipsparseIndexBase_t idx_base_A = argus.baseA; hipsparseIndexBase_t idx_base_C = argus.baseB; hipsparseDirection_t dir = argus.dirA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = unique_ptr_descr_A->descr; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; hipsparseSetMatIndexBase(descr_A, idx_base_A); hipsparseSetMatIndexBase(descr_C, idx_base_C); if(m == 0 || n == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse does not support m == 0 for csr2bsr return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base_A)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // mb and nb can be modified if reading from a file int mb = (m + row_block_dim_A - 1) / row_block_dim_A; int nb = (n + col_block_dim_A - 1) / col_block_dim_A; int mb_C = (mb * row_block_dim_A + row_block_dim_C - 1) / row_block_dim_C; int nb_C = (nb * col_block_dim_A + col_block_dim_C - 1) / col_block_dim_C; // allocate memory on device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dbsr_row_ptr_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb + 1)), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); int* dbsr_row_ptr_A = (int*)dbsr_row_ptr_A_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_val, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); size_t buffer_size_conversion; CHECK_HIPSPARSE_ERROR(hipsparseXcsr2gebsr_bufferSize(handle, dir, m, n, descr_A, dcsr_val, dcsr_row_ptr, dcsr_col_ind, row_block_dim_A, col_block_dim_A, &buffer_size_conversion)); auto dbuffer_conversion_managed = hipsparse_unique_ptr{device_malloc(buffer_size_conversion), device_free}; void* dbuffer_conversion = dbuffer_conversion_managed.get(); // Obtain BSR nnzb first on the host and then using the device and ensure they give the same results CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); int nnzb; CHECK_HIPSPARSE_ERROR(hipsparseXcsr2gebsrNnz(handle, dir, m, n, descr_A, dcsr_row_ptr, dcsr_col_ind, descr_A, dbsr_row_ptr_A, row_block_dim_A, col_block_dim_A, &nnzb, dbuffer_conversion)); // Allocate memory on the device auto dbsr_col_ind_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnzb), device_free}; auto dbsr_val_A_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * nnzb * row_block_dim_A * col_block_dim_A), device_free}; auto dbsr_row_ptr_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb_C + 1)), device_free}; int* dbsr_col_ind_A = (int*)dbsr_col_ind_A_managed.get(); T* dbsr_val_A = (T*)dbsr_val_A_managed.get(); int* dbsr_row_ptr_C = (int*)dbsr_row_ptr_C_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseXcsr2gebsr(handle, dir, m, n, descr_A, dcsr_val, dcsr_row_ptr, dcsr_col_ind, descr_A, dbsr_val_A, dbsr_row_ptr_A, dbsr_col_ind_A, row_block_dim_A, col_block_dim_A, dbuffer_conversion)); // Copy output from device to host std::vector hbsr_row_ptr_A(mb + 1); std::vector hbsr_col_ind_A(nnzb); std::vector hbsr_val_A(nnzb * row_block_dim_A * col_block_dim_A); CHECK_HIP_ERROR(hipMemcpy( hbsr_row_ptr_A.data(), dbsr_row_ptr_A, sizeof(int) * (mb + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hbsr_col_ind_A.data(), dbsr_col_ind_A, sizeof(int) * nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsr_val_A.data(), dbsr_val_A, sizeof(T) * nnzb * row_block_dim_A * col_block_dim_A, hipMemcpyDeviceToHost)); int buffer_size = 0; CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2gebsr_bufferSize(handle, dir, mb, nb, nnzb, descr_A, dbsr_val_A, dbsr_row_ptr_A, dbsr_col_ind_A, row_block_dim_A, col_block_dim_A, row_block_dim_C, col_block_dim_C, &buffer_size)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * buffer_size), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); // Obtain BSR nnzb first on the host and then using the device and ensure they give the same results CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); int hnnzb_C; CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, nnzb, descr_A, dbsr_row_ptr_A, dbsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, dbsr_row_ptr_C, row_block_dim_C, col_block_dim_C, &hnnzb_C, dbuffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); auto dnnzb_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dnnzb_C = (int*)dnnzb_C_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, nnzb, descr_A, dbsr_row_ptr_A, dbsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, dbsr_row_ptr_C, row_block_dim_C, col_block_dim_C, dnnzb_C, dbuffer)); int hnnzb_C_copied_from_device; CHECK_HIP_ERROR( hipMemcpy(&hnnzb_C_copied_from_device, dnnzb_C, sizeof(int), hipMemcpyDeviceToHost)); if(argus.unit_check) { // Check that using host and device pointer mode gives the same result unit_check_general(1, 1, 1, &hnnzb_C_copied_from_device, &hnnzb_C); } // Allocate memory on the device auto dbsr_col_ind_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * hnnzb_C), device_free}; auto dbsr_val_C_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * hnnzb_C * row_block_dim_C * col_block_dim_C), device_free}; int* dbsr_col_ind_C = (int*)dbsr_col_ind_C_managed.get(); T* dbsr_val_C = (T*)dbsr_val_C_managed.get(); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, dbsr_val_A, dbsr_row_ptr_A, dbsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, dbsr_val_C, dbsr_row_ptr_C, dbsr_col_ind_C, row_block_dim_C, col_block_dim_C, dbuffer)); // Copy output from device to host std::vector hbsr_row_ptr_C(mb_C + 1); std::vector hbsr_col_ind_C(hnnzb_C); std::vector hbsr_val_C(hnnzb_C * row_block_dim_C * col_block_dim_C); CHECK_HIP_ERROR(hipMemcpy(hbsr_row_ptr_C.data(), dbsr_row_ptr_C, sizeof(int) * (mb_C + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hbsr_col_ind_C.data(), dbsr_col_ind_C, sizeof(int) * hnnzb_C, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsr_val_C.data(), dbsr_val_C, sizeof(T) * hnnzb_C * row_block_dim_C * col_block_dim_C, hipMemcpyDeviceToHost)); // Host csr2bsr conversion std::vector hbsr_row_ptr_C_gold; std::vector hbsr_col_ind_C_gold; std::vector hbsr_val_C_gold; // call host gebsr2gebsr here host_gebsr_to_gebsr(dir, mb, nb, nnzb, hbsr_val_A, hbsr_row_ptr_A, hbsr_col_ind_A, row_block_dim_A, col_block_dim_A, idx_base_A, hbsr_val_C_gold, hbsr_row_ptr_C_gold, hbsr_col_ind_C_gold, row_block_dim_C, col_block_dim_C, idx_base_C); int nnzb_C_gold = hbsr_row_ptr_C_gold[mb_C] - hbsr_row_ptr_C_gold[0]; // Unit check unit_check_general(1, 1, 1, &nnzb_C_gold, &hnnzb_C); unit_check_general(1, mb_C + 1, 1, hbsr_row_ptr_C_gold.data(), hbsr_row_ptr_C.data()); unit_check_general(1, hnnzb_C, 1, hbsr_col_ind_C_gold.data(), hbsr_col_ind_C.data()); unit_check_general(1, hnnzb_C * row_block_dim_C * col_block_dim_C, 1, hbsr_val_C_gold.data(), hbsr_val_C.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, dbsr_val_A, dbsr_row_ptr_A, dbsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, dbsr_val_C, dbsr_row_ptr_C, dbsr_col_ind_C, row_block_dim_C, col_block_dim_C, dbuffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, dbsr_val_A, dbsr_row_ptr_A, dbsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, dbsr_val_C, dbsr_row_ptr_C, dbsr_col_ind_C, row_block_dim_C, col_block_dim_C, dbuffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = gebsr2gebsr_gbyte_count(mb, mb_C, row_block_dim_A, col_block_dim_A, row_block_dim_C, col_block_dim_C, nnzb, hnnzb_C); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::MbA, mb, display_key_t::NbA, nb, display_key_t::MbC, mb_C, display_key_t::NbC, nb_C, display_key_t::row_block_dimA, row_block_dim_A, display_key_t::col_block_dimA, col_block_dim_A, display_key_t::row_block_dimC, row_block_dim_C, display_key_t::col_block_dimC, col_block_dim_C, display_key_t::nnzbA, nnzb, display_key_t::nnzbC, hnnzb_C, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GEBSR2GEBSR_HPP ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5683992 hipsparse/clients/include/testing_gemmi.hpp0000664000175100017510000006525415206065364021457 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_GEMMI_HPP #define TESTING_GEMMI_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_gemmi_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int safe_size = 100; T alpha = make_DataType(0.6); T beta = make_DataType(0.2); std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dA_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dC_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* dptr = (int*)dptr_managed.get(); int* drow = (int*)drow_managed.get(); T* dval = (T*)dval_managed.get(); T* dA = (T*)dA_managed.get(); T* dC = (T*)dC_managed.get(); verify_hipsparse_status_invalid_handle(hipsparseXgemmi(nullptr, safe_size, safe_size, safe_size, safe_size, &alpha, dA, safe_size, dval, dptr, drow, &beta, dC, safe_size)); verify_hipsparse_status_invalid_pointer(hipsparseXgemmi(handle, safe_size, safe_size, safe_size, safe_size, nullptr, dA, safe_size, dval, dptr, drow, &beta, dC, safe_size), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgemmi(handle, safe_size, safe_size, safe_size, safe_size, &alpha, nullptr, safe_size, dval, dptr, drow, &beta, dC, safe_size), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgemmi(handle, safe_size, safe_size, safe_size, safe_size, &alpha, dA, safe_size, nullptr, dptr, drow, &beta, dC, safe_size), "Error: cscValB is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgemmi(handle, safe_size, safe_size, safe_size, safe_size, &alpha, dA, safe_size, dval, nullptr, drow, &beta, dC, safe_size), "Error: cscColPtrB is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgemmi(handle, safe_size, safe_size, safe_size, safe_size, &alpha, dA, safe_size, dval, dptr, nullptr, &beta, dC, safe_size), "Error: cscRowIndB is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgemmi(handle, safe_size, safe_size, safe_size, safe_size, &alpha, dA, safe_size, dval, dptr, drow, nullptr, dC, safe_size), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgemmi(handle, safe_size, safe_size, safe_size, safe_size, &alpha, dA, safe_size, dval, dptr, drow, &beta, nullptr, safe_size), "Error: C is nullptr"); verify_hipsparse_status_invalid_size(hipsparseXgemmi(handle, -1, safe_size, safe_size, safe_size, &alpha, dA, safe_size, dval, dptr, drow, &beta, dC, safe_size), "Error: m is invalid"); verify_hipsparse_status_invalid_size(hipsparseXgemmi(handle, safe_size, -1, safe_size, safe_size, &alpha, dA, safe_size, dval, dptr, drow, &beta, dC, safe_size), "Error: n is invalid"); verify_hipsparse_status_invalid_size(hipsparseXgemmi(handle, safe_size, safe_size, -1, safe_size, &alpha, dA, safe_size, dval, dptr, drow, &beta, dC, safe_size), "Error: k is invalid"); verify_hipsparse_status_invalid_size(hipsparseXgemmi(handle, safe_size, safe_size, safe_size, -1, &alpha, dA, safe_size, dval, dptr, drow, &beta, dC, safe_size), "Error: nnz is invalid"); verify_hipsparse_status_invalid_size(hipsparseXgemmi(handle, safe_size, safe_size, safe_size, safe_size, &alpha, dA, -1, dval, dptr, drow, &beta, dC, safe_size), "Error: lda is invalid"); verify_hipsparse_status_invalid_size(hipsparseXgemmi(handle, safe_size, safe_size, safe_size, safe_size, &alpha, dA, safe_size, dval, dptr, drow, &beta, dC, -1), "Error: ldc is invalid"); #endif } template hipsparseStatus_t testing_gemmi(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int M = argus.M; int N = argus.N; int K = argus.K; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; if(M == 0 || N == 0 || K == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcsc_col_ptrB; std::vector hcsc_row_indB; std::vector hcsc_valB; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix( filename, N, K, nnz, hcsc_col_ptrB, hcsc_row_indB, hcsc_valB, HIPSPARSE_INDEX_BASE_ZERO)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } int lda = std::max(1, M); int ldc = std::max(1, M); int Annz = lda * K; int Cnnz = ldc * N; // Host structures - Dense matrix B and C std::vector hA(Annz); std::vector hC_1(Cnnz); std::vector hC_2(Cnnz); std::vector hC_gold(Cnnz); hipsparseInit(hA, M, K); hipsparseInit(hC_gold, M, N); // allocate memory on device auto dcsc_col_ptrB_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (N + 1)), device_free}; auto dcsc_row_indB_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsc_valB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dA_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * Annz), device_free}; auto dC_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * Cnnz), device_free}; auto dC_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * Cnnz), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dcsc_col_ptrB = (int*)dcsc_col_ptrB_managed.get(); int* dcsc_row_indB = (int*)dcsc_row_indB_managed.get(); T* dcsc_valB = (T*)dcsc_valB_managed.get(); T* dA = (T*)dA_managed.get(); T* dC_1 = (T*)dC_1_managed.get(); T* dC_2 = (T*)dC_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy( dcsc_col_ptrB, hcsc_col_ptrB.data(), sizeof(int) * (N + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsc_row_indB, hcsc_row_indB.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsc_valB, hcsc_valB.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dA, hA.data(), sizeof(T) * Annz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_1, hC_gold.data(), sizeof(T) * Cnnz, hipMemcpyHostToDevice)); if(argus.unit_check) { CHECK_HIP_ERROR(hipMemcpy(dC_2, dC_1, sizeof(T) * Cnnz, hipMemcpyDeviceToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXgemmi(handle, M, N, K, nnz, &h_alpha, dA, lda, dcsc_valB, dcsc_col_ptrB, dcsc_row_indB, &h_beta, dC_1, ldc)); // pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXgemmi(handle, M, N, K, nnz, d_alpha, dA, lda, dcsc_valB, dcsc_col_ptrB, dcsc_row_indB, d_beta, dC_2, ldc)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hC_1.data(), dC_1, sizeof(T) * Cnnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hC_2.data(), dC_2, sizeof(T) * Cnnz, hipMemcpyDeviceToHost)); // CPU for(int i = 0; i < M; ++i) { for(int j = 0; j < N; ++j) { T sum = make_DataType(0); int col_begin = hcsc_col_ptrB[j]; int col_end = hcsc_col_ptrB[j + 1]; for(int k = col_begin; k < col_end; ++k) { int row_B = hcsc_row_indB[k]; T val_B = hcsc_valB[k]; T val_A = hA[row_B * lda + i]; sum = testing_fma(val_A, val_B, sum); } hC_gold[j * ldc + i] = testing_fma(h_beta, hC_gold[j * ldc + i], testing_mult(h_alpha, sum)); } } unit_check_near(M, N, ldc, hC_gold.data(), hC_1.data()); unit_check_near(M, N, ldc, hC_gold.data(), hC_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgemmi(handle, M, N, K, nnz, &h_alpha, dA, lda, dcsc_valB, dcsc_col_ptrB, dcsc_row_indB, &h_beta, dC_1, ldc)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgemmi(handle, M, N, K, nnz, &h_alpha, dA, lda, dcsc_valB, dcsc_col_ptrB, dcsc_row_indB, &h_beta, dC_1, ldc)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = gemmi_gflop_count(M, nnz, M * N, h_beta != make_DataType(0.0)); double gbyte_count = gemmi_gbyte_count(N, nnz, M * K, M * N, h_beta != make_DataType(0.0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, M, display_key_t::N, N, display_key_t::K, K, display_key_t::nnzA, M * K, display_key_t::nnzB, nnz, display_key_t::nnzC, M * N, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GEMMI_HPP ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5683992 hipsparse/clients/include/testing_gemvi.hpp0000664000175100017510000003463615206065364021470 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_GEMVI_HPP #define TESTING_GEMVI_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include using namespace hipsparse; using namespace hipsparse_test; template void testing_gemvi_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int m = 100; int n = 100; int nnz = 100; int lda = 100; static constexpr hipsparseOperation_t opType = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; T alpha = make_DataType(0.6); T beta = make_DataType(0.1); std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * n), device_free}; auto x_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto xInd_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto y_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; T* A = (T*)A_managed.get(); T* x = (T*)x_managed.get(); int* xInd = (int*)xInd_managed.get(); T* y = (T*)y_managed.get(); // gemvi void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, 100)); verify_hipsparse_status_invalid_handle(hipsparseXgemvi( nullptr, opType, m, n, &alpha, A, lda, nnz, x, xInd, &beta, y, idxBase, buffer)); verify_hipsparse_status_invalid_pointer( hipsparseXgemvi( handle, opType, m, n, (T*)nullptr, A, lda, nnz, x, xInd, &beta, y, idxBase, buffer), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgemvi(handle, opType, m, n, &alpha, (T*)nullptr, lda, nnz, x, xInd, &beta, y, idxBase, buffer), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgemvi(handle, opType, m, n, &alpha, A, lda, nnz, (T*)nullptr, xInd, &beta, y, idxBase, buffer), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgemvi( handle, opType, m, n, &alpha, A, lda, nnz, x, nullptr, &beta, y, idxBase, buffer), "Error: xInd is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgemvi( handle, opType, m, n, &alpha, A, lda, nnz, x, xInd, (T*)nullptr, y, idxBase, buffer), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgemvi(handle, opType, m, n, &alpha, A, lda, nnz, x, xInd, &beta, (T*)nullptr, idxBase, buffer), "Error: y is nullptr"); verify_hipsparse_status_invalid_size( hipsparseXgemvi( handle, opType, -1, n, &alpha, A, lda, nnz, x, xInd, &beta, y, idxBase, buffer), "Error: m is invalid"); verify_hipsparse_status_invalid_size( hipsparseXgemvi( handle, opType, m, -1, &alpha, A, lda, nnz, x, xInd, &beta, y, idxBase, buffer), "Error: n is invalid"); verify_hipsparse_status_invalid_size( hipsparseXgemvi( handle, opType, m, n, &alpha, A, -1, nnz, x, xInd, &beta, y, idxBase, buffer), "Error: lda is invalid"); verify_hipsparse_status_invalid_size( hipsparseXgemvi( handle, opType, m, n, &alpha, A, lda, -1, x, xInd, &beta, y, idxBase, buffer), "Error: nnz is invalid"); verify_hipsparse_status_invalid_size( hipsparseXgemvi( handle, opType, m, n, &alpha, A, lda, n + 1, x, xInd, &beta, y, idxBase, buffer), "Error: nnz is invalid"); CHECK_HIP_ERROR(hipFree(buffer)); #endif } template hipsparseStatus_t testing_gemvi(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int m = argus.M; int n = argus.N; int nnz = argus.nnz; T alpha = make_DataType(argus.alpha); T beta = make_DataType(argus.beta); hipsparseOperation_t trans = argus.transA; hipsparseIndexBase_t idxBase = argus.baseA; std::string filename = argus.filename; int lda = m; // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hA(m * n); std::vector hx_val(nnz); std::vector hx_ind(nnz); std::vector hy(m); std::vector hy_gold(m); // Initial Data on CPU srand(12345ULL); hipsparseInitIndex(hx_ind.data(), nnz, 1, n); hipsparseInit(hx_val, 1, nnz); hipsparseInit(hy, 1, m); hy_gold = hy; for(int i = 0; i < m * n; ++i) { hA[i] = random_generator(); } // Allocate memory on device auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dA_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * n), device_free}; int* dx_ind = (int*)dx_ind_managed.get(); T* dx_val = (T*)dx_val_managed.get(); T* dy = (T*)dy_managed.get(); T* dA = (T*)dA_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dx_ind, hx_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx_val, hx_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy, hy.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dA, hA.data(), sizeof(T) * m * n, hipMemcpyHostToDevice)); // gemvi bufferSize int bufferSize; void* externalBuffer; CHECK_HIPSPARSE_ERROR(hipsparseXgemvi_bufferSize(handle, trans, m, n, nnz, &bufferSize)); CHECK_HIP_ERROR(hipMalloc(&externalBuffer, bufferSize)); if(argus.unit_check) { // gemvi CHECK_HIPSPARSE_ERROR(hipsparseXgemvi(handle, trans, m, n, &alpha, dA, lda, nnz, dx_val, dx_ind, &beta, dy, idxBase, externalBuffer)); // CPU for(int i = 0; i < m; ++i) { T sum = make_DataType(0); for(int j = 0; j < nnz; ++j) { sum = testing_fma(hx_val[j], hA[(hx_ind[j] - idxBase) * lda + i], sum); } hy_gold[i] = testing_fma(alpha, sum, testing_mult(beta, hy_gold[i])); } // Verify results against host CHECK_HIP_ERROR(hipMemcpy(hy.data(), dy, sizeof(T) * m, hipMemcpyDeviceToHost)); unit_check_near(m, 1, 1, hy_gold.data(), hy.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgemvi(handle, trans, m, n, &alpha, dA, lda, nnz, dx_val, dx_ind, &beta, dy, idxBase, externalBuffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgemvi(handle, trans, m, n, &alpha, dA, lda, nnz, dx_val, dx_ind, &beta, dy, idxBase, externalBuffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = gemvi_gflop_count(m, nnz); double gbyte_count = gemvi_gbyte_count((trans == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : n, nnz, beta != make_DataType(0.0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::trans, hipsparse_operation2string(trans), display_key_t::alpha, alpha, display_key_t::beta, beta, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(externalBuffer)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GEMVI_HPP ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5683992 hipsparse/clients/include/testing_gpsv_interleaved_batch.hpp0000664000175100017510000002746215206065364025062 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5683992 hipsparse/clients/include/testing_gthr.hpp0000664000175100017510000001440115206065364021311 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_GTHR_HPP #define TESTING_GTHR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include using namespace hipsparse; using namespace hipsparse_test; template void testing_gthr_bad_arg(const Arguments& argus) { int nnz = 100; int safe_size = 100; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; T* dx_val = (T*)dx_val_managed.get(); int* dx_ind = (int*)dx_ind_managed.get(); T* dy = (T*)dy_managed.get(); #if(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_pointer( hipsparseXgthr(handle, nnz, dy, dx_val, (int*)nullptr, idx_base), "Error: x_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgthr(handle, nnz, dy, (T*)nullptr, dx_ind, idx_base), "Error: x_val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgthr(handle, nnz, (T*)nullptr, dx_val, dx_ind, idx_base), "Error: y is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXgthr((hipsparseHandle_t) nullptr, nnz, dy, dx_val, dx_ind, idx_base)); #endif } template hipsparseStatus_t testing_gthr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int N = argus.N; int nnz = argus.nnz; hipsparseIndexBase_t idx_base = argus.baseA; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hx_ind(nnz); std::vector hx_val(nnz); std::vector hx_val_gold(nnz); std::vector hy(N); // Initial Data on CPU srand(12345ULL); hipsparseInitIndex(hx_ind.data(), nnz, 1, N); hipsparseInit(hy, 1, N); // allocate memory on device auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * N), device_free}; int* dx_ind = (int*)dx_ind_managed.get(); T* dx_val = (T*)dx_val_managed.get(); T* dy = (T*)dy_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dx_ind, hx_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy, hy.data(), sizeof(T) * N, hipMemcpyHostToDevice)); if(argus.unit_check) { // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXgthr(handle, nnz, dy, dx_val, dx_ind, idx_base)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hx_val.data(), dx_val, sizeof(T) * nnz, hipMemcpyDeviceToHost)); // CPU for(int i = 0; i < nnz; ++i) { hx_val_gold[i] = hy[hx_ind[i] - idx_base]; } // enable unit check, notice unit check is not invasive, but norm check is, // unit check and norm check can not be interchanged their order unit_check_general(1, nnz, 1, hx_val_gold.data(), hx_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgthr(handle, nnz, dy, dx_val, dx_ind, idx_base)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgthr(handle, nnz, dy, dx_val, dx_ind, idx_base)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = gthr_gbyte_count(nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::nnz, nnz, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GTHR_HPP ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5683992 hipsparse/clients/include/testing_gthrz.hpp0000664000175100017510000001506215206065364021507 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_GTHRZ_HPP #define TESTING_GTHRZ_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include using namespace hipsparse; using namespace hipsparse_test; template void testing_gthrz_bad_arg(const Arguments& argus) { int nnz = 100; int safe_size = 100; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; T* dx_val = (T*)dx_val_managed.get(); int* dx_ind = (int*)dx_ind_managed.get(); T* dy = (T*)dy_managed.get(); #if(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_pointer( hipsparseXgthrz(handle, nnz, dy, dx_val, (int*)nullptr, idx_base), "Error: x_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgthrz(handle, nnz, dy, (T*)nullptr, dx_ind, idx_base), "Error: x_val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgthrz(handle, nnz, (T*)nullptr, dx_val, dx_ind, idx_base), "Error: y is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXgthrz((hipsparseHandle_t) nullptr, nnz, dy, dx_val, dx_ind, idx_base)); #endif } template hipsparseStatus_t testing_gthrz(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int N = argus.N; int nnz = argus.nnz; hipsparseIndexBase_t idx_base = argus.baseA; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hx_ind(nnz); std::vector hx_val(nnz); std::vector hx_val_gold(nnz); std::vector hy(N); std::vector hy_gold(N); // Initial Data on CPU srand(12345ULL); hipsparseInitIndex(hx_ind.data(), nnz, 1, N); hipsparseInit(hy, 1, N); hy_gold = hy; // allocate memory on device auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * N), device_free}; int* dx_ind = (int*)dx_ind_managed.get(); T* dx_val = (T*)dx_val_managed.get(); T* dy = (T*)dy_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dx_ind, hx_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy, hy.data(), sizeof(T) * N, hipMemcpyHostToDevice)); if(argus.unit_check) { // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXgthrz(handle, nnz, dy, dx_val, dx_ind, idx_base)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hx_val.data(), dx_val, sizeof(T) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy.data(), dy, sizeof(T) * N, hipMemcpyDeviceToHost)); // CPU for(int i = 0; i < nnz; ++i) { hx_val_gold[i] = hy_gold[hx_ind[i] - idx_base]; hy_gold[hx_ind[i] - idx_base] = make_DataType(0.0); } // enable unit check, notice unit check is not invasive, but norm check is, // unit check and norm check can not be interchanged their order unit_check_general(1, nnz, 1, hx_val_gold.data(), hx_val.data()); unit_check_general(1, N, 1, hy_gold.data(), hy.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgthrz(handle, nnz, dy, dx_val, dx_ind, idx_base)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgthrz(handle, nnz, dy, dx_val, dx_ind, idx_base)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = gthrz_gbyte_count(nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::nnz, nnz, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GTHRZ_HPP ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.569399 hipsparse/clients/include/testing_gtsv.hpp0000664000175100017510000002160015206065364021327 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.569399 hipsparse/clients/include/testing_gtsv2_nopivot.hpp0000664000175100017510000002170115206065364023171 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.569399 hipsparse/clients/include/testing_gtsv2_strided_batch.hpp0000664000175100017510000002500515206065364024273 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.569399 hipsparse/clients/include/testing_gtsv_interleaved_batch.hpp0000664000175100017510000002347515206065364025066 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.569399 hipsparse/clients/include/testing_hyb2csr.hpp0000664000175100017510000002225415206065364021726 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_HYB2CSR_HPP #define TESTING_HYB2CSR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_hyb2csr_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int safe_size = 100; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_hyb(new hyb_struct); hipsparseHybMat_t hyb = unique_ptr_hyb->hyb; testhyb* dhyb = (testhyb*)hyb; dhyb->m = safe_size; dhyb->n = safe_size; dhyb->ell_nnz = safe_size; dhyb->coo_nnz = safe_size; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* csr_col_ind = (int*)csr_col_ind_managed.get(); T* csr_val = (T*)csr_val_managed.get(); verify_hipsparse_status_invalid_pointer( hipsparseXhyb2csr(handle, descr, hyb, csr_val, (int*)nullptr, csr_col_ind), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXhyb2csr(handle, descr, hyb, csr_val, csr_row_ptr, (int*)nullptr), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXhyb2csr(handle, descr, hyb, (T*)nullptr, csr_row_ptr, csr_col_ind), "Error: csr_val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXhyb2csr( handle, (hipsparseMatDescr_t) nullptr, hyb, csr_val, csr_row_ptr, csr_col_ind), "Error: csr_val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXhyb2csr( handle, descr, (hipsparseHybMat_t) nullptr, csr_val, csr_row_ptr, csr_col_ind), "Error: csr_val is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXhyb2csr( (hipsparseHandle_t) nullptr, descr, hyb, csr_val, csr_row_ptr, csr_col_ind)); #endif } template hipsparseStatus_t testing_hyb2csr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) int m = argus.M; int n = argus.N; hipsparseIndexBase_t idx_base = argus.baseA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_hyb(new hyb_struct); hipsparseHybMat_t hyb = unique_ptr_hyb->hyb; CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); srand(12345ULL); // Host structures std::vector hcsr_row_ptr_gold; std::vector hcsr_col_ind_gold; std::vector hcsr_val_gold; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix( filename, m, n, nnz, hcsr_row_ptr_gold, hcsr_col_ind_gold, hcsr_val_gold, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Allocate memory on the device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); // Copy data from host to device CHECK_HIP_ERROR(hipMemcpy( dcsr_row_ptr, hcsr_row_ptr_gold.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy( dcsr_col_ind, hcsr_col_ind_gold.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_val, hcsr_val_gold.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); // Convert CSR to HYB CHECK_HIPSPARSE_ERROR(hipsparseXcsr2hyb(handle, m, n, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, hyb, 0, HIPSPARSE_HYB_PARTITION_AUTO)); // Set all CSR arrays to zero CHECK_HIP_ERROR(hipMemset(dcsr_row_ptr, 0, sizeof(int) * (m + 1))); CHECK_HIP_ERROR(hipMemset(dcsr_col_ind, 0, sizeof(int) * nnz)); CHECK_HIP_ERROR(hipMemset(dcsr_val, 0, sizeof(T) * nnz)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR( hipsparseXhyb2csr(handle, descr, hyb, dcsr_val, dcsr_row_ptr, dcsr_col_ind)); // Copy output from device to host std::vector hcsr_row_ptr(m + 1); std::vector hcsr_col_ind(nnz); std::vector hcsr_val(nnz); CHECK_HIP_ERROR(hipMemcpy( hcsr_row_ptr.data(), dcsr_row_ptr, sizeof(int) * (m + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_col_ind.data(), dcsr_col_ind, sizeof(int) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val.data(), dcsr_val, sizeof(T) * nnz, hipMemcpyDeviceToHost)); // Unit check unit_check_general(1, m + 1, 1, hcsr_row_ptr_gold.data(), hcsr_row_ptr.data()); unit_check_general(1, nnz, 1, hcsr_col_ind_gold.data(), hcsr_col_ind.data()); unit_check_general(1, nnz, 1, hcsr_val_gold.data(), hcsr_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXhyb2csr(handle, descr, hyb, dcsr_val, dcsr_row_ptr, dcsr_col_ind)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXhyb2csr(handle, descr, hyb, dcsr_val, dcsr_row_ptr, dcsr_col_ind)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; testhyb* dhyb = (testhyb*)hyb; double gbyte_count = hyb2csr_gbyte_count(m, nnz, dhyb->ell_nnz, dhyb->coo_nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_HYB2CSR_HPP ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.569399 hipsparse/clients/include/testing_hybmv.hpp0000664000175100017510000003411215206065364021473 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2019 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_HYBMV_HPP #define TESTING_HYBMV_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include using namespace hipsparse; using namespace hipsparse_test; #define ELL_IND_ROW(i, el, m, width) (el) * (m) + (i) #define ELL_IND_EL(i, el, m, width) (el) + (width) * (i) #define ELL_IND(i, el, m, width) ELL_IND_ROW(i, el, m, width) template void testing_hybmv_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int safe_size = 100; T alpha = make_DataType(0.6); T beta = make_DataType(0.2); hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_hyb(new hyb_struct); hipsparseHybMat_t hyb = unique_ptr_hyb->hyb; testhyb* dhyb = (testhyb*)hyb; dhyb->m = safe_size; dhyb->n = safe_size; dhyb->ell_nnz = safe_size; dhyb->coo_nnz = safe_size; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; T* dx = (T*)dx_managed.get(); T* dy = (T*)dy_managed.get(); verify_hipsparse_status_invalid_pointer( hipsparseXhybmv(handle, transA, &alpha, descr, hyb, (T*)nullptr, &beta, dy), "Error: dx is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXhybmv(handle, transA, &alpha, descr, hyb, dx, &beta, (T*)nullptr), "Error: dy is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXhybmv(handle, transA, (T*)nullptr, descr, hyb, dx, &beta, dy), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXhybmv(handle, transA, &alpha, descr, hyb, dx, (T*)nullptr, dy), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXhybmv(handle, transA, &alpha, descr, (hipsparseHybMat_t) nullptr, dx, &beta, dy), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXhybmv(handle, transA, &alpha, (hipsparseMatDescr_t) nullptr, hyb, dx, &beta, dy), "Error: descr is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXhybmv((hipsparseHandle_t) nullptr, transA, &alpha, descr, hyb, dx, &beta, dy)); #endif } template hipsparseStatus_t testing_hybmv(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) int m = argus.M; int n = argus.N; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseHybPartition_t part = argus.part; int user_ell_width = argus.ell_width; std::string filename = argus.filename; T zero = make_DataType(0.0); T one = make_DataType(1.0); std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); std::unique_ptr unique_ptr_hyb(new hyb_struct); hipsparseHybMat_t hyb = unique_ptr_hyb->hyb; srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcol_ind; std::vector hval; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcol_ind, hval, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hx(n); std::vector hy_1(m); std::vector hy_2(m); std::vector hy_gold(m); hipsparseInit(hx, 1, n); hipsparseInit(hy_1, 1, m); // copy vector is easy in STL; hy_gold = hx: save a copy in hy_gold which will be output of CPU hy_2 = hy_1; hy_gold = hy_1; // allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * n), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dx = (T*)dx_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcol_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hval.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx, hx.data(), sizeof(T) * n, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_1, hy_1.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // ELL width limit int width_limit = (m > 0) ? ((2 * nnz - 1) / m + 1) : 0; // Limit ELL user width if(part == HIPSPARSE_HYB_PARTITION_USER) { user_ell_width = (m > 0) ? (user_ell_width * nnz / m) : 0; user_ell_width = std::min(width_limit, user_ell_width); } // Convert CSR to HYB hipsparseStatus_t status = hipsparseXcsr2hyb(handle, m, n, descr, dval, dptr, dcol, hyb, user_ell_width, part); if(part == HIPSPARSE_HYB_PARTITION_MAX) { // Compute max ELL width int ell_max_width = 0; for(int i = 0; i < m; ++i) { ell_max_width = std::max(hcsr_row_ptr[i + 1] - hcsr_row_ptr[i], ell_max_width); } if(ell_max_width > width_limit) { verify_hipsparse_status_invalid_value(status, "ell_max_width > width_limit"); return HIPSPARSE_STATUS_SUCCESS; } } if(argus.unit_check) { // Copy HYB structure to CPU testhyb* dhyb = (testhyb*)hyb; int ell_nnz = dhyb->ell_nnz; int coo_nnz = dhyb->coo_nnz; std::vector hell_col(ell_nnz); std::vector hell_val(ell_nnz); std::vector hcoo_row(coo_nnz); std::vector hcoo_col(coo_nnz); std::vector hcoo_val(coo_nnz); if(ell_nnz > 0) { CHECK_HIP_ERROR(hipMemcpy( hell_col.data(), dhyb->ell_col_ind, sizeof(int) * ell_nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hell_val.data(), dhyb->ell_val, sizeof(T) * ell_nnz, hipMemcpyDeviceToHost)); } if(coo_nnz > 0) { CHECK_HIP_ERROR(hipMemcpy( hcoo_row.data(), dhyb->coo_row_ind, sizeof(int) * coo_nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcoo_col.data(), dhyb->coo_col_ind, sizeof(int) * coo_nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcoo_val.data(), dhyb->coo_val, sizeof(T) * coo_nnz, hipMemcpyDeviceToHost)); } CHECK_HIP_ERROR(hipMemcpy(dy_2, hy_2.data(), sizeof(T) * m, hipMemcpyHostToDevice)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseXhybmv(handle, transA, &h_alpha, descr, hyb, dx, &h_beta, dy_1)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseXhybmv(handle, transA, d_alpha, descr, hyb, dx, d_beta, dy_2)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hy_1.data(), dy_1, sizeof(T) * m, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_2.data(), dy_2, sizeof(T) * m, hipMemcpyDeviceToHost)); // CPU // ELL part if(ell_nnz > 0) { for(int i = 0; i < m; ++i) { T sum = zero; for(int p = 0; p < dhyb->ell_width; ++p) { int idx = ELL_IND(i, p, m, dhyb->ell_width); int col = hell_col[idx] - idx_base; if(col >= 0 && col < n) { sum = sum + testing_mult(hell_val[idx], hx[col]); } else { break; } } if(h_beta != zero) { hy_gold[i] = testing_mult(h_beta, hy_gold[i]) + testing_mult(h_alpha, sum); } else { hy_gold[i] = testing_mult(h_alpha, sum); } } } // COO part if(coo_nnz >= 0) { T coo_beta = (ell_nnz > 0) ? one : h_beta; for(int i = 0; i < m; ++i) { hy_gold[i] = testing_mult(hy_gold[i], coo_beta); } for(int i = 0; i < coo_nnz; ++i) { int row = hcoo_row[i] - idx_base; int col = hcoo_col[i] - idx_base; hy_gold[row] = hy_gold[row] + testing_mult(h_alpha, testing_mult(hcoo_val[i], hx[col])); } } unit_check_near(1, m, 1, hy_gold.data(), hy_1.data()); unit_check_near(1, m, 1, hy_gold.data(), hy_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXhybmv(handle, transA, &h_alpha, descr, hyb, dx, &h_beta, dy_1)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXhybmv(handle, transA, &h_alpha, descr, hyb, dx, &h_beta, dy_1)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = spmv_gflop_count(m, nnz, h_beta != make_DataType(0.0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::partition, hipsparse_partition2string(part), display_key_t::ell_width, user_ell_width, display_key_t::gflops, gpu_gflops, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_HYBMV_HPP ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.569399 hipsparse/clients/include/testing_identity.hpp0000664000175100017510000001051515206065364022200 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779985139.569399 hipsparse/clients/include/testing_nnz.hpp0000664000175100017510000003210315206065364021151 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5703993 hipsparse/clients/include/testing_prune_csr2csr.hpp0000664000175100017510000011165515206065364023150 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_PRUNE_CSR2CSR_HPP #define TESTING_PRUNE_CSR2CSR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_prune_csr2csr_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) size_t safe_size = 1; int M = 1; int N = 1; int nnz_A = 1; T threshold = static_cast(1); int nnz_total_dev_host_ptr = 1; size_t buffer_size = 1; hipsparseStatus_t status; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = unique_ptr_descr_A->descr; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; auto csr_row_ptr_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto csr_col_ind_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto csr_row_ptr_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto csr_col_ind_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto temp_buffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* csr_row_ptr_A = (int*)csr_row_ptr_A_managed.get(); int* csr_col_ind_A = (int*)csr_col_ind_A_managed.get(); T* csr_val_A = (T*)csr_val_A_managed.get(); int* csr_row_ptr_C = (int*)csr_row_ptr_C_managed.get(); int* csr_col_ind_C = (int*)csr_col_ind_C_managed.get(); T* csr_val_C = (T*)csr_val_C_managed.get(); T* temp_buffer = (T*)temp_buffer_managed.get(); int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(csr_row_ptr_C, local_ptr, sizeof(int) * (safe_size + 1), hipMemcpyHostToDevice)); // Test hipsparseXpruneCsr2csr_bufferSize status = hipsparseXpruneCsr2csr_bufferSize(nullptr, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, &buffer_size); verify_hipsparse_status_invalid_handle(status); status = hipsparseXpruneCsr2csr_bufferSize(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer size is nullptr"); // Test hipsparseXpruneCsr2csrNnz status = hipsparseXpruneCsr2csrNnz(nullptr, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_handle(status); status = hipsparseXpruneCsr2csrNnz(handle, -1, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: M is invalid"); status = hipsparseXpruneCsr2csrNnz(handle, M, -1, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: N is invalid"); status = hipsparseXpruneCsr2csrNnz(handle, M, N, -1, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: nnz_A is invalid"); status = hipsparseXpruneCsr2csrNnz(handle, M, N, nnz_A, nullptr, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_A is nullptr"); status = hipsparseXpruneCsr2csrNnz(handle, M, N, nnz_A, descr_A, (const T*)nullptr, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_val_A is nullptr"); status = hipsparseXpruneCsr2csrNnz(handle, M, N, nnz_A, descr_A, csr_val_A, nullptr, csr_col_ind_A, &threshold, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr_A is nullptr"); status = hipsparseXpruneCsr2csrNnz(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, nullptr, &threshold, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind is nullptr"); status = hipsparseXpruneCsr2csrNnz(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, (const T*)nullptr, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: threshold is nullptr"); status = hipsparseXpruneCsr2csrNnz(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, nullptr, csr_row_ptr_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_C is nullptr"); status = hipsparseXpruneCsr2csrNnz(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, nullptr, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr_C is nullptr"); status = hipsparseXpruneCsr2csrNnz(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_row_ptr_C, nullptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: nnz_total_dev_host_ptr is nullptr"); // Test hipsparseXpruneCsr2csr status = hipsparseXpruneCsr2csr(nullptr, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, temp_buffer); verify_hipsparse_status_invalid_handle(status); status = hipsparseXpruneCsr2csr(handle, -1, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: M is invalid"); status = hipsparseXpruneCsr2csr(handle, M, -1, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: N is invalid"); status = hipsparseXpruneCsr2csr(handle, M, N, -1, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: nnz_A is invalid"); status = hipsparseXpruneCsr2csr(handle, M, N, nnz_A, nullptr, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_A is nullptr"); status = hipsparseXpruneCsr2csr(handle, M, N, nnz_A, descr_A, (const T*)nullptr, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_val_A is nullptr"); status = hipsparseXpruneCsr2csr(handle, M, N, nnz_A, descr_A, csr_val_A, nullptr, csr_col_ind_A, &threshold, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr_A is nullptr"); status = hipsparseXpruneCsr2csr(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, nullptr, &threshold, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind_A is nullptr"); status = hipsparseXpruneCsr2csr(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, (const T*)nullptr, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: threshold is nullptr"); status = hipsparseXpruneCsr2csr(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, nullptr, csr_val_C, csr_row_ptr_C, csr_col_ind_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_C is nullptr"); status = hipsparseXpruneCsr2csr(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, (T*)nullptr, csr_row_ptr_C, csr_col_ind_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_val_C is nullptr"); status = hipsparseXpruneCsr2csr(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_val_C, nullptr, csr_col_ind_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr_C is nullptr"); status = hipsparseXpruneCsr2csr(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_val_C, csr_row_ptr_C, nullptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind_C is nullptr"); #endif } template hipsparseStatus_t testing_prune_csr2csr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) int M = argus.M; int N = argus.N; T threshold = make_DataType(argus.threshold); hipsparseIndexBase_t csr_idx_base_A = argus.baseA; hipsparseIndexBase_t csr_idx_base_C = argus.baseB; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = unique_ptr_descr_A->descr; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_A, csr_idx_base_A)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_C, csr_idx_base_C)); if(M == 0 || N == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector h_csr_row_ptr_A; std::vector h_csr_col_ind_A; std::vector h_csr_val_A; // Read or construct CSR matrix int nnz_A = 0; if(!generate_csr_matrix( filename, M, N, nnz_A, h_csr_row_ptr_A, h_csr_col_ind_A, h_csr_val_A, csr_idx_base_A)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Allocate device memory auto d_nnz_total_dev_host_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; auto d_csr_row_ptr_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; auto d_csr_row_ptr_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; auto d_csr_col_ind_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz_A), device_free}; auto d_csr_val_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_A), device_free}; int* d_nnz_total_dev_host_ptr = (int*)d_nnz_total_dev_host_ptr_managed.get(); int* d_csr_row_ptr_C = (int*)d_csr_row_ptr_C_managed.get(); int* d_csr_row_ptr_A = (int*)d_csr_row_ptr_A_managed.get(); int* d_csr_col_ind_A = (int*)d_csr_col_ind_A_managed.get(); T* d_csr_val_A = (T*)d_csr_val_A_managed.get(); // Transfer. CHECK_HIP_ERROR(hipMemcpy( d_csr_row_ptr_A, h_csr_row_ptr_A.data(), sizeof(int) * (M + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy( d_csr_col_ind_A, h_csr_col_ind_A.data(), sizeof(int) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(d_csr_val_A, h_csr_val_A.data(), sizeof(T) * nnz_A, hipMemcpyHostToDevice)); size_t buffer_size = 4; CHECK_HIPSPARSE_ERROR(hipsparseXpruneCsr2csr_bufferSize(handle, M, N, nnz_A, descr_A, d_csr_val_A, d_csr_row_ptr_A, d_csr_col_ind_A, &threshold, descr_C, (const T*)nullptr, d_csr_row_ptr_C, (const int*)nullptr, &buffer_size)); auto d_temp_buffer_managed = hipsparse_unique_ptr{device_malloc(buffer_size), device_free}; T* d_temp_buffer = (T*)d_temp_buffer_managed.get(); auto d_threshold_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; T* d_threshold = (T*)d_threshold_managed.get(); CHECK_HIP_ERROR(hipMemcpy(d_threshold, &threshold, sizeof(T), hipMemcpyHostToDevice)); std::vector h_nnz_total_dev_host_ptr(1); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXpruneCsr2csrNnz(handle, M, N, nnz_A, descr_A, d_csr_val_A, d_csr_row_ptr_A, d_csr_col_ind_A, &threshold, descr_C, d_csr_row_ptr_C, &h_nnz_total_dev_host_ptr[0], d_temp_buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXpruneCsr2csrNnz(handle, M, N, nnz_A, descr_A, d_csr_val_A, d_csr_row_ptr_A, d_csr_col_ind_A, d_threshold, descr_C, d_csr_row_ptr_C, d_nnz_total_dev_host_ptr, d_temp_buffer)); std::vector h_nnz_total_copied_from_device(1); CHECK_HIP_ERROR(hipMemcpy(h_nnz_total_copied_from_device.data(), d_nnz_total_dev_host_ptr, sizeof(int), hipMemcpyDeviceToHost)); if(argus.unit_check) { unit_check_general( 1, 1, 1, h_nnz_total_dev_host_ptr.data(), h_nnz_total_copied_from_device.data()); } auto d_csr_col_ind_C_managed = hipsparse_unique_ptr{ device_malloc(sizeof(int) * h_nnz_total_dev_host_ptr[0]), device_free}; auto d_csr_val_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * h_nnz_total_dev_host_ptr[0]), device_free}; int* d_csr_col_ind_C = (int*)d_csr_col_ind_C_managed.get(); T* d_csr_val_C = (T*)d_csr_val_C_managed.get(); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXpruneCsr2csr(handle, M, N, nnz_A, descr_A, d_csr_val_A, d_csr_row_ptr_A, d_csr_col_ind_A, &threshold, descr_C, d_csr_val_C, d_csr_row_ptr_C, d_csr_col_ind_C, d_temp_buffer)); std::vector h_csr_row_ptr_C(M + 1); std::vector h_csr_col_ind_C(h_nnz_total_dev_host_ptr[0]); std::vector h_csr_val_C(h_nnz_total_dev_host_ptr[0]); CHECK_HIP_ERROR(hipMemcpy( h_csr_row_ptr_C.data(), d_csr_row_ptr_C, sizeof(int) * (M + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(h_csr_col_ind_C.data(), d_csr_col_ind_C, sizeof(int) * h_nnz_total_dev_host_ptr[0], hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(h_csr_val_C.data(), d_csr_val_C, sizeof(T) * h_nnz_total_dev_host_ptr[0], hipMemcpyDeviceToHost)); // call host and check results std::vector h_nnz_C_cpu(1); std::vector h_csr_row_ptr_cpu; std::vector h_csr_col_ind_cpu; std::vector h_csr_val_cpu; host_prune_csr_to_csr(M, N, nnz_A, h_csr_row_ptr_A, h_csr_col_ind_A, h_csr_val_A, h_nnz_C_cpu[0], h_csr_row_ptr_cpu, h_csr_col_ind_cpu, h_csr_val_cpu, csr_idx_base_A, csr_idx_base_C, threshold); unit_check_general(1, 1, 1, h_nnz_C_cpu.data(), h_nnz_total_dev_host_ptr.data()); unit_check_general(1, (M + 1), 1, h_csr_row_ptr_cpu.data(), h_csr_row_ptr_C.data()); unit_check_general( 1, h_nnz_total_dev_host_ptr[0], 1, h_csr_col_ind_cpu.data(), h_csr_col_ind_C.data()); unit_check_general( 1, h_nnz_total_dev_host_ptr[0], 1, h_csr_val_cpu.data(), h_csr_val_C.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXpruneCsr2csr(handle, M, N, nnz_A, descr_A, d_csr_val_A, d_csr_row_ptr_A, d_csr_col_ind_A, &threshold, descr_C, d_csr_val_C, d_csr_row_ptr_C, d_csr_col_ind_C, d_temp_buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXpruneCsr2csr(handle, M, N, nnz_A, descr_A, d_csr_val_A, d_csr_row_ptr_A, d_csr_col_ind_A, &threshold, descr_C, d_csr_val_C, d_csr_row_ptr_C, d_csr_col_ind_C, d_temp_buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = prune_csr2csr_gbyte_count(M, nnz_A, h_nnz_total_dev_host_ptr[0]); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, M, display_key_t::N, N, display_key_t::nnzA, nnz_A, display_key_t::nnzC, h_nnz_total_dev_host_ptr[0], display_key_t::threshold, threshold, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_PRUNE_CSR2CSR_HPP ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5703993 hipsparse/clients/include/testing_prune_csr2csr_by_percentage.hpp0000664000175100017510000014017415206065364026035 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_PRUNE_CSR2CSR_BY_PERCENTAGE_HPP #define TESTING_PRUNE_CSR2CSR_BY_PERCENTAGE_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_prune_csr2csr_by_percentage_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) size_t safe_size = 1; int M = 1; int N = 1; int nnz_A = 1; T percentage = static_cast(0); int nnz_total_dev_host_ptr = 1; size_t buffer_size = 1; hipsparseStatus_t status; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = unique_ptr_descr_A->descr; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; std::unique_ptr unique_ptr_info(new prune_struct); pruneInfo_t info = unique_ptr_info->info; auto csr_row_ptr_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto csr_col_ind_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto csr_row_ptr_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto csr_col_ind_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto temp_buffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* csr_row_ptr_A = (int*)csr_row_ptr_A_managed.get(); int* csr_col_ind_A = (int*)csr_col_ind_A_managed.get(); T* csr_val_A = (T*)csr_val_A_managed.get(); int* csr_row_ptr_C = (int*)csr_row_ptr_C_managed.get(); int* csr_col_ind_C = (int*)csr_col_ind_C_managed.get(); T* csr_val_C = (T*)csr_val_C_managed.get(); T* temp_buffer = (T*)temp_buffer_managed.get(); int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(csr_row_ptr_C, local_ptr, sizeof(int) * (safe_size + 1), hipMemcpyHostToDevice)); // Test hipsparseXpruneCsr2csrByPercentage_bufferSize status = hipsparseXpruneCsr2csrByPercentage_bufferSize(nullptr, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, &buffer_size); verify_hipsparse_status_invalid_handle(status); status = hipsparseXpruneCsr2csrByPercentage_bufferSize(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer size is nullptr"); // Test hipsparseXpruneCsr2csrNnzByPercentage status = hipsparseXpruneCsr2csrNnzByPercentage(nullptr, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_handle(status); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, -1, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: M is invalid"); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, M, -1, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: N is invalid"); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, -1, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: nnz_A is invalid"); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, (T)-1, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: percentage is less than 0"); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, (T)101, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: percentage is greater than 100"); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, nnz_A, nullptr, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_A is nullptr"); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, nnz_A, descr_A, (const T*)nullptr, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_val_A is nullptr"); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, nullptr, csr_col_ind_A, percentage, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr_A is nullptr"); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, nullptr, percentage, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind is nullptr"); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, nullptr, csr_row_ptr_C, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_C is nullptr"); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, nullptr, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr_C is nullptr"); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_row_ptr_C, nullptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: nnz_total_dev_host_ptr is nullptr"); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, info, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer is nullptr"); // Test hipsparseXpruneCsr2csrByPercentage status = hipsparseXpruneCsr2csrByPercentage(nullptr, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_handle(status); status = hipsparseXpruneCsr2csrByPercentage(handle, -1, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: M is invalid"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, -1, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: N is invalid"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, -1, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: nnz_A is invalid"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, (T)-1, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: percentage is less than 0"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, (T)101, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: percentage is greater than 100"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, nullptr, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_A is nullptr"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, (const T*)nullptr, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_val_A is nullptr"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, nullptr, csr_col_ind_A, percentage, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr_A is nullptr"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, nullptr, percentage, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind_A is nullptr"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, nullptr, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_C is nullptr"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, (T*)nullptr, csr_row_ptr_C, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_val_C is nullptr"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_val_C, nullptr, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr_C is nullptr"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_val_C, csr_row_ptr_C, nullptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind_C is nullptr"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer is nullptr"); #endif } template hipsparseStatus_t testing_prune_csr2csr_by_percentage(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) int M = argus.M; int N = argus.N; T percentage = make_DataType(argus.percentage); hipsparseIndexBase_t csr_idx_base_A = argus.baseA; hipsparseIndexBase_t csr_idx_base_C = argus.baseB; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = unique_ptr_descr_A->descr; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; std::unique_ptr unique_ptr_info(new prune_struct); pruneInfo_t info = unique_ptr_info->info; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_A, csr_idx_base_A)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_C, csr_idx_base_C)); if(M == 0 || N == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector h_csr_row_ptr_A; std::vector h_csr_col_ind_A; std::vector h_csr_val_A; // Read or construct CSR matrix int nnz_A = 0; if(!generate_csr_matrix( filename, M, N, nnz_A, h_csr_row_ptr_A, h_csr_col_ind_A, h_csr_val_A, csr_idx_base_A)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Allocate device memory auto d_nnz_total_dev_host_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; auto d_csr_row_ptr_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; auto d_csr_row_ptr_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; auto d_csr_col_ind_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz_A), device_free}; auto d_csr_val_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_A), device_free}; int* d_nnz_total_dev_host_ptr = (int*)d_nnz_total_dev_host_ptr_managed.get(); int* d_csr_row_ptr_C = (int*)d_csr_row_ptr_C_managed.get(); int* d_csr_row_ptr_A = (int*)d_csr_row_ptr_A_managed.get(); int* d_csr_col_ind_A = (int*)d_csr_col_ind_A_managed.get(); T* d_csr_val_A = (T*)d_csr_val_A_managed.get(); // Transfer. CHECK_HIP_ERROR(hipMemcpy( d_csr_row_ptr_A, h_csr_row_ptr_A.data(), sizeof(int) * (M + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy( d_csr_col_ind_A, h_csr_col_ind_A.data(), sizeof(int) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(d_csr_val_A, h_csr_val_A.data(), sizeof(T) * nnz_A, hipMemcpyHostToDevice)); size_t buffer_size; CHECK_HIPSPARSE_ERROR(hipsparseXpruneCsr2csrByPercentage_bufferSize(handle, M, N, nnz_A, descr_A, d_csr_val_A, d_csr_row_ptr_A, d_csr_col_ind_A, percentage, descr_C, (const T*)nullptr, d_csr_row_ptr_C, (const int*)nullptr, info, &buffer_size)); auto d_temp_buffer_managed = hipsparse_unique_ptr{device_malloc(buffer_size), device_free}; T* d_temp_buffer = (T*)d_temp_buffer_managed.get(); std::vector h_nnz_total_dev_host_ptr(1); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, nnz_A, descr_A, d_csr_val_A, d_csr_row_ptr_A, d_csr_col_ind_A, percentage, descr_C, d_csr_row_ptr_C, &h_nnz_total_dev_host_ptr[0], info, d_temp_buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, nnz_A, descr_A, d_csr_val_A, d_csr_row_ptr_A, d_csr_col_ind_A, percentage, descr_C, d_csr_row_ptr_C, d_nnz_total_dev_host_ptr, info, d_temp_buffer)); std::vector h_nnz_total_copied_from_device(1); CHECK_HIP_ERROR(hipMemcpy(h_nnz_total_copied_from_device.data(), d_nnz_total_dev_host_ptr, sizeof(int), hipMemcpyDeviceToHost)); if(argus.unit_check) { unit_check_general( 1, 1, 1, h_nnz_total_dev_host_ptr.data(), h_nnz_total_copied_from_device.data()); } auto d_csr_col_ind_C_managed = hipsparse_unique_ptr{ device_malloc(sizeof(int) * h_nnz_total_dev_host_ptr[0]), device_free}; auto d_csr_val_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * h_nnz_total_dev_host_ptr[0]), device_free}; int* d_csr_col_ind_C = (int*)d_csr_col_ind_C_managed.get(); T* d_csr_val_C = (T*)d_csr_val_C_managed.get(); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, d_csr_val_A, d_csr_row_ptr_A, d_csr_col_ind_A, percentage, descr_C, d_csr_val_C, d_csr_row_ptr_C, d_csr_col_ind_C, info, d_temp_buffer)); std::vector h_csr_row_ptr_C(M + 1); std::vector h_csr_col_ind_C(h_nnz_total_dev_host_ptr[0]); std::vector h_csr_val_C(h_nnz_total_dev_host_ptr[0]); CHECK_HIP_ERROR(hipMemcpy( h_csr_row_ptr_C.data(), d_csr_row_ptr_C, sizeof(int) * (M + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(h_csr_col_ind_C.data(), d_csr_col_ind_C, sizeof(int) * h_nnz_total_dev_host_ptr[0], hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(h_csr_val_C.data(), d_csr_val_C, sizeof(T) * h_nnz_total_dev_host_ptr[0], hipMemcpyDeviceToHost)); // call host and check results std::vector h_nnz_C_cpu(1); std::vector h_csr_row_ptr_cpu; std::vector h_csr_col_ind_cpu; std::vector h_csr_val_cpu; host_prune_csr_to_csr_by_percentage(M, N, nnz_A, h_csr_row_ptr_A, h_csr_col_ind_A, h_csr_val_A, h_nnz_C_cpu[0], h_csr_row_ptr_cpu, h_csr_col_ind_cpu, h_csr_val_cpu, csr_idx_base_A, csr_idx_base_C, percentage); unit_check_general(1, 1, 1, h_nnz_C_cpu.data(), h_nnz_total_dev_host_ptr.data()); unit_check_general(1, (M + 1), 1, h_csr_row_ptr_cpu.data(), h_csr_row_ptr_C.data()); unit_check_general( 1, h_nnz_total_dev_host_ptr[0], 1, h_csr_col_ind_cpu.data(), h_csr_col_ind_C.data()); unit_check_general( 1, h_nnz_total_dev_host_ptr[0], 1, h_csr_val_cpu.data(), h_csr_val_C.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, d_csr_val_A, d_csr_row_ptr_A, d_csr_col_ind_A, percentage, descr_C, d_csr_val_C, d_csr_row_ptr_C, d_csr_col_ind_C, info, d_temp_buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, d_csr_val_A, d_csr_row_ptr_A, d_csr_col_ind_A, percentage, descr_C, d_csr_val_C, d_csr_row_ptr_C, d_csr_col_ind_C, info, d_temp_buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = prune_csr2csr_by_percentage_gbyte_count(M, nnz_A, h_nnz_total_dev_host_ptr[0]); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, M, display_key_t::N, N, display_key_t::nnzA, nnz_A, display_key_t::nnzC, h_nnz_total_dev_host_ptr[0], display_key_t::percentage, percentage, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_PRUNE_CSR2CSR_BY_PERCENTAGE_HPP ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5703993 hipsparse/clients/include/testing_prune_dense2csr.hpp0000664000175100017510000005410315206065364023451 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_PRUNE_DENSE2CSR_HPP #define TESTING_PRUNE_DENSE2CSR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_prune_dense2csr_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) size_t safe_size = 100; int M = 1; int N = 1; int LDA = M; T threshold = static_cast(1); int nnz_total_dev_host_ptr = 100; size_t buffer_size = 100; hipsparseStatus_t status; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto csr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto temp_buffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* csr_col_ind = (int*)csr_col_ind_managed.get(); T* csr_val = (T*)csr_val_managed.get(); T* A = (T*)A_managed.get(); T* temp_buffer = (T*)temp_buffer_managed.get(); int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(csr_row_ptr, local_ptr, sizeof(int) * (1 + 1), hipMemcpyHostToDevice)); // Test hipsparseXpruneDense2csr_bufferSize status = hipsparseXpruneDense2csr_bufferSize( nullptr, M, N, A, LDA, &threshold, descr, csr_val, csr_row_ptr, csr_col_ind, &buffer_size); verify_hipsparse_status_invalid_handle(status); status = hipsparseXpruneDense2csr_bufferSize( handle, M, N, A, LDA, &threshold, descr, csr_val, csr_row_ptr, csr_col_ind, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer size is nullptr"); // Test hipsparseXpruneDense2csrNnz status = hipsparseXpruneDense2csrNnz(nullptr, M, N, A, LDA, &threshold, descr, csr_row_ptr, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_handle(status); status = hipsparseXpruneDense2csrNnz(handle, -1, N, A, LDA, &threshold, descr, csr_row_ptr, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: M is invalid"); status = hipsparseXpruneDense2csrNnz(handle, M, -1, A, LDA, &threshold, descr, csr_row_ptr, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: N is invalid"); status = hipsparseXpruneDense2csrNnz( handle, M, N, A, -1, &threshold, descr, csr_row_ptr, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: LDA is invalid"); status = hipsparseXpruneDense2csrNnz(handle, M, N, (const T*)nullptr, LDA, &threshold, descr, csr_row_ptr, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: A is nullptr"); status = hipsparseXpruneDense2csrNnz(handle, M, N, A, LDA, (const T*)nullptr, descr, csr_row_ptr, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: threshold is nullptr"); status = hipsparseXpruneDense2csrNnz(handle, M, N, A, LDA, &threshold, nullptr, csr_row_ptr, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); status = hipsparseXpruneDense2csrNnz( handle, M, N, A, LDA, &threshold, descr, nullptr, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr is nullptr"); status = hipsparseXpruneDense2csrNnz( handle, M, N, A, LDA, &threshold, descr, csr_row_ptr, nullptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: nnz_total_dev_host_ptr is nullptr"); // Test hipsparseXpruneDense2csr status = hipsparseXpruneDense2csr( nullptr, M, N, A, LDA, &threshold, descr, csr_val, csr_row_ptr, csr_col_ind, temp_buffer); verify_hipsparse_status_invalid_handle(status); status = hipsparseXpruneDense2csr( handle, -1, N, A, LDA, &threshold, descr, csr_val, csr_row_ptr, csr_col_ind, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: M is invalid"); status = hipsparseXpruneDense2csr( handle, M, -1, A, LDA, &threshold, descr, csr_val, csr_row_ptr, csr_col_ind, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: N is invalid"); status = hipsparseXpruneDense2csr( handle, M, N, A, -1, &threshold, descr, csr_val, csr_row_ptr, csr_col_ind, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: LDA is invalid"); status = hipsparseXpruneDense2csr(handle, M, N, (const T*)nullptr, LDA, &threshold, descr, csr_val, csr_row_ptr, csr_col_ind, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: A is nullptr"); status = hipsparseXpruneDense2csr(handle, M, N, A, LDA, (const T*)nullptr, descr, csr_val, csr_row_ptr, csr_col_ind, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: threshold is nullptr"); status = hipsparseXpruneDense2csr( handle, M, N, A, LDA, &threshold, nullptr, csr_val, csr_row_ptr, csr_col_ind, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); status = hipsparseXpruneDense2csr(handle, M, N, A, LDA, &threshold, descr, (T*)nullptr, csr_row_ptr, csr_col_ind, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_val is nullptr"); status = hipsparseXpruneDense2csr( handle, M, N, A, LDA, &threshold, descr, csr_val, nullptr, csr_col_ind, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr is nullptr"); status = hipsparseXpruneDense2csr( handle, M, N, A, LDA, &threshold, descr, csr_val, csr_row_ptr, nullptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind is nullptr"); #endif } template hipsparseStatus_t testing_prune_dense2csr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) int M = argus.M; int N = argus.N; int LDA = argus.lda; T threshold = make_DataType(argus.threshold); hipsparseIndexBase_t idx_base = argus.baseA; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); if(M == 0 || N == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ return HIPSPARSE_STATUS_SUCCESS; #endif } // Allocate host memory std::vector h_A(LDA * N); std::vector h_nnz_total_dev_host_ptr(1); // Allocate device memory auto d_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * LDA * N), device_free}; auto d_nnz_total_dev_host_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; auto d_csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; T* d_A = (T*)d_A_managed.get(); int* d_nnz_total_dev_host_ptr = (int*)d_nnz_total_dev_host_ptr_managed.get(); int* d_csr_row_ptr = (int*)d_csr_row_ptr_managed.get(); // Initialize the entire allocated memory. for(int i = 0; i < LDA; ++i) { for(int j = 0; j < N; ++j) { h_A[j * LDA + i] = make_DataType(-1); } } // Initialize a random dense matrix. srand(0); gen_dense_random_sparsity_pattern(M, N, h_A.data(), LDA, HIPSPARSE_ORDER_COL, 0.2); // Transfer. CHECK_HIP_ERROR(hipMemcpy(d_A, h_A.data(), sizeof(T) * LDA * N, hipMemcpyHostToDevice)); size_t buffer_size = 512; CHECK_HIPSPARSE_ERROR(hipsparseXpruneDense2csr_bufferSize(handle, M, N, d_A, LDA, &threshold, descr, (const T*)nullptr, d_csr_row_ptr, (const int*)nullptr, &buffer_size)); auto d_temp_buffer_managed = hipsparse_unique_ptr{device_malloc(buffer_size), device_free}; T* d_temp_buffer = (T*)d_temp_buffer_managed.get(); auto d_threshold_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; T* d_threshold = (T*)d_threshold_managed.get(); CHECK_HIP_ERROR(hipMemcpy(d_threshold, &threshold, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXpruneDense2csrNnz(handle, M, N, d_A, LDA, &threshold, descr, d_csr_row_ptr, &h_nnz_total_dev_host_ptr[0], d_temp_buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXpruneDense2csrNnz(handle, M, N, d_A, LDA, d_threshold, descr, d_csr_row_ptr, d_nnz_total_dev_host_ptr, d_temp_buffer)); std::vector h_nnz_total_copied_from_device(1); CHECK_HIP_ERROR(hipMemcpy(h_nnz_total_copied_from_device.data(), d_nnz_total_dev_host_ptr, sizeof(int), hipMemcpyDeviceToHost)); if(argus.unit_check) { unit_check_general( 1, 1, 1, h_nnz_total_dev_host_ptr.data(), h_nnz_total_copied_from_device.data()); } auto d_csr_col_ind_managed = hipsparse_unique_ptr{ device_malloc(sizeof(int) * h_nnz_total_dev_host_ptr[0]), device_free}; auto d_csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * h_nnz_total_dev_host_ptr[0]), device_free}; int* d_csr_col_ind = (int*)d_csr_col_ind_managed.get(); T* d_csr_val = (T*)d_csr_val_managed.get(); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXpruneDense2csr(handle, M, N, d_A, LDA, &threshold, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, d_temp_buffer)); std::vector h_csr_row_ptr(M + 1); std::vector h_csr_col_ind(h_nnz_total_dev_host_ptr[0]); std::vector h_csr_val(h_nnz_total_dev_host_ptr[0]); CHECK_HIP_ERROR(hipMemcpy( h_csr_row_ptr.data(), d_csr_row_ptr, sizeof(int) * (M + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(h_csr_col_ind.data(), d_csr_col_ind, sizeof(int) * h_nnz_total_dev_host_ptr[0], hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(h_csr_val.data(), d_csr_val, sizeof(T) * h_nnz_total_dev_host_ptr[0], hipMemcpyDeviceToHost)); // call host and check results std::vector h_nnz_cpu(1); std::vector h_csr_row_ptr_cpu; std::vector h_csr_col_ind_cpu; std::vector h_csr_val_cpu; host_prune_dense2csr(M, N, h_A, LDA, idx_base, threshold, h_nnz_cpu[0], h_csr_val_cpu, h_csr_row_ptr_cpu, h_csr_col_ind_cpu); unit_check_general(1, 1, 1, h_nnz_cpu.data(), h_nnz_total_dev_host_ptr.data()); unit_check_general(1, (M + 1), 1, h_csr_row_ptr_cpu.data(), h_csr_row_ptr.data()); unit_check_general( 1, h_nnz_total_dev_host_ptr[0], 1, h_csr_col_ind_cpu.data(), h_csr_col_ind.data()); unit_check_general( 1, h_nnz_total_dev_host_ptr[0], 1, h_csr_val_cpu.data(), h_csr_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXpruneDense2csr(handle, M, N, d_A, LDA, &threshold, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, d_temp_buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXpruneDense2csr(handle, M, N, d_A, LDA, &threshold, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, d_temp_buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = prune_dense2csr_gbyte_count(M, N, h_nnz_total_dev_host_ptr[0]); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, M, display_key_t::N, N, display_key_t::LD, LDA, display_key_t::nnz, h_nnz_total_dev_host_ptr[0], display_key_t::threshold, threshold, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_PRUNE_DENSE2CSR_HPP ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5703993 hipsparse/clients/include/testing_prune_dense2csr_by_percentage.hpp0000664000175100017510000007704715206065364026354 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_PRUNE_DENSE2CSR_BY_PERCENTAGE_HPP #define TESTING_PRUNE_DENSE2CSR_BY_PERCENTAGE_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_prune_dense2csr_by_percentage_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) size_t safe_size = 1; int M = 1; int N = 1; int LDA = M; T percentage = static_cast(1); int nnz_total_dev_host_ptr = 1; size_t buffer_size = 1; hipsparseStatus_t status; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_info(new prune_struct); pruneInfo_t info = unique_ptr_info->info; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto csr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto temp_buffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* csr_col_ind = (int*)csr_col_ind_managed.get(); T* csr_val = (T*)csr_val_managed.get(); T* A = (T*)A_managed.get(); T* temp_buffer = (T*)temp_buffer_managed.get(); int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(csr_row_ptr, local_ptr, sizeof(int) * (1 + 1), hipMemcpyHostToDevice)); // Test hipsparseXpruneDense2csrByPercentage_bufferSize status = hipsparseXpruneDense2csrByPercentage_bufferSize(nullptr, M, N, A, LDA, percentage, descr, csr_val, csr_row_ptr, csr_col_ind, info, &buffer_size); verify_hipsparse_status_invalid_handle(status); status = hipsparseXpruneDense2csrByPercentage_bufferSize( handle, M, N, A, LDA, percentage, descr, csr_val, csr_row_ptr, csr_col_ind, info, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer size is nullptr"); // Test hipsparseXpruneDense2csrNnzByPercentage status = hipsparseXpruneDense2csrNnzByPercentage(nullptr, M, N, A, LDA, percentage, descr, csr_row_ptr, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_handle(status); status = hipsparseXpruneDense2csrNnzByPercentage(handle, -1, N, A, LDA, percentage, descr, csr_row_ptr, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: M is invalid"); status = hipsparseXpruneDense2csrNnzByPercentage(handle, M, -1, A, LDA, percentage, descr, csr_row_ptr, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: N is invalid"); status = hipsparseXpruneDense2csrNnzByPercentage(handle, M, N, A, -1, percentage, descr, csr_row_ptr, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: LDA is invalid"); status = hipsparseXpruneDense2csrNnzByPercentage(handle, M, N, A, LDA, (T)-1.0, descr, csr_row_ptr, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: percentage is less than 0"); status = hipsparseXpruneDense2csrNnzByPercentage(handle, M, N, A, LDA, (T)101.0, descr, csr_row_ptr, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: percentage is more than 100"); status = hipsparseXpruneDense2csrNnzByPercentage(handle, M, N, (const T*)nullptr, LDA, percentage, descr, csr_row_ptr, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: A is nullptr"); status = hipsparseXpruneDense2csrNnzByPercentage(handle, M, N, A, LDA, percentage, nullptr, csr_row_ptr, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); status = hipsparseXpruneDense2csrNnzByPercentage(handle, M, N, A, LDA, percentage, descr, nullptr, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr is nullptr"); status = hipsparseXpruneDense2csrNnzByPercentage( handle, M, N, A, LDA, percentage, descr, csr_row_ptr, nullptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: nnz_total_dev_host_ptr is nullptr"); status = hipsparseXpruneDense2csrNnzByPercentage(handle, M, N, A, LDA, percentage, descr, csr_row_ptr, &nnz_total_dev_host_ptr, info, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer size is nullptr"); // Test hipsparseXpruneDense2csrByPercentage status = hipsparseXpruneDense2csrByPercentage(nullptr, M, N, A, LDA, percentage, descr, csr_val, csr_row_ptr, csr_col_ind, info, temp_buffer); verify_hipsparse_status_invalid_handle(status); status = hipsparseXpruneDense2csrByPercentage(handle, -1, N, A, LDA, percentage, descr, csr_val, csr_row_ptr, csr_col_ind, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: M is invalid"); status = hipsparseXpruneDense2csrByPercentage(handle, M, -1, A, LDA, percentage, descr, csr_val, csr_row_ptr, csr_col_ind, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: N is invalid"); status = hipsparseXpruneDense2csrByPercentage(handle, M, N, A, -1, percentage, descr, csr_val, csr_row_ptr, csr_col_ind, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: LDA is invalid"); status = hipsparseXpruneDense2csrByPercentage( handle, M, N, A, LDA, (T)-1.0, descr, csr_val, csr_row_ptr, csr_col_ind, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: percentage is less than 0"); status = hipsparseXpruneDense2csrByPercentage(handle, M, N, A, LDA, (T)101.0, descr, csr_val, csr_row_ptr, csr_col_ind, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: percentage is more than 100"); status = hipsparseXpruneDense2csrByPercentage(handle, M, N, (const T*)nullptr, LDA, percentage, descr, csr_val, csr_row_ptr, csr_col_ind, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: A is nullptr"); status = hipsparseXpruneDense2csrByPercentage(handle, M, N, A, LDA, percentage, nullptr, csr_val, csr_row_ptr, csr_col_ind, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); status = hipsparseXpruneDense2csrByPercentage(handle, M, N, A, LDA, percentage, descr, (T*)nullptr, csr_row_ptr, csr_col_ind, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_val is nullptr"); status = hipsparseXpruneDense2csrByPercentage( handle, M, N, A, LDA, percentage, descr, csr_val, nullptr, csr_col_ind, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr is nullptr"); status = hipsparseXpruneDense2csrByPercentage( handle, M, N, A, LDA, percentage, descr, csr_val, csr_row_ptr, nullptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind is nullptr"); status = hipsparseXpruneDense2csrByPercentage( handle, M, N, A, LDA, percentage, descr, csr_val, csr_row_ptr, csr_col_ind, info, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer is nullptr"); #endif } template hipsparseStatus_t testing_prune_dense2csr_by_percentage(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) int M = argus.M; int N = argus.N; int LDA = argus.lda; T percentage = argus.get_percentage(); hipsparseIndexBase_t idx_base = argus.baseA; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_info(new prune_struct); pruneInfo_t info = unique_ptr_info->info; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); if(M == 0 || N == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ return HIPSPARSE_STATUS_SUCCESS; #endif } // Allocate host memory std::vector h_A(LDA * N); std::vector h_nnz_total_dev_host_ptr(1); // Allocate device memory auto d_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * LDA * N), device_free}; auto d_nnz_total_dev_host_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; auto d_csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; T* d_A = (T*)d_A_managed.get(); int* d_nnz_total_dev_host_ptr = (int*)d_nnz_total_dev_host_ptr_managed.get(); int* d_csr_row_ptr = (int*)d_csr_row_ptr_managed.get(); // Initialize the entire allocated memory. for(int i = 0; i < LDA; ++i) { for(int j = 0; j < N; ++j) { h_A[j * LDA + i] = make_DataType(-1); } } // Initialize a random dense matrix. srand(0); gen_dense_random_sparsity_pattern(M, N, h_A.data(), LDA, HIPSPARSE_ORDER_COL, 0.2); // Transfer. CHECK_HIP_ERROR(hipMemcpy(d_A, h_A.data(), sizeof(T) * LDA * N, hipMemcpyHostToDevice)); size_t buffer_size = 512; CHECK_HIPSPARSE_ERROR(hipsparseXpruneDense2csrByPercentage_bufferSize(handle, M, N, d_A, LDA, percentage, descr, (const T*)nullptr, d_csr_row_ptr, (const int*)nullptr, info, &buffer_size)); auto d_temp_buffer_managed = hipsparse_unique_ptr{device_malloc(buffer_size), device_free}; T* d_temp_buffer = (T*)d_temp_buffer_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXpruneDense2csrNnzByPercentage(handle, M, N, d_A, LDA, percentage, descr, d_csr_row_ptr, &h_nnz_total_dev_host_ptr[0], info, d_temp_buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXpruneDense2csrNnzByPercentage(handle, M, N, d_A, LDA, percentage, descr, d_csr_row_ptr, d_nnz_total_dev_host_ptr, info, d_temp_buffer)); std::vector h_nnz_total_copied_from_device(1); CHECK_HIP_ERROR(hipMemcpy(h_nnz_total_copied_from_device.data(), d_nnz_total_dev_host_ptr, sizeof(int), hipMemcpyDeviceToHost)); if(argus.unit_check) { unit_check_general( 1, 1, 1, h_nnz_total_dev_host_ptr.data(), h_nnz_total_copied_from_device.data()); } auto d_csr_col_ind_managed = hipsparse_unique_ptr{ device_malloc(sizeof(int) * h_nnz_total_dev_host_ptr[0]), device_free}; auto d_csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * h_nnz_total_dev_host_ptr[0]), device_free}; int* d_csr_col_ind = (int*)d_csr_col_ind_managed.get(); T* d_csr_val = (T*)d_csr_val_managed.get(); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXpruneDense2csrByPercentage(handle, M, N, d_A, LDA, percentage, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, info, d_temp_buffer)); std::vector h_csr_row_ptr(M + 1); std::vector h_csr_col_ind(h_nnz_total_dev_host_ptr[0]); std::vector h_csr_val(h_nnz_total_dev_host_ptr[0]); CHECK_HIP_ERROR(hipMemcpy( h_csr_row_ptr.data(), d_csr_row_ptr, sizeof(int) * (M + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(h_csr_col_ind.data(), d_csr_col_ind, sizeof(int) * h_nnz_total_dev_host_ptr[0], hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(h_csr_val.data(), d_csr_val, sizeof(T) * h_nnz_total_dev_host_ptr[0], hipMemcpyDeviceToHost)); // call host and check results std::vector h_nnz_cpu(1); std::vector h_csr_row_ptr_cpu; std::vector h_csr_col_ind_cpu; std::vector h_csr_val_cpu; host_prune_dense2csr_by_percentage(M, N, h_A, LDA, idx_base, percentage, h_nnz_cpu[0], h_csr_val_cpu, h_csr_row_ptr_cpu, h_csr_col_ind_cpu); unit_check_general(1, 1, 1, h_nnz_cpu.data(), h_nnz_total_dev_host_ptr.data()); unit_check_general(1, (M + 1), 1, h_csr_row_ptr_cpu.data(), h_csr_row_ptr.data()); unit_check_general( 1, h_nnz_total_dev_host_ptr[0], 1, h_csr_col_ind_cpu.data(), h_csr_col_ind.data()); unit_check_general( 1, h_nnz_total_dev_host_ptr[0], 1, h_csr_val_cpu.data(), h_csr_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXpruneDense2csrByPercentage(handle, M, N, d_A, LDA, percentage, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, info, d_temp_buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXpruneDense2csrByPercentage(handle, M, N, d_A, LDA, percentage, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, info, d_temp_buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = prune_dense2csr_by_percentage_gbyte_count(M, N, h_nnz_total_dev_host_ptr[0]); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, M, display_key_t::M, N, display_key_t::nnz, h_nnz_total_dev_host_ptr[0], display_key_t::percentage, percentage, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_PRUNE_DENSE2CSR_BY_PERCENTAGE_HPP ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5703993 hipsparse/clients/include/testing_rot.hpp0000664000175100017510000002437515206065364021164 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5703993 hipsparse/clients/include/testing_roti.hpp0000664000175100017510000002261615206065364021331 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_ROTI_HPP #define TESTING_ROTI_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include using namespace hipsparse; using namespace hipsparse_test; template void testing_roti_bad_arg(const Arguments& argus) { int nnz = 100; int safe_size = 100; T c = 3.7; T s = 1.2; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; T* dx_val = (T*)dx_val_managed.get(); int* dx_ind = (int*)dx_ind_managed.get(); T* dy = (T*)dy_managed.get(); verify_hipsparse_status_invalid_value( hipsparseXroti(handle, -1, dx_val, dx_ind, dy, &c, &s, idx_base), "Error: nnz is invalid"); // cusparse returns success when passed nullptrs #if(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_pointer( hipsparseXroti(handle, nnz, dx_val, (int*)nullptr, dy, &c, &s, idx_base), "Error: x_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXroti(handle, nnz, (T*)nullptr, dx_ind, dy, &c, &s, idx_base), "Error: x_val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXroti(handle, nnz, dx_val, dx_ind, (T*)nullptr, &c, &s, idx_base), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXroti(handle, nnz, dx_val, dx_ind, dy, (T*)nullptr, &s, idx_base), "Error: c is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXroti(handle, nnz, dx_val, dx_ind, dy, &c, (T*)nullptr, idx_base), "Error: s is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXroti(nullptr, nnz, dx_val, dx_ind, dy, &c, &s, idx_base)); #endif } template hipsparseStatus_t testing_roti(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int N = argus.N; int nnz = argus.nnz; T c = argus.get_alpha(); T s = argus.get_beta(); hipsparseIndexBase_t idx_base = argus.baseA; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hx_ind(nnz); std::vector hx_val_1(nnz); std::vector hx_val_2(nnz); std::vector hx_val_gold(nnz); std::vector hy_1(N); std::vector hy_2(N); std::vector hy_gold(N); // Initial Data on CPU srand(12345ULL); hipsparseInitIndex(hx_ind.data(), nnz, 1, N); hipsparseInit(hx_val_1, 1, nnz); hipsparseInit(hy_1, 1, N); hx_val_2 = hx_val_1; hx_val_gold = hx_val_1; hy_2 = hy_1; hy_gold = hy_1; // allocate memory on device auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dx_val_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dx_val_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * N), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * N), device_free}; auto dc_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto ds_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dx_ind = (int*)dx_ind_managed.get(); T* dx_val_1 = (T*)dx_val_1_managed.get(); T* dx_val_2 = (T*)dx_val_2_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* dc = (T*)dc_managed.get(); T* ds = (T*)ds_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dx_ind, hx_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx_val_1, hx_val_1.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_1, hy_1.data(), sizeof(T) * N, hipMemcpyHostToDevice)); if(argus.unit_check) { CHECK_HIP_ERROR( hipMemcpy(dx_val_2, hx_val_2.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_2, hy_2.data(), sizeof(T) * N, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dc, &c, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(ds, &s, sizeof(T), hipMemcpyHostToDevice)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseXroti(handle, nnz, dx_val_1, dx_ind, dy_1, &c, &s, idx_base)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseXroti(handle, nnz, dx_val_2, dx_ind, dy_2, dc, ds, idx_base)); // copy output from device to CPU CHECK_HIP_ERROR( hipMemcpy(hx_val_1.data(), dx_val_1, sizeof(T) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hx_val_2.data(), dx_val_2, sizeof(T) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_1.data(), dy_1, sizeof(T) * N, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_2.data(), dy_2, sizeof(T) * N, hipMemcpyDeviceToHost)); // CPU for(int i = 0; i < nnz; ++i) { int idx = hx_ind[i] - idx_base; T x = hx_val_gold[i]; T y = hy_gold[idx]; hx_val_gold[i] = c * x + s * y; hy_gold[idx] = c * y - s * x; } // enable unit check, notice unit check is not invasive, but norm check is, // unit check and norm check can not be interchanged their order unit_check_general(1, nnz, 1, hx_val_gold.data(), hx_val_1.data()); unit_check_general(1, nnz, 1, hx_val_gold.data(), hx_val_2.data()); unit_check_general(1, N, 1, hy_gold.data(), hy_1.data()); unit_check_general(1, N, 1, hy_gold.data(), hy_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXroti(handle, nnz, dx_val_1, dx_ind, dy_1, &c, &s, idx_base)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXroti(handle, nnz, dx_val_1, dx_ind, dy_1, &c, &s, idx_base)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = roti_gflop_count(nnz); double gbyte_count = roti_gbyte_count(nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); display_timing_info(display_key_t::nnz, nnz, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_ROTI_HPP ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5703993 hipsparse/clients/include/testing_scatter.hpp0000664000175100017510000001552715206065364022024 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5703993 hipsparse/clients/include/testing_sctr.hpp0000664000175100017510000001507515206065364021330 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SCTR_HPP #define TESTING_SCTR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include using namespace hipsparse; using namespace hipsparse_test; template void testing_sctr_bad_arg(const Arguments& argus) { int nnz = 100; int safe_size = 100; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; T* dx_val = (T*)dx_val_managed.get(); int* dx_ind = (int*)dx_ind_managed.get(); T* dy = (T*)dy_managed.get(); verify_hipsparse_status_invalid_value(hipsparseXsctr(handle, -1, dx_val, dx_ind, dy, idx_base), "Error: nnz is invalid"); // cusparse returns success for these #if(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_pointer( hipsparseXsctr(handle, nnz, dx_val, (int*)nullptr, dy, idx_base), "Error: x_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXsctr(handle, nnz, (T*)nullptr, dx_ind, dy, idx_base), "Error: x_val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXsctr(handle, nnz, dx_val, dx_ind, (T*)nullptr, idx_base), "Error: y is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXsctr(nullptr, nnz, dx_val, dx_ind, dy, idx_base)); #endif } template hipsparseStatus_t testing_sctr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int N = argus.N; int nnz = argus.nnz; hipsparseIndexBase_t idx_base = argus.baseA; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hx_ind(nnz); std::vector hx_val(nnz); std::vector hy(N); std::vector hy_gold(N); // Initial Data on CPU srand(12345ULL); hipsparseInitIndex(hx_ind.data(), nnz, 1, N); hipsparseInit(hx_val, 1, nnz); hipsparseInit(hy, 1, N); hy_gold = hy; // allocate memory on device auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * N), device_free}; int* dx_ind = (int*)dx_ind_managed.get(); T* dx_val = (T*)dx_val_managed.get(); T* dy = (T*)dy_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dx_ind, hx_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx_val, hx_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy, hy.data(), sizeof(T) * N, hipMemcpyHostToDevice)); if(argus.unit_check) { // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXsctr(handle, nnz, dx_val, dx_ind, dy, idx_base)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hy.data(), dy, sizeof(T) * N, hipMemcpyDeviceToHost)); // CPU for(int i = 0; i < nnz; ++i) { hy_gold[hx_ind[i] - idx_base] = hx_val[i]; } // enable unit check, notice unit check is not invasive, but norm check is, // unit check and norm check can not be interchanged their order unit_check_general(1, N, 1, hy_gold.data(), hy.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXsctr(handle, nnz, dx_val, dx_ind, dy, idx_base)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXsctr(handle, nnz, dx_val, dx_ind, dy, idx_base)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = sctr_gbyte_count(nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::nnz, nnz, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SCTR_HPP ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5703993 hipsparse/clients/include/testing_sddmm_coo.hpp0000664000175100017510000004754515206065364022330 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5703993 hipsparse/clients/include/testing_sddmm_coo_aos.hpp0000664000175100017510000004727515206065364023172 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5713992 hipsparse/clients/include/testing_sddmm_csc.hpp0000664000175100017510000005002615206065364022304 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5713992 hipsparse/clients/include/testing_sddmm_csr.hpp0000664000175100017510000004773515206065364022340 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5713992 hipsparse/clients/include/testing_sparse_to_dense_coo.hpp0000664000175100017510000002652415206065364024373 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5713992 hipsparse/clients/include/testing_sparse_to_dense_csc.hpp0000664000175100017510000003144215206065364024356 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5713992 hipsparse/clients/include/testing_sparse_to_dense_csr.hpp0000664000175100017510000002765015206065364024403 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5713992 hipsparse/clients/include/testing_spgemm_csr.hpp0000664000175100017510000011754615206065364022522 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5713992 hipsparse/clients/include/testing_spgemmreuse_csr.hpp0000664000175100017510000005715715206065364023567 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5713992 hipsparse/clients/include/testing_spmat_descr.hpp0000664000175100017510000017234315206065364022663 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5723991 hipsparse/clients/include/testing_spmm_batched_coo.hpp0000664000175100017510000005202415206065364023636 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5723991 hipsparse/clients/include/testing_spmm_batched_csc.hpp0000664000175100017510000005254715206065364023640 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5723991 hipsparse/clients/include/testing_spmm_batched_csr.hpp0000664000175100017510000005267615206065364023662 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5723991 hipsparse/clients/include/testing_spmm_bell.hpp0000664000175100017510000004343415206065364022327 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPMM_BELL_HPP #define TESTING_SPMM_BELL_HPP #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; void testing_spmm_bell_bad_arg(void) { #if(!defined(CUDART_VERSION)) int32_t n = 100; int32_t m = 100; int32_t k = 100; int32_t ell_blocksize = 2; int32_t ell_cols = 10; int32_t safe_size = 100; float alpha = 0.6; float beta = 0.2; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; hipsparseSpMMAlg_t alg = HIPSPARSE_SPMM_BLOCKED_ELL_ALG1; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dC_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int32_t* dind = (int32_t*)dind_managed.get(); float* dval = (float*)dval_managed.get(); float* dB = (float*)dB_managed.get(); float* dC = (float*)dC_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SpMM structures hipsparseSpMatDescr_t A; hipsparseDnMatDescr_t B, C; size_t bsize; // Create SpMM structures verify_hipsparse_status_success( hipsparseCreateBlockedEll( &A, m, k, ell_blocksize, ell_cols, dind, dval, idxType, idxBase, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&B, k, n, k, dB, dataType, order), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&C, m, n, m, dC, dataType, order), "success"); // SpMM buffer verify_hipsparse_status_invalid_handle(hipsparseSpMM_bufferSize( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, &bsize), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, &bsize), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, &bsize), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, &bsize), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, &bsize), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, nullptr), "Error: bsize is nullptr"); // SpMM_preprocess verify_hipsparse_status_invalid_handle(hipsparseSpMM_preprocess( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // SpMM verify_hipsparse_status_invalid_handle( hipsparseSpMM(nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(B), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(C), "success"); #endif } template hipsparseStatus_t testing_spmm_bell() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) std::vector hval = {make_DataType(1.0), make_DataType(2.0), make_DataType(3.0), make_DataType(4.0), make_DataType(5.0), make_DataType(6.0), make_DataType(7.0), make_DataType(8.0), make_DataType(9.0), make_DataType(10.0), make_DataType(11.0), make_DataType(12.0), make_DataType(13.0), make_DataType(14.0), make_DataType(15.0), make_DataType(16.0)}; std::vector hcol_ind = {1, 2, 1, 2, 1, 2, 3, 4, 1, 2, 3, 4, 5, 6, 5, 6}; std::vector hrow_ptr = {1, 3, 5, 9, 13, 15, 17}; std::vector hbell_val = {make_DataType(1.0), make_DataType(2.0), make_DataType(3.0), make_DataType(4.0), make_DataType(-7.0), make_DataType(-7.0), make_DataType(-7.0), make_DataType(-7.0), make_DataType(5.0), make_DataType(6.0), make_DataType(7.0), make_DataType(8.0), make_DataType(9.0), make_DataType(10.0), make_DataType(11.0), make_DataType(12.0), make_DataType(13.0), make_DataType(14.0), make_DataType(15.0), make_DataType(16.0), make_DataType(-7.0), make_DataType(-7.0), make_DataType(-7.0), make_DataType(-7.0)}; std::vector hbell_ind = {1, 0, 1, 2, 3, 0}; I ell_cols = 4; I ell_blocksize = 2; I m = 6; I k = 6; I nnz = 16; I n = 2; I ldb = k; I ldc = m; T h_alpha = make_DataType(2.0); T h_beta = make_DataType(1.0); hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ONE; hipsparseSpMMAlg_t alg = HIPSPARSE_SPMM_BLOCKED_ELL_ALG1; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::vector hB = {make_DataType(1.0), make_DataType(1.0), make_DataType(-1.0), make_DataType(2.0), make_DataType(1.0), make_DataType(3.0), make_DataType(-1.0), make_DataType(4.0), make_DataType(1.0), make_DataType(5.0), make_DataType(-1.0), make_DataType(6.0)}; std::vector hC_1 = {make_DataType(1.0), make_DataType(1.0), make_DataType(-1.0), make_DataType(2.0), make_DataType(1.0), make_DataType(3.0), make_DataType(-1.0), make_DataType(4.0), make_DataType(1.0), make_DataType(5.0), make_DataType(-1.0), make_DataType(6.0)}; std::vector hC_gold = {make_DataType(35.0), make_DataType(41.0), make_DataType(115.0), make_DataType(126.0), make_DataType(25.0), make_DataType(31.0), make_DataType(149.0), make_DataType(172.0), make_DataType(155.0), make_DataType(169.0), make_DataType(45.0), make_DataType(58.0)}; std::vector hC_2(hC_1); // allocate memory on device auto drow_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (m + 1)), device_free}; auto dcol_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dbell_ind_managed = hipsparse_unique_ptr{ device_malloc(sizeof(I) * (ell_cols / ell_blocksize) * (m / ell_blocksize)), device_free}; auto dbell_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * ell_cols * m), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * k * n), device_free}; auto dC_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * n), device_free}; auto dC_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * n), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* drow_ptr = (I*)drow_ptr_managed.get(); I* dcol_ind = (I*)dcol_ind_managed.get(); T* dval = (T*)dval_managed.get(); T* dB = (T*)dB_managed.get(); T* dC_1 = (T*)dC_1_managed.get(); T* dC_2 = (T*)dC_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); I* dbell_ind = (I*)dbell_ind_managed.get(); T* dbell_val = (T*)dbell_val_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(drow_ptr, hrow_ptr.data(), sizeof(I) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol_ind, hcol_ind.data(), sizeof(I) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hval.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * k * n, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_1, hC_1.data(), sizeof(T) * m * n, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_2, hC_2.data(), sizeof(T) * m * n, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dbell_ind, hbell_ind.data(), sizeof(I) * (ell_cols / ell_blocksize) * (m / ell_blocksize), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dbell_val, hbell_val.data(), sizeof(T) * ell_cols * m, hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t A_bell; CHECK_HIPSPARSE_ERROR(hipsparseCreateBlockedEll( &A_bell, m, k, ell_blocksize, ell_cols, dbell_ind, dbell_val, typeI, idx_base, typeT)); hipsparseSpMatDescr_t A_csr; CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr( &A_csr, m, k, nnz, drow_ptr, dcol_ind, dval, typeI, typeI, idx_base, typeT)); // Create dense matrices hipsparseDnMatDescr_t B, C1, C2; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&B, k, n, ldb, dB, typeT, order)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C1, m, n, ldc, dC_1, typeT, order)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C2, m, n, ldc, dC_2, typeT, order)); // Query SpMM buffer size_t bufferSize_bell; CHECK_HIPSPARSE_ERROR(hipsparseSpMM_bufferSize( handle, transA, transB, &h_alpha, A_bell, B, &h_beta, C1, typeT, alg, &bufferSize_bell)); void* buffer_bell; CHECK_HIP_ERROR(hipMalloc(&buffer_bell, bufferSize_bell)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) CHECK_HIPSPARSE_ERROR(hipsparseSpMM_preprocess( handle, transA, transB, &h_alpha, A_bell, B, &h_beta, C1, typeT, alg, buffer_bell)); #endif CHECK_HIPSPARSE_ERROR(hipsparseSpMM( handle, transA, transB, &h_alpha, A_bell, B, &h_beta, C1, typeT, alg, buffer_bell)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) CHECK_HIPSPARSE_ERROR(hipsparseSpMM_preprocess( handle, transA, transB, d_alpha, A_bell, B, d_beta, C2, typeT, alg, buffer_bell)); #endif CHECK_HIPSPARSE_ERROR(hipsparseSpMM( handle, transA, transB, d_alpha, A_bell, B, d_beta, C2, typeT, alg, buffer_bell)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hC_1.data(), dC_1, sizeof(T) * m * n, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hC_2.data(), dC_2, sizeof(T) * m * n, hipMemcpyDeviceToHost)); unit_check_near(1, m * n, 1, hC_gold.data(), hC_1.data()); unit_check_near(1, m * n, 1, hC_gold.data(), hC_2.data()); CHECK_HIP_ERROR(hipFree(buffer_bell)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A_csr)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A_bell)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(B)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C2)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPMM_BELL_HPP ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5723991 hipsparse/clients/include/testing_spmm_coo.hpp0000664000175100017510000004656715206065364022203 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5723991 hipsparse/clients/include/testing_spmm_csc.hpp0000664000175100017510000004643215206065364022162 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5723991 hipsparse/clients/include/testing_spmm_csr.hpp0000664000175100017510000004634615206065364022205 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5723991 hipsparse/clients/include/testing_spmv_coo.hpp0000664000175100017510000003525615206065364022205 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5723991 hipsparse/clients/include/testing_spmv_coo_aos.hpp0000664000175100017510000003462715206065364023050 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5723991 hipsparse/clients/include/testing_spmv_csr.hpp0000664000175100017510000004304715206065364022211 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2022 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPMV_CSR_HPP #define TESTING_SPMV_CSR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse_test; void testing_spmv_csr_bad_arg(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION > 10010 \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) int64_t m = 100; int64_t n = 100; int64_t nnz = 100; int64_t safe_size = 100; float alpha = 0.6; float beta = 0.2; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; #if(!defined(CUDART_VERSION)) hipsparseSpMVAlg_t alg = HIPSPARSE_MV_ALG_DEFAULT; #else #if(CUDART_VERSION >= 12000) hipsparseSpMVAlg_t alg = HIPSPARSE_SPMV_ALG_DEFAULT; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 12000) hipsparseSpMVAlg_t alg = HIPSPARSE_MV_ALG_DEFAULT; #endif #endif std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); float* dval = (float*)dval_managed.get(); float* dx = (float*)dx_managed.get(); float* dy = (float*)dy_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SpMV structures hipsparseSpMatDescr_t A; hipsparseDnVecDescr_t x, y; size_t bsize; // Create SpMV structures verify_hipsparse_status_success( hipsparseCreateCsr(&A, m, n, nnz, dptr, dcol, dval, idxType, idxType, idxBase, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnVec(&x, n, dx, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnVec(&y, m, dy, dataType), "success"); // SpMV buffer verify_hipsparse_status_invalid_handle( hipsparseSpMV_bufferSize(nullptr, transA, &alpha, A, x, &beta, y, dataType, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize(handle, transA, nullptr, A, x, &beta, y, dataType, alg, &bsize), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize( handle, transA, &alpha, nullptr, x, &beta, y, dataType, alg, &bsize), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize( handle, transA, &alpha, A, nullptr, &beta, y, dataType, alg, &bsize), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize(handle, transA, &alpha, A, x, nullptr, y, dataType, alg, &bsize), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize( handle, transA, &alpha, A, x, &beta, nullptr, dataType, alg, &bsize), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize(handle, transA, &alpha, A, x, &beta, y, dataType, alg, nullptr), "Error: bsize is nullptr"); // SpMV preprocess (optional) verify_hipsparse_status_invalid_handle( hipsparseSpMV_preprocess(nullptr, transA, &alpha, A, x, &beta, y, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_preprocess(handle, transA, nullptr, A, x, &beta, y, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_preprocess(handle, transA, &alpha, nullptr, x, &beta, y, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_preprocess(handle, transA, &alpha, A, nullptr, &beta, y, dataType, alg, dbuf), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_preprocess(handle, transA, &alpha, A, x, nullptr, y, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_preprocess(handle, transA, &alpha, A, x, &beta, nullptr, dataType, alg, dbuf), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_preprocess( handle, transA, &alpha, A, x, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // SpMV verify_hipsparse_status_invalid_handle( hipsparseSpMV(nullptr, transA, &alpha, A, x, &beta, y, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, nullptr, A, x, &beta, y, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, &alpha, nullptr, x, &beta, y, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, &alpha, A, nullptr, &beta, y, dataType, alg, dbuf), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, &alpha, A, x, nullptr, y, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, &alpha, A, x, &beta, nullptr, dataType, alg, dbuf), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, &alpha, A, x, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnVec(x), "success"); verify_hipsparse_status_success(hipsparseDestroyDnVec(y), "success"); #endif } template hipsparseStatus_t testing_spmv_csr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION > 10010 \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) J m = argus.M; J n = argus.N; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseSpMVAlg_t alg = static_cast(argus.spmv_alg); std::string filename = argus.filename; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipsparseIndexType_t typeJ = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hcsr_row_ptr; std::vector hcol_ind; std::vector hval; // Initial Data on CPU srand(12345ULL); I nnz; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcol_ind, hval, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hx(n); std::vector hy_1(m); std::vector hy_2(m); std::vector hy_gold(m); hipsparseInit(hx, 1, n); hipsparseInit(hy_1, 1, m); // copy vector is easy in STL; hy_gold = hx: save a copy in hy_gold which will be output of CPU hy_2 = hy_1; hy_gold = hy_1; // allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (m + 1)), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * n), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* dptr = (I*)dptr_managed.get(); J* dcol = (J*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dx = (T*)dx_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsr_row_ptr.data(), sizeof(I) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcol_ind.data(), sizeof(J) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hval.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx, hx.data(), sizeof(T) * n, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_1, hy_1.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_2, hy_2.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t A; CHECK_HIPSPARSE_ERROR( hipsparseCreateCsr(&A, m, n, nnz, dptr, dcol, dval, typeI, typeJ, idx_base, typeT)); // Create dense vectors hipsparseDnVecDescr_t x, y1, y2; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&x, n, dx, typeT)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&y1, m, dy_1, typeT)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&y2, m, dy_2, typeT)); // Query SpMV buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSpMV_bufferSize( handle, transA, &h_alpha, A, x, &h_beta, y1, typeT, alg, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); // Preprocess (optional) CHECK_HIPSPARSE_ERROR( hipsparseSpMV_preprocess(handle, transA, &h_alpha, A, x, &h_beta, y1, typeT, alg, buffer)); if(argus.unit_check) { // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseSpMV(handle, transA, &h_alpha, A, x, &h_beta, y1, typeT, alg, buffer)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSpMV(handle, transA, d_alpha, A, x, d_beta, y2, typeT, alg, buffer)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hy_1.data(), dy_1, sizeof(T) * m, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_2.data(), dy_2, sizeof(T) * m, hipMemcpyDeviceToHost)); // Query for warpSize hipDeviceProp_t prop; CHECK_HIP_ERROR(hipGetDeviceProperties(&prop, 0)); int WF_SIZE; I nnz_per_row = nnz / m; if(prop.warpSize == 32) { if(nnz_per_row < 4) WF_SIZE = 2; else if(nnz_per_row < 8) WF_SIZE = 4; else if(nnz_per_row < 16) WF_SIZE = 8; else if(nnz_per_row < 32) WF_SIZE = 16; else WF_SIZE = 32; } else if(prop.warpSize == 64) { if(nnz_per_row < 4) WF_SIZE = 2; else if(nnz_per_row < 8) WF_SIZE = 4; else if(nnz_per_row < 16) WF_SIZE = 8; else if(nnz_per_row < 32) WF_SIZE = 16; else if(nnz_per_row < 64) WF_SIZE = 32; else WF_SIZE = 64; } else { return HIPSPARSE_STATUS_INTERNAL_ERROR; } for(J i = 0; i < m; ++i) { std::vector sum(WF_SIZE, make_DataType(0.0)); for(I j = hcsr_row_ptr[i] - idx_base; j < hcsr_row_ptr[i + 1] - idx_base; j += WF_SIZE) { for(int k = 0; k < WF_SIZE; ++k) { if(j + k < hcsr_row_ptr[i + 1] - idx_base) { sum[k] = testing_fma(testing_mult(h_alpha, hval[j + k]), hx[hcol_ind[j + k] - idx_base], sum[k]); } } } for(int j = 1; j < WF_SIZE; j <<= 1) { for(int k = 0; k < WF_SIZE - j; ++k) { sum[k] = sum[k] + sum[k + j]; } } if(h_beta == make_DataType(0.0)) { hy_gold[i] = sum[0]; } else { hy_gold[i] = testing_fma(h_beta, hy_gold[i], sum[0]); } } unit_check_near(1, m, 1, hy_gold.data(), hy_1.data()); unit_check_near(1, m, 1, hy_gold.data(), hy_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseSpMV(handle, transA, &h_alpha, A, x, &h_beta, y1, typeT, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseSpMV(handle, transA, &h_alpha, A, x, &h_beta, y1, typeT, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = spmv_gflop_count(m, nnz, h_beta != make_DataType(0.0)); double gbyte_count = csrmv_gbyte_count(m, n, nnz, h_beta != make_DataType(0.0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::transA, transA, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::algorithm, hipsparse_spmvalg2string(alg), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(x)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y2)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPMV_CSR_HPP ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5723991 hipsparse/clients/include/testing_spsm_coo.hpp0000664000175100017510000004477315206065364022206 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5733993 hipsparse/clients/include/testing_spsm_csr.hpp0000664000175100017510000004466115206065364022211 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5733993 hipsparse/clients/include/testing_spsv_coo.hpp0000664000175100017510000003721315206065364022206 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5733993 hipsparse/clients/include/testing_spsv_csr.hpp0000664000175100017510000003714415206065364022220 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5733993 hipsparse/clients/include/testing_spvec_descr.hpp0000664000175100017510000001351715206065364022654 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5733993 hipsparse/clients/include/testing_spvv.hpp0000664000175100017510000002456615206065364021360 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5733993 hipsparse/clients/include/unit.hpp0000664000175100017510000000432415206065364017572 0ustar00jenkinsjenkins/* ************************************************************************ * 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5733993 hipsparse/clients/include/utility.hpp0000664000175100017510000065260015206065364020324 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_UTILITY_HPP #define TESTING_UTILITY_HPP #include #include #include #include #include #include #include #include #include #include #include #include #ifdef GOOGLE_TEST #include "gtest/gtest.h" #endif #ifdef _OPENMP #include #endif /*! \brief Return path of this executable */ std::string hipsparse_exepath(); /*! \brief Return path where the test data file (hipsparse_test.data) is located */ std::string hipsparse_datapath(); inline void missing_file_error_message(const char* filename) { std::cerr << "#" << std::endl; std::cerr << "# error:" << std::endl; std::cerr << "# cannot open file '" << filename << "'" << std::endl; std::cerr << "#" << std::endl; std::cerr << "# PLEASE READ CAREFULLY !" << std::endl; std::cerr << "#" << std::endl; std::cerr << "# What could be the reason of this error: " << std::endl; std::cerr << "# You are running the testing application and it expects to find the file " "at the specified location. This means that either you did not download the test " "matrices, or you did not specify the location of the folder containing your " "files. If you want to specify the location of the folder containing your files, " "then you will find the needed information with 'hipsparse-test --help'." "If you need to download matrices, then a cmake script " "'hipsparse_clientmatrices.cmake' is available from the hipsparse client package." << std::endl; std::cerr << "#" << std::endl; std::cerr << "# Examples: 'hipsparse_clientmatrices.cmake -DCMAKE_MATRICES_DIR='" << std::endl; std::cerr << "# 'hipsparse-test --matrices-dir '" << std::endl; std::cerr << "# (or 'export " "HIPSPARSE_CLIENTS_MATRICES_DIR=;hipsparse-test')" << std::endl; std::cerr << "#" << std::endl; } static const char* s_hipsparse_clients_matrices_dir = nullptr; inline const char* get_hipsparse_clients_matrices_dir() { return s_hipsparse_clients_matrices_dir; } inline std::string get_filename(const std::string& matrix_filename) { std::string matrix_filename_with_ext = matrix_filename; // Check if file already has extension, keep it, otherwise add .bin extension size_t last_dot_pos = matrix_filename_with_ext.find_last_of('.'); if(last_dot_pos == std::string::npos || last_dot_pos == 0) { matrix_filename_with_ext += ".bin"; } const char* matrices_dir = get_hipsparse_clients_matrices_dir(); if(matrices_dir == nullptr) { matrices_dir = getenv("HIPSPARSE_CLIENTS_MATRICES_DIR"); } std::string r; if(matrices_dir != nullptr) { r = std::string(matrices_dir) + "/" + matrix_filename_with_ext; } else { r = hipsparse_exepath() + "../matrices/" + matrix_filename_with_ext; } FILE* tmpf = fopen(r.c_str(), "r"); if(!tmpf) { missing_file_error_message(r.c_str()); std::cerr << "exit(HIPSPARSE_STATUS_INTERNAL_ERROR)" << std::endl; exit(HIPSPARSE_STATUS_INTERNAL_ERROR); } else { fclose(tmpf); } return r; } /*!\file * \brief provide data initialization and timing utilities. */ // BSR indexing macros #define BSR_IND(j, bi, bj, dir) \ ((dir == HIPSPARSE_DIRECTION_ROW) ? BSR_IND_R(j, bi, bj) : BSR_IND_C(j, bi, bj)) #define BSR_IND_R(j, bi, bj) (bsr_dim * bsr_dim * (j) + (bi)*bsr_dim + (bj)) #define BSR_IND_C(j, bi, bj) (bsr_dim * bsr_dim * (j) + (bi) + (bj)*bsr_dim) #define CHECK_HIP_ERROR(error) \ if(error != hipSuccess) \ { \ fprintf(stderr, \ "error: '%s'(%d) at %s:%d\n", \ hipGetErrorString(error), \ error, \ __FILE__, \ __LINE__); \ exit(EXIT_FAILURE); \ } #if(!defined(CUDART_VERSION) || (CUDART_VERSION >= 11003)) #define CHECK_HIPSPARSE_ERROR_CASE__(token_) \ case token_: \ fprintf(stderr, #token_); \ break #define CHECK_HIPSPARSE_ERROR(error) \ { \ auto local_error = (error); \ if(local_error != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "hipSPARSE error: "); \ switch(local_error) \ { \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_SUCCESS); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_NOT_INITIALIZED); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_ALLOC_FAILED); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_INVALID_VALUE); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_ARCH_MISMATCH); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_MAPPING_ERROR); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_EXECUTION_FAILED); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_INTERNAL_ERROR); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_ZERO_PIVOT); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_NOT_SUPPORTED); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_INSUFFICIENT_RESOURCES); \ } \ fprintf(stderr, "\n"); \ return local_error; \ } \ } \ (void)0 #else #define CHECK_HIPSPARSE_ERROR_CASE__(token_) \ case token_: \ fprintf(stderr, #token_); \ break #define CHECK_HIPSPARSE_ERROR(error) \ { \ auto local_error = (error); \ if(local_error != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "hipSPARSE error: "); \ switch(local_error) \ { \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_SUCCESS); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_NOT_INITIALIZED); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_ALLOC_FAILED); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_INVALID_VALUE); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_ARCH_MISMATCH); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_MAPPING_ERROR); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_EXECUTION_FAILED); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_INTERNAL_ERROR); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_ZERO_PIVOT); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_NOT_SUPPORTED); \ } \ fprintf(stderr, "\n"); \ return local_error; \ } \ } \ (void)0 #endif #ifdef __HIP_PLATFORM_NVIDIA__ static inline hipComplex operator-(const hipComplex& op) { hipComplex ret; ret.x = -op.x; ret.y = -op.y; return ret; } static inline hipDoubleComplex operator-(const hipDoubleComplex& op) { hipDoubleComplex ret; ret.x = -op.x; ret.y = -op.y; return ret; } static inline bool operator==(const hipComplex& lhs, const hipComplex& rhs) { return lhs.x == rhs.x && lhs.y == rhs.y; } static inline bool operator==(const hipDoubleComplex& lhs, const hipDoubleComplex& rhs) { return lhs.x == rhs.x && lhs.y == rhs.y; } static inline bool operator!=(const hipComplex& lhs, const hipComplex& rhs) { return !(lhs == rhs); } static inline bool operator!=(const hipDoubleComplex& lhs, const hipDoubleComplex& rhs) { return !(lhs == rhs); } static inline hipComplex operator+(const hipComplex& lhs, const hipComplex& rhs) { hipComplex ret; ret.x = lhs.x + rhs.x; ret.y = lhs.y + rhs.y; return ret; } static inline hipDoubleComplex operator+(const hipDoubleComplex& lhs, const hipDoubleComplex& rhs) { hipDoubleComplex ret; ret.x = lhs.x + rhs.x; ret.y = lhs.y + rhs.y; return ret; } static inline hipComplex operator-(const hipComplex& lhs, const hipComplex& rhs) { hipComplex ret; ret.x = lhs.x - rhs.x; ret.y = lhs.y - rhs.y; return ret; } static inline hipDoubleComplex operator-(const hipDoubleComplex& lhs, const hipDoubleComplex& rhs) { hipDoubleComplex ret; ret.x = lhs.x - rhs.x; ret.y = lhs.y - rhs.y; return ret; } static inline hipComplex operator*(const hipComplex& lhs, const hipComplex& rhs) { hipComplex ret; ret.x = lhs.x * rhs.x - lhs.y * rhs.y; ret.y = lhs.x * rhs.y + lhs.y * rhs.x; return ret; } static inline hipDoubleComplex operator*(const hipDoubleComplex& lhs, const hipDoubleComplex& rhs) { hipDoubleComplex ret; ret.x = lhs.x * rhs.x - lhs.y * rhs.y; ret.y = lhs.x * rhs.y + lhs.y * rhs.x; return ret; } static inline hipComplex operator/(const hipComplex& lhs, const hipComplex& rhs) { hipComplex ret; ret.x = (lhs.x * rhs.x + lhs.y * rhs.y); ret.y = (rhs.x * lhs.y - lhs.x * rhs.y); ret.x = ret.x / (rhs.x * rhs.x + rhs.y * rhs.y); ret.y = ret.y / (rhs.x * rhs.x + rhs.y * rhs.y); return ret; } static inline hipDoubleComplex operator/(const hipDoubleComplex& lhs, const hipDoubleComplex& rhs) { hipDoubleComplex ret; ret.x = (lhs.x * rhs.x + lhs.y * rhs.y); ret.y = (rhs.x * lhs.y - lhs.x * rhs.y); ret.x = ret.x / (rhs.x * rhs.x + rhs.y * rhs.y); ret.y = ret.y / (rhs.x * rhs.x + rhs.y * rhs.y); return ret; } static inline hipComplex operator+=(hipComplex& lhs, const hipComplex& rhs) { lhs.x += rhs.x; lhs.y += rhs.y; return lhs; } static inline hipDoubleComplex operator+=(hipDoubleComplex& lhs, const hipDoubleComplex& rhs) { lhs.x += rhs.x; lhs.y += rhs.y; return lhs; } #endif /* ============================================================================================ */ /*! \brief Make data type */ template inline T make_DataType2(double real, double imag) { return static_cast(real); } template <> inline hipComplex make_DataType2(double real, double imag) { return make_hipFloatComplex(static_cast(real), static_cast(imag)); } template <> inline hipDoubleComplex make_DataType2(double real, double imag) { return make_hipDoubleComplex(real, imag); } template inline T make_DataType(double real, double imag = 0.0) { return make_DataType2(real, imag); } /* ============================================================================================ */ /*! \brief mult */ template inline T testing_mult(T p, T q) { return p * q; } template <> inline hipComplex testing_mult(hipComplex p, hipComplex q) { return hipCmulf(p, q); } template <> inline hipDoubleComplex testing_mult(hipDoubleComplex p, hipDoubleComplex q) { return hipCmul(p, q); } /* ============================================================================================ */ /*! \brief div */ template inline T testing_div(T p, T q) { return p / q; } template <> inline hipComplex testing_div(hipComplex p, hipComplex q) { return hipCdivf(p, q); } template <> inline hipDoubleComplex testing_div(hipDoubleComplex p, hipDoubleComplex q) { return hipCdiv(p, q); } /* ============================================================================================ */ /*! \brief fma */ template inline T testing_fma(T p, T q, T r) { return std::fma(p, q, r); } template <> inline hipComplex testing_fma(hipComplex p, hipComplex q, hipComplex r) { return hipCfmaf(p, q, r); } template <> inline hipDoubleComplex testing_fma(hipDoubleComplex p, hipDoubleComplex q, hipDoubleComplex r) { return hipCfma(p, q, r); } /* ============================================================================================ */ /*! \brief abs */ static inline float testing_abs(float x) { return std::abs(x); } static inline double testing_abs(double x) { return std::abs(x); } static inline float testing_abs(hipComplex x) { return hipCabsf(x); } static inline double testing_abs(hipDoubleComplex x) { return hipCabs(x); } /* ============================================================================================ */ /*! \brief conj */ static inline float testing_conj(float x) { return x; } static inline double testing_conj(double x) { return x; } static inline hipComplex testing_conj(hipComplex x) { return make_DataType(x.x, -x.y); } static inline hipDoubleComplex testing_conj(hipDoubleComplex x) { return make_DataType(x.x, -x.y); } template inline T testing_conj(T val, bool conj) { return conj ? testing_conj(val) : val; } /* ============================================================================================ */ /*! \brief real */ static inline float testing_real(float x) { return std::real(x); } static inline double testing_real(double x) { return std::real(x); } static inline float testing_real(hipComplex x) { return hipCrealf(x); } static inline double testing_real(hipDoubleComplex x) { return hipCreal(x); } /* ============================================================================================ */ /* generate random number :*/ /*! \brief generate a random number between [0, 0.999...] . */ template inline T random_generator() { // return rand()/( (T)RAND_MAX + 1); return make_DataType(rand() % 10 + 1, rand() % 10 + 1); // generate a integer number between [1, 10] }; /* ============================================================================================ */ /*! \brief matrix/vector initialization: */ // for vector x (M=1, N=lengthX); // for complex number, the real/imag part would be initialized with the same value template void hipsparseInit(std::vector& A, int M, int N) { for(int i = 0; i < M; ++i) { for(int j = 0; j < N; ++j) { A[i + j] = random_generator(); } } }; /* ============================================================================================ */ /*! \brief vector initialization: */ // initialize sparse index vector with nnz entries ranging from start to end template void hipsparseInitIndex(I* x, int nnz, int start, int end) { std::vector check(end - start, false); int num = 0; while(num < nnz) { int val = start + rand() % (end - start); if(!check[val - start]) { x[num] = val; check[val - start] = true; ++num; } } std::sort(x, x + nnz); }; /* ============================================================================================ */ /*! \brief csr matrix initialization */ template void hipsparseInitCSR( std::vector& ptr, std::vector& col, std::vector& val, int nrow, int ncol, int nnz) { // Row offsets ptr[0] = 0; ptr[nrow] = nnz; for(int i = 1; i < nrow; ++i) { ptr[i] = rand() % (nnz - 1) + 1; } std::sort(ptr.begin(), ptr.end()); // Column indices for(int i = 0; i < nrow; ++i) { hipsparseInitIndex(&col[ptr[i]], ptr[i + 1] - ptr[i], 0, ncol - 1); std::sort(&col[ptr[i]], &col[ptr[i + 1]]); } // Random values for(int i = 0; i < nnz; ++i) { val[i] = random_generator(); } } /* ============================================================================================ */ /*! \brief Generate 2D laplacian on unit square in CSR format */ template J gen_2d_laplacian(int ndim, std::vector& rowptr, std::vector& col, std::vector& val, hipsparseIndexBase_t idx_base) { if(ndim == 0) { return 0; } J n = ndim * ndim; I nnz_mat = n * 5 - ndim * 4; rowptr.resize(n + 1); col.resize(nnz_mat); val.resize(nnz_mat); I nnz = 0; // Fill local arrays for(int i = 0; i < ndim; ++i) { for(int j = 0; j < ndim; ++j) { J idx = i * ndim + j; rowptr[idx] = nnz + idx_base; // if no upper boundary element, connect with upper neighbor if(i != 0) { col[nnz] = idx - ndim + idx_base; val[nnz] = make_DataType(-1.0); ++nnz; } // if no left boundary element, connect with left neighbor if(j != 0) { col[nnz] = idx - 1 + idx_base; val[nnz] = make_DataType(-1.0); ++nnz; } // element itself col[nnz] = idx + idx_base; val[nnz] = make_DataType(4.0); ++nnz; // if no right boundary element, connect with right neighbor if(j != ndim - 1) { col[nnz] = idx + 1 + idx_base; val[nnz] = make_DataType(-1.0); ++nnz; } // if no lower boundary element, connect with lower neighbor if(i != ndim - 1) { col[nnz] = idx + ndim + idx_base; val[nnz] = make_DataType(-1.0); ++nnz; } } } rowptr[n] = nnz + idx_base; return n; } /* ============================================================================================ */ /*! \brief Generate a random sparsity pattern with a dense format, generated floating point values of type T are positive and normalized. */ template void gen_dense_random_sparsity_pattern( int m, int n, T* A, int lda, hipsparseOrder_t order, float sparsity_ratio = 0.3) { if(order == HIPSPARSE_ORDER_COL) { for(int j = 0; j < n; ++j) { for(int i = 0; i < m; ++i) { const float d = ((float)rand()) / ((float)RAND_MAX); A[j * lda + i] = (d < sparsity_ratio) ? testing_div(make_DataType(rand()), make_DataType(RAND_MAX)) : make_DataType(0); } } } else { for(int j = 0; j < m; ++j) { for(int i = 0; i < n; ++i) { const float d = ((float)rand()) / ((float)RAND_MAX); A[j * lda + i] = (d < sparsity_ratio) ? testing_div(make_DataType(rand()), make_DataType(RAND_MAX)) : make_DataType(0); } } } } /* ============================================================================================ */ /*! \brief Generate a random sparse matrix in COO format */ template void gen_matrix_coo(I m, I n, I nnz, std::vector& row_ind, std::vector& col_ind, std::vector& val, hipsparseIndexBase_t idx_base) { if((I)row_ind.size() != nnz) { row_ind.resize(nnz); } if((I)col_ind.size() != nnz) { col_ind.resize(nnz); } if((I)val.size() != nnz) { val.resize(nnz); } // Uniform distributed row indices for(I i = 0; i < nnz; ++i) { row_ind[i] = rand() % m; } // Sort row indices std::sort(row_ind.begin(), row_ind.end()); // Sample column indices std::vector check(nnz, false); { I i = 0; while(i < nnz) { I begin = i; while(row_ind[i] == row_ind[begin]) { ++i; if(i >= nnz) { break; } } // Sample i disjunct column indices I idx = begin; while(idx < i) { #define MM_PI 3.1415 // Normal distribution around the diagonal I rng = (i - begin) * sqrt(-2.0 * log((double)rand() / RAND_MAX)) * cos(2.0 * MM_PI * (double)rand() / RAND_MAX); if(m <= n) { rng += row_ind[begin]; } // Repeat if running out of bounds if(rng < 0 || rng > n - 1) { continue; } // Check for disjunct column index in current row if(!check[rng]) { check[rng] = true; col_ind[idx] = rng; ++idx; } } // Reset disjunct check array for(I j = begin; j < i; ++j) { check[col_ind[j]] = false; } // Partially sort column indices std::sort(&col_ind[begin], &col_ind[i]); } } // Correct index base accordingly if(idx_base == HIPSPARSE_INDEX_BASE_ONE) { for(I i = 0; i < nnz; ++i) { ++row_ind[i]; ++col_ind[i]; } } // Sample random values for(I i = 0; i < nnz; ++i) { val[i] = random_generator(); //(double) rand() / RAND_MAX; } } /* ============================================================================================ */ /*! \brief Read matrix from mtx file in COO format */ template static inline void read_mtx_value(std::istringstream& is, I& row, I& col, int8_t& val) { is >> row >> col >> val; } template static void read_mtx_value(std::istringstream& is, I& row, I& col, float& val) { is >> row >> col >> val; } template static void read_mtx_value(std::istringstream& is, I& row, I& col, double& val) { is >> row >> col >> val; } template static void read_mtx_value(std::istringstream& is, I& row, I& col, hipComplex& val) { float real; float imag; is >> row >> col >> real >> imag; val = make_DataType(real, imag); } template static void read_mtx_value(std::istringstream& is, I& row, I& col, hipDoubleComplex& val) { double real; double imag; is >> row >> col >> real >> imag; val = make_DataType(real, imag); } template static void sort(std::vector& perm, std::vector& unsorted_row, std::vector& unsorted_col) { std::sort(perm.begin(), perm.end(), [&](const I& a, const I& b) { if(unsorted_row[a] < unsorted_row[b]) { return true; } else if(unsorted_row[a] == unsorted_row[b]) { return (unsorted_col[a] < unsorted_col[b]); } else { return false; } }); } template inline void scan(const char* line, I* nrow, I* ncol, int64_t* nnz) { sscanf(line, "%d %d %ld", nrow, ncol, nnz); } template <> inline void scan(const char* line, int64_t* nrow, int64_t* ncol, int64_t* nnz) { sscanf(line, "%ld %ld %ld", nrow, ncol, nnz); } template int read_mtx_matrix(const char* filename, I& nrow, I& ncol, int64_t& nnz, std::vector& row, std::vector& col, std::vector& val, hipsparseIndexBase_t idx_base) { const char* env = getenv("GTEST_LISTENER"); if(!env || strcmp(env, "NO_PASS_LINE_IN_LOG")) { printf("Reading matrix %s...", filename); fflush(stdout); } FILE* f = fopen(filename, "r"); if(!f) { fprintf(stderr, "Failed to open matrix file %s because it does not exist. Please download the " "matrix file using the install script with -c flag.", filename); return -1; } char line[1024]; // Check for banner if(!fgets(line, 1024, f)) { return -1; } char banner[16]; char array[16]; char coord[16]; char data[16]; char type[16]; // Extract banner if(sscanf(line, "%15s %15s %15s %15s %15s", banner, array, coord, data, type) != 5) { return -1; } // Convert to lower case for(char* p = array; *p != '\0'; *p = tolower(*p), p++) ; for(char* p = coord; *p != '\0'; *p = tolower(*p), p++) ; for(char* p = data; *p != '\0'; *p = tolower(*p), p++) ; for(char* p = type; *p != '\0'; *p = tolower(*p), p++) ; // Check banner if(strncmp(line, "%%MatrixMarket", 14) != 0) { return -1; } // Check array type if(strcmp(array, "matrix") != 0) { return -1; } // Check coord if(strcmp(coord, "coordinate") != 0) { return -1; } // Check data if(strcmp(data, "real") != 0 && strcmp(data, "integer") != 0 && strcmp(data, "pattern") != 0) { return -1; } // Check type if(strcmp(type, "general") != 0 && strcmp(type, "symmetric") != 0) { return -1; } // Symmetric flag int symm = !strcmp(type, "symmetric"); // Skip comments while(fgets(line, 1024, f)) { if(line[0] != '%') { break; } } // Read dimensions int64_t snnz; scan(line, &nrow, &ncol, &snnz); nnz = symm ? (snnz - nrow) * 2 + nrow : snnz; std::vector unsorted_row(nnz); std::vector unsorted_col(nnz); std::vector unsorted_val(nnz); // Read entries int64_t idx = 0; while(fgets(line, 1024, f)) { if(idx >= nnz) { return 1; } I irow; I icol; T ival; std::istringstream ss(line); if(!strcmp(data, "pattern")) { ss >> irow >> icol; ival = make_DataType(1.0); } else { read_mtx_value(ss, irow, icol, ival); } if(idx_base == HIPSPARSE_INDEX_BASE_ZERO) { --irow; --icol; } unsorted_row[idx] = irow; unsorted_col[idx] = icol; unsorted_val[idx] = ival; ++idx; if(symm && irow != icol) { if(idx >= nnz) { return 1; } unsorted_row[idx] = icol; unsorted_col[idx] = irow; unsorted_val[idx] = ival; ++idx; } } fclose(f); row.resize(nnz); col.resize(nnz); val.resize(nnz); // Sort by row and column index std::vector perm(nnz); for(int64_t i = 0; i < nnz; ++i) { perm[i] = i; } sort(perm, unsorted_row, unsorted_col); for(int64_t i = 0; i < nnz; ++i) { row[i] = unsorted_row[perm[i]]; col[i] = unsorted_col[perm[i]]; val[i] = unsorted_val[perm[i]]; } if(!env || strcmp(env, "NO_PASS_LINE_IN_LOG")) { printf("done.\n"); fflush(stdout); } return 0; } /* ============================================================================================ */ /*! \brief Read matrix from binary file in CSR format */ template int read_bin_matrix(const char* filename, J& nrow, J& ncol, I& nnz, std::vector& ptr, std::vector& col, std::vector& val, hipsparseIndexBase_t idx_base) { const char* env = getenv("GTEST_LISTENER"); if(!env || strcmp(env, "NO_PASS_LINE_IN_LOG")) { printf("Reading matrix %s...", filename); fflush(stdout); } FILE* f = fopen(filename, "rb"); if(!f) { return -1; } int err; int nrowf, ncolf, nnzf; err = fread(&nrowf, sizeof(int), 1, f); err |= fread(&ncolf, sizeof(int), 1, f); err |= fread(&nnzf, sizeof(int), 1, f); if(!err) { fclose(f); return -1; } nrow = (J)nrowf; ncol = (J)ncolf; nnz = (I)nnzf; // Allocate memory std::vector ptrf(nrow + 1); std::vector colf(nnz); std::vector valf(nnz); ptr.resize(nrow + 1); col.resize(nnz); val.resize(nnz); err |= fread(ptrf.data(), sizeof(int), nrow + 1, f); err |= fread(colf.data(), sizeof(int), nnz, f); err |= fread(valf.data(), sizeof(double), nnz, f); if(!err) { fclose(f); return -1; } fclose(f); for(J i = 0; i < nrow + 1; ++i) { ptr[i] = (I)ptrf[i]; } for(I i = 0; i < nnz; ++i) { col[i] = (J)colf[i]; val[i] = make_DataType(valf[i]); } if(idx_base == HIPSPARSE_INDEX_BASE_ONE) { for(J i = 0; i < nrow + 1; ++i) { ++ptr[i]; } for(I i = 0; i < nnz; ++i) { ++col[i]; } } if(!env || strcmp(env, "NO_PASS_LINE_IN_LOG")) { printf("done.\n"); fflush(stdout); } return 0; } /* ============================================================================================ */ /*! \brief Generate CSR matrix from file. File can be either mtx or bin. If filename is empty, a random matrix is generated*/ template bool generate_csr_matrix(const std::string filename, J& nrow, J& ncol, I& nnz, std::vector& csr_row_ptr, std::vector& csr_col_ind, std::vector& csr_val, hipsparseIndexBase_t idx_base) { // If no filename passed, generate matrix if(filename == "" || filename == "*") { double scale = 0.02; if(nrow > 1000 || ncol > 1000) { scale = 2.0 / std::max(nrow, ncol); } nnz = nrow * scale * ncol; std::vector coo_row_ind; gen_matrix_coo(nrow, ncol, (J)nnz, coo_row_ind, csr_col_ind, csr_val, idx_base); csr_row_ptr.resize(nrow + 1, 0); for(int i = 0; i < nnz; ++i) { ++csr_row_ptr[coo_row_ind[i] + 1 - idx_base]; } csr_row_ptr[0] = idx_base; for(int i = 0; i < nrow; ++i) { csr_row_ptr[i + 1] += csr_row_ptr[i]; } return true; } else { std::string full_filename_path = get_filename(filename); std::string extension = full_filename_path.substr(full_filename_path.find_last_of(".") + 1); if(extension == "bin") { if(read_bin_matrix(full_filename_path.c_str(), nrow, ncol, nnz, csr_row_ptr, csr_col_ind, csr_val, idx_base) == 0) { return true; } } else if(extension == "mtx") { int64_t nnz_count; std::vector coo_row_ind; if(read_mtx_matrix(full_filename_path.c_str(), nrow, ncol, nnz_count, coo_row_ind, csr_col_ind, csr_val, idx_base) == 0) { if(nnz_count < std::numeric_limits::max()) { nnz = (I)nnz_count; csr_row_ptr.resize(nrow + 1, 0); for(int i = 0; i < nnz; ++i) { ++csr_row_ptr[coo_row_ind[i] + 1 - idx_base]; } csr_row_ptr[0] = idx_base; for(int i = 0; i < nrow; ++i) { csr_row_ptr[i + 1] += csr_row_ptr[i]; } return true; } } } } return false; } /* ============================================================================================ */ /*! \brief Generate COO matrix from file. File can be either mtx or bin. If filename is empty, a random matrix is generated*/ template bool generate_coo_matrix(const std::string filename, I& nrow, I& ncol, I& nnz, std::vector& coo_row_ind, std::vector& coo_col_ind, std::vector& coo_val, hipsparseIndexBase_t idx_base) { // If no filename passed, generate matrix if(filename == "" || filename == "*") { double scale = 0.02; if(nrow > 1000 || ncol > 1000) { scale = 2.0 / std::max(nrow, ncol); } nnz = nrow * scale * ncol; gen_matrix_coo(nrow, ncol, nnz, coo_row_ind, coo_col_ind, coo_val, idx_base); return true; } else { std::string full_filename_path = get_filename(filename); std::string extension = full_filename_path.substr(full_filename_path.find_last_of(".") + 1); if(extension == "bin") { std::vector csr_row_ptr; if(read_bin_matrix(full_filename_path.c_str(), nrow, ncol, nnz, csr_row_ptr, coo_col_ind, coo_val, idx_base) == 0) { coo_row_ind.resize(nnz); for(I i = 0; i < nrow; ++i) { I row_begin = csr_row_ptr[i] - idx_base; I row_end = csr_row_ptr[i + 1] - idx_base; for(I j = row_begin; j < row_end; ++j) { coo_row_ind[j] = i + idx_base; } } return true; } } else if(extension == "mtx") { int64_t nnz_count; if(read_mtx_matrix(full_filename_path.c_str(), nrow, ncol, nnz_count, coo_row_ind, coo_col_ind, coo_val, idx_base) == 0) { if(nnz_count < std::numeric_limits::max()) { nnz = (I)nnz_count; return true; } } } } return false; } /* ============================================================================================ */ /*! \brief Compute incomplete LU factorization without fill-ins and no pivoting using CSR * matrix storage format. */ static inline float testing_neg(float val) { return -val; } static inline double testing_neg(double val) { return -val; } static inline hipComplex testing_neg(hipComplex val) { hipComplex ret; ret.x = -val.x; ret.y = -val.y; return ret; } static inline hipDoubleComplex testing_neg(hipDoubleComplex val) { hipDoubleComplex ret; ret.x = -val.x; ret.y = -val.y; return ret; } template void host_nnz(hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const T* A, int lda, int* nnzPerRowColumn, int* nnzTotalDevHostPtr) { int mn = (dirA == HIPSPARSE_DIRECTION_ROW) ? m : n; #ifdef _OPENMP #pragma omp parallel for #endif for(int j = 0; j < mn; ++j) { nnzPerRowColumn[j] = 0; } for(int j = 0; j < n; ++j) { for(int i = 0; i < m; ++i) { if(A[j * lda + i] != make_DataType(0)) { if(dirA == HIPSPARSE_DIRECTION_ROW) { nnzPerRowColumn[i] += 1; } else { nnzPerRowColumn[j] += 1; } } } } int sum = 0; #ifdef _OPENMP #pragma omp parallel for reduction(+ : sum) #endif for(int j = 0; j < mn; ++j) { sum = sum + nnzPerRowColumn[j]; } nnzTotalDevHostPtr[0] = sum; } template void host_dense2csx(int m, int n, hipsparseIndexBase_t base, const T* A, int ld, const int* nnz_per_row_columns, T* csx_val, int* csx_row_col_ptr, int* csx_col_row_ind) { static constexpr T s_zero = {}; int len = (HIPSPARSE_DIRECTION_ROW == DIRA) ? m : n; *csx_row_col_ptr = base; for(int i = 0; i < len; ++i) { csx_row_col_ptr[i + 1] = nnz_per_row_columns[i] + csx_row_col_ptr[i]; } switch(DIRA) { case HIPSPARSE_DIRECTION_COLUMN: { for(int j = 0; j < n; ++j) { for(int i = 0; i < m; ++i) { if(A[j * ld + i] != s_zero) { *csx_val++ = A[j * ld + i]; *csx_col_row_ind++ = i + base; } } } break; } case HIPSPARSE_DIRECTION_ROW: { // // Does not matter having an orthogonal traversal ... testing only. // Otherwise, we would use csxRowPtrA to store the shifts. // and once the job is done a simple memory move would reinitialize the csxRowPtrA to its initial state) // for(int i = 0; i < m; ++i) { for(int j = 0; j < n; ++j) { if(A[j * ld + i] != s_zero) { *csx_val++ = A[j * ld + i]; *csx_col_row_ind++ = j + base; } } } break; } } } template void host_prune_dense2csr(int m, int n, const std::vector& A, int lda, hipsparseIndexBase_t base, T threshold, int& nnz, std::vector& csr_val, std::vector& csr_row_ptr, std::vector& csr_col_ind) { csr_row_ptr.resize(m + 1, 0); csr_row_ptr[0] = base; #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < m; i++) { for(int j = 0; j < n; j++) { if(testing_abs(A[lda * j + i]) > threshold) { csr_row_ptr[i + 1]++; } } } for(int i = 1; i <= m; i++) { csr_row_ptr[i] += csr_row_ptr[i - 1]; } nnz = csr_row_ptr[m] - csr_row_ptr[0]; csr_col_ind.resize(nnz); csr_val.resize(nnz); int index = 0; for(int i = 0; i < m; i++) { for(int j = 0; j < n; j++) { if(testing_abs(A[lda * j + i]) > threshold) { csr_val[index] = A[lda * j + i]; csr_col_ind[index] = j + base; index++; } } } } template void host_prune_dense2csr_by_percentage(int m, int n, const std::vector& A, int lda, hipsparseIndexBase_t base, T percentage, int& nnz, std::vector& csr_val, std::vector& csr_row_ptr, std::vector& csr_col_ind) { int nnz_A = m * n; int pos = std::ceil(nnz_A * (percentage / 100)) - 1; pos = std::min(pos, nnz_A - 1); pos = std::max(pos, 0); std::vector sorted_A(nnz_A); for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { sorted_A[m * i + j] = std::abs(A[lda * i + j]); } } std::sort(sorted_A.begin(), sorted_A.end()); T threshold = (nnz_A > 0) ? sorted_A[pos] : make_DataType(0); host_prune_dense2csr(m, n, A, lda, base, threshold, nnz, csr_val, csr_row_ptr, csr_col_ind); } template void host_csx2dense(int m, int n, hipsparseIndexBase_t base, const T* csx_val, const int* csx_row_col_ptr, const int* csx_col_row_ind, T* A, int ld) { static constexpr T s_zero = {}; switch(DIRA) { case HIPSPARSE_DIRECTION_COLUMN: { for(int col = 0; col < n; ++col) { for(int row = 0; row < m; ++row) { A[row + ld * col] = s_zero; } const int bound = csx_row_col_ptr[col + 1] - base; for(int at = csx_row_col_ptr[col] - base; at < bound; ++at) { A[(csx_col_row_ind[at] - base) + ld * col] = csx_val[at]; } } break; } case HIPSPARSE_DIRECTION_ROW: { for(int row = 0; row < m; ++row) { for(int col = 0; col < n; ++col) { A[col * ld + row] = s_zero; } const int bound = csx_row_col_ptr[row + 1] - base; for(int at = csx_row_col_ptr[row] - base; at < bound; ++at) { A[(csx_col_row_ind[at] - base) * ld + row] = csx_val[at]; } } break; } } } template inline void host_csr_to_csr_compress(int M, int N, const std::vector& csr_row_ptr_A, const std::vector& csr_col_ind_A, const std::vector& csr_val_A, std::vector& csr_row_ptr_C, std::vector& csr_col_ind_C, std::vector& csr_val_C, hipsparseIndexBase_t base, T tol) { if(M <= 0 || N <= 0) { return; } // find how many entries will be in each compressed CSR matrix row std::vector nnz_per_row(M); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < M; i++) { int start = csr_row_ptr_A[i] - base; int end = csr_row_ptr_A[i + 1] - base; int count = 0; for(int j = start; j < end; j++) { if(testing_abs(csr_val_A[j]) > testing_real(tol) && testing_abs(csr_val_A[j]) > (std::numeric_limits::min)()) { count++; } } nnz_per_row[i] = count; } // add up total number of entries int nnz_C = 0; for(int i = 0; i < M; i++) { nnz_C += nnz_per_row[i]; } //column indices and value arrays for compressed CSR matrix csr_col_ind_C.resize(nnz_C); csr_val_C.resize(nnz_C); // fill in row pointer array for compressed CSR matrix csr_row_ptr_C.resize(M + 1); csr_row_ptr_C[0] = base; for(int i = 0; i < M; i++) { csr_row_ptr_C[i + 1] = csr_row_ptr_C[i] + nnz_per_row[i]; } // fill in column indices and value arrays for compressed CSR matrix #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < M; i++) { int start = csr_row_ptr_A[i] - base; int end = csr_row_ptr_A[i + 1] - base; int index = csr_row_ptr_C[i] - base; for(int j = start; j < end; j++) { if(testing_abs(csr_val_A[j]) > testing_real(tol) && testing_abs(csr_val_A[j]) > (std::numeric_limits::min)()) { csr_col_ind_C[index] = csr_col_ind_A[j]; csr_val_C[index] = csr_val_A[j]; index++; } } } } template inline void host_prune_csr_to_csr(int M, int N, int nnz_A, const std::vector& csr_row_ptr_A, const std::vector& csr_col_ind_A, const std::vector& csr_val_A, int& nnz_C, std::vector& csr_row_ptr_C, std::vector& csr_col_ind_C, std::vector& csr_val_C, hipsparseIndexBase_t csr_base_A, hipsparseIndexBase_t csr_base_C, T threshold) { csr_row_ptr_C.resize(M + 1, 0); csr_row_ptr_C[0] = csr_base_C; #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < M; i++) { for(int j = csr_row_ptr_A[i] - csr_base_A; j < csr_row_ptr_A[i + 1] - csr_base_A; j++) { if(testing_abs(csr_val_A[j]) > threshold && testing_abs(csr_val_A[j]) > (std::numeric_limits::min)()) { csr_row_ptr_C[i + 1]++; } } } for(int i = 1; i <= M; i++) { csr_row_ptr_C[i] += csr_row_ptr_C[i - 1]; } nnz_C = csr_row_ptr_C[M] - csr_row_ptr_C[0]; csr_col_ind_C.resize(nnz_C); csr_val_C.resize(nnz_C); int index = 0; for(int i = 0; i < M; i++) { for(int j = csr_row_ptr_A[i] - csr_base_A; j < csr_row_ptr_A[i + 1] - csr_base_A; j++) { if(testing_abs(csr_val_A[j]) > threshold && testing_abs(csr_val_A[j]) > (std::numeric_limits::min)()) { csr_col_ind_C[index] = (csr_col_ind_A[j] - csr_base_A) + csr_base_C; csr_val_C[index] = csr_val_A[j]; index++; } } } } template void host_prune_csr_to_csr_by_percentage(int M, int N, int nnz_A, const std::vector& csr_row_ptr_A, const std::vector& csr_col_ind_A, const std::vector& csr_val_A, int& nnz_C, std::vector& csr_row_ptr_C, std::vector& csr_col_ind_C, std::vector& csr_val_C, hipsparseIndexBase_t csr_base_A, hipsparseIndexBase_t csr_base_C, T percentage) { int pos = std::ceil(nnz_A * (percentage / 100)) - 1; pos = std::min(pos, nnz_A - 1); pos = std::max(pos, 0); std::vector sorted_A(nnz_A); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < nnz_A; i++) { sorted_A[i] = testing_abs(csr_val_A[i]); } std::sort(sorted_A.begin(), sorted_A.end()); T threshold = sorted_A[pos]; host_prune_csr_to_csr(M, N, nnz_A, csr_row_ptr_A, csr_col_ind_A, csr_val_A, nnz_C, csr_row_ptr_C, csr_col_ind_C, csr_val_C, csr_base_A, csr_base_C, threshold); } template inline void host_csr_to_csc(J M, J N, I nnz, const I* csr_row_ptr, const J* csr_col_ind, const T* csr_val, //const std::vector& csr_row_ptr, //const std::vector& csr_col_ind, //const std::vector& csr_val, std::vector& csc_row_ind, std::vector& csc_col_ptr, std::vector& csc_val, hipsparseAction_t action, hipsparseIndexBase_t base) { csc_row_ind.resize(nnz); csc_col_ptr.resize(N + 1, 0); csc_val.resize(nnz); // Determine nnz per column for(I i = 0; i < nnz; ++i) { ++csc_col_ptr[csr_col_ind[i] + 1 - base]; } // Scan for(J i = 0; i < N; ++i) { csc_col_ptr[i + 1] += csc_col_ptr[i]; } // Fill row indices and values for(J i = 0; i < M; ++i) { I row_begin = csr_row_ptr[i] - base; I row_end = csr_row_ptr[i + 1] - base; for(I j = row_begin; j < row_end; ++j) { J col = csr_col_ind[j] - base; I idx = csc_col_ptr[col]; csc_row_ind[idx] = i + base; csc_val[idx] = csr_val[j]; ++csc_col_ptr[col]; } } // Shift column pointer array for(J i = N; i > 0; --i) { csc_col_ptr[i] = csc_col_ptr[i - 1] + base; } csc_col_ptr[0] = base; } template inline void host_csr_to_bsr(hipsparseDirection_t direction, int M, int N, int block_dim, int& nnzb, hipsparseIndexBase_t csr_base, const std::vector& csr_row_ptr, const std::vector& csr_col_ind, const std::vector& csr_val, hipsparseIndexBase_t bsr_base, std::vector& bsr_row_ptr, std::vector& bsr_col_ind, std::vector& bsr_val) { int mb = (M + block_dim - 1) / block_dim; int nb = (N + block_dim - 1) / block_dim; // quick return if block_dim == 1 if(block_dim == 1) { bsr_row_ptr.resize(mb + 1, 0); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(size_t i = 0; i < csr_row_ptr.size(); i++) { bsr_row_ptr[i] = (csr_row_ptr[i] - csr_base) + bsr_base; } nnzb = bsr_row_ptr[mb] - bsr_row_ptr[0]; bsr_col_ind.resize(nnzb, 0); bsr_val.resize(nnzb * block_dim * block_dim, make_DataType(0)); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(size_t i = 0; i < csr_col_ind.size(); i++) { bsr_col_ind[i] = (csr_col_ind[i] - csr_base) + bsr_base; } #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(size_t i = 0; i < csr_val.size(); i++) { bsr_val[i] = csr_val[i]; } return; } // determine number of non-zero block columns for each block row of the bsr matrix bsr_row_ptr.resize(mb + 1, 0); bsr_row_ptr[0] = bsr_base; #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < mb; i++) { int start = csr_row_ptr[i * block_dim] - csr_base; int end = csr_row_ptr[std::min(M, block_dim * i + block_dim)] - csr_base; std::vector temp(nb, 0); for(int j = start; j < end; j++) { int blockCol = (csr_col_ind[j] - csr_base) / block_dim; temp[blockCol] = 1; } int sum = 0; for(size_t j = 0; j < temp.size(); j++) { sum += temp[j]; } bsr_row_ptr[i + 1] = sum; } for(int i = 0; i < mb; i++) { bsr_row_ptr[i + 1] += bsr_row_ptr[i]; } nnzb = bsr_row_ptr[mb] - bsr_row_ptr[0]; // find bsr col indices array bsr_col_ind.resize(nnzb, 0); bsr_val.resize(nnzb * block_dim * block_dim, make_DataType(0)); int colIndex = 0; for(int i = 0; i < mb; i++) { int start = csr_row_ptr[i * block_dim] - csr_base; int end = csr_row_ptr[std::min(M, block_dim * i + block_dim)] - csr_base; std::vector temp(nb, 0); for(int j = start; j < end; j++) { int blockCol = (csr_col_ind[j] - csr_base) / block_dim; temp[blockCol] = 1; } for(int j = 0; j < nb; j++) { if(temp[j] == 1) { bsr_col_ind[colIndex] = j + bsr_base; colIndex++; } } } // find bsr values array for(int i = 0; i < M; i++) { int blockRow = i / block_dim; int start = csr_row_ptr[i] - csr_base; int end = csr_row_ptr[i + 1] - csr_base; for(int j = start; j < end; j++) { int blockCol = (csr_col_ind[j] - csr_base) / block_dim; colIndex = -1; for(int k = bsr_row_ptr[blockRow] - bsr_base; k < bsr_row_ptr[blockRow + 1] - bsr_base; k++) { if(bsr_col_ind[k] - bsr_base == blockCol) { colIndex = k - (bsr_row_ptr[blockRow] - bsr_base); break; } } assert(colIndex != -1); int blockIndex = 0; if(direction == HIPSPARSE_DIRECTION_ROW) { blockIndex = (csr_col_ind[j] - csr_base) % block_dim + (i % block_dim) * block_dim; } else { blockIndex = ((csr_col_ind[j] - csr_base) % block_dim) * block_dim + (i % block_dim); } int index = (bsr_row_ptr[blockRow] - bsr_base) * block_dim * block_dim + colIndex * block_dim * block_dim + blockIndex; bsr_val[index] = csr_val[j]; } } } template void host_bsr_to_bsc(int mb, int nb, int nnzb, int bsr_dim, const int* bsr_row_ptr, const int* bsr_col_ind, const T* bsr_val, std::vector& bsc_row_ind, std::vector& bsc_col_ptr, std::vector& bsc_val, hipsparseIndexBase_t bsr_base, hipsparseIndexBase_t bsc_base) { bsc_row_ind.resize(nnzb); bsc_col_ptr.resize(nb + 1, 0); bsc_val.resize(nnzb * bsr_dim * bsr_dim); // Determine nnz per column for(int i = 0; i < nnzb; ++i) { ++bsc_col_ptr[bsr_col_ind[i] + 1 - bsr_base]; } // Scan for(int i = 0; i < nb; ++i) { bsc_col_ptr[i + 1] += bsc_col_ptr[i]; } // Fill row indices and values for(int i = 0; i < mb; ++i) { int row_begin = bsr_row_ptr[i] - bsr_base; int row_end = bsr_row_ptr[i + 1] - bsr_base; for(int j = row_begin; j < row_end; ++j) { int col = bsr_col_ind[j] - bsr_base; int idx = bsc_col_ptr[col]; bsc_row_ind[idx] = i + bsc_base; for(int bi = 0; bi < bsr_dim; ++bi) { for(int bj = 0; bj < bsr_dim; ++bj) { bsc_val[bsr_dim * bsr_dim * idx + bi + bj * bsr_dim] = bsr_val[bsr_dim * bsr_dim * j + bi * bsr_dim + bj]; } } ++bsc_col_ptr[col]; } } // Shift column pointer array for(int i = nb; i > 0; --i) { bsc_col_ptr[i] = bsc_col_ptr[i - 1] + bsc_base; } bsc_col_ptr[0] = bsc_base; } template inline void host_gebsr_to_csr(hipsparseDirection_t direction, int mb, int nb, int nnzb, const std::vector& bsr_val, const std::vector& bsr_row_ptr, const std::vector& bsr_col_ind, int row_block_dim, int col_block_dim, hipsparseIndexBase_t bsr_base, std::vector& csr_val, std::vector& csr_row_ptr, std::vector& csr_col_ind, hipsparseIndexBase_t csr_base) { csr_col_ind.resize(nnzb * row_block_dim * col_block_dim); csr_row_ptr.resize(mb * row_block_dim + 1); csr_val.resize(nnzb * row_block_dim * col_block_dim); int at = 0; csr_row_ptr[0] = csr_base; for(int i = 0; i < mb; ++i) { for(int r = 0; r < row_block_dim; ++r) { int row = i * row_block_dim + r; for(int k = bsr_row_ptr[i] - bsr_base; k < bsr_row_ptr[i + 1] - bsr_base; ++k) { int j = bsr_col_ind[k] - bsr_base; for(int c = 0; c < col_block_dim; ++c) { int col = col_block_dim * j + c; csr_col_ind[at] = col + csr_base; if(direction == HIPSPARSE_DIRECTION_ROW) { csr_val[at] = bsr_val[k * row_block_dim * col_block_dim + col_block_dim * r + c]; } else { csr_val[at] = bsr_val[k * row_block_dim * col_block_dim + row_block_dim * c + r]; } ++at; } } csr_row_ptr[row + 1] = csr_row_ptr[row] + (bsr_row_ptr[i + 1] - bsr_row_ptr[i]) * col_block_dim; } } } template inline void host_csr_to_gebsr(hipsparseDirection_t direction, int m, int n, int row_block_dim, int col_block_dim, int& nnzb, hipsparseIndexBase_t csr_base, const std::vector& csr_row_ptr, const std::vector& csr_col_ind, const std::vector& csr_val, hipsparseIndexBase_t bsr_base, std::vector& bsr_row_ptr, std::vector& bsr_col_ind, std::vector& bsr_val) { int mb = (m + row_block_dim - 1) / row_block_dim; int nnz = csr_col_ind.size(); bsr_row_ptr.resize(mb + 1, 0); std::vector temp(nnz); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < nnz; i++) { temp[i] = (csr_col_ind[i] - csr_base) / col_block_dim; } #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < mb; i++) { int frow = row_block_dim * i; int lrow = row_block_dim * (i + 1); if(lrow > m) { lrow = m; } int start = csr_row_ptr[frow] - csr_base; int end = csr_row_ptr[lrow] - csr_base; std::sort(temp.begin() + start, temp.begin() + end); } #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < mb; i++) { int frow = row_block_dim * i; int lrow = row_block_dim * (i + 1); if(lrow > m) { lrow = m; } int start = csr_row_ptr[frow] - csr_base; int end = csr_row_ptr[lrow] - csr_base; int col = -1; int count = 0; for(int j = start; j < end; j++) { if(temp[j] > col) { col = temp[j]; temp[j] = -1; temp[start + count] = col; count++; } else { temp[j] = -1; } } bsr_row_ptr[i + 1] = count; } // fill GEBSR row pointer array bsr_row_ptr[0] = bsr_base; for(int i = 0; i < mb; i++) { bsr_row_ptr[i + 1] += bsr_row_ptr[i]; } nnzb = bsr_row_ptr[mb] - bsr_row_ptr[0]; bsr_col_ind.resize(nnzb); bsr_val.resize(nnzb * row_block_dim * col_block_dim, make_DataType(0)); // fill GEBSR col indices array { int index = 0; for(int i = 0; i < nnz; i++) { if(temp[i] != -1) { bsr_col_ind[index] = temp[i] + bsr_base; index++; } } } // fill GEBSR values array #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < m; i++) { int start = csr_row_ptr[i] - csr_base; int end = csr_row_ptr[i + 1] - csr_base; int bstart = bsr_row_ptr[i / row_block_dim] - bsr_base; int bend = bsr_row_ptr[i / row_block_dim + 1] - bsr_base; int local_row = i % row_block_dim; for(int j = start; j < end; j++) { int col = csr_col_ind[j] - csr_base; int local_col = col % col_block_dim; { int index = 0; for(int k = bstart; k < bend; k++) { if(bsr_col_ind[k] - bsr_base == col / col_block_dim) { index = k; bstart = k; break; } } if(direction == HIPSPARSE_DIRECTION_ROW) { bsr_val[row_block_dim * col_block_dim * index + col_block_dim * local_row + local_col] = csr_val[j]; } else { bsr_val[row_block_dim * col_block_dim * index + row_block_dim * local_col + local_row] = csr_val[j]; } } } } } template inline void host_gebsr_to_gebsr(hipsparseDirection_t direction, int mb, int nb, int nnzb, const std::vector& bsr_val_A, const std::vector& bsr_row_ptr_A, const std::vector& bsr_col_ind_A, int row_block_dim_A, int col_block_dim_A, hipsparseIndexBase_t base_A, std::vector& bsr_val_C, std::vector& bsr_row_ptr_C, std::vector& bsr_col_ind_C, int row_block_dim_C, int col_block_dim_C, hipsparseIndexBase_t base_C) { int m = mb * row_block_dim_A; int n = nb * col_block_dim_A; // convert GEBSR to CSR format std::vector csr_row_ptr; std::vector csr_col_ind; std::vector csr_val; host_gebsr_to_csr(direction, mb, nb, nnzb, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, base_A, csr_val, csr_row_ptr, csr_col_ind, HIPSPARSE_INDEX_BASE_ZERO); // convert CSR to GEBSR format int nnzb_C; host_csr_to_gebsr(direction, m, n, row_block_dim_C, col_block_dim_C, nnzb_C, HIPSPARSE_INDEX_BASE_ZERO, csr_row_ptr, csr_col_ind, csr_val, base_C, bsr_row_ptr_C, bsr_col_ind_C, bsr_val_C); } template void host_gebsr_to_gebsc(int Mb, int Nb, int nnzb, const std::vector& bsr_row_ptr, const std::vector& bsr_col_ind, const std::vector& bsr_val, int row_block_dim, int col_block_dim, std::vector& bsc_row_ind, std::vector& bsc_col_ptr, std::vector& bsc_val, hipsparseAction_t action, hipsparseIndexBase_t base) { bsc_row_ind.resize(nnzb); bsc_col_ptr.resize(Nb + 1, 0); bsc_val.resize(nnzb); const int block_shift = row_block_dim * col_block_dim; // // Determine nnz per column // for(int i = 0; i < nnzb; ++i) { ++bsc_col_ptr[bsr_col_ind[i] + 1 - base]; } // Scan for(int i = 0; i < Nb; ++i) { bsc_col_ptr[i + 1] += bsc_col_ptr[i]; } // Fill row indices and values for(int i = 0; i < Mb; ++i) { const int row_begin = bsr_row_ptr[i] - base; const int row_end = bsr_row_ptr[i + 1] - base; for(int j = row_begin; j < row_end; ++j) { const int col = bsr_col_ind[j] - base; const int idx = bsc_col_ptr[col]; bsc_row_ind[idx] = i + base; for(int k = 0; k < block_shift; ++k) { bsc_val[idx * block_shift + k] = bsr_val[j * block_shift + k]; } ++bsc_col_ptr[col]; } } // Shift column pointer array for(int i = Nb; i > 0; --i) { bsc_col_ptr[i] = bsc_col_ptr[i - 1] + base; } bsc_col_ptr[0] = base; } template inline void host_bsr_to_csr(hipsparseDirection_t direction, int Mb, int Nb, int block_dim, hipsparseIndexBase_t bsr_base, const std::vector& bsr_row_ptr, const std::vector& bsr_col_ind, const std::vector& bsr_val, hipsparseIndexBase_t csr_base, std::vector& csr_row_ptr, std::vector& csr_col_ind, std::vector& csr_val) { int m = Mb * block_dim; int nnzb = bsr_row_ptr[Mb] - bsr_row_ptr[0]; csr_row_ptr.resize(m + 1, 0); csr_col_ind.resize(nnzb * block_dim * block_dim, 0); csr_val.resize(nnzb * block_dim * block_dim, make_DataType(0)); // quick return if block_dim == 1 if(block_dim == 1) { #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(size_t i = 0; i < bsr_row_ptr.size(); i++) { csr_row_ptr[i] = (bsr_row_ptr[i] - bsr_base) + csr_base; } #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(size_t i = 0; i < bsr_col_ind.size(); i++) { csr_col_ind[i] = (bsr_col_ind[i] - bsr_base) + csr_base; } #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(size_t i = 0; i < bsr_val.size(); i++) { csr_val[i] = bsr_val[i]; } return; } csr_row_ptr[0] = csr_base; // find csr row ptr array for(int i = 0; i < Mb; i++) { int entries_in_row = block_dim * (bsr_row_ptr[i + 1] - bsr_row_ptr[i]); for(int j = 0; j < block_dim; j++) { csr_row_ptr[i * block_dim + j + 1] = csr_row_ptr[i * block_dim + j] + entries_in_row; } } int entries_in_block = block_dim * block_dim; // find csr col indices and values arrays #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < Mb; i++) { int entries_in_Row = (bsr_row_ptr[i + 1] - bsr_row_ptr[i]) * block_dim; int entries_in_row_sum = (bsr_row_ptr[i] - bsr_base) * entries_in_block; for(int j = bsr_row_ptr[i] - bsr_base; j < bsr_row_ptr[i + 1] - bsr_base; j++) { int col = bsr_col_ind[j] - bsr_base; int offset = entries_in_row_sum + block_dim * (j - (bsr_row_ptr[i] - bsr_base)); for(int k = 0; k < block_dim; k++) { for(int l = 0; l < block_dim; l++) { csr_col_ind[offset + k * entries_in_Row + l] = block_dim * col + l + csr_base; if(direction == HIPSPARSE_DIRECTION_ROW) { csr_val[offset + k * entries_in_Row + l] = bsr_val[j * entries_in_block + k * block_dim + l]; } else { csr_val[offset + k * entries_in_Row + l] = bsr_val[j * entries_in_block + k + block_dim * l]; } } } } } } template inline void host_bsrmv(hipsparseDirection_t dir, hipsparseOperation_t trans, int mb, int nb, int nnzb, T alpha, const int* bsr_row_ptr, const int* bsr_col_ind, const T* bsr_val, int bsr_dim, const T* x, T beta, T* y, hipsparseIndexBase_t base) { // Quick return if(alpha == make_DataType(0)) { if(beta != make_DataType(1)) { for(int i = 0; i < mb * bsr_dim; ++i) { y[i] = testing_mult(beta, y[i]); } } return; } int WFSIZE; if(bsr_dim == 2) { int blocks_per_row = nnzb / mb; if(blocks_per_row < 8) { WFSIZE = 4; } else if(blocks_per_row < 16) { WFSIZE = 8; } else if(blocks_per_row < 32) { WFSIZE = 16; } else if(blocks_per_row < 64) { WFSIZE = 32; } else { WFSIZE = 64; } } else if(bsr_dim <= 8) { WFSIZE = 8; } else if(bsr_dim <= 16) { WFSIZE = 16; } else { WFSIZE = 32; } #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int row = 0; row < mb; ++row) { int row_begin = bsr_row_ptr[row] - base; int row_end = bsr_row_ptr[row + 1] - base; if(bsr_dim == 2) { std::vector sum0(WFSIZE, make_DataType(0)); std::vector sum1(WFSIZE, make_DataType(0)); for(int j = row_begin; j < row_end; j += WFSIZE) { for(int k = 0; k < WFSIZE; ++k) { if(j + k < row_end) { int col = bsr_col_ind[j + k] - base; if(dir == HIPSPARSE_DIRECTION_COLUMN) { sum0[k] = testing_fma(bsr_val[bsr_dim * bsr_dim * (j + k) + 0], x[col * bsr_dim + 0], sum0[k]); sum1[k] = testing_fma(bsr_val[bsr_dim * bsr_dim * (j + k) + 1], x[col * bsr_dim + 0], sum1[k]); sum0[k] = testing_fma(bsr_val[bsr_dim * bsr_dim * (j + k) + 2], x[col * bsr_dim + 1], sum0[k]); sum1[k] = testing_fma(bsr_val[bsr_dim * bsr_dim * (j + k) + 3], x[col * bsr_dim + 1], sum1[k]); } else { sum0[k] = testing_fma(bsr_val[bsr_dim * bsr_dim * (j + k) + 0], x[col * bsr_dim + 0], sum0[k]); sum0[k] = testing_fma(bsr_val[bsr_dim * bsr_dim * (j + k) + 1], x[col * bsr_dim + 1], sum0[k]); sum1[k] = testing_fma(bsr_val[bsr_dim * bsr_dim * (j + k) + 2], x[col * bsr_dim + 0], sum1[k]); sum1[k] = testing_fma(bsr_val[bsr_dim * bsr_dim * (j + k) + 3], x[col * bsr_dim + 1], sum1[k]); } } } } for(int j = 1; j < WFSIZE; j <<= 1) { for(int k = 0; k < WFSIZE - j; ++k) { sum0[k] = sum0[k] + sum0[k + j]; sum1[k] = sum1[k] + sum1[k + j]; } } if(beta != make_DataType(0)) { y[row * bsr_dim + 0] = testing_fma(beta, y[row * bsr_dim + 0], testing_mult(alpha, sum0[0])); y[row * bsr_dim + 1] = testing_fma(beta, y[row * bsr_dim + 1], testing_mult(alpha, sum1[0])); } else { y[row * bsr_dim + 0] = testing_mult(alpha, sum0[0]); y[row * bsr_dim + 1] = testing_mult(alpha, sum1[0]); } } else { for(int bi = 0; bi < bsr_dim; ++bi) { std::vector sum(WFSIZE, make_DataType(0)); for(int j = row_begin; j < row_end; ++j) { int col = bsr_col_ind[j] - base; for(int bj = 0; bj < bsr_dim; bj += WFSIZE) { for(int k = 0; k < WFSIZE; ++k) { if(bj + k < bsr_dim) { if(dir == HIPSPARSE_DIRECTION_COLUMN) { sum[k] = testing_fma( bsr_val[bsr_dim * bsr_dim * j + bsr_dim * (bj + k) + bi], x[bsr_dim * col + (bj + k)], sum[k]); } else { sum[k] = testing_fma( bsr_val[bsr_dim * bsr_dim * j + bsr_dim * bi + (bj + k)], x[bsr_dim * col + (bj + k)], sum[k]); } } } } } for(int j = 1; j < WFSIZE; j <<= 1) { for(int k = 0; k < WFSIZE - j; ++k) { sum[k] = sum[k] + sum[k + j]; } } if(beta != make_DataType(0)) { y[row * bsr_dim + bi] = testing_fma(beta, y[row * bsr_dim + bi], testing_mult(alpha, sum[0])); } else { y[row * bsr_dim + bi] = testing_mult(alpha, sum[0]); } } } } } template inline void host_csrmv(hipsparseOperation_t trans, J M, J N, I nnz, T alpha, const I* csr_row_ptr, const J* csr_col_ind, const T* csr_val, const T* x, T beta, T* y, hipsparseIndexBase_t base) { if(trans == HIPSPARSE_OPERATION_NON_TRANSPOSE) { // Get device properties int dev; hipDeviceProp_t prop; std::ignore = hipGetDevice(&dev); std::ignore = hipGetDeviceProperties(&prop, dev); int WF_SIZE; J nnz_per_row = (M == 0) ? 0 : (nnz / M); if(nnz_per_row < 4) WF_SIZE = 2; else if(nnz_per_row < 8) WF_SIZE = 4; else if(nnz_per_row < 16) WF_SIZE = 8; else if(nnz_per_row < 32) WF_SIZE = 16; else if(nnz_per_row < 64 || prop.warpSize == 32) WF_SIZE = 32; else WF_SIZE = 64; for(J i = 0; i < M; ++i) { I row_begin = csr_row_ptr[i] - base; I row_end = csr_row_ptr[i + 1] - base; std::vector sum(WF_SIZE, static_cast(0)); for(I j = row_begin; j < row_end; j += WF_SIZE) { for(int k = 0; k < WF_SIZE; ++k) { if(j + k < row_end) { sum[k] = testing_fma(testing_mult(alpha, csr_val[j + k]), x[csr_col_ind[j + k] - base], sum[k]); } } } for(int j = 1; j < WF_SIZE; j <<= 1) { for(int k = 0; k < WF_SIZE - j; ++k) { sum[k] = sum[k] + sum[k + j]; } } if(beta == make_DataType(0.0)) { y[i] = sum[0]; } else { y[i] = testing_fma(beta, y[i], sum[0]); } } } else { // Scale y with beta for(J i = 0; i < N; ++i) { y[i] = testing_mult(y[i], beta); } // Transposed SpMV for(J i = 0; i < M; ++i) { I row_begin = csr_row_ptr[i] - base; I row_end = csr_row_ptr[i + 1] - base; T row_val = testing_mult(alpha, x[i]); for(I j = row_begin; j < row_end; ++j) { J col = csr_col_ind[j] - base; T val = (trans == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE) ? testing_conj(csr_val[j]) : csr_val[j]; y[col] = testing_fma(val, row_val, y[col]); } } } } template inline void host_bsrmm(int Mb, int N, int Kb, int block_dim, hipsparseDirection_t dir, hipsparseOperation_t transA, hipsparseOperation_t transB, T alpha, const std::vector& bsr_row_ptr_A, const std::vector& bsr_col_ind_A, const std::vector& bsr_val_A, const std::vector& B, int ldb, T beta, std::vector& C, int ldc, hipsparseIndexBase_t base) { if(transA != HIPSPARSE_OPERATION_NON_TRANSPOSE) { return; } if(transB != HIPSPARSE_OPERATION_NON_TRANSPOSE && transB != HIPSPARSE_OPERATION_TRANSPOSE) { return; } int M = Mb * block_dim; #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < M; i++) { int local_row = i % block_dim; int row_begin = bsr_row_ptr_A[i / block_dim] - base; int row_end = bsr_row_ptr_A[i / block_dim + 1] - base; for(int j = 0; j < N; j++) { int idx_C = i + j * ldc; T sum = make_DataType(0.0); for(int s = row_begin; s < row_end; s++) { for(int t = 0; t < block_dim; t++) { int idx_A = (dir == HIPSPARSE_DIRECTION_ROW) ? block_dim * block_dim * s + block_dim * local_row + t : block_dim * block_dim * s + block_dim * t + local_row; int idx_B = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? j * ldb + block_dim * (bsr_col_ind_A[s] - base) + t : (block_dim * (bsr_col_ind_A[s] - base) + t) * ldb + j; sum = sum + testing_mult(alpha, testing_mult(bsr_val_A[idx_A], B[idx_B])); } } if(beta == make_DataType(0.0)) { C[idx_C] = sum; } else { C[idx_C] = sum + testing_mult(beta, C[idx_C]); } } } } template void host_csrmm(J M, J N, J K, hipsparseOperation_t transA, hipsparseOperation_t transB, T alpha, const I* csr_row_ptr_A, const J* csr_col_ind_A, const T* csr_val_A, const T* B, J ldb, hipsparseOrder_t orderB, T beta, T* C, J ldc, hipsparseOrder_t orderC, hipsparseIndexBase_t base, bool force_conj_A) { bool conj_A = (transA == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE || force_conj_A); bool conj_B = (transB == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE); if(transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) { #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(J i = 0; i < M; i++) { for(J j = 0; j < N; ++j) { I row_begin = csr_row_ptr_A[i] - base; I row_end = csr_row_ptr_A[i + 1] - base; J idx_C = orderC == HIPSPARSE_ORDER_COL ? i + j * ldc : i * ldc + j; T sum = make_DataType(0); for(I k = row_begin; k < row_end; ++k) { J idx_B = 0; if((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE && orderB == HIPSPARSE_ORDER_COL) || (transB == HIPSPARSE_OPERATION_TRANSPOSE && orderB != HIPSPARSE_ORDER_COL) || (transB == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE && orderB != HIPSPARSE_ORDER_COL)) { idx_B = (csr_col_ind_A[k] - base + j * ldb); } else { idx_B = (j + (csr_col_ind_A[k] - base) * ldb); } sum = testing_fma( testing_conj(csr_val_A[k], conj_A), testing_conj(B[idx_B], conj_B), sum); } if(beta == make_DataType(0)) { C[idx_C] = testing_mult(alpha, sum); } else { C[idx_C] = testing_fma(beta, C[idx_C], testing_mult(alpha, sum)); } } } } else { // scale C by beta for(J i = 0; i < K; i++) { for(J j = 0; j < N; ++j) { J idx_C = (orderC == HIPSPARSE_ORDER_COL) ? i + j * ldc : i * ldc + j; C[idx_C] = testing_mult(beta, C[idx_C]); } } for(J i = 0; i < M; i++) { I row_begin = csr_row_ptr_A[i] - base; I row_end = csr_row_ptr_A[i + 1] - base; for(J j = 0; j < N; ++j) { for(I k = row_begin; k < row_end; ++k) { J col = csr_col_ind_A[k] - base; T val = testing_conj(csr_val_A[k], conj_A); J idx_B = 0; if((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE && orderB == HIPSPARSE_ORDER_COL) || (transB == HIPSPARSE_OPERATION_TRANSPOSE && orderB != HIPSPARSE_ORDER_COL) || (transB == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE && orderB != HIPSPARSE_ORDER_COL)) { idx_B = (i + j * ldb); } else { idx_B = (j + i * ldb); } J idx_C = (orderC == HIPSPARSE_ORDER_COL) ? col + j * ldc : col * ldc + j; C[idx_C] = C[idx_C] + testing_mult(alpha, testing_mult(val, testing_conj(B[idx_B], conj_B))); } } } } } template void host_csrmm_batched(J M, J N, J K, J batch_count_A, J offsets_batch_stride_A, I columns_values_batch_stride_A, hipsparseOperation_t transA, hipsparseOperation_t transB, T alpha, const I* csr_row_ptr_A, const J* csr_col_ind_A, const T* csr_val_A, const T* B, J ldb, J batch_count_B, I batch_stride_B, hipsparseOrder_t order_B, T beta, T* C, J ldc, J batch_count_C, I batch_stride_C, hipsparseOrder_t order_C, hipsparseIndexBase_t base, bool force_conj_A) { bool Ci_A_Bi = (batch_count_A == 1 && batch_count_B == batch_count_C); bool Ci_Ai_B = (batch_count_B == 1 && batch_count_A == batch_count_C); bool Ci_Ai_Bi = (batch_count_A == batch_count_C && batch_count_A == batch_count_B); if(!Ci_A_Bi && !Ci_Ai_B && !Ci_Ai_Bi) { return; } if(Ci_A_Bi) { for(J i = 0; i < batch_count_C; i++) { host_csrmm(M, N, K, transA, transB, alpha, csr_row_ptr_A, csr_col_ind_A, csr_val_A, B + batch_stride_B * i, ldb, order_B, beta, C + batch_stride_C * i, ldc, order_C, base, force_conj_A); } } else if(Ci_Ai_B) { for(J i = 0; i < batch_count_C; i++) { host_csrmm(M, N, K, transA, transB, alpha, csr_row_ptr_A + offsets_batch_stride_A * i, csr_col_ind_A + columns_values_batch_stride_A * i, csr_val_A + columns_values_batch_stride_A * i, B, ldb, order_B, beta, C + batch_stride_C * i, ldc, order_C, base, force_conj_A); } } else if(Ci_Ai_Bi) { for(J i = 0; i < batch_count_C; i++) { host_csrmm(M, N, K, transA, transB, alpha, csr_row_ptr_A + offsets_batch_stride_A * i, csr_col_ind_A + columns_values_batch_stride_A * i, csr_val_A + columns_values_batch_stride_A * i, B + batch_stride_B * i, ldb, order_B, beta, C + batch_stride_C * i, ldc, order_C, base, force_conj_A); } } } template void host_cscmm(J M, J N, J K, hipsparseOperation_t transA, hipsparseOperation_t transB, T alpha, const I* csc_col_ptr_A, const J* csc_row_ind_A, const T* csc_val_A, const T* B, J ldb, hipsparseOrder_t order_B, T beta, T* C, J ldc, hipsparseOrder_t order_C, hipsparseIndexBase_t base) { switch(transA) { case HIPSPARSE_OPERATION_NON_TRANSPOSE: { return host_csrmm(K, N, M, HIPSPARSE_OPERATION_TRANSPOSE, transB, alpha, csc_col_ptr_A, csc_row_ind_A, csc_val_A, B, ldb, order_B, beta, C, ldc, order_C, base, false); } case HIPSPARSE_OPERATION_TRANSPOSE: { return host_csrmm(K, N, M, HIPSPARSE_OPERATION_NON_TRANSPOSE, transB, alpha, csc_col_ptr_A, csc_row_ind_A, csc_val_A, B, ldb, order_B, beta, C, ldc, order_C, base, false); } case HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE: { return host_csrmm(K, N, M, HIPSPARSE_OPERATION_NON_TRANSPOSE, transB, alpha, csc_col_ptr_A, csc_row_ind_A, csc_val_A, B, ldb, order_B, beta, C, ldc, order_C, base, true); } } } template void host_cscmm_batched(J M, J N, J K, J batch_count_A, I offsets_batch_stride_A, I rows_values_batch_stride_A, hipsparseOperation_t transA, hipsparseOperation_t transB, T alpha, const I* csc_col_ptr_A, const J* csc_row_ind_A, const T* csc_val_A, const T* B, J ldb, J batch_count_B, I batch_stride_B, hipsparseOrder_t order_B, T beta, T* C, J ldc, J batch_count_C, I batch_stride_C, hipsparseOrder_t order_C, hipsparseIndexBase_t base) { switch(transA) { case HIPSPARSE_OPERATION_NON_TRANSPOSE: { return host_csrmm_batched(K, N, M, batch_count_A, offsets_batch_stride_A, rows_values_batch_stride_A, HIPSPARSE_OPERATION_TRANSPOSE, transB, alpha, csc_col_ptr_A, csc_row_ind_A, csc_val_A, B, ldb, batch_count_B, batch_stride_B, order_B, beta, C, ldc, batch_count_C, batch_stride_C, order_C, base, false); } case HIPSPARSE_OPERATION_TRANSPOSE: { return host_csrmm_batched(K, N, M, batch_count_A, offsets_batch_stride_A, rows_values_batch_stride_A, HIPSPARSE_OPERATION_NON_TRANSPOSE, transB, alpha, csc_col_ptr_A, csc_row_ind_A, csc_val_A, B, ldb, batch_count_B, batch_stride_B, order_B, beta, C, ldc, batch_count_C, batch_stride_C, order_C, base, false); } case HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE: { return host_csrmm_batched(K, N, M, batch_count_A, offsets_batch_stride_A, rows_values_batch_stride_A, HIPSPARSE_OPERATION_NON_TRANSPOSE, transB, alpha, csc_col_ptr_A, csc_row_ind_A, csc_val_A, B, ldb, batch_count_B, batch_stride_B, order_B, beta, C, ldc, batch_count_C, batch_stride_C, order_C, base, true); } } } template void host_coomm(I M, I N, I K, I nnz, hipsparseOperation_t transA, hipsparseOperation_t transB, T alpha, const I* coo_row_ind_A, const I* coo_col_ind_A, const T* coo_val_A, const T* B, I ldb, hipsparseOrder_t order_B, T beta, T* C, I ldc, hipsparseOrder_t order_C, hipsparseIndexBase_t base) { bool conj_A = (transA == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE); bool conj_B = (transB == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE); if(transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) { for(I j = 0; j < N; j++) { #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(I i = 0; i < M; ++i) { I idx_C = (order_C == HIPSPARSE_ORDER_COL) ? i + j * ldc : i * ldc + j; C[idx_C] = testing_mult(beta, C[idx_C]); } } #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(I j = 0; j < N; j++) { for(I i = 0; i < nnz; ++i) { I row = coo_row_ind_A[i] - base; I col = coo_col_ind_A[i] - base; T val = testing_mult(alpha, coo_val_A[i]); I idx_C = (order_C == HIPSPARSE_ORDER_COL) ? row + j * ldc : row * ldc + j; I idx_B = 0; if((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE && order_B == HIPSPARSE_ORDER_COL) || (transB != HIPSPARSE_OPERATION_NON_TRANSPOSE && order_B != HIPSPARSE_ORDER_COL)) { idx_B = (col + j * ldb); } else { idx_B = (j + col * ldb); } C[idx_C] = testing_fma(val, testing_conj(B[idx_B], conj_B), C[idx_C]); } } } else { for(I j = 0; j < N; j++) { #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(I i = 0; i < K; ++i) { I idx_C = (order_C == HIPSPARSE_ORDER_COL) ? i + j * ldc : i * ldc + j; C[idx_C] = testing_mult(beta, C[idx_C]); } } #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(I j = 0; j < N; j++) { for(I i = 0; i < nnz; ++i) { I row = coo_row_ind_A[i] - base; I col = coo_col_ind_A[i] - base; T val = testing_mult(alpha, testing_conj(coo_val_A[i], conj_A)); I idx_C = (order_C == HIPSPARSE_ORDER_COL) ? col + j * ldc : col * ldc + j; I idx_B = 0; if((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE && order_B == HIPSPARSE_ORDER_COL) || (transB != HIPSPARSE_OPERATION_NON_TRANSPOSE && order_B != HIPSPARSE_ORDER_COL)) { idx_B = (row + j * ldb); } else { idx_B = (j + row * ldb); } C[idx_C] = testing_fma(val, testing_conj(B[idx_B], conj_B), C[idx_C]); } } } } template void host_coomm_batched(I M, I N, I K, I nnz, I batch_count_A, I batch_stride_A, hipsparseOperation_t transA, hipsparseOperation_t transB, T alpha, const I* coo_row_ind_A, const I* coo_col_ind_A, const T* coo_val_A, const T* B, I ldb, I batch_count_B, I batch_stride_B, hipsparseOrder_t order_B, T beta, T* C, I ldc, I batch_count_C, I batch_stride_C, hipsparseOrder_t order_C, hipsparseIndexBase_t base) { bool Ci_A_Bi = (batch_count_A == 1 && batch_count_B == batch_count_C); bool Ci_Ai_B = (batch_count_B == 1 && batch_count_A == batch_count_C); bool Ci_Ai_Bi = (batch_count_A == batch_count_C && batch_count_A == batch_count_B); if(!Ci_A_Bi && !Ci_Ai_B && !Ci_Ai_Bi) { return; } if(Ci_A_Bi) { for(I i = 0; i < batch_count_C; i++) { host_coomm(M, N, K, nnz, transA, transB, alpha, coo_row_ind_A, coo_col_ind_A, coo_val_A, B + batch_stride_B * i, ldb, order_B, beta, C + batch_stride_C * i, ldc, order_C, base); } } else if(Ci_Ai_B) { for(I i = 0; i < batch_count_C; i++) { host_coomm(M, N, K, nnz, transA, transB, alpha, coo_row_ind_A + batch_stride_A * i, coo_col_ind_A + batch_stride_A * i, coo_val_A + batch_stride_A * i, B, ldb, order_B, beta, C + batch_stride_C * i, ldc, order_C, base); } } else if(Ci_Ai_Bi) { for(I i = 0; i < batch_count_C; i++) { host_coomm(M, N, K, nnz, transA, transB, alpha, coo_row_ind_A + batch_stride_A * i, coo_col_ind_A + batch_stride_A * i, coo_val_A + batch_stride_A * i, B + batch_stride_B * i, ldb, order_B, beta, C + batch_stride_C * i, ldc, order_C, base); } } } template int csrilu0(int m, const int* ptr, const int* col, T* val, hipsparseIndexBase_t idx_base, bool boost, double boost_tol, T boost_val) { // pointer of upper part of each row std::vector diag_offset(m); std::vector nnz_entries(m, 0); // ai = 0 to N loop over all rows for(int ai = 0; ai < m; ++ai) { // ai-th row entries int row_start = ptr[ai] - idx_base; int row_end = ptr[ai + 1] - idx_base; int j; // nnz position of ai-th row in val array for(j = row_start; j < row_end; ++j) { nnz_entries[col[j] - idx_base] = j; } bool has_diag = false; // loop over ai-th row nnz entries for(j = row_start; j < row_end; ++j) { // if nnz entry is in lower matrix if(col[j] - idx_base < ai) { int col_j = col[j] - idx_base; int diag_j = diag_offset[col_j]; T diag_val = val[diag_j]; if(boost) { diag_val = (boost_tol >= testing_abs(diag_val)) ? boost_val : diag_val; val[diag_j] = diag_val; } else { // Check for numeric pivot if(diag_val == make_DataType(0.0)) { // Numerical zero diagonal return col_j + idx_base; } } // multiplication factor val[j] = testing_div(val[j], diag_val); // loop over upper offset pointer and do linear combination for nnz entry for(int k = diag_j + 1; k < ptr[col_j + 1] - idx_base; ++k) { // if nnz at this position do linear combination if(nnz_entries[col[k] - idx_base] != 0) { int idx = nnz_entries[col[k] - idx_base]; val[idx] = testing_fma(testing_neg(val[j]), val[k], val[idx]); } } } else if(col[j] - idx_base == ai) { has_diag = true; break; } else { break; } } if(!has_diag) { // Structural zero digonal return ai + idx_base; } // set diagonal pointer to diagonal element diag_offset[ai] = j; // clear nnz entries for(j = row_start; j < row_end; ++j) { nnz_entries[col[j] - idx_base] = 0; } } return -1; } template inline void host_bsrilu02(hipsparseDirection_t dir, int mb, int bsr_dim, const std::vector& bsr_row_ptr, const std::vector& bsr_col_ind, std::vector& bsr_val, hipsparseIndexBase_t base, int* struct_pivot, int* numeric_pivot, bool boost, double boost_tol, T boost_val) { // Initialize pivots *struct_pivot = mb + 1; *numeric_pivot = mb + 1; // Temporary vector to hold diagonal offset to access diagonal BSR block std::vector diag_offset(mb); std::vector nnz_entries(mb, -1); // First diagonal block is index 0 if(mb > 0) { diag_offset[0] = 0; } // Loop over all BSR rows for(int i = 0; i < mb; ++i) { // Flag whether we have a diagonal block or not bool has_diag = false; // BSR column entry and exit point int row_begin = bsr_row_ptr[i] - base; int row_end = bsr_row_ptr[i + 1] - base; int j; // Set up entry points for linear combination for(j = row_begin; j < row_end; ++j) { int col_j = bsr_col_ind[j] - base; nnz_entries[col_j] = j; } // Process lower diagonal BSR blocks (diagonal BSR block is excluded) for(j = row_begin; j < row_end; ++j) { // Column index of current BSR block int bsr_col = bsr_col_ind[j] - base; // If this is a diagonal block, set diagonal flag to true and skip // all upcoming blocks as we exceed the lower matrix part if(bsr_col == i) { has_diag = true; break; } // Skip all upper matrix blocks if(bsr_col > i) { break; } // Process all lower matrix BSR blocks // Obtain corresponding row entry and exit point that corresponds with the // current BSR column. Actually, we skip all lower matrix column indices, // therefore starting with the diagonal entry. int diag_j = diag_offset[bsr_col]; int row_end_j = bsr_row_ptr[bsr_col + 1] - base; // Loop through all rows within the BSR block for(int bi = 0; bi < bsr_dim; ++bi) { T diag = bsr_val[BSR_IND(diag_j, bi, bi, dir)]; // Process all rows within the BSR block for(int bk = 0; bk < bsr_dim; ++bk) { T val = bsr_val[BSR_IND(j, bk, bi, dir)]; // Multiplication factor bsr_val[BSR_IND(j, bk, bi, dir)] = val = testing_div(val, diag); // Loop through columns of bk-th row and do linear combination for(int bj = bi + 1; bj < bsr_dim; ++bj) { bsr_val[BSR_IND(j, bk, bj, dir)] = testing_fma(-val, bsr_val[BSR_IND(diag_j, bi, bj, dir)], bsr_val[BSR_IND(j, bk, bj, dir)]); } } } // Loop over upper offset pointer and do linear combination for nnz entry for(int k = diag_j + 1; k < row_end_j; ++k) { int bsr_col_k = bsr_col_ind[k] - base; if(nnz_entries[bsr_col_k] != -1) { int m = nnz_entries[bsr_col_k]; // Loop through all rows within the BSR block for(int bi = 0; bi < bsr_dim; ++bi) { // Loop through columns of bi-th row and do linear combination for(int bj = 0; bj < bsr_dim; ++bj) { T sum = make_DataType(0); for(int bk = 0; bk < bsr_dim; ++bk) { sum = testing_fma(bsr_val[BSR_IND(j, bi, bk, dir)], bsr_val[BSR_IND(k, bk, bj, dir)], sum); } bsr_val[BSR_IND(m, bi, bj, dir)] = bsr_val[BSR_IND(m, bi, bj, dir)] - sum; } } } } } // Check for structural pivot if(!has_diag) { *struct_pivot = std::min(*struct_pivot, i + base); break; } // Process diagonal if(bsr_col_ind[j] - base == i) { // Loop through all rows within the BSR block for(int bi = 0; bi < bsr_dim; ++bi) { T diag = bsr_val[BSR_IND(j, bi, bi, dir)]; if(boost) { diag = (boost_tol >= testing_abs(diag)) ? boost_val : diag; bsr_val[BSR_IND(j, bi, bi, dir)] = diag; } else { // Check for numeric pivot if(diag == make_DataType(0)) { *numeric_pivot = std::min(*numeric_pivot, bsr_col_ind[j]); continue; } } // Process all rows within the BSR block after bi-th row for(int bk = bi + 1; bk < bsr_dim; ++bk) { T val = bsr_val[BSR_IND(j, bk, bi, dir)]; // Multiplication factor bsr_val[BSR_IND(j, bk, bi, dir)] = val = testing_div(val, diag); // Loop through remaining columns of bk-th row and do linear combination for(int bj = bi + 1; bj < bsr_dim; ++bj) { bsr_val[BSR_IND(j, bk, bj, dir)] = testing_fma(-val, bsr_val[BSR_IND(j, bi, bj, dir)], bsr_val[BSR_IND(j, bk, bj, dir)]); } } } } // Store diagonal BSR block entry point int row_diag = diag_offset[i] = j; // Process upper diagonal BSR blocks for(j = row_diag + 1; j < row_end; ++j) { // Loop through all rows within the BSR block for(int bi = 0; bi < bsr_dim; ++bi) { // Process all rows within the BSR block after bi-th row for(int bk = bi + 1; bk < bsr_dim; ++bk) { // Loop through columns of bk-th row and do linear combination for(int bj = 0; bj < bsr_dim; ++bj) { bsr_val[BSR_IND(j, bk, bj, dir)] = testing_fma(-bsr_val[BSR_IND(row_diag, bk, bi, dir)], bsr_val[BSR_IND(j, bi, bj, dir)], bsr_val[BSR_IND(j, bk, bj, dir)]); } } } } // Reset entry points for(j = row_begin; j < row_end; ++j) { int col_j = bsr_col_ind[j] - base; nnz_entries[col_j] = -1; } } *struct_pivot = (*struct_pivot == mb + 1) ? -1 : *struct_pivot; *numeric_pivot = (*numeric_pivot == mb + 1) ? -1 : *numeric_pivot; } template inline void host_bsric02(hipsparseDirection_t direction, int Mb, int block_dim, const std::vector& bsr_row_ptr, const std::vector& bsr_col_ind, std::vector& bsr_val, hipsparseIndexBase_t base, int* struct_pivot, int* numeric_pivot) { int M = Mb * block_dim; // Initialize pivot *struct_pivot = -1; *numeric_pivot = -1; if(bsr_col_ind.size() == 0 && bsr_val.size() == 0) { return; } // pointer of upper part of each row std::vector diag_block_offset(Mb); std::vector diag_offset(M, -1); std::vector nnz_entries(M, -1); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < Mb; i++) { int row_begin = bsr_row_ptr[i] - base; int row_end = bsr_row_ptr[i + 1] - base; for(int j = row_begin; j < row_end; j++) { if(bsr_col_ind[j] - base == i) { diag_block_offset[i] = j; break; } } } for(int i = 0; i < M; i++) { int local_row = i % block_dim; int row_begin = bsr_row_ptr[i / block_dim] - base; int row_end = bsr_row_ptr[i / block_dim + 1] - base; for(int j = row_begin; j < row_end; j++) { int block_col_j = bsr_col_ind[j] - base; for(int k = 0; k < block_dim; k++) { if(direction == HIPSPARSE_DIRECTION_ROW) { nnz_entries[block_dim * block_col_j + k] = block_dim * block_dim * j + block_dim * local_row + k; } else { nnz_entries[block_dim * block_col_j + k] = block_dim * block_dim * j + block_dim * k + local_row; } } } T sum = make_DataType(0); int diag_val_index = -1; bool has_diag = false; bool break_outer_loop = false; for(int j = row_begin; j < row_end; j++) { int block_col_j = bsr_col_ind[j] - base; for(int k = 0; k < block_dim; k++) { int col_j = block_dim * block_col_j + k; // Mark diagonal and skip row if(col_j == i) { diag_val_index = block_dim * block_dim * j + block_dim * k + k; has_diag = true; break_outer_loop = true; break; } // Skip upper triangular if(col_j > i) { break_outer_loop = true; break; } T val_j; if(direction == HIPSPARSE_DIRECTION_ROW) { val_j = bsr_val[block_dim * block_dim * j + block_dim * local_row + k]; } else { val_j = bsr_val[block_dim * block_dim * j + block_dim * k + local_row]; } int local_row_j = col_j % block_dim; int row_begin_j = bsr_row_ptr[col_j / block_dim] - base; int row_end_j = diag_block_offset[col_j / block_dim]; int row_diag_j = diag_offset[col_j]; T local_sum = make_DataType(0); T inv_diag = row_diag_j != -1 ? bsr_val[row_diag_j] : make_DataType(0); // Check for numeric zero if(inv_diag == make_DataType(0)) { // Numerical non-invertible block diagonal if(*numeric_pivot == -1) { *numeric_pivot = block_col_j + base; } *numeric_pivot = std::min(*numeric_pivot, block_col_j + base); inv_diag = make_DataType(1); } inv_diag = testing_div(make_DataType(1), inv_diag); // loop over upper offset pointer and do linear combination for nnz entry for(int l = row_begin_j; l < row_end_j + 1; l++) { int block_col_l = bsr_col_ind[l] - base; for(int m = 0; m < block_dim; m++) { int idx = nnz_entries[block_dim * block_col_l + m]; if(idx != -1 && block_dim * block_col_l + m < col_j) { if(direction == HIPSPARSE_DIRECTION_ROW) { local_sum = testing_fma(bsr_val[block_dim * block_dim * l + block_dim * local_row_j + m], testing_conj(bsr_val[idx]), local_sum); } else { local_sum = testing_fma(bsr_val[block_dim * block_dim * l + block_dim * m + local_row_j], testing_conj(bsr_val[idx]), local_sum); } } } } val_j = testing_mult((val_j - local_sum), inv_diag); sum = testing_fma(val_j, testing_conj(val_j), sum); if(direction == HIPSPARSE_DIRECTION_ROW) { bsr_val[block_dim * block_dim * j + block_dim * local_row + k] = val_j; } else { bsr_val[block_dim * block_dim * j + block_dim * k + local_row] = val_j; } } if(break_outer_loop) { break; } } if(!has_diag) { // Structural missing block diagonal if(*struct_pivot == -1) { *struct_pivot = i / block_dim + base; } } // Process diagonal entry if(has_diag) { T diag_entry = make_DataType(std::sqrt(testing_abs(bsr_val[diag_val_index] - sum))); bsr_val[diag_val_index] = diag_entry; if(diag_entry == make_DataType(0)) { // Numerical non-invertible block diagonal if(*numeric_pivot == -1) { *numeric_pivot = i / block_dim + base; } *numeric_pivot = std::min(*numeric_pivot, i / block_dim + base); } // Store diagonal offset diag_offset[i] = diag_val_index; } for(int j = row_begin; j < row_end; j++) { int block_col_j = bsr_col_ind[j] - base; for(int k = 0; k < block_dim; k++) { if(direction == HIPSPARSE_DIRECTION_ROW) { nnz_entries[block_dim * block_col_j + k] = -1; } else { nnz_entries[block_dim * block_col_j + k] = -1; } } } } } template void csric0(int M, const int* csr_row_ptr, const int* csr_col_ind, T* csr_val, hipsparseIndexBase_t idx_base, int& struct_pivot, int& numeric_pivot) { // Initialize pivot struct_pivot = -1; numeric_pivot = -1; // pointer of upper part of each row std::vector diag_offset(M); std::vector nnz_entries(M, 0); // ai = 0 to N loop over all rows for(int ai = 0; ai < M; ++ai) { // ai-th row entries int row_begin = csr_row_ptr[ai] - idx_base; int row_end = csr_row_ptr[ai + 1] - idx_base; int j; // nnz position of ai-th row in val array for(j = row_begin; j < row_end; ++j) { nnz_entries[csr_col_ind[j] - idx_base] = j; } T sum = make_DataType(0.0); bool has_diag = false; // loop over ai-th row nnz entries for(j = row_begin; j < row_end; ++j) { int col_j = csr_col_ind[j] - idx_base; T val_j = csr_val[j]; // Mark diagonal and skip row if(col_j == ai) { has_diag = true; break; } // Skip upper triangular if(col_j > ai) { break; } int row_begin_j = csr_row_ptr[col_j] - idx_base; int row_diag_j = diag_offset[col_j]; T local_sum = make_DataType(0.0); T inv_diag = csr_val[row_diag_j]; // Check for numeric zero if(inv_diag == make_DataType(0.0)) { // Numerical zero diagonal numeric_pivot = col_j + idx_base; return; } inv_diag = testing_div(make_DataType(1.0), inv_diag); // loop over upper offset pointer and do linear combination for nnz entry for(int k = row_begin_j; k < row_diag_j; ++k) { int col_k = csr_col_ind[k] - idx_base; // if nnz at this position do linear combination if(nnz_entries[col_k] != 0) { int idx = nnz_entries[col_k]; local_sum = testing_fma(csr_val[k], testing_conj(csr_val[idx]), local_sum); } } val_j = testing_mult((val_j - local_sum), inv_diag); sum = testing_fma(val_j, testing_conj(val_j), sum); csr_val[j] = val_j; } if(!has_diag) { // Structural (and numerical) zero diagonal struct_pivot = ai + idx_base; numeric_pivot = ai + idx_base; return; } // Process diagonal entry T diag_entry = make_DataType(std::sqrt(testing_abs(csr_val[j] - sum))); csr_val[j] = diag_entry; // Store diagonal offset diag_offset[ai] = j; // clear nnz entries for(j = row_begin; j < row_end; ++j) { nnz_entries[csr_col_ind[j] - idx_base] = 0; } } } /* ============================================================================================ */ /*! \brief Sparse triangular system solve using CSR storage format. */ template static inline void host_lssolve(J M, J nrhs, hipsparseOperation_t transB, T alpha, const std::vector& csr_row_ptr, const std::vector& csr_col_ind, const std::vector& csr_val, std::vector& B, J ldb, hipsparseOrder_t order_B, hipsparseDiagType_t diag_type, hipsparseIndexBase_t base, J* struct_pivot, J* numeric_pivot) { // Get device properties int dev; hipDeviceProp_t prop; std::ignore = hipGetDevice(&dev); std::ignore = hipGetDeviceProperties(&prop, dev); #ifdef _OPENMP #pragma omp parallel for #endif for(J i = 0; i < nrhs; ++i) { std::vector temp(prop.warpSize); // Process lower triangular part for(J row = 0; row < M; ++row) { temp.assign(prop.warpSize, make_DataType(0.0)); J idx_B = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE && order_B == HIPSPARSE_ORDER_COL) ? i * ldb + row : row * ldb + i; if(transB == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE) { temp[0] = testing_mult(alpha, testing_conj(B[idx_B])); } else { temp[0] = testing_mult(alpha, B[idx_B]); } I diag = -1; I row_begin = csr_row_ptr[row] - base; I row_end = csr_row_ptr[row + 1] - base; T diag_val = make_DataType(0.0); for(I l = row_begin; l < row_end; l += prop.warpSize) { for(int k = 0; k < prop.warpSize; ++k) { I j = l + k; // Do not run out of bounds if(j >= row_end) { break; } J local_col = csr_col_ind[j] - base; T local_val = csr_val[j]; if(local_val == make_DataType(0.0) && local_col == row && diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { // Numerical zero pivot found, avoid division by 0 and store // index for later use *numeric_pivot = std::min(*numeric_pivot, row + base); local_val = make_DataType(1.0); } // Ignore all entries that are above the diagonal if(local_col > row) { break; } // Diagonal entry if(local_col == row) { // If diagonal type is non unit, do division by diagonal entry // This is not required for unit diagonal for obvious reasons if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { diag = j; diag_val = testing_div(make_DataType(1.0), local_val); } break; } // Lower triangular part J idx = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE && order_B == HIPSPARSE_ORDER_COL) ? i * ldb + local_col : local_col * ldb + i; T neg_val = testing_mult(make_DataType(-1.0), local_val); if(transB == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE) { temp[k] = testing_fma(neg_val, testing_conj(B[idx]), temp[k]); } else { temp[k] = testing_fma(neg_val, B[idx], temp[k]); } } } for(int j = 1; j < prop.warpSize; j <<= 1) { for(int k = 0; k < prop.warpSize - j; ++k) { temp[k] = temp[k] + temp[k + j]; } } if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { if(diag == -1) { *struct_pivot = std::min(*struct_pivot, row + base); } B[idx_B] = testing_mult(temp[0], diag_val); } else { B[idx_B] = temp[0]; } } } } template static inline void host_ussolve(J M, J nrhs, hipsparseOperation_t transB, T alpha, const std::vector& csr_row_ptr, const std::vector& csr_col_ind, const std::vector& csr_val, std::vector& B, J ldb, hipsparseOrder_t order_B, hipsparseDiagType_t diag_type, hipsparseIndexBase_t base, J* struct_pivot, J* numeric_pivot) { // Get device properties int dev; hipDeviceProp_t prop; std::ignore = hipGetDevice(&dev); std::ignore = hipGetDeviceProperties(&prop, dev); #ifdef _OPENMP #pragma omp parallel for #endif for(J i = 0; i < nrhs; ++i) { std::vector temp(prop.warpSize); // Process upper triangular part for(J row = M - 1; row >= 0; --row) { temp.assign(prop.warpSize, make_DataType(0.0)); J idx_B = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE && order_B == HIPSPARSE_ORDER_COL) ? i * ldb + row : row * ldb + i; if(transB == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE) { temp[0] = testing_mult(alpha, testing_conj(B[idx_B])); } else { temp[0] = testing_mult(alpha, B[idx_B]); } I diag = -1; I row_begin = csr_row_ptr[row] - base; I row_end = csr_row_ptr[row + 1] - base; T diag_val = make_DataType(0.0); for(I l = row_end - 1; l >= row_begin; l -= prop.warpSize) { for(int k = 0; k < prop.warpSize; ++k) { I j = l - k; // Do not run out of bounds if(j < row_begin) { break; } J local_col = csr_col_ind[j] - base; T local_val = csr_val[j]; // Ignore all entries that are below the diagonal if(local_col < row) { continue; } // Diagonal entry if(local_col == row) { if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { // Check for numerical zero if(local_val == make_DataType(0.0)) { *numeric_pivot = std::min(*numeric_pivot, row + base); local_val = make_DataType(1.0); } diag = j; diag_val = testing_div(make_DataType(1.0), local_val); } continue; } // Upper triangular part J idx = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE && order_B == HIPSPARSE_ORDER_COL) ? i * ldb + local_col : local_col * ldb + i; T neg_val = testing_mult(make_DataType(-1.0), local_val); if(transB == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE) { temp[k] = testing_fma(neg_val, testing_conj(B[idx]), temp[k]); } else { temp[k] = testing_fma(neg_val, B[idx], temp[k]); } } } for(int j = 1; j < prop.warpSize; j <<= 1) { for(int k = 0; k < prop.warpSize - j; ++k) { temp[k] = temp[k] + temp[k + j]; } } if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { if(diag == -1) { *struct_pivot = std::min(*struct_pivot, row + base); } B[idx_B] = testing_mult(temp[0], diag_val); } else { B[idx_B] = temp[0]; } } } } template void host_bsrsm(int mb, int nrhs, int nnzb, hipsparseDirection_t dir, hipsparseOperation_t transA, hipsparseOperation_t transX, T alpha, const int* bsr_row_ptr, const int* bsr_col_ind, const T* bsr_val, int bsr_dim, const T* B, int ldb, T* X, int ldx, hipsparseDiagType_t diag_type, hipsparseFillMode_t fill_mode, hipsparseIndexBase_t base, int* struct_pivot, int* numeric_pivot) { // Initialize pivot *struct_pivot = mb + 1; *numeric_pivot = mb + 1; if(transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) { if(fill_mode == HIPSPARSE_FILL_MODE_LOWER) { bsr_lsolve(dir, transX, mb, nrhs, alpha, bsr_row_ptr, bsr_col_ind, bsr_val, bsr_dim, B, ldb, X, ldx, diag_type, base, struct_pivot, numeric_pivot); } else { bsr_usolve(dir, transX, mb, nrhs, alpha, bsr_row_ptr, bsr_col_ind, bsr_val, bsr_dim, B, ldb, X, ldx, diag_type, base, struct_pivot, numeric_pivot); } } else if(transA == HIPSPARSE_OPERATION_TRANSPOSE) { // Transpose matrix std::vector bsrt_row_ptr(mb + 1); std::vector bsrt_col_ind(nnzb); std::vector bsrt_val(nnzb * bsr_dim * bsr_dim); host_bsr_to_bsc(mb, mb, nnzb, bsr_dim, bsr_row_ptr, bsr_col_ind, bsr_val, bsrt_col_ind, bsrt_row_ptr, bsrt_val, base, base); if(fill_mode == HIPSPARSE_FILL_MODE_LOWER) { bsr_usolve(dir, transX, mb, nrhs, alpha, bsrt_row_ptr.data(), bsrt_col_ind.data(), bsrt_val.data(), bsr_dim, B, ldb, X, ldx, diag_type, base, struct_pivot, numeric_pivot); } else { bsr_lsolve(dir, transX, mb, nrhs, alpha, bsrt_row_ptr.data(), bsrt_col_ind.data(), bsrt_val.data(), bsr_dim, B, ldb, X, ldx, diag_type, base, struct_pivot, numeric_pivot); } } *numeric_pivot = std::min(*numeric_pivot, *struct_pivot); *struct_pivot = (*struct_pivot == mb + 1) ? -1 : *struct_pivot; *numeric_pivot = (*numeric_pivot == mb + 1) ? -1 : *numeric_pivot; } template void host_csr_lsolve(J M, T alpha, const I* csr_row_ptr, const J* csr_col_ind, const T* csr_val, const T* x, T* y, hipsparseDiagType_t diag_type, hipsparseIndexBase_t base, J* struct_pivot, J* numeric_pivot) { // Get device properties int dev; hipDeviceProp_t prop; std::ignore = hipGetDevice(&dev); std::ignore = hipGetDeviceProperties(&prop, dev); std::vector temp(prop.warpSize); // Process lower triangular part for(J row = 0; row < M; ++row) { temp.assign(prop.warpSize, make_DataType(0.0)); temp[0] = testing_mult(alpha, x[row]); I diag = -1; I row_begin = csr_row_ptr[row] - base; I row_end = csr_row_ptr[row + 1] - base; T diag_val = make_DataType(0.0); for(I l = row_begin; l < row_end; l += prop.warpSize) { for(int k = 0; k < prop.warpSize; ++k) { I j = l + k; // Do not run out of bounds if(j >= row_end) { break; } J local_col = csr_col_ind[j] - base; T local_val = csr_val[j]; if(local_val == make_DataType(0.0) && local_col == row && diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { // Numerical zero pivot found, avoid division by 0 // and store index for later use. *numeric_pivot = std::min(*numeric_pivot, row + base); local_val = make_DataType(1); } // Ignore all entries that are above the diagonal if(local_col > row) { break; } // Diagonal entry if(local_col == row) { // If diagonal type is non unit, do division by diagonal entry // This is not required for unit diagonal for obvious reasons if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { diag = j; diag_val = testing_div(make_DataType(1), local_val); } break; } // Lower triangular part temp[k] = testing_fma(-local_val, y[local_col], temp[k]); } } for(int j = 1; j < prop.warpSize; j <<= 1) { for(int k = 0; k < prop.warpSize - j; ++k) { temp[k] = temp[k] + temp[k + j]; } } if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { if(diag == -1) { *struct_pivot = std::min(*struct_pivot, row + base); } y[row] = testing_mult(temp[0], diag_val); } else { y[row] = temp[0]; } } } template void host_csr_usolve(J M, T alpha, const I* csr_row_ptr, const J* csr_col_ind, const T* csr_val, const T* x, T* y, hipsparseDiagType_t diag_type, hipsparseIndexBase_t base, J* struct_pivot, J* numeric_pivot) { // Get device properties int dev; hipDeviceProp_t prop; std::ignore = hipGetDevice(&dev); std::ignore = hipGetDeviceProperties(&prop, dev); std::vector temp(prop.warpSize); // Process upper triangular part for(J row = M - 1; row >= 0; --row) { temp.assign(prop.warpSize, make_DataType(0)); temp[0] = testing_mult(alpha, x[row]); I diag = -1; I row_begin = csr_row_ptr[row] - base; I row_end = csr_row_ptr[row + 1] - base; T diag_val = make_DataType(0); for(I l = row_end - 1; l >= row_begin; l -= prop.warpSize) { for(int k = 0; k < prop.warpSize; ++k) { I j = l - k; // Do not run out of bounds if(j < row_begin) { break; } J local_col = csr_col_ind[j] - base; T local_val = csr_val[j]; // Ignore all entries that are below the diagonal if(local_col < row) { continue; } // Diagonal entry if(local_col == row) { if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { // Check for numerical zero if(local_val == make_DataType(0)) { *numeric_pivot = std::min(*numeric_pivot, row + base); local_val = make_DataType(1); } diag = j; diag_val = testing_div(make_DataType(1), local_val); } continue; } // Upper triangular part temp[k] = testing_fma(-local_val, y[local_col], temp[k]); } } for(int j = 1; j < prop.warpSize; j <<= 1) { for(int k = 0; k < prop.warpSize - j; ++k) { temp[k] = temp[k] + temp[k + j]; } } if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { if(diag == -1) { *struct_pivot = std::min(*struct_pivot, row + base); } y[row] = testing_mult(temp[0], diag_val); } else { y[row] = temp[0]; } } } template void host_csrsv(hipsparseOperation_t trans, J M, I nnz, T alpha, const I* csr_row_ptr, const J* csr_col_ind, const T* csr_val, const T* x, T* y, hipsparseDiagType_t diag_type, hipsparseFillMode_t fill_mode, hipsparseIndexBase_t base, J* struct_pivot, J* numeric_pivot) { // Initialize pivot *struct_pivot = M + 1; *numeric_pivot = M + 1; if(trans == HIPSPARSE_OPERATION_NON_TRANSPOSE) { if(fill_mode == HIPSPARSE_FILL_MODE_LOWER) { host_csr_lsolve(M, alpha, csr_row_ptr, csr_col_ind, csr_val, x, y, diag_type, base, struct_pivot, numeric_pivot); } else { host_csr_usolve(M, alpha, csr_row_ptr, csr_col_ind, csr_val, x, y, diag_type, base, struct_pivot, numeric_pivot); } } else if(trans == HIPSPARSE_OPERATION_TRANSPOSE || trans == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE) { // Transpose matrix std::vector csrt_row_ptr(M + 1); std::vector csrt_col_ind(nnz); std::vector csrt_val(nnz); host_csr_to_csc(M, M, nnz, csr_row_ptr, csr_col_ind, csr_val, csrt_col_ind, csrt_row_ptr, csrt_val, HIPSPARSE_ACTION_NUMERIC, base); if(trans == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE) { for(size_t i = 0; i < csrt_val.size(); i++) { csrt_val[i] = testing_conj(csrt_val[i]); } } if(fill_mode == HIPSPARSE_FILL_MODE_LOWER) { host_csr_usolve(M, alpha, csrt_row_ptr.data(), csrt_col_ind.data(), csrt_val.data(), x, y, diag_type, base, struct_pivot, numeric_pivot); } else { host_csr_lsolve(M, alpha, csrt_row_ptr.data(), csrt_col_ind.data(), csrt_val.data(), x, y, diag_type, base, struct_pivot, numeric_pivot); } } *numeric_pivot = std::min(*numeric_pivot, *struct_pivot); *struct_pivot = (*struct_pivot == M + 1) ? -1 : *struct_pivot; *numeric_pivot = (*numeric_pivot == M + 1) ? -1 : *numeric_pivot; } template void host_coosv(hipsparseOperation_t trans, I M, I nnz, T alpha, const std::vector& coo_row_ind, const std::vector& coo_col_ind, const std::vector& coo_val, const std::vector& x, std::vector& y, hipsparseDiagType_t diag_type, hipsparseFillMode_t fill_mode, hipsparseIndexBase_t base, I* struct_pivot, I* numeric_pivot) { std::vector csr_row_ptr(M + 1); //host_coo_to_csr(M, coo_row_ind, csr_row_ptr, base); // coo2csr on host for(I i = 0; i < nnz; ++i) { ++csr_row_ptr[coo_row_ind[i] + 1 - base]; } csr_row_ptr[0] = base; for(I i = 0; i < M; ++i) { csr_row_ptr[i + 1] += csr_row_ptr[i]; } host_csrsv(trans, M, nnz, alpha, csr_row_ptr.data(), coo_col_ind.data(), coo_val.data(), x.data(), y.data(), diag_type, fill_mode, base, struct_pivot, numeric_pivot); } template void host_csrsm2(J M, J nrhs, I nnz, hipsparseOperation_t transA, hipsparseOperation_t transB, T alpha, const std::vector& csr_row_ptr, const std::vector& csr_col_ind, const std::vector& csr_val, std::vector& B, J ldb, hipsparseOrder_t order_B, hipsparseDiagType_t diag_type, hipsparseFillMode_t fill_mode, hipsparseIndexBase_t base, J* struct_pivot, J* numeric_pivot) { // Initialize pivot *struct_pivot = M + 1; *numeric_pivot = M + 1; if(transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) { if(fill_mode == HIPSPARSE_FILL_MODE_LOWER) { host_lssolve(M, nrhs, transB, alpha, csr_row_ptr, csr_col_ind, csr_val, B, ldb, order_B, diag_type, base, struct_pivot, numeric_pivot); } else { host_ussolve(M, nrhs, transB, alpha, csr_row_ptr, csr_col_ind, csr_val, B, ldb, order_B, diag_type, base, struct_pivot, numeric_pivot); } } else if(transA == HIPSPARSE_OPERATION_TRANSPOSE || transA == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE) { // Transpose matrix std::vector csrt_row_ptr(M + 1); std::vector csrt_col_ind(nnz); std::vector csrt_val(nnz); host_csr_to_csc(M, M, nnz, csr_row_ptr.data(), csr_col_ind.data(), csr_val.data(), csrt_col_ind, csrt_row_ptr, csrt_val, HIPSPARSE_ACTION_NUMERIC, base); if(transA == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE) { for(size_t i = 0; i < csrt_val.size(); i++) { csrt_val[i] = testing_conj(csrt_val[i]); } } if(fill_mode == HIPSPARSE_FILL_MODE_LOWER) { host_ussolve(M, nrhs, transB, alpha, csrt_row_ptr, csrt_col_ind, csrt_val, B, ldb, order_B, diag_type, base, struct_pivot, numeric_pivot); } else { host_lssolve(M, nrhs, transB, alpha, csrt_row_ptr, csrt_col_ind, csrt_val, B, ldb, order_B, diag_type, base, struct_pivot, numeric_pivot); } } *numeric_pivot = std::min(*numeric_pivot, *struct_pivot); *struct_pivot = (*struct_pivot == M + 1) ? -1 : *struct_pivot; *numeric_pivot = (*numeric_pivot == M + 1) ? -1 : *numeric_pivot; } template void host_csrsm(J M, J nrhs, I nnz, hipsparseOperation_t trans_A, hipsparseOperation_t trans_B, T alpha, const std::vector& csr_row_ptr, const std::vector& csr_col_ind, const std::vector& csr_val, const std::vector& B, J ldb, hipsparseOrder_t order_B, std::vector& C, J ldc, hipsparseOrder_t order_C, hipsparseDiagType_t diag_type, hipsparseFillMode_t fill_mode, hipsparseIndexBase_t base, J* struct_pivot, J* numeric_pivot) { J B_m = (trans_B == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? M : nrhs; J B_n = (trans_B == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? nrhs : M; J C_m = M; J C_n = nrhs; // Copy B to C if(order_B == HIPSPARSE_ORDER_COL) { if(trans_B == HIPSPARSE_OPERATION_NON_TRANSPOSE) { if(order_C == HIPSPARSE_ORDER_COL) { for(J j = 0; j < B_n; j++) { for(J i = 0; i < B_m; i++) { C[i + ldc * j] = B[i + ldb * j]; } } } else { for(J j = 0; j < B_n; j++) { for(J i = 0; i < B_m; i++) { C[i * ldc + j] = B[i + ldb * j]; } } } } else { if(order_C == HIPSPARSE_ORDER_COL) { for(J j = 0; j < B_n; j++) { for(J i = 0; i < B_m; i++) { C[i * ldc + j] = B[i + ldb * j]; } } } else { for(J j = 0; j < B_n; j++) { for(J i = 0; i < B_m; i++) { C[i + ldc * j] = B[i + ldb * j]; } } } } } else { if(trans_B == HIPSPARSE_OPERATION_NON_TRANSPOSE) { if(order_C == HIPSPARSE_ORDER_COL) { for(J j = 0; j < B_n; j++) { for(J i = 0; i < B_m; i++) { C[i + ldc * j] = B[ldb * i + j]; } } } else { for(J j = 0; j < B_n; j++) { for(J i = 0; i < B_m; i++) { C[i * ldc + j] = B[ldb * i + j]; } } } } else { if(order_C == HIPSPARSE_ORDER_COL) { for(J j = 0; j < B_n; j++) { for(J i = 0; i < B_m; i++) { C[i * ldc + j] = B[ldb * i + j]; } } } else { for(J j = 0; j < B_n; j++) { for(J i = 0; i < B_m; i++) { C[i + ldc * j] = B[ldb * i + j]; } } } } } if(trans_B == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE) { if(order_C == HIPSPARSE_ORDER_COL) { for(J j = 0; j < C_n; j++) { for(J i = 0; i < C_m; i++) { C[i + ldc * j] = testing_conj(C[i + ldc * j]); } } } else { for(J i = 0; i < C_m; i++) { for(J j = 0; j < C_n; j++) { C[ldc * i + j] = testing_conj(C[ldc * i + j]); } } } } hipsparseOperation_t trans_C = HIPSPARSE_OPERATION_NON_TRANSPOSE; host_csrsm2(M, nrhs, nnz, trans_A, trans_C, alpha, csr_row_ptr, csr_col_ind, csr_val, C, ldc, order_C, diag_type, fill_mode, base, struct_pivot, numeric_pivot); } template void host_coosm(I M, I nrhs, I nnz, hipsparseOperation_t transA, hipsparseOperation_t transB, T alpha, const std::vector& coo_row_ind, const std::vector& coo_col_ind, const std::vector& coo_val, const std::vector& B, I ldb, hipsparseOrder_t order_B, std::vector& C, I ldc, hipsparseOrder_t order_C, hipsparseDiagType_t diag_type, hipsparseFillMode_t fill_mode, hipsparseIndexBase_t base, I* struct_pivot, I* numeric_pivot) { I B_m = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? M : nrhs; I B_n = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? nrhs : M; I C_m = M; I C_n = nrhs; // Copy B to C if(order_B == HIPSPARSE_ORDER_COL) { if(transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) { if(order_C == HIPSPARSE_ORDER_COL) { for(I j = 0; j < B_n; j++) { for(I i = 0; i < B_m; i++) { C[i + ldc * j] = B[i + ldb * j]; } } } else { for(I j = 0; j < B_n; j++) { for(I i = 0; i < B_m; i++) { C[i * ldc + j] = B[i + ldb * j]; } } } } else { if(order_C == HIPSPARSE_ORDER_COL) { for(I j = 0; j < B_n; j++) { for(I i = 0; i < B_m; i++) { C[i * ldc + j] = B[i + ldb * j]; } } } else { for(I j = 0; j < B_n; j++) { for(I i = 0; i < B_m; i++) { C[i + ldc * j] = B[i + ldb * j]; } } } } } else { if(transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) { if(order_C == HIPSPARSE_ORDER_COL) { for(I j = 0; j < B_n; j++) { for(I i = 0; i < B_m; i++) { C[i + ldc * j] = B[ldb * i + j]; } } } else { for(I j = 0; j < B_n; j++) { for(I i = 0; i < B_m; i++) { C[i * ldc + j] = B[ldb * i + j]; } } } } else { if(order_C == HIPSPARSE_ORDER_COL) { for(I j = 0; j < B_n; j++) { for(I i = 0; i < B_m; i++) { C[i * ldc + j] = B[ldb * i + j]; } } } else { for(I j = 0; j < B_n; j++) { for(I i = 0; i < B_m; i++) { C[i + ldc * j] = B[ldb * i + j]; } } } } } if(transB == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE) { if(order_C == HIPSPARSE_ORDER_COL) { for(I j = 0; j < C_n; j++) { for(I i = 0; i < C_m; i++) { C[i + ldc * j] = testing_conj(C[i + ldc * j]); } } } else { for(I i = 0; i < C_m; i++) { for(I j = 0; j < C_n; j++) { C[ldc * i + j] = testing_conj(C[ldc * i + j]); } } } } hipsparseOperation_t transC = HIPSPARSE_OPERATION_NON_TRANSPOSE; std::vector csr_row_ptr(M + 1); //host_coo_to_csr(M, coo_row_ind, csr_row_ptr, base); // coo2csr on host for(I i = 0; i < nnz; ++i) { ++csr_row_ptr[coo_row_ind[i] + 1 - base]; } csr_row_ptr[0] = base; for(I i = 0; i < M; ++i) { csr_row_ptr[i + 1] += csr_row_ptr[i]; } host_csrsm2(M, nrhs, nnz, transA, transC, alpha, csr_row_ptr, coo_col_ind, coo_val, C, ldc, order_C, diag_type, fill_mode, base, struct_pivot, numeric_pivot); } /* ============================================================================================ */ /*! \brief Sparse triangular lower solve using BSR storage format. */ template void bsr_lsolve(hipsparseDirection_t dir, hipsparseOperation_t trans_X, int mb, int nrhs, T alpha, const int* bsr_row_ptr, const int* bsr_col_ind, const T* bsr_val, int bsr_dim, const T* B, int ldb, T* X, int ldx, hipsparseDiagType_t diag_type, hipsparseIndexBase_t base, int* struct_pivot, int* numeric_pivot) { #ifdef _OPENMP #pragma omp parallel for #endif for(int i = 0; i < nrhs; ++i) { // Process lower triangular part for(int bsr_row = 0; bsr_row < mb; ++bsr_row) { int bsr_row_begin = bsr_row_ptr[bsr_row] - base; int bsr_row_end = bsr_row_ptr[bsr_row + 1] - base; // Loop over blocks rows for(int bi = 0; bi < bsr_dim; ++bi) { int diag = -1; int local_row = bsr_row * bsr_dim + bi; int idx_B = (trans_X == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? i * ldb + local_row : local_row * ldb + i; int idx_X = (trans_X == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? i * ldx + local_row : local_row * ldx + i; T sum = testing_mult(alpha, B[idx_B]); T diag_val = make_DataType(0); // Loop over BSR columns for(int j = bsr_row_begin; j < bsr_row_end; ++j) { int bsr_col = bsr_col_ind[j] - base; // Loop over blocks columns for(int bj = 0; bj < bsr_dim; ++bj) { int local_col = bsr_col * bsr_dim + bj; T local_val = (dir == HIPSPARSE_DIRECTION_ROW) ? bsr_val[bsr_dim * bsr_dim * j + bi * bsr_dim + bj] : bsr_val[bsr_dim * bsr_dim * j + bi + bj * bsr_dim]; if(local_val == make_DataType(0) && local_col == local_row && diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { // Numerical zero pivot found, avoid division by 0 // and store index for later use. *numeric_pivot = std::min(*numeric_pivot, bsr_row + base); local_val = make_DataType(1); } // Ignore all entries that are above the diagonal if(local_col > local_row) { break; } // Diagonal if(local_col == local_row) { // If diagonal type is non unit, do division by diagonal entry // This is not required for unit diagonal for obvious reasons if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { diag = j; diag_val = testing_div(make_DataType(1), local_val); } break; } // Lower triangular part int idx = (trans_X == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? i * ldx + local_col : local_col * ldx + i; sum = testing_fma(-local_val, X[idx], sum); } } if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { if(diag == -1) { *struct_pivot = std::min(*struct_pivot, bsr_row + base); } X[idx_X] = testing_mult(sum, diag_val); } else { X[idx_X] = sum; } } } } } /* ============================================================================================ */ /*! \brief Sparse triangular upper solve using BSR storage format. */ template void bsr_usolve(hipsparseDirection_t dir, hipsparseOperation_t trans_X, int mb, int nrhs, T alpha, const int* bsr_row_ptr, const int* bsr_col_ind, const T* bsr_val, int bsr_dim, const T* B, int ldb, T* X, int ldx, hipsparseDiagType_t diag_type, hipsparseIndexBase_t base, int* struct_pivot, int* numeric_pivot) { #ifdef _OPENMP #pragma omp parallel for #endif for(int i = 0; i < nrhs; ++i) { // Process upper triangular part for(int bsr_row = mb - 1; bsr_row >= 0; --bsr_row) { int bsr_row_begin = bsr_row_ptr[bsr_row] - base; int bsr_row_end = bsr_row_ptr[bsr_row + 1] - base; for(int bi = bsr_dim - 1; bi >= 0; --bi) { int local_row = bsr_row * bsr_dim + bi; int idx_B = (trans_X == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? i * ldb + local_row : local_row * ldb + i; int idx_X = (trans_X == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? i * ldx + local_row : local_row * ldx + i; T sum = testing_mult(alpha, B[idx_B]); int diag = -1; T diag_val = make_DataType(0); for(int j = bsr_row_end - 1; j >= bsr_row_begin; --j) { int bsr_col = bsr_col_ind[j] - base; for(int bj = bsr_dim - 1; bj >= 0; --bj) { int local_col = bsr_col * bsr_dim + bj; T local_val = dir == HIPSPARSE_DIRECTION_ROW ? bsr_val[bsr_dim * bsr_dim * j + bi * bsr_dim + bj] : bsr_val[bsr_dim * bsr_dim * j + bi + bj * bsr_dim]; // Ignore all entries that are below the diagonal if(local_col < local_row) { continue; } // Diagonal if(local_col == local_row) { if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { // Check for numerical zero if(local_val == make_DataType(0)) { *numeric_pivot = std::min(*numeric_pivot, bsr_row + base); local_val = make_DataType(1); } diag = j; diag_val = testing_div(make_DataType(1), local_val); } continue; } // Upper triangular part int idx = (trans_X == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? i * ldx + local_col : local_col * ldx + i; sum = testing_fma(-local_val, X[idx], sum); } } if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { if(diag == -1) { *struct_pivot = std::min(*struct_pivot, bsr_row + base); } X[idx_X] = testing_mult(sum, diag_val); } else { X[idx_X] = sum; } } } } } template void bsrsv(hipsparseOperation_t trans, hipsparseDirection_t dir, int mb, int nnzb, T alpha, const int* bsr_row_ptr, const int* bsr_col_ind, const T* bsr_val, int bsr_dim, const T* x, T* y, hipsparseDiagType_t diag_type, hipsparseFillMode_t fill_mode, hipsparseIndexBase_t base, int* struct_pivot, int* numeric_pivot) { // Initialize pivot *struct_pivot = mb + 1; *numeric_pivot = mb + 1; if(trans == HIPSPARSE_OPERATION_NON_TRANSPOSE) { if(fill_mode == HIPSPARSE_FILL_MODE_LOWER) { bsr_lsolve(dir, HIPSPARSE_OPERATION_NON_TRANSPOSE, mb, 1, alpha, bsr_row_ptr, bsr_col_ind, bsr_val, bsr_dim, x, mb * bsr_dim, y, mb * bsr_dim, diag_type, base, struct_pivot, numeric_pivot); } else { bsr_usolve(dir, HIPSPARSE_OPERATION_NON_TRANSPOSE, mb, 1, alpha, bsr_row_ptr, bsr_col_ind, bsr_val, bsr_dim, x, mb * bsr_dim, y, mb * bsr_dim, diag_type, base, struct_pivot, numeric_pivot); } } else if(trans == HIPSPARSE_OPERATION_TRANSPOSE) { // Transpose matrix std::vector bsrt_row_ptr; std::vector bsrt_col_ind; std::vector bsrt_val; host_bsr_to_bsc(mb, mb, nnzb, bsr_dim, bsr_row_ptr, bsr_col_ind, bsr_val, bsrt_col_ind, bsrt_row_ptr, bsrt_val, base, base); if(fill_mode == HIPSPARSE_FILL_MODE_LOWER) { bsr_usolve(dir, HIPSPARSE_OPERATION_NON_TRANSPOSE, mb, 1, alpha, bsrt_row_ptr.data(), bsrt_col_ind.data(), bsrt_val.data(), bsr_dim, x, mb * bsr_dim, y, mb * bsr_dim, diag_type, base, struct_pivot, numeric_pivot); } else { bsr_lsolve(dir, HIPSPARSE_OPERATION_NON_TRANSPOSE, mb, 1, alpha, bsrt_row_ptr.data(), bsrt_col_ind.data(), bsrt_val.data(), bsr_dim, x, mb * bsr_dim, y, mb * bsr_dim, diag_type, base, struct_pivot, numeric_pivot); } } *numeric_pivot = std::min(*numeric_pivot, *struct_pivot); *struct_pivot = (*struct_pivot == mb + 1) ? -1 : *struct_pivot; *numeric_pivot = (*numeric_pivot == mb + 1) ? -1 : *numeric_pivot; } /* ============================================================================================ */ /*! \brief Sparse triangular lower solve using CSR storage format. */ template int csr_lsolve(hipsparseOperation_t trans, int m, const int* ptr, const int* col, const T* val, T alpha, const T* x, T* y, hipsparseIndexBase_t idx_base, hipsparseDiagType_t diag_type, unsigned int wf_size) { const int* csr_row_ptr = ptr; const int* csr_col_ind = col; const T* csr_val = val; std::vector vptr; std::vector vcol; std::vector vval; if(trans == HIPSPARSE_OPERATION_TRANSPOSE) { int nnz = ptr[m] - idx_base; vptr.resize(m + 1); vcol.resize(nnz); vval.resize(nnz); // Transpose transpose_csr( m, m, nnz, ptr, col, val, vptr.data(), vcol.data(), vval.data(), idx_base, idx_base); csr_row_ptr = vptr.data(); csr_col_ind = vcol.data(); csr_val = vval.data(); } int pivot = (std::numeric_limits::max)(); std::vector temp(wf_size); for(int i = 0; i < m; ++i) { temp.assign(wf_size, make_DataType(0.0)); temp[0] = testing_mult(alpha, x[i]); int diag = -1; int row_begin = csr_row_ptr[i] - idx_base; int row_end = csr_row_ptr[i + 1] - idx_base; T diag_val = make_DataType(0.0); for(int l = row_begin; l < row_end; l += wf_size) { for(unsigned int k = 0; k < wf_size; ++k) { int j = l + k; // Do not run out of bounds if(j >= row_end) { break; } int col_j = csr_col_ind[j] - idx_base; T val_j = csr_val[j]; if(col_j < i) { // Lower part temp[k] = testing_fma(-csr_val[j], y[col_j], temp[k]); } else if(col_j == i) { // Diagonal if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { // Check for numerical zero if(val_j == make_DataType(0.0)) { pivot = std::min(pivot, i + idx_base); val_j = make_DataType(1.0); } diag = j; diag_val = testing_div(make_DataType(1.0), val_j); } break; } else { // Upper part break; } } } for(unsigned int j = 1; j < wf_size; j <<= 1) { for(unsigned int k = 0; k < wf_size - j; ++k) { temp[k] = temp[k] + temp[k + j]; } } if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { if(diag == -1) { pivot = std::min(pivot, i + idx_base); } y[i] = testing_mult(temp[0], diag_val); } else { y[i] = temp[0]; } } if(pivot != (std::numeric_limits::max)()) { return pivot; } return -1; } /* ============================================================================================ */ /*! \brief Sparse triangular upper solve using CSR storage format. */ template int csr_usolve(hipsparseOperation_t trans, int m, const int* ptr, const int* col, const T* val, T alpha, const T* x, T* y, hipsparseIndexBase_t idx_base, hipsparseDiagType_t diag_type, unsigned int wf_size) { const int* csr_row_ptr = ptr; const int* csr_col_ind = col; const T* csr_val = val; std::vector vptr; std::vector vcol; std::vector vval; if(trans == HIPSPARSE_OPERATION_TRANSPOSE) { int nnz = ptr[m] - idx_base; vptr.resize(m + 1); vcol.resize(nnz); vval.resize(nnz); // Transpose transpose_csr( m, m, nnz, ptr, col, val, vptr.data(), vcol.data(), vval.data(), idx_base, idx_base); csr_row_ptr = vptr.data(); csr_col_ind = vcol.data(); csr_val = vval.data(); } int pivot = (std::numeric_limits::max)(); std::vector temp(wf_size); for(int i = m - 1; i >= 0; --i) { temp.assign(wf_size, make_DataType(0.0)); temp[0] = testing_mult(alpha, x[i]); int diag = -1; int row_begin = csr_row_ptr[i] - idx_base; int row_end = csr_row_ptr[i + 1] - idx_base; T diag_val = make_DataType(0.0); for(int l = row_end - 1; l >= row_begin; l -= wf_size) { for(unsigned int k = 0; k < wf_size; ++k) { int j = l - k; // Do not run out of bounds if(j < row_begin) { break; } int col_j = csr_col_ind[j] - idx_base; T val_j = csr_val[j]; if(col_j < i) { // Lower part continue; } else if(col_j == i) { // Diagonal if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { // Check for numerical zero if(val_j == make_DataType(0.0)) { pivot = std::min(pivot, i + idx_base); val_j = make_DataType(1.0); } diag = j; diag_val = testing_div(make_DataType(1.0), val_j); } continue; } else { // Upper part temp[k] = testing_fma(-csr_val[j], y[col_j], temp[k]); } } } for(unsigned int j = 1; j < wf_size; j <<= 1) { for(unsigned int k = 0; k < wf_size - j; ++k) { temp[k] = temp[k] + temp[k + j]; } } if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { if(diag == -1) { pivot = std::min(pivot, i + idx_base); } y[i] = testing_mult(temp[0], diag_val); } else { y[i] = temp[0]; } } if(pivot != (std::numeric_limits::max)()) { return pivot; } return -1; } /* ============================================================================================ */ /*! \brief Transpose sparse matrix using CSR storage format. */ template void transpose_csr(J m, J n, I nnz, const I* csr_row_ptr_A, const J* csr_col_ind_A, const T* csr_val_A, I* csr_row_ptr_B, J* csr_col_ind_B, T* csr_val_B, hipsparseIndexBase_t idx_base_A, hipsparseIndexBase_t idx_base_B) { memset(csr_row_ptr_B, 0, sizeof(I) * (n + 1)); // Determine nnz per column for(I i = 0; i < nnz; ++i) { ++csr_row_ptr_B[csr_col_ind_A[i] + 1 - idx_base_A]; } // Scan for(J i = 0; i < n; ++i) { csr_row_ptr_B[i + 1] += csr_row_ptr_B[i]; } // Fill row indices and values for(J i = 0; i < m; ++i) { I row_begin = csr_row_ptr_A[i] - idx_base_A; I row_end = csr_row_ptr_A[i + 1] - idx_base_A; for(I j = row_begin; j < row_end; ++j) { J col = csr_col_ind_A[j] - idx_base_A; I idx = csr_row_ptr_B[col]; csr_col_ind_B[idx] = i + idx_base_B; csr_val_B[idx] = csr_val_A[j]; ++csr_row_ptr_B[col]; } } // Shift column pointer array for(J i = n; i > 0; --i) { csr_row_ptr_B[i] = csr_row_ptr_B[i - 1] + idx_base_B; } csr_row_ptr_B[0] = idx_base_B; } /* ============================================================================================ */ /*! \brief Transpose sparse matrix using CSR storage format. */ template void transpose_bsr(int mb, int nb, int nnzb, int bsr_dim, const int* bsr_row_ptr_A, const int* bsr_col_ind_A, const T* bsr_val_A, int* bsr_row_ptr_B, int* bsr_col_ind_B, T* bsr_val_B, hipsparseIndexBase_t idx_base_A, hipsparseIndexBase_t idx_base_B) { memset(bsr_row_ptr_B, 0, sizeof(int) * (nb + 1)); // Determine nnz per column for(int i = 0; i < nnzb; ++i) { ++bsr_row_ptr_B[bsr_col_ind_A[i] + 1 - idx_base_A]; } // Scan for(int i = 0; i < nb; ++i) { bsr_row_ptr_B[i + 1] += bsr_row_ptr_B[i]; } // Fill row indices and values for(int i = 0; i < mb; ++i) { int row_begin = bsr_row_ptr_A[i] - idx_base_A; int row_end = bsr_row_ptr_A[i + 1] - idx_base_A; for(int j = row_begin; j < row_end; ++j) { int col = bsr_col_ind_A[j] - idx_base_A; int idx = bsr_row_ptr_B[col]; bsr_col_ind_B[idx] = i + idx_base_B; for(int bi = 0; bi < bsr_dim; ++bi) { for(int bj = 0; bj < bsr_dim; ++bj) { bsr_val_B[bsr_dim * bsr_dim * idx + bi + bj * bsr_dim] = bsr_val_A[bsr_dim * bsr_dim * j + bi * bsr_dim + bj]; } } ++bsr_row_ptr_B[col]; } } // Shift column pointer array for(int i = nb; i > 0; --i) { bsr_row_ptr_B[i] = bsr_row_ptr_B[i - 1] + idx_base_B; } bsr_row_ptr_B[0] = idx_base_B; } /* ============================================================================================ */ /*! \brief Compute sparse matrix sparse matrix addition. */ template static int host_csrgeam_nnz(int M, int N, T alpha, const int* csr_row_ptr_A, const int* csr_col_ind_A, T beta, const int* csr_row_ptr_B, const int* csr_col_ind_B, int* csr_row_ptr_C, hipsparseIndexBase_t base_A, hipsparseIndexBase_t base_B, hipsparseIndexBase_t base_C) { #ifdef _OPENMP #pragma omp parallel #endif { std::vector nnz(N, -1); #ifdef _OPENMP int nthreads = omp_get_num_threads(); int tid = omp_get_thread_num(); #else int nthreads = 1; int tid = 0; #endif int rows_per_thread = (M + nthreads - 1) / nthreads; int chunk_begin = rows_per_thread * tid; int chunk_end = std::min(chunk_begin + rows_per_thread, M); // Index base csr_row_ptr_C[0] = base_C; // Loop over rows for(int i = chunk_begin; i < chunk_end; ++i) { // Initialize csr row pointer with previous row offset csr_row_ptr_C[i + 1] = 0; int row_begin_A = csr_row_ptr_A[i] - base_A; int row_end_A = csr_row_ptr_A[i + 1] - base_A; // Loop over columns of A for(int j = row_begin_A; j < row_end_A; ++j) { int col_A = csr_col_ind_A[j] - base_A; nnz[col_A] = i; ++csr_row_ptr_C[i + 1]; } int row_begin_B = csr_row_ptr_B[i] - base_B; int row_end_B = csr_row_ptr_B[i + 1] - base_B; // Loop over columns of B for(int j = row_begin_B; j < row_end_B; ++j) { int col_B = csr_col_ind_B[j] - base_B; // Check if a new nnz is generated if(nnz[col_B] != i) { nnz[col_B] = i; ++csr_row_ptr_C[i + 1]; } } } } // Scan to obtain row offsets for(int i = 0; i < M; ++i) { csr_row_ptr_C[i + 1] += csr_row_ptr_C[i]; } return csr_row_ptr_C[M] - base_C; } template static void host_csrgeam(int M, int N, T alpha, const int* csr_row_ptr_A, const int* csr_col_ind_A, const T* csr_val_A, T beta, const int* csr_row_ptr_B, const int* csr_col_ind_B, const T* csr_val_B, const int* csr_row_ptr_C, int* csr_col_ind_C, T* csr_val_C, hipsparseIndexBase_t base_A, hipsparseIndexBase_t base_B, hipsparseIndexBase_t base_C) { #ifdef _OPENMP #pragma omp parallel #endif { std::vector nnz(N, -1); #ifdef _OPENMP int nthreads = omp_get_num_threads(); int tid = omp_get_thread_num(); #else int nthreads = 1; int tid = 0; #endif int rows_per_thread = (M + nthreads - 1) / nthreads; int chunk_begin = rows_per_thread * tid; int chunk_end = std::min(chunk_begin + rows_per_thread, M); // Loop over rows for(int i = chunk_begin; i < chunk_end; ++i) { int row_begin_C = csr_row_ptr_C[i] - base_C; int row_end_C = row_begin_C; int row_begin_A = csr_row_ptr_A[i] - base_A; int row_end_A = csr_row_ptr_A[i + 1] - base_A; // Copy A into C for(int j = row_begin_A; j < row_end_A; ++j) { // Current column of A int col_A = csr_col_ind_A[j] - base_A; // Current value of A T val_A = testing_mult(alpha, csr_val_A[j]); nnz[col_A] = row_end_C; csr_col_ind_C[row_end_C] = col_A + base_C; csr_val_C[row_end_C] = val_A; ++row_end_C; } int row_begin_B = csr_row_ptr_B[i] - base_B; int row_end_B = csr_row_ptr_B[i + 1] - base_B; // Loop over columns of B for(int j = row_begin_B; j < row_end_B; ++j) { // Current column of B int col_B = csr_col_ind_B[j] - base_B; // Current value of B T val_B = testing_mult(beta, csr_val_B[j]); // Check if a new nnz is generated or if the value is added if(nnz[col_B] < row_begin_C) { nnz[col_B] = row_end_C; csr_col_ind_C[row_end_C] = col_B + base_C; csr_val_C[row_end_C] = val_B; ++row_end_C; } else { csr_val_C[nnz[col_B]] = csr_val_C[nnz[col_B]] + val_B; } } } } int nnz = csr_row_ptr_C[M] - base_C; std::vector col(nnz); std::vector val(nnz); for(int i = 0; i < nnz; ++i) { col[i] = csr_col_ind_C[i]; val[i] = csr_val_C[i]; } #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < M; ++i) { int row_begin = csr_row_ptr_C[i] - base_C; int row_end = csr_row_ptr_C[i + 1] - base_C; int row_nnz = row_end - row_begin; std::vector perm(row_nnz); for(int j = 0; j < row_nnz; ++j) { perm[j] = j; } int* col_entry = &col[row_begin]; T* val_entry = &val[row_begin]; std::sort(perm.begin(), perm.end(), [&](const int& a, const int& b) { return col_entry[a] <= col_entry[b]; }); for(int j = 0; j < row_nnz; ++j) { csr_col_ind_C[row_begin + j] = col_entry[perm[j]]; csr_val_C[row_begin + j] = val_entry[perm[j]]; } } } /* ============================================================================================ */ /*! \brief Compute sparse matrix sparse matrix multiplication. */ template static I host_csrgemm2_nnz(J m, J n, J k, const T* alpha, const I* csr_row_ptr_A, const J* csr_col_ind_A, const I* csr_row_ptr_B, const J* csr_col_ind_B, const T* beta, const I* csr_row_ptr_D, const J* csr_col_ind_D, I* csr_row_ptr_C, hipsparseIndexBase_t idx_base_A, hipsparseIndexBase_t idx_base_B, hipsparseIndexBase_t idx_base_C, hipsparseIndexBase_t idx_base_D) { #ifdef _OPENMP #pragma omp parallel #endif { std::vector nnz(n, -1); #ifdef _OPENMP int nthreads = omp_get_num_threads(); int tid = omp_get_thread_num(); #else int nthreads = 1; int tid = 0; #endif J rows_per_thread = (m + nthreads - 1) / nthreads; J chunk_begin = rows_per_thread * tid; J chunk_end = std::min(chunk_begin + rows_per_thread, m); // Index base csr_row_ptr_C[0] = idx_base_C; // Loop over rows of A for(J i = chunk_begin; i < chunk_end; ++i) { // Initialize csr row pointer with previous row offset csr_row_ptr_C[i + 1] = 0; if(alpha) { I row_begin_A = csr_row_ptr_A[i] - idx_base_A; I row_end_A = csr_row_ptr_A[i + 1] - idx_base_A; // Loop over columns of A for(I j = row_begin_A; j < row_end_A; ++j) { // Current column of A J col_A = csr_col_ind_A[j] - idx_base_A; I row_begin_B = csr_row_ptr_B[col_A] - idx_base_B; I row_end_B = csr_row_ptr_B[col_A + 1] - idx_base_B; // Loop over columns of B in row col_A for(I irow = row_begin_B; irow < row_end_B; ++irow) { // Current column of B J col_B = csr_col_ind_B[irow] - idx_base_B; // Check if a new nnz is generated if(nnz[col_B] != i) { nnz[col_B] = i; ++csr_row_ptr_C[i + 1]; } } } } // Add nnz of D if beta != 0 if(beta) { I row_begin_D = csr_row_ptr_D[i] - idx_base_D; I row_end_D = csr_row_ptr_D[i + 1] - idx_base_D; // Loop over columns of D for(I j = row_begin_D; j < row_end_D; ++j) { J col_D = csr_col_ind_D[j] - idx_base_D; // Check if a new nnz is generated if(nnz[col_D] != i) { nnz[col_D] = i; ++csr_row_ptr_C[i + 1]; } } } } } // Scan to obtain row offsets for(J i = 0; i < m; ++i) { csr_row_ptr_C[i + 1] += csr_row_ptr_C[i]; } return csr_row_ptr_C[m] - idx_base_C; } template static void host_csrgemm2(J m, J n, J k, const T* alpha, const I* csr_row_ptr_A, const J* csr_col_ind_A, const T* csr_val_A, const I* csr_row_ptr_B, const J* csr_col_ind_B, const T* csr_val_B, const T* beta, const I* csr_row_ptr_D, const J* csr_col_ind_D, const T* csr_val_D, const I* csr_row_ptr_C, J* csr_col_ind_C, T* csr_val_C, hipsparseIndexBase_t idx_base_A, hipsparseIndexBase_t idx_base_B, hipsparseIndexBase_t idx_base_C, hipsparseIndexBase_t idx_base_D) { #ifdef _OPENMP #pragma omp parallel #endif { std::vector nnz(n, -1); #ifdef _OPENMP int nthreads = omp_get_num_threads(); int tid = omp_get_thread_num(); #else int nthreads = 1; int tid = 0; #endif J rows_per_thread = (m + nthreads - 1) / nthreads; J chunk_begin = rows_per_thread * tid; J chunk_end = std::min(chunk_begin + rows_per_thread, m); // Loop over rows of A for(J i = chunk_begin; i < chunk_end; ++i) { I row_begin_C = csr_row_ptr_C[i] - idx_base_C; I row_end_C = row_begin_C; if(alpha) { I row_begin_A = csr_row_ptr_A[i] - idx_base_A; I row_end_A = csr_row_ptr_A[i + 1] - idx_base_A; // Loop over columns of A for(I j = row_begin_A; j < row_end_A; ++j) { // Current column of A J col_A = csr_col_ind_A[j] - idx_base_A; // Current value of A T val_A = testing_mult(*alpha, csr_val_A[j]); I row_begin_B = csr_row_ptr_B[col_A] - idx_base_B; I row_end_B = csr_row_ptr_B[col_A + 1] - idx_base_B; // Loop over columns of B in row col_A for(I l = row_begin_B; l < row_end_B; ++l) { // Current column of B J col_B = csr_col_ind_B[l] - idx_base_B; // Current value of B T val_B = csr_val_B[l]; // Check if a new nnz is generated or if the product is appended if(nnz[col_B] < row_begin_C) { nnz[col_B] = row_end_C; csr_col_ind_C[row_end_C] = col_B + idx_base_C; csr_val_C[row_end_C] = testing_mult(val_A, val_B); ++row_end_C; } else { csr_val_C[nnz[col_B]] = csr_val_C[nnz[col_B]] + testing_mult(val_A, val_B); } } } } // Add nnz of D if beta != 0 if(beta) { I row_begin_D = csr_row_ptr_D[i] - idx_base_D; I row_end_D = csr_row_ptr_D[i + 1] - idx_base_D; // Loop over columns of D for(I j = row_begin_D; j < row_end_D; ++j) { // Current column of D J col_D = csr_col_ind_D[j] - idx_base_D; // Current value of D T val_D = testing_mult(*beta, csr_val_D[j]); // Check if a new nnz is generated or if the value is added if(nnz[col_D] < row_begin_C) { nnz[col_D] = row_end_C; csr_col_ind_C[row_end_C] = col_D + idx_base_C; csr_val_C[row_end_C] = val_D; ++row_end_C; } else { csr_val_C[nnz[col_D]] = csr_val_C[nnz[col_D]] + val_D; } } } } } I nnz_C = csr_row_ptr_C[m] - idx_base_C; std::vector col(nnz_C); std::vector val(nnz_C); memcpy(col.data(), csr_col_ind_C, sizeof(J) * nnz_C); memcpy(val.data(), csr_val_C, sizeof(T) * nnz_C); #ifdef _OPENMP #pragma omp parallel for #endif for(J i = 0; i < m; ++i) { I row_begin = csr_row_ptr_C[i] - idx_base_C; I row_end = csr_row_ptr_C[i + 1] - idx_base_C; J row_nnz = row_end - row_begin; std::vector perm(row_nnz); for(J j = 0; j < row_nnz; ++j) { perm[j] = j; } J* col_entry = &col[row_begin]; T* val_entry = &val[row_begin]; std::sort(perm.begin(), perm.end(), [&](const I& a, const I& b) { return col_entry[a] <= col_entry[b]; }); for(J j = 0; j < row_nnz; ++j) { csr_col_ind_C[row_begin + j] = col_entry[perm[j]]; csr_val_C[row_begin + j] = val_entry[perm[j]]; } } } #ifdef __cplusplus extern "C" { #endif /* ============================================================================================ */ /* query for hipsparse version and git commit SHA-1. */ void query_version(char* version); /* ============================================================================================ */ /* device query and print out their ID and name */ int query_device_property(); /* set current device to device_id */ void set_device(int device_id); /* ============================================================================================ */ /* timing: HIP only provides very limited timers function clock() and not general; hipsparse sync CPU and device and use more accurate CPU timer*/ /*! \brief CPU Timer(in microsecond): synchronize with the default device and return wall time */ double get_time_us(void); /*! \brief CPU Timer(in microsecond): synchronize with given queue/stream and return wall time */ double get_time_us_sync(hipStream_t stream); #ifdef __cplusplus } #endif struct testhyb { int m; int n; hipsparseHybPartition_t partition; int ell_nnz; int ell_width; int* ell_col_ind; void* ell_val; int coo_nnz; int* coo_row_ind; int* coo_col_ind; void* coo_val; }; template hipsparseIndexType_t getIndexType() { return (typeid(I) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; } template hipDataType getDataType() { return (typeid(T) == typeid(int8_t)) ? HIP_R_8I : (typeid(T) == typeid(float)) ? HIP_R_32F : ((typeid(T) == typeid(double)) ? HIP_R_64F : ((typeid(T) == typeid(hipComplex) ? HIP_C_32F : HIP_C_64F))); } #endif // TESTING_UTILITY_HPP ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5803993 hipsparse/clients/samples/0000775000175100017510000000000015206065364016120 5ustar00jenkinsjenkins././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5733993 hipsparse/clients/samples/CMakeLists.txt0000664000175100017510000000776215206065364020674 0ustar00jenkinsjenkins# ######################################################################## # 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 $) if (BUILD_CLIENTS_ONLY) target_include_directories(${EXAMPLE_TARGET} PRIVATE ${hipsparse_INCLUDE_DIRS}/hipsparse) endif() # 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 if (NOT WIN32) # C program for checking hipsparse headers are C compatible. add_hipsparse_example(example_c_headers.c) if(NOT USE_CUDA) add_hipsparse_example(example_axpyi.c) endif() endif() 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() if(NOT USE_CUDA) # Build documentation examples FILE(GLOB_RECURSE DOCUMENTATION_EXAMPLES documentation_examples/*.cpp) foreach(file ${DOCUMENTATION_EXAMPLES}) message(STATUS "Found .cpp file: ${file}") add_hipsparse_example(${file}) endforeach() endif() ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5783992 hipsparse/clients/samples/documentation_examples/0000775000175100017510000000000015206065364022667 5ustar00jenkinsjenkins././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5753992 hipsparse/clients/samples/documentation_examples/conversion/0000775000175100017510000000000015206065364025054 5ustar00jenkinsjenkins././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5743992 hipsparse/clients/samples/documentation_examples/conversion/example_hipsparse_bsr2csr.cpp0000664000175100017510000001503415206065364032734 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); hipsparseMatDescr_t csr_descr; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&csr_descr)); hipsparseMatDescr_t bsr_descr; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&bsr_descr)); // Sparse matrix in BSR format // 1 2 | 0 3 | 0 0 // 0 4 | 5 0 | 0 1 // --------------- // A = 6 0 | 0 7 | 8 0 // 0 0 | 3 0 | 2 2 // --------------- // 1 0 | 0 0 | 4 3 // 7 2 | 0 0 | 1 4 int hbsrRowPtr[4] = {0, 3, 6, 8}; int hbsrColInd[8] = {0, 1, 2, 0, 1, 2, 0, 2}; float hbsrVal[32] = {1.0f, 2.0f, 0.0f, 4.0f, 0.0f, 3.0f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 6.0f, 0.0f, 0.0f, 0.0f, 0.0f, 7.0f, 3.0f, 0.0f, 8.0f, 0.0f, 2.0f, 2.0f, 1.0f, 0.0f, 7.0f, 2.0f, 4.0f, 3.0f, 1.0f, 4.0f}; int m = 6; int n = 6; int nnz = 32; int mb = 3; int nb = 3; int nnzb = 8; int blockDim = 2; hipsparseDirection_t dir = HIPSPARSE_DIRECTION_ROW; int* dbsrRowPtr = nullptr; int* dbsrColInd = nullptr; float* dbsrVal = nullptr; HIP_CHECK(hipMalloc((void**)&dbsrRowPtr, sizeof(int) * (mb + 1))); HIP_CHECK(hipMalloc((void**)&dbsrColInd, sizeof(int) * nnzb)); HIP_CHECK(hipMalloc((void**)&dbsrVal, sizeof(float) * blockDim * blockDim * nnzb)); HIP_CHECK(hipMemcpy(dbsrRowPtr, hbsrRowPtr, sizeof(int) * (mb + 1), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dbsrColInd, hbsrColInd, sizeof(int) * nnzb, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy( dbsrVal, hbsrVal, sizeof(float) * blockDim * blockDim * nnzb, hipMemcpyHostToDevice)); int* dcsrRowPtr = nullptr; int* dcsrColInd = nullptr; float* dcsrVal = nullptr; HIP_CHECK(hipMalloc((void**)&dcsrRowPtr, sizeof(int) * (m + 1))); HIP_CHECK(hipMalloc((void**)&dcsrColInd, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dcsrVal, sizeof(float) * nnz)); HIPSPARSE_CHECK(hipsparseSbsr2csr(handle, dir, mb, nb, bsr_descr, dbsrVal, dbsrRowPtr, dbsrColInd, blockDim, csr_descr, dcsrVal, dcsrRowPtr, dcsrColInd)); std::vector hcsrRowPtr(m + 1); std::vector hcsrColInd(nnz); std::vector hcsrVal(nnz); // Copy back to the host HIP_CHECK( hipMemcpy(hcsrRowPtr.data(), dcsrRowPtr, sizeof(int) * (m + 1), hipMemcpyDeviceToHost)); HIP_CHECK(hipMemcpy(hcsrColInd.data(), dcsrColInd, sizeof(int) * nnz, hipMemcpyDeviceToHost)); HIP_CHECK(hipMemcpy(hcsrVal.data(), dcsrVal, sizeof(float) * nnz, hipMemcpyDeviceToHost)); std::cout << "C" << std::endl; for(int i = 0; i < m; i++) { int start = hcsrRowPtr[i]; int end = hcsrRowPtr[i + 1]; std::vector temp(n, 0.0f); for(int j = start; j < end; j++) { temp[hcsrColInd[j]] = hcsrVal[j]; } for(int j = 0; j < n; j++) { std::cout << temp[j] << " "; } std::cout << "" << std::endl; } std::cout << "" << std::endl; HIP_CHECK(hipFree(dbsrRowPtr)); HIP_CHECK(hipFree(dbsrColInd)); HIP_CHECK(hipFree(dbsrVal)); HIP_CHECK(hipFree(dcsrRowPtr)); HIP_CHECK(hipFree(dcsrColInd)); HIP_CHECK(hipFree(dcsrVal)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(csr_descr)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(bsr_descr)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5743992 hipsparse/clients/samples/documentation_examples/conversion/example_hipsparse_coo2csr.cpp0000664000175100017510000000742315206065364032731 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // Sparse matrix in COO format // 1 2 0 3 0 // A = 0 4 5 0 0 // 6 0 0 7 8 int hcooRowInd[8] = {0, 0, 0, 1, 1, 2, 2, 2}; int hcooColInd[8] = {0, 1, 3, 1, 2, 0, 3, 4}; float hcooVal[8] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f}; int m = 3; int n = 5; int nnz = 8; hipsparseIndexBase_t base = HIPSPARSE_INDEX_BASE_ZERO; int* dcooRowInd = nullptr; int* dcooColInd = nullptr; HIP_CHECK(hipMalloc((void**)&dcooRowInd, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dcooColInd, sizeof(int) * nnz)); HIP_CHECK(hipMemcpy(dcooRowInd, hcooRowInd, sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcooColInd, hcooColInd, sizeof(int) * nnz, hipMemcpyHostToDevice)); int* dcsrRowPtr = nullptr; HIP_CHECK(hipMalloc((void**)&dcsrRowPtr, sizeof(int) * (m + 1))); HIPSPARSE_CHECK(hipsparseXcoo2csr(handle, dcooRowInd, nnz, m, dcsrRowPtr, base)); HIP_CHECK(hipFree(dcooRowInd)); HIP_CHECK(hipFree(dcooColInd)); HIP_CHECK(hipFree(dcsrRowPtr)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5743992 hipsparse/clients/samples/documentation_examples/conversion/example_hipsparse_coosort_by_column.cpp0000664000175100017510000001113215206065364035106 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // Sparse matrix in COO format (with unsorted column indices) // 1 2 0 3 0 // A = 0 4 5 0 0 // 6 0 0 7 8 int hcooRowInd[8] = {0, 0, 0, 1, 1, 2, 2, 2}; int hcooColInd[8] = {0, 1, 3, 1, 2, 0, 3, 4}; float hcooVal[8] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f}; int m = 3; int n = 5; int nnz = 8; hipsparseIndexBase_t base = HIPSPARSE_INDEX_BASE_ZERO; int* dcooRowInd = nullptr; int* dcooColInd = nullptr; float* dcooVal = nullptr; HIP_CHECK(hipMalloc((void**)&dcooRowInd, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dcooColInd, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dcooVal, sizeof(float) * nnz)); HIP_CHECK(hipMemcpy(dcooRowInd, hcooRowInd, sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcooColInd, hcooColInd, sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcooVal, hcooVal, sizeof(float) * nnz, hipMemcpyHostToDevice)); size_t bufferSize; HIPSPARSE_CHECK( hipsparseXcoosort_bufferSizeExt(handle, m, n, nnz, dcooRowInd, dcooColInd, &bufferSize)); void* dbuffer = nullptr; HIP_CHECK(hipMalloc((void**)&dbuffer, bufferSize)); int* dperm = nullptr; HIP_CHECK(hipMalloc((void**)&dperm, sizeof(int) * nnz)); HIPSPARSE_CHECK(hipsparseCreateIdentityPermutation(handle, nnz, dperm)); HIPSPARSE_CHECK( hipsparseXcoosortByColumn(handle, m, n, nnz, dcooRowInd, dcooColInd, dperm, dbuffer)); float* dcooValSorted = nullptr; HIP_CHECK(hipMalloc((void**)&dcooValSorted, sizeof(float) * nnz)); HIPSPARSE_CHECK(hipsparseSgthr(handle, nnz, dcooVal, dcooValSorted, dperm, base)); HIP_CHECK(hipFree(dcooRowInd)); HIP_CHECK(hipFree(dcooColInd)); HIP_CHECK(hipFree(dcooVal)); HIP_CHECK(hipFree(dcooValSorted)); HIP_CHECK(hipFree(dperm)); HIP_CHECK(hipFree(dbuffer)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5743992 hipsparse/clients/samples/documentation_examples/conversion/example_hipsparse_coosort_by_row.cpp0000664000175100017510000001112315206065364034420 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // Sparse matrix in COO format (with unsorted row indices) // 1 2 0 3 0 // A = 0 4 5 0 0 // 6 0 0 7 8 int hcooRowInd[8] = {0, 2, 0, 1, 1, 0, 2, 2}; int hcooColInd[8] = {0, 0, 1, 1, 2, 3, 3, 4}; float hcooVal[8] = {1.0f, 6.0f, 2.0f, 4.0f, 5.0f, 3.0f, 7.0f, 8.0f}; int m = 3; int n = 5; int nnz = 8; hipsparseIndexBase_t base = HIPSPARSE_INDEX_BASE_ZERO; int* dcooRowInd = nullptr; int* dcooColInd = nullptr; float* dcooVal = nullptr; HIP_CHECK(hipMalloc((void**)&dcooRowInd, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dcooColInd, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dcooVal, sizeof(float) * nnz)); HIP_CHECK(hipMemcpy(dcooRowInd, hcooRowInd, sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcooColInd, hcooColInd, sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcooVal, hcooVal, sizeof(float) * nnz, hipMemcpyHostToDevice)); size_t bufferSize; HIPSPARSE_CHECK( hipsparseXcoosort_bufferSizeExt(handle, m, n, nnz, dcooRowInd, dcooColInd, &bufferSize)); void* dbuffer = nullptr; HIP_CHECK(hipMalloc((void**)&dbuffer, bufferSize)); int* dperm = nullptr; HIP_CHECK(hipMalloc((void**)&dperm, sizeof(int) * nnz)); HIPSPARSE_CHECK(hipsparseCreateIdentityPermutation(handle, nnz, dperm)); HIPSPARSE_CHECK( hipsparseXcoosortByRow(handle, m, n, nnz, dcooRowInd, dcooColInd, dperm, dbuffer)); float* dcooValSorted = nullptr; HIP_CHECK(hipMalloc((void**)&dcooValSorted, sizeof(float) * nnz)); HIPSPARSE_CHECK(hipsparseSgthr(handle, nnz, dcooVal, dcooValSorted, dperm, base)); HIP_CHECK(hipFree(dcooRowInd)); HIP_CHECK(hipFree(dcooColInd)); HIP_CHECK(hipFree(dcooVal)); HIP_CHECK(hipFree(dcooValSorted)); HIP_CHECK(hipFree(dperm)); HIP_CHECK(hipFree(dbuffer)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000022300000000000010212 xustar00119 path=hipsparse/clients/samples/documentation_examples/conversion/example_hipsparse_create_identity_permutation.cpp 28 mtime=1779985139.5743992 hipsparse/clients/samples/documentation_examples/conversion/example_hipsparse_create_identity_permut0000664000175100017510000000554315206065364035347 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); int n = 10; int* dperm = nullptr; HIP_CHECK(hipMalloc((void**)&dperm, sizeof(int) * n)); HIPSPARSE_CHECK(hipsparseCreateIdentityPermutation(handle, n, dperm)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5743992 hipsparse/clients/samples/documentation_examples/conversion/example_hipsparse_cscsort.cpp0000664000175100017510000001121315206065364033027 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); hipsparseMatDescr_t descr; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descr)); // Sparse matrix in CSC format (unsorted row indices) // 1 2 0 3 0 // A = 0 4 5 0 0 // 6 0 0 7 8 int hcscRowInd[8] = {2, 0, 1, 0, 1, 2, 0, 2}; int hcscColPtr[6] = {0, 2, 4, 5, 7, 8}; float hcscVal[8] = {6.0f, 1.0f, 4.0f, 2.0f, 5.0f, 7.0f, 3.0f, 8.0f}; int m = 3; int n = 5; int nnz = 8; int* dcscRowInd = nullptr; int* dcscColPtr = nullptr; float* dcscVal = nullptr; HIP_CHECK(hipMalloc((void**)&dcscRowInd, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dcscColPtr, sizeof(int) * (n + 1))); HIP_CHECK(hipMalloc((void**)&dcscVal, sizeof(float) * nnz)); HIP_CHECK(hipMemcpy(dcscRowInd, hcscRowInd, sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcscColPtr, hcscColPtr, sizeof(int) * (n + 1), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcscVal, hcscVal, sizeof(float) * nnz, hipMemcpyHostToDevice)); size_t bufferSize; HIPSPARSE_CHECK( hipsparseXcscsort_bufferSizeExt(handle, m, n, nnz, dcscColPtr, dcscRowInd, &bufferSize)); void* dbuffer = nullptr; HIP_CHECK(hipMalloc((void**)&dbuffer, bufferSize)); int* dperm = nullptr; HIP_CHECK(hipMalloc((void**)&dperm, sizeof(int) * nnz)); HIPSPARSE_CHECK(hipsparseCreateIdentityPermutation(handle, nnz, dperm)); HIPSPARSE_CHECK( hipsparseXcscsort(handle, m, n, nnz, descr, dcscColPtr, dcscRowInd, dperm, dbuffer)); float* dcscValSorted = nullptr; HIP_CHECK(hipMalloc((void**)&dcscValSorted, sizeof(float) * nnz)); HIPSPARSE_CHECK( hipsparseSgthr(handle, nnz, dcscVal, dcscValSorted, dperm, HIPSPARSE_INDEX_BASE_ZERO)); HIP_CHECK(hipFree(dcscRowInd)); HIP_CHECK(hipFree(dcscColPtr)); HIP_CHECK(hipFree(dcscVal)); HIP_CHECK(hipFree(dcscValSorted)); HIP_CHECK(hipFree(dbuffer)); HIP_CHECK(hipFree(dperm)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descr)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5743992 hipsparse/clients/samples/documentation_examples/conversion/example_hipsparse_csr2bsr.cpp0000664000175100017510000001345215206065364032736 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // Matrix descriptor hipsparseMatDescr_t csr_descr; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&csr_descr)); hipsparseMatDescr_t bsr_descr; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&bsr_descr)); // Sparse matrix in CSR format // 1 2 0 3 0 // A = 0 4 5 0 0 // 6 0 0 7 8 int hcsrRowPtr[4] = {0, 3, 5, 8}; int hcsrColInd[8] = {0, 1, 3, 1, 2, 0, 3, 4}; float hcsrVal[8] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f}; int m = 3; int n = 5; int nnz = 8; int blockDim = 3; hipsparseDirection_t dir = HIPSPARSE_DIRECTION_ROW; int mb = (m + blockDim - 1) / blockDim; int nb = (n + blockDim - 1) / blockDim; int* dcsrRowPtr = nullptr; int* dcsrColInd = nullptr; float* dcsrVal = nullptr; HIP_CHECK(hipMalloc((void**)&dcsrRowPtr, sizeof(int) * (m + 1))); HIP_CHECK(hipMalloc((void**)&dcsrColInd, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dcsrVal, sizeof(float) * nnz)); HIP_CHECK(hipMemcpy(dcsrRowPtr, hcsrRowPtr, sizeof(int) * (m + 1), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrColInd, hcsrColInd, sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrVal, hcsrVal, sizeof(float) * nnz, hipMemcpyHostToDevice)); int* dbsrRowPtr = nullptr; HIP_CHECK(hipMalloc((void**)&dbsrRowPtr, sizeof(int) * (mb + 1))); int nnzb; HIPSPARSE_CHECK(hipsparseXcsr2bsrNnz(handle, dir, m, n, csr_descr, dcsrRowPtr, dcsrColInd, blockDim, bsr_descr, dbsrRowPtr, &nnzb)); int* dbsrColInd = nullptr; float* dbsrVal = nullptr; HIP_CHECK(hipMalloc((void**)&dbsrColInd, sizeof(int) * nnzb)); HIP_CHECK(hipMalloc((void**)&dbsrVal, sizeof(float) * blockDim * blockDim * nnzb)); HIPSPARSE_CHECK(hipsparseScsr2bsr(handle, dir, m, n, csr_descr, dcsrVal, dcsrRowPtr, dcsrColInd, blockDim, bsr_descr, dbsrVal, dbsrRowPtr, dbsrColInd)); HIP_CHECK(hipFree(dcsrRowPtr)); HIP_CHECK(hipFree(dcsrColInd)); HIP_CHECK(hipFree(dcsrVal)); HIP_CHECK(hipFree(dbsrRowPtr)); HIP_CHECK(hipFree(dbsrColInd)); HIP_CHECK(hipFree(dbsrVal)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(csr_descr)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(bsr_descr)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5743992 hipsparse/clients/samples/documentation_examples/conversion/example_hipsparse_csr2csc.cpp0000664000175100017510000001143015206065364032712 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // Sparse matrix in CSR format // 1 2 0 3 0 // A = 0 4 5 0 0 // 6 0 0 7 8 int hcsrRowPtr[4] = {0, 3, 5, 8}; int hcsrColInd[8] = {0, 1, 3, 1, 2, 0, 3, 4}; float hcsrVal[8] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f}; int m = 3; int n = 5; int nnz = 8; hipsparseIndexBase_t base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseAction_t action = HIPSPARSE_ACTION_NUMERIC; int* dcsrRowPtr = nullptr; int* dcsrColInd = nullptr; float* dcsrVal = nullptr; HIP_CHECK(hipMalloc((void**)&dcsrRowPtr, sizeof(int) * (m + 1))); HIP_CHECK(hipMalloc((void**)&dcsrColInd, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dcsrVal, sizeof(float) * nnz)); HIP_CHECK(hipMemcpy(dcsrRowPtr, hcsrRowPtr, sizeof(int) * (m + 1), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrColInd, hcsrColInd, sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrVal, hcsrVal, sizeof(float) * nnz, hipMemcpyHostToDevice)); int* dcscRowInd = nullptr; int* dcscColPtr = nullptr; float* dcsc_val = nullptr; HIP_CHECK(hipMalloc((void**)&dcscRowInd, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dcscColPtr, sizeof(int) * (n + 1))); HIP_CHECK(hipMalloc((void**)&dcsc_val, sizeof(float) * nnz)); HIPSPARSE_CHECK(hipsparseScsr2csc(handle, m, n, nnz, dcsrVal, dcsrRowPtr, dcsrColInd, dcsc_val, dcscRowInd, dcscColPtr, action, base)); HIP_CHECK(hipFree(dcsrRowPtr)); HIP_CHECK(hipFree(dcsrColInd)); HIP_CHECK(hipFree(dcsrVal)); HIP_CHECK(hipFree(dcscRowInd)); HIP_CHECK(hipFree(dcscColPtr)); HIP_CHECK(hipFree(dcsc_val)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5743992 hipsparse/clients/samples/documentation_examples/conversion/example_hipsparse_csr2csc_ex2.cpp0000664000175100017510000001403015206065364033467 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // Sparse matrix in CSR format // 1 2 0 3 0 // A = 0 4 5 0 0 // 6 0 0 7 8 int hcsrRowPtr[4] = {0, 3, 5, 8}; int hcsrColInd[8] = {0, 1, 3, 1, 2, 0, 3, 4}; float hcsrVal[8] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f}; int m = 3; int n = 5; int nnz = 8; hipsparseIndexBase_t base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseAction_t action = HIPSPARSE_ACTION_NUMERIC; hipsparseCsr2CscAlg_t alg = HIPSPARSE_CSR2CSC_ALG_DEFAULT; int* dcsrRowPtr = nullptr; int* dcsrColInd = nullptr; float* dcsrVal = nullptr; HIP_CHECK(hipMalloc((void**)&dcsrRowPtr, sizeof(int) * (m + 1))); HIP_CHECK(hipMalloc((void**)&dcsrColInd, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dcsrVal, sizeof(float) * nnz)); HIP_CHECK(hipMemcpy(dcsrRowPtr, hcsrRowPtr, sizeof(int) * (m + 1), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrColInd, hcsrColInd, sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrVal, hcsrVal, sizeof(float) * nnz, hipMemcpyHostToDevice)); int* dcscRowInd = nullptr; int* dcscColPtr = nullptr; float* dcsc_val = nullptr; HIP_CHECK(hipMalloc((void**)&dcscRowInd, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dcscColPtr, sizeof(int) * (n + 1))); HIP_CHECK(hipMalloc((void**)&dcsc_val, sizeof(float) * nnz)); size_t bufferSize; HIPSPARSE_CHECK(hipsparseCsr2cscEx2_bufferSize(handle, m, n, nnz, dcsrVal, dcsrRowPtr, dcsrColInd, dcsc_val, dcscColPtr, dcscRowInd, HIP_R_32F, action, base, alg, &bufferSize)); void* dbuffer = nullptr; HIP_CHECK(hipMalloc((void**)&dbuffer, bufferSize)); HIPSPARSE_CHECK(hipsparseCsr2cscEx2(handle, m, n, nnz, dcsrVal, dcsrRowPtr, dcsrColInd, dcsc_val, dcscColPtr, dcscRowInd, HIP_R_32F, action, base, alg, dbuffer)); HIP_CHECK(hipFree(dcsrRowPtr)); HIP_CHECK(hipFree(dcsrColInd)); HIP_CHECK(hipFree(dcsrVal)); HIP_CHECK(hipFree(dcscRowInd)); HIP_CHECK(hipFree(dcscColPtr)); HIP_CHECK(hipFree(dcsc_val)); HIP_CHECK(hipFree(dbuffer)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5753992 hipsparse/clients/samples/documentation_examples/conversion/example_hipsparse_csr2csr_compress.cpp0000664000175100017510000001266615206065364034660 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // Matrix descriptor hipsparseMatDescr_t descr; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descr)); // Sparse matrix in CSR format // 1 2 0 3 0 // A = 0 4 5 0 0 // 6 0 0 7 8 int hcsrRowPtrA[4] = {0, 3, 5, 8}; int hcsrColIndA[8] = {0, 1, 3, 1, 2, 0, 3, 4}; float hcsrValA[8] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f}; int m = 3; int n = 5; int nnzA = 8; float tol = 5.9f; int* dcsrRowPtrA = nullptr; int* dcsrColIndA = nullptr; float* dcsrValA = nullptr; HIP_CHECK(hipMalloc((void**)&dcsrRowPtrA, sizeof(int) * (m + 1))); HIP_CHECK(hipMalloc((void**)&dcsrColIndA, sizeof(int) * nnzA)); HIP_CHECK(hipMalloc((void**)&dcsrValA, sizeof(float) * nnzA)); HIP_CHECK(hipMemcpy(dcsrRowPtrA, hcsrRowPtrA, sizeof(int) * (m + 1), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrColIndA, hcsrColIndA, sizeof(int) * nnzA, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrValA, hcsrValA, sizeof(float) * nnzA, hipMemcpyHostToDevice)); // Allocate memory for the nnz_per_row array int* dnnz_per_row; HIP_CHECK(hipMalloc((void**)&dnnz_per_row, sizeof(int) * m)); // Call snnz_compress() which fills in nnz_per_row array and finds the number // of entries that will be in the compressed CSR matrix int nnzC; HIPSPARSE_CHECK( hipsparseSnnz_compress(handle, m, descr, dcsrValA, dcsrRowPtrA, dnnz_per_row, &nnzC, tol)); int* dcsrRowPtrC = nullptr; int* dcsrColIndC = nullptr; float* dcsrValC = nullptr; HIP_CHECK(hipMalloc((void**)&dcsrRowPtrC, sizeof(int) * (m + 1))); HIP_CHECK(hipMalloc((void**)&dcsrColIndC, sizeof(int) * nnzC)); HIP_CHECK(hipMalloc((void**)&dcsrValC, sizeof(float) * nnzC)); HIPSPARSE_CHECK(hipsparseScsr2csr_compress(handle, m, n, descr, dcsrValA, dcsrColIndA, dcsrRowPtrA, nnzA, dnnz_per_row, dcsrValC, dcsrColIndC, dcsrRowPtrC, tol)); HIP_CHECK(hipFree(dcsrRowPtrA)); HIP_CHECK(hipFree(dcsrColIndA)); HIP_CHECK(hipFree(dcsrValA)); HIP_CHECK(hipFree(dcsrRowPtrC)); HIP_CHECK(hipFree(dcsrColIndC)); HIP_CHECK(hipFree(dcsrValC)); HIP_CHECK(hipFree(dnnz_per_row)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descr)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5753992 hipsparse/clients/samples/documentation_examples/conversion/example_hipsparse_csr2dense.cpp0000664000175100017510000001012015206065364033233 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // Matrix descriptor hipsparseMatDescr_t descr; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descr)); // Sparse matrix in CSR format // 1 2 0 3 0 // A = 0 4 5 0 0 // 6 0 0 7 8 int hcsrRowPtr[4] = {0, 3, 5, 8}; int hcsrColInd[8] = {0, 1, 3, 1, 2, 0, 3, 4}; float hcsrVal[8] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f}; int m = 3; int n = 5; int ld = 3; int nnz = 8; int* dcsrRowPtr = nullptr; int* dcsrColInd = nullptr; float* dcsrVal = nullptr; HIP_CHECK(hipMalloc((void**)&dcsrRowPtr, sizeof(int) * (m + 1))); HIP_CHECK(hipMalloc((void**)&dcsrColInd, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dcsrVal, sizeof(float) * nnz)); HIP_CHECK(hipMemcpy(dcsrRowPtr, hcsrRowPtr, sizeof(int) * (m + 1), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrColInd, hcsrColInd, sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrVal, hcsrVal, sizeof(float) * nnz, hipMemcpyHostToDevice)); float* ddense_A = nullptr; HIP_CHECK(hipMalloc((void**)&ddense_A, sizeof(float) * ld * n)); HIPSPARSE_CHECK( hipsparseScsr2dense(handle, m, n, descr, dcsrVal, dcsrRowPtr, dcsrColInd, ddense_A, ld)); HIP_CHECK(hipFree(dcsrRowPtr)); HIP_CHECK(hipFree(dcsrColInd)); HIP_CHECK(hipFree(dcsrVal)); HIP_CHECK(hipFree(ddense_A)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descr)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5753992 hipsparse/clients/samples/documentation_examples/conversion/example_hipsparse_csr2gebsr.cpp0000664000175100017510000001711715206065364033254 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); hipsparseMatDescr_t csr_descr; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&csr_descr)); hipsparseMatDescr_t bsr_descr; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&bsr_descr)); // Sparse matrix in CSR format // 1 2 0 3 0 0 // 0 4 5 0 0 1 // A = 6 0 0 7 8 0 // 0 0 3 0 2 2 // 1 0 0 0 4 3 // 7 2 0 0 1 4 int hcsrRowPtr[7] = {0, 3, 6, 9, 12, 15, 19}; int hcsrColInd[19] = {0, 1, 3, 1, 2, 5, 0, 3, 4, 2, 4, 5, 0, 4, 5, 0, 1, 4, 5}; float hcsrVal[19] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 1.0f, 6.0f, 7.0f, 8.0f, 3.0f, 2.0f, 2.0f, 1.0f, 4.0f, 3.0f, 7.0f, 2.0f, 1.0f, 4.0f}; int m = 6; int n = 6; int nnz = 19; int rowBlockDim = 3; int colBlockDim = 2; hipsparseDirection_t dir = HIPSPARSE_DIRECTION_ROW; hipsparseIndexBase_t base = HIPSPARSE_INDEX_BASE_ZERO; int mb = (m + rowBlockDim - 1) / rowBlockDim; int nb = (n + colBlockDim - 1) / colBlockDim; int* dcsrRowPtr = nullptr; int* dcsrColInd = nullptr; float* dcsrVal = nullptr; HIP_CHECK(hipMalloc((void**)&dcsrRowPtr, sizeof(int) * (m + 1))); HIP_CHECK(hipMalloc((void**)&dcsrColInd, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dcsrVal, sizeof(float) * nnz)); HIP_CHECK(hipMemcpy(dcsrRowPtr, hcsrRowPtr, sizeof(int) * (m + 1), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrColInd, hcsrColInd, sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrVal, hcsrVal, sizeof(float) * nnz, hipMemcpyHostToDevice)); int* dbsrRowPtr = nullptr; HIP_CHECK(hipMalloc((void**)&dbsrRowPtr, sizeof(int) * (mb + 1))); size_t bufferSize; HIPSPARSE_CHECK(hipsparseScsr2gebsr_bufferSize(handle, dir, m, n, csr_descr, dcsrVal, dcsrRowPtr, dcsrColInd, rowBlockDim, colBlockDim, &bufferSize)); void* dbuffer = nullptr; HIP_CHECK(hipMalloc((void**)&dbuffer, bufferSize)); int nnzb; HIPSPARSE_CHECK(hipsparseXcsr2gebsrNnz(handle, dir, m, n, csr_descr, dcsrRowPtr, dcsrColInd, bsr_descr, dbsrRowPtr, rowBlockDim, colBlockDim, &nnzb, dbuffer)); int* dbsrColInd = nullptr; float* dbsrVal = nullptr; HIP_CHECK(hipMalloc((void**)&dbsrColInd, sizeof(int) * nnzb)); HIP_CHECK(hipMalloc((void**)&dbsrVal, sizeof(float) * rowBlockDim * colBlockDim * nnzb)); HIPSPARSE_CHECK(hipsparseScsr2gebsr(handle, dir, m, n, csr_descr, dcsrVal, dcsrRowPtr, dcsrColInd, bsr_descr, dbsrVal, dbsrRowPtr, dbsrColInd, rowBlockDim, colBlockDim, dbuffer)); HIP_CHECK(hipFree(dcsrRowPtr)); HIP_CHECK(hipFree(dcsrColInd)); HIP_CHECK(hipFree(dcsrVal)); HIP_CHECK(hipFree(dbsrRowPtr)); HIP_CHECK(hipFree(dbsrColInd)); HIP_CHECK(hipFree(dbsrVal)); HIP_CHECK(hipFree(dbuffer)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(csr_descr)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(bsr_descr)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5753992 hipsparse/clients/samples/documentation_examples/conversion/example_hipsparse_csr2hyb.cpp0000664000175100017510000001040515206065364032725 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); hipsparseMatDescr_t descr; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descr)); // Sparse matrix in CSR format // 1 2 0 3 0 // A = 0 4 5 0 0 // 6 0 0 7 8 int hcsrRowPtr[4] = {0, 3, 5, 8}; int hcsrColInd[8] = {0, 1, 3, 1, 2, 0, 3, 4}; float hcsrVal[8] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f}; int m = 3; int n = 5; int nnz = 8; int userEllWidth = 2; hipsparseHybPartition_t partitionType = HIPSPARSE_HYB_PARTITION_AUTO; int* dcsrRowPtr = nullptr; int* dcsrColInd = nullptr; float* dcsrVal = nullptr; HIP_CHECK(hipMalloc((void**)&dcsrRowPtr, sizeof(int) * (m + 1))); HIP_CHECK(hipMalloc((void**)&dcsrColInd, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dcsrVal, sizeof(float) * nnz)); HIP_CHECK(hipMemcpy(dcsrRowPtr, hcsrRowPtr, sizeof(int) * (m + 1), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrColInd, hcsrColInd, sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrVal, hcsrVal, sizeof(float) * nnz, hipMemcpyHostToDevice)); hipsparseHybMat_t hyb; HIPSPARSE_CHECK(hipsparseCreateHybMat(&hyb)); HIPSPARSE_CHECK(hipsparseScsr2hyb( handle, m, n, descr, dcsrVal, dcsrRowPtr, dcsrColInd, hyb, userEllWidth, partitionType)); HIP_CHECK(hipFree(dcsrRowPtr)); HIP_CHECK(hipFree(dcsrColInd)); HIP_CHECK(hipFree(dcsrVal)); HIPSPARSE_CHECK(hipsparseDestroyHybMat(hyb)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descr)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5753992 hipsparse/clients/samples/documentation_examples/conversion/example_hipsparse_csrsort.cpp0000664000175100017510000001120115206065364033043 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); hipsparseMatDescr_t descr; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descr)); // Sparse matrix in CSR format (columns unsorted) // 1 2 0 3 0 // A = 0 4 5 0 0 // 6 0 0 7 8 int hcsrRowPtr[4] = {0, 3, 5, 8}; int hcsrColInd[8] = {3, 1, 0, 2, 1, 0, 4, 3}; float hcsrVal[8] = {3.0f, 2.0f, 1.0f, 5.0f, 4.0f, 6.0f, 8.0f, 7.0f}; int m = 3; int n = 5; int nnz = 8; int* dcsrRowPtr = nullptr; int* dcsrColInd = nullptr; float* dcsrVal = nullptr; HIP_CHECK(hipMalloc((void**)&dcsrRowPtr, sizeof(int) * (m + 1))); HIP_CHECK(hipMalloc((void**)&dcsrColInd, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dcsrVal, sizeof(float) * nnz)); HIP_CHECK(hipMemcpy(dcsrRowPtr, hcsrRowPtr, sizeof(int) * (m + 1), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrColInd, hcsrColInd, sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrVal, hcsrVal, sizeof(float) * nnz, hipMemcpyHostToDevice)); size_t bufferSize; HIPSPARSE_CHECK( hipsparseXcsrsort_bufferSizeExt(handle, m, n, nnz, dcsrRowPtr, dcsrColInd, &bufferSize)); void* dbuffer = nullptr; HIP_CHECK(hipMalloc((void**)&dbuffer, bufferSize)); int* dperm = nullptr; HIP_CHECK(hipMalloc((void**)&dperm, sizeof(int) * nnz)); HIPSPARSE_CHECK(hipsparseCreateIdentityPermutation(handle, nnz, dperm)); HIPSPARSE_CHECK( hipsparseXcsrsort(handle, m, n, nnz, descr, dcsrRowPtr, dcsrColInd, dperm, dbuffer)); float* dcsrValSorted = nullptr; HIP_CHECK(hipMalloc((void**)&dcsrValSorted, sizeof(float) * nnz)); HIPSPARSE_CHECK( hipsparseSgthr(handle, nnz, dcsrVal, dcsrValSorted, dperm, HIPSPARSE_INDEX_BASE_ZERO)); HIP_CHECK(hipFree(dcsrRowPtr)); HIP_CHECK(hipFree(dcsrColInd)); HIP_CHECK(hipFree(dcsrVal)); HIP_CHECK(hipFree(dcsrValSorted)); HIP_CHECK(hipFree(dbuffer)); HIP_CHECK(hipFree(dperm)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descr)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5753992 hipsparse/clients/samples/documentation_examples/conversion/example_hipsparse_dense2csr.cpp0000664000175100017510000001040215206065364033236 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // Matrix descriptor hipsparseMatDescr_t descr; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descr)); // Dense matrix in column order // 1 2 0 3 0 // A = 0 4 5 0 0 // 6 0 0 7 8 float hdense_A[15] = { 1.0f, 0.0f, 6.0f, 2.0f, 4.0f, 0.0f, 0.0f, 5.0f, 0.0f, 3.0f, 0.0f, 7.0f, 0.0f, 0.0f, 8.0f}; int m = 3; int n = 5; hipsparseDirection_t dir = HIPSPARSE_DIRECTION_ROW; float* ddense_A = nullptr; HIP_CHECK(hipMalloc((void**)&ddense_A, sizeof(float) * m * n)); HIP_CHECK(hipMemcpy(ddense_A, hdense_A, sizeof(float) * m * n, hipMemcpyHostToDevice)); // Allocate memory for the nnz_per_row_columns array int* dnnz_per_row; HIP_CHECK(hipMalloc((void**)&dnnz_per_row, sizeof(int) * m)); int nnz_A; HIPSPARSE_CHECK(hipsparseSnnz(handle, dir, m, n, descr, ddense_A, m, dnnz_per_row, &nnz_A)); // Allocate sparse CSR matrix int* dcsrRowPtr = nullptr; int* dcsrColInd = nullptr; float* dcsrVal = nullptr; HIP_CHECK(hipMalloc((void**)&dcsrRowPtr, sizeof(int) * (m + 1))); HIP_CHECK(hipMalloc((void**)&dcsrColInd, sizeof(int) * nnz_A)); HIP_CHECK(hipMalloc((void**)&dcsrVal, sizeof(float) * nnz_A)); HIPSPARSE_CHECK(hipsparseSdense2csr( handle, m, n, descr, ddense_A, m, dnnz_per_row, dcsrVal, dcsrRowPtr, dcsrColInd)); HIP_CHECK(hipFree(dcsrRowPtr)); HIP_CHECK(hipFree(dcsrColInd)); HIP_CHECK(hipFree(dcsrVal)); HIP_CHECK(hipFree(dnnz_per_row)); HIP_CHECK(hipFree(ddense_A)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descr)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5753992 hipsparse/clients/samples/documentation_examples/conversion/example_hipsparse_gebsr2csr.cpp0000664000175100017510000001342215206065364033247 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); hipsparseMatDescr_t csr_descr; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&csr_descr)); hipsparseMatDescr_t bsr_descr; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&bsr_descr)); // Sparse matrix in GEBSR format // 1 2 | 0 3 | 0 0 // 0 4 | 5 0 | 0 1 // A = 6 0 | 0 7 | 8 0 // --------------- // 0 0 | 3 0 | 2 2 // 1 0 | 0 0 | 4 3 // 7 2 | 0 0 | 1 4 int hbsrRowPtr[3] = {0, 3, 6}; int hbsrColInd[6] = {0, 1, 2, 0, 1, 2}; float hbsrVal[36] = {1.0f, 2.0f, 0.0f, 4.0f, 6.0f, 0.0f, 0.0f, 3.0f, 5.0f, 0.0f, 0.0f, 7.0f, 0.0f, 0.0f, 0.0f, 1.0f, 8.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 7.0f, 2.0f, 3.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f, 2.0f, 4.0f, 3.0f, 1.0f, 4.0f}; int m = 6; int n = 6; int nnz = 36; int mb = 2; int nb = 3; int nnzb = 6; int rowBlockDim = 3; int colBlockDim = 2; hipsparseDirection_t dir = HIPSPARSE_DIRECTION_ROW; int* dbsrRowPtr = nullptr; int* dbsrColInd = nullptr; float* dbsrVal = nullptr; HIP_CHECK(hipMalloc((void**)&dbsrRowPtr, sizeof(int) * (mb + 1))); HIP_CHECK(hipMalloc((void**)&dbsrColInd, sizeof(int) * nnzb)); HIP_CHECK(hipMalloc((void**)&dbsrVal, sizeof(float) * rowBlockDim * colBlockDim * nnzb)); HIP_CHECK(hipMemcpy(dbsrRowPtr, hbsrRowPtr, sizeof(int) * (mb + 1), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dbsrColInd, hbsrColInd, sizeof(int) * nnzb, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy( dbsrVal, hbsrVal, sizeof(float) * rowBlockDim * colBlockDim * nnzb, hipMemcpyHostToDevice)); int* dcsrRowPtr = nullptr; int* dcsrColInd = nullptr; float* dcsrVal = nullptr; HIP_CHECK(hipMalloc((void**)&dcsrRowPtr, sizeof(int) * (m + 1))); HIP_CHECK(hipMalloc((void**)&dcsrColInd, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dcsrVal, sizeof(float) * nnz)); HIPSPARSE_CHECK(hipsparseSgebsr2csr(handle, dir, mb, nb, bsr_descr, dbsrVal, dbsrRowPtr, dbsrColInd, rowBlockDim, colBlockDim, csr_descr, dcsrVal, dcsrRowPtr, dcsrColInd)); HIP_CHECK(hipFree(dbsrRowPtr)); HIP_CHECK(hipFree(dbsrColInd)); HIP_CHECK(hipFree(dbsrVal)); HIP_CHECK(hipFree(dcsrRowPtr)); HIP_CHECK(hipFree(dcsrColInd)); HIP_CHECK(hipFree(dcsrVal)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(csr_descr)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(bsr_descr)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5753992 hipsparse/clients/samples/documentation_examples/conversion/example_hipsparse_gebsr2gebsc.cpp0000664000175100017510000001466215206065364033552 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // Sparse matrix in BSR format // 1 2 | 0 3 | 0 0 // 0 4 | 5 0 | 0 1 // A = 6 0 | 0 7 | 8 0 // --------------- // 0 0 | 3 0 | 2 2 // 1 0 | 0 0 | 4 3 // 7 2 | 0 0 | 1 4 int hbsrRowPtr[3] = {0, 3, 6}; int hbsrColInd[6] = {0, 1, 2, 0, 1, 2}; float hbsrVal[36] = {1.0f, 2.0f, 0.0f, 4.0f, 6.0f, 0.0f, 0.0f, 3.0f, 5.0f, 0.0f, 0.0f, 7.0f, 0.0f, 0.0f, 0.0f, 1.0f, 8.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 7.0f, 2.0f, 3.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f, 2.0f, 4.0f, 3.0f, 1.0f, 4.0f}; int m = 6; int n = 6; int rowBlockDim = 3; int colBlockDim = 2; int nnzb = 6; hipsparseDirection_t dir = HIPSPARSE_DIRECTION_ROW; hipsparseAction_t action = HIPSPARSE_ACTION_NUMERIC; hipsparseIndexBase_t base = HIPSPARSE_INDEX_BASE_ZERO; int mb = (m + rowBlockDim - 1) / rowBlockDim; int nb = (n + colBlockDim - 1) / colBlockDim; int* dbsrRowPtr = nullptr; int* dbsrColInd = nullptr; float* dbsrVal = nullptr; HIP_CHECK(hipMalloc((void**)&dbsrRowPtr, sizeof(int) * (mb + 1))); HIP_CHECK(hipMalloc((void**)&dbsrColInd, sizeof(int) * nnzb)); HIP_CHECK(hipMalloc((void**)&dbsrVal, sizeof(float) * rowBlockDim * colBlockDim * nnzb)); HIP_CHECK(hipMemcpy(dbsrRowPtr, hbsrRowPtr, sizeof(int) * (mb + 1), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dbsrColInd, hbsrColInd, sizeof(int) * nnzb, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy( dbsrVal, hbsrVal, sizeof(float) * rowBlockDim * colBlockDim * nnzb, hipMemcpyHostToDevice)); int* dbscRowInd = nullptr; int* dbscColPtr = nullptr; float* dbscVal = nullptr; HIP_CHECK(hipMalloc((void**)&dbscRowInd, sizeof(int) * nnzb)); HIP_CHECK(hipMalloc((void**)&dbscColPtr, sizeof(int) * (nb + 1))); HIP_CHECK(hipMalloc((void**)&dbscVal, sizeof(float) * rowBlockDim * colBlockDim * nnzb)); size_t bufferSize; HIPSPARSE_CHECK(hipsparseSgebsr2gebsc_bufferSize(handle, mb, nb, nnzb, dbsrVal, dbsrRowPtr, dbsrColInd, rowBlockDim, colBlockDim, &bufferSize)); void* dbuffer = nullptr; HIP_CHECK(hipMalloc((void**)&dbuffer, bufferSize)); HIPSPARSE_CHECK(hipsparseSgebsr2gebsc(handle, mb, nb, nnzb, dbsrVal, dbsrRowPtr, dbsrColInd, rowBlockDim, colBlockDim, dbscVal, dbscRowInd, dbscColPtr, action, base, dbuffer)); HIP_CHECK(hipFree(dbsrRowPtr)); HIP_CHECK(hipFree(dbsrColInd)); HIP_CHECK(hipFree(dbsrVal)); HIP_CHECK(hipFree(dbscRowInd)); HIP_CHECK(hipFree(dbscColPtr)); HIP_CHECK(hipFree(dbscVal)); HIP_CHECK(hipFree(dbuffer)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5753992 hipsparse/clients/samples/documentation_examples/conversion/example_hipsparse_gebsr2gebsr.cpp0000664000175100017510000002031215206065364033556 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); hipsparseMatDescr_t descrA; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descrA)); hipsparseMatDescr_t descrC; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descrC)); // Sparse matrix in BSR format // 1 2 | 0 3 | 0 0 // 0 4 | 5 0 | 0 1 // A = 6 0 | 0 7 | 8 0 // --------------- // 0 0 | 3 0 | 2 2 // 1 0 | 0 0 | 4 3 // 7 2 | 0 0 | 1 4 int hbsrRowPtrA[3] = {0, 3, 6}; int hbsrColIndA[6] = {0, 1, 2, 0, 1, 2}; float hbsrValA[36] = {1.0f, 2.0f, 0.0f, 4.0f, 6.0f, 0.0f, 0.0f, 3.0f, 5.0f, 0.0f, 0.0f, 7.0f, 0.0f, 0.0f, 0.0f, 1.0f, 8.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 7.0f, 2.0f, 3.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f, 2.0f, 4.0f, 3.0f, 1.0f, 4.0f}; int m = 6; int n = 6; int rowBlockDimA = 3; int colBlockDimA = 2; int rowBlockDimC = 2; int colBlockDimC = 2; hipsparseDirection_t dirA = HIPSPARSE_DIRECTION_ROW; int mbA = (m + rowBlockDimA - 1) / rowBlockDimA; int nbA = (n + colBlockDimA - 1) / colBlockDimA; int nnzbA = 6; int mbC = (m + rowBlockDimC - 1) / rowBlockDimC; int nbC = (n + colBlockDimC - 1) / colBlockDimC; int* dbsrRowPtrA = nullptr; int* dbsrColIndA = nullptr; float* dbsrValA = nullptr; HIP_CHECK(hipMalloc((void**)&dbsrRowPtrA, sizeof(int) * (mbA + 1))); HIP_CHECK(hipMalloc((void**)&dbsrColIndA, sizeof(int) * nnzbA)); HIP_CHECK(hipMalloc((void**)&dbsrValA, sizeof(float) * rowBlockDimA * colBlockDimA * nnzbA)); HIP_CHECK(hipMemcpy(dbsrRowPtrA, hbsrRowPtrA, sizeof(int) * (mbA + 1), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dbsrColIndA, hbsrColIndA, sizeof(int) * nnzbA, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dbsrValA, hbsrValA, sizeof(float) * rowBlockDimA * colBlockDimA * nnzbA, hipMemcpyHostToDevice)); int* dbsrRowPtrC = nullptr; HIP_CHECK(hipMalloc((void**)&dbsrRowPtrC, sizeof(int) * (mbC + 1))); int bufferSize; HIPSPARSE_CHECK(hipsparseSgebsr2gebsr_bufferSize(handle, dirA, mbA, nbA, nnzbA, descrA, dbsrValA, dbsrRowPtrA, dbsrColIndA, rowBlockDimA, colBlockDimA, rowBlockDimC, colBlockDimC, &bufferSize)); void* dbuffer = nullptr; HIP_CHECK(hipMalloc((void**)&dbuffer, bufferSize)); int nnzbC; HIPSPARSE_CHECK(hipsparseXgebsr2gebsrNnz(handle, dirA, mbA, nbA, nnzbA, descrA, dbsrRowPtrA, dbsrColIndA, rowBlockDimA, colBlockDimA, descrC, dbsrRowPtrC, rowBlockDimC, colBlockDimC, &nnzbC, dbuffer)); HIP_CHECK(hipDeviceSynchronize()); int* dbsrColIndC = nullptr; float* dbsrValC = nullptr; HIP_CHECK(hipMalloc((void**)&dbsrColIndC, sizeof(int) * nnzbC)); HIP_CHECK(hipMalloc((void**)&dbsrValC, sizeof(float) * rowBlockDimC * colBlockDimC * nnzbC)); HIPSPARSE_CHECK(hipsparseSgebsr2gebsr(handle, dirA, mbA, nbA, nnzbA, descrA, dbsrValA, dbsrRowPtrA, dbsrColIndA, rowBlockDimA, colBlockDimA, descrC, dbsrValC, dbsrRowPtrC, dbsrColIndC, rowBlockDimC, colBlockDimC, dbuffer)); HIP_CHECK(hipFree(dbsrRowPtrA)); HIP_CHECK(hipFree(dbsrColIndA)); HIP_CHECK(hipFree(dbsrValA)); HIP_CHECK(hipFree(dbsrRowPtrC)); HIP_CHECK(hipFree(dbsrColIndC)); HIP_CHECK(hipFree(dbsrValC)); HIP_CHECK(hipFree(dbuffer)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descrA)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descrC)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5753992 hipsparse/clients/samples/documentation_examples/conversion/example_hipsparse_nnz_compress.cpp0000664000175100017510000001002215206065364034064 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // Matrix descriptor hipsparseMatDescr_t descr_A; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descr_A)); // 1 2 0 3 0 // A = 0 4 5 0 0 // 6 0 0 7 8 float tol = 4.2f; int m = 3; int n = 5; int nnz_A = 8; int hcsrRowPtr_A[4] = {0, 3, 5, 8}; float hcsrVal_A[8] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f}; int* dcsrRowPtr_A = nullptr; float* dcsrVal_A = nullptr; HIP_CHECK(hipMalloc((void**)&dcsrRowPtr_A, sizeof(int) * (m + 1))); HIP_CHECK(hipMalloc((void**)&dcsrVal_A, sizeof(float) * nnz_A)); HIP_CHECK(hipMemcpy(dcsrRowPtr_A, hcsrRowPtr_A, sizeof(int) * (m + 1), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrVal_A, hcsrVal_A, sizeof(float) * nnz_A, hipMemcpyHostToDevice)); // Allocate memory for the nnz_per_row array int* dnnz_per_row; HIP_CHECK(hipMalloc((void**)&dnnz_per_row, sizeof(int) * m)); // Call snnz_compress() which fills in nnz_per_row array and finds the number // of entries that will be in the compressed CSR matrix int nnz_C; HIPSPARSE_CHECK(hipsparseSnnz_compress( handle, m, descr_A, dcsrVal_A, dcsrRowPtr_A, dnnz_per_row, &nnz_C, tol)); HIP_CHECK(hipFree(dcsrRowPtr_A)); HIP_CHECK(hipFree(dcsrVal_A)); HIP_CHECK(hipFree(dnnz_per_row)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descr_A)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5753992 hipsparse/clients/samples/documentation_examples/conversion/example_hipsparse_prune_dense2csr.cpp0000664000175100017510000001063115206065364034453 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // Matrix descriptor hipsparseMatDescr_t descr; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descr)); // Dense matrix in column order // 1 2 0 3 0 // A = 0 4 5 0 0 // 6 0 0 7 8 float hdense_A[15] = { 1.0f, 0.0f, 6.0f, 2.0f, 4.0f, 0.0f, 0.0f, 5.0f, 0.0f, 3.0f, 0.0f, 7.0f, 0.0f, 0.0f, 8.0f}; int m = 3; int n = 5; int lda = m; float threshold = 4.0f; float* ddense_A = nullptr; HIP_CHECK(hipMalloc((void**)&ddense_A, sizeof(float) * lda * n)); HIP_CHECK(hipMemcpy(ddense_A, hdense_A, sizeof(float) * lda * n, hipMemcpyHostToDevice)); // Allocate sparse CSR matrix int* dcsrRowPtr = nullptr; HIP_CHECK(hipMalloc((void**)&dcsrRowPtr, sizeof(int) * (m + 1))); size_t bufferSize; HIPSPARSE_CHECK(hipsparseSpruneDense2csr_bufferSize( handle, m, n, ddense_A, lda, &threshold, descr, nullptr, dcsrRowPtr, nullptr, &bufferSize)); void* dbuffer = nullptr; HIP_CHECK(hipMalloc((void**)&dbuffer, bufferSize)); int nnz_A; HIPSPARSE_CHECK(hipsparseSpruneDense2csrNnz( handle, m, n, ddense_A, lda, &threshold, descr, dcsrRowPtr, &nnz_A, dbuffer)); int* dcsrColInd = nullptr; float* dcsrVal = nullptr; HIP_CHECK(hipMalloc((void**)&dcsrColInd, sizeof(int) * nnz_A)); HIP_CHECK(hipMalloc((void**)&dcsrVal, sizeof(float) * nnz_A)); HIPSPARSE_CHECK(hipsparseSpruneDense2csr( handle, m, n, ddense_A, lda, &threshold, descr, dcsrVal, dcsrRowPtr, dcsrColInd, dbuffer)); HIP_CHECK(hipFree(dcsrRowPtr)); HIP_CHECK(hipFree(dcsrColInd)); HIP_CHECK(hipFree(dcsrVal)); HIP_CHECK(hipFree(ddense_A)); HIP_CHECK(hipFree(dbuffer)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descr)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000022500000000000010214 xustar00121 path=hipsparse/clients/samples/documentation_examples/conversion/example_hipsparse_prune_dense2csr_by_percentage.cpp 28 mtime=1779985139.5753992 hipsparse/clients/samples/documentation_examples/conversion/example_hipsparse_prune_dense2csr_by_per0000664000175100017510000001364415206065364035241 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // Matrix descriptor hipsparseMatDescr_t descr; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descr)); // Dense matrix in column order // 1 2 0 3 0 // A = 0 4 5 0 0 // 6 0 0 7 8 float hdense_A[15] = { 1.0f, 0.0f, 6.0f, 2.0f, 4.0f, 0.0f, 0.0f, 5.0f, 0.0f, 3.0f, 0.0f, 7.0f, 0.0f, 0.0f, 8.0f}; int m = 3; int n = 5; int lda = m; float percentage = 70.0f; float* ddense_A = nullptr; HIP_CHECK(hipMalloc((void**)&ddense_A, sizeof(float) * lda * n)); HIP_CHECK(hipMemcpy(ddense_A, hdense_A, sizeof(float) * lda * n, hipMemcpyHostToDevice)); // Allocate sparse CSR matrix int* dcsrRowPtr = nullptr; HIP_CHECK(hipMalloc((void**)&dcsrRowPtr, sizeof(int) * (m + 1))); pruneInfo_t info; HIPSPARSE_CHECK(hipsparseCreatePruneInfo(&info)); size_t bufferSize; HIPSPARSE_CHECK(hipsparseSpruneDense2csrByPercentage_bufferSize(handle, m, n, ddense_A, lda, percentage, descr, nullptr, dcsrRowPtr, nullptr, info, &bufferSize)); void* dbuffer = nullptr; HIP_CHECK(hipMalloc((void**)&dbuffer, bufferSize)); int nnz_A; HIPSPARSE_CHECK(hipsparseSpruneDense2csrNnzByPercentage( handle, m, n, ddense_A, lda, percentage, descr, dcsrRowPtr, &nnz_A, info, dbuffer)); int* dcsrColInd = nullptr; float* dcsrVal = nullptr; HIP_CHECK(hipMalloc((void**)&dcsrColInd, sizeof(int) * nnz_A)); HIP_CHECK(hipMalloc((void**)&dcsrVal, sizeof(float) * nnz_A)); HIPSPARSE_CHECK(hipsparseSpruneDense2csrByPercentage(handle, m, n, ddense_A, lda, percentage, descr, dcsrVal, dcsrRowPtr, dcsrColInd, info, dbuffer)); HIP_CHECK(hipFree(dcsrRowPtr)); HIP_CHECK(hipFree(dcsrColInd)); HIP_CHECK(hipFree(dcsrVal)); HIP_CHECK(hipFree(ddense_A)); HIP_CHECK(hipFree(dbuffer)); HIPSPARSE_CHECK(hipsparseDestroyPruneInfo(info)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descr)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5763993 hipsparse/clients/samples/documentation_examples/extra/0000775000175100017510000000000015206065364024012 5ustar00jenkinsjenkins././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5753992 hipsparse/clients/samples/documentation_examples/extra/example_hipsparse_csrgeam.cpp0000664000175100017510000002017215206065364031732 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { const int m = 4; const int n = 4; const int nnzA = 9; const int nnzB = 6; float alpha{1.0f}; float beta{1.0f}; // A, B, and C are m×n // A // 1 0 0 2 // 3 4 0 0 // 5 6 7 8 // 0 0 9 0 std::vector hcsrRowPtrA = {0, 2, 4, 8, 9}; std::vector hcsrColIndA = {0, 3, 0, 1, 0, 1, 2, 3, 2}; std::vector hcsrValA = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f}; // B // 0 1 0 0 // 1 0 1 0 // 0 1 0 1 // 0 0 1 0 std::vector hcsrRowPtrB = {0, 1, 3, 5, 6}; std::vector hcsrColIndB = {1, 0, 2, 1, 3, 2}; std::vector hcsrValB = {1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}; // Device memory management: Allocate and copy A, B int* dcsrRowPtrA; int* dcsrColIndA; float* dcsrValA; int* dcsrRowPtrB; int* dcsrColIndB; float* dcsrValB; int* dcsrRowPtrC; HIP_CHECK(hipMalloc((void**)&dcsrRowPtrA, (m + 1) * sizeof(int))); HIP_CHECK(hipMalloc((void**)&dcsrColIndA, nnzA * sizeof(int))); HIP_CHECK(hipMalloc((void**)&dcsrValA, nnzA * sizeof(float))); HIP_CHECK(hipMalloc((void**)&dcsrRowPtrB, (m + 1) * sizeof(int))); HIP_CHECK(hipMalloc((void**)&dcsrColIndB, nnzB * sizeof(int))); HIP_CHECK(hipMalloc((void**)&dcsrValB, nnzB * sizeof(float))); HIP_CHECK(hipMalloc((void**)&dcsrRowPtrC, (m + 1) * sizeof(int))); HIP_CHECK( hipMemcpy(dcsrRowPtrA, hcsrRowPtrA.data(), (m + 1) * sizeof(int), hipMemcpyHostToDevice)); HIP_CHECK( hipMemcpy(dcsrColIndA, hcsrColIndA.data(), nnzA * sizeof(int), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrValA, hcsrValA.data(), nnzA * sizeof(float), hipMemcpyHostToDevice)); HIP_CHECK( hipMemcpy(dcsrRowPtrB, hcsrRowPtrB.data(), (m + 1) * sizeof(int), hipMemcpyHostToDevice)); HIP_CHECK( hipMemcpy(dcsrColIndB, hcsrColIndB.data(), nnzB * sizeof(int), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrValB, hcsrValB.data(), nnzB * sizeof(float), hipMemcpyHostToDevice)); hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); hipsparseMatDescr_t descrA; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descrA)); hipsparseMatDescr_t descrB; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descrB)); hipsparseMatDescr_t descrC; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descrC)); int nnzC; HIPSPARSE_CHECK(hipsparseXcsrgeamNnz(handle, m, n, descrA, nnzA, dcsrRowPtrA, dcsrColIndA, descrB, nnzB, dcsrRowPtrB, dcsrColIndB, descrC, dcsrRowPtrC, &nnzC)); int* dcsrColIndC = nullptr; float* dcsrValC = nullptr; HIP_CHECK(hipMalloc((void**)&dcsrColIndC, sizeof(int) * nnzC)); HIP_CHECK(hipMalloc((void**)&dcsrValC, sizeof(float) * nnzC)); HIPSPARSE_CHECK(hipsparseScsrgeam(handle, m, n, &alpha, descrA, nnzA, dcsrValA, dcsrRowPtrA, dcsrColIndA, &beta, descrB, nnzB, dcsrValB, dcsrRowPtrB, dcsrColIndB, descrC, dcsrValC, dcsrRowPtrC, dcsrColIndC)); std::vector hcsrRowPtrC(m + 1); std::vector hcsrColIndC(nnzC); std::vector hcsrValC(nnzC); // Copy back to the host HIP_CHECK( hipMemcpy(hcsrRowPtrC.data(), dcsrRowPtrC, sizeof(int) * (m + 1), hipMemcpyDeviceToHost)); HIP_CHECK( hipMemcpy(hcsrColIndC.data(), dcsrColIndC, sizeof(int) * nnzC, hipMemcpyDeviceToHost)); HIP_CHECK(hipMemcpy(hcsrValC.data(), dcsrValC, sizeof(float) * nnzC, hipMemcpyDeviceToHost)); std::cout << "C" << std::endl; for(int i = 0; i < m; i++) { int start = hcsrRowPtrC[i]; int end = hcsrRowPtrC[i + 1]; std::vector temp(n, 0.0f); for(int j = start; j < end; j++) { temp[hcsrColIndC[j]] = hcsrValC[j]; } for(int j = 0; j < n; j++) { std::cout << temp[j] << " "; } std::cout << "" << std::endl; } std::cout << "" << std::endl; HIP_CHECK(hipFree(dcsrRowPtrA)); HIP_CHECK(hipFree(dcsrColIndA)); HIP_CHECK(hipFree(dcsrValA)); HIP_CHECK(hipFree(dcsrRowPtrB)); HIP_CHECK(hipFree(dcsrColIndB)); HIP_CHECK(hipFree(dcsrValB)); HIP_CHECK(hipFree(dcsrRowPtrC)); HIP_CHECK(hipFree(dcsrColIndC)); HIP_CHECK(hipFree(dcsrValC)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descrA)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descrB)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descrC)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); return 0; } //! [doc example] ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5753992 hipsparse/clients/samples/documentation_examples/extra/example_hipsparse_csrgeam2.cpp0000664000175100017510000002315115206065364032014 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { const int m = 4; const int n = 4; const int nnzA = 9; const int nnzB = 6; float alpha{1.0f}; float beta{1.0f}; // A, B, and C are m×n // A // 1 0 0 2 // 3 4 0 0 // 5 6 7 8 // 0 0 9 0 std::vector hcsrRowPtrA = {0, 2, 4, 8, 9}; std::vector hcsrColIndA = {0, 3, 0, 1, 0, 1, 2, 3, 2}; std::vector hcsrValA = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f}; // B // 0 1 0 0 // 1 0 1 0 // 0 1 0 1 // 0 0 1 0 std::vector hcsrRowPtrB = {0, 1, 3, 5, 6}; std::vector hcsrColIndB = {1, 0, 2, 1, 3, 2}; std::vector hcsrValB = {1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}; // Device memory management: Allocate and copy A, B int* dcsrRowPtrA; int* dcsrColIndA; float* dcsrValA; int* dcsrRowPtrB; int* dcsrColIndB; float* dcsrValB; int* dcsrRowPtrC; HIP_CHECK(hipMalloc((void**)&dcsrRowPtrA, (m + 1) * sizeof(int))); HIP_CHECK(hipMalloc((void**)&dcsrColIndA, nnzA * sizeof(int))); HIP_CHECK(hipMalloc((void**)&dcsrValA, nnzA * sizeof(float))); HIP_CHECK(hipMalloc((void**)&dcsrRowPtrB, (m + 1) * sizeof(int))); HIP_CHECK(hipMalloc((void**)&dcsrColIndB, nnzB * sizeof(int))); HIP_CHECK(hipMalloc((void**)&dcsrValB, nnzB * sizeof(float))); HIP_CHECK(hipMalloc((void**)&dcsrRowPtrC, (m + 1) * sizeof(int))); HIP_CHECK( hipMemcpy(dcsrRowPtrA, hcsrRowPtrA.data(), (m + 1) * sizeof(int), hipMemcpyHostToDevice)); HIP_CHECK( hipMemcpy(dcsrColIndA, hcsrColIndA.data(), nnzA * sizeof(int), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrValA, hcsrValA.data(), nnzA * sizeof(float), hipMemcpyHostToDevice)); HIP_CHECK( hipMemcpy(dcsrRowPtrB, hcsrRowPtrB.data(), (m + 1) * sizeof(int), hipMemcpyHostToDevice)); HIP_CHECK( hipMemcpy(dcsrColIndB, hcsrColIndB.data(), nnzB * sizeof(int), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrValB, hcsrValB.data(), nnzB * sizeof(float), hipMemcpyHostToDevice)); hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); hipsparseMatDescr_t descrA; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descrA)); hipsparseMatDescr_t descrB; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descrB)); hipsparseMatDescr_t descrC; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descrC)); size_t bufferSize; HIPSPARSE_CHECK(hipsparseScsrgeam2_bufferSizeExt(handle, m, n, &alpha, descrA, nnzA, dcsrValA, dcsrRowPtrA, dcsrColIndA, &beta, descrB, nnzB, dcsrValB, dcsrRowPtrB, dcsrColIndB, descrC, nullptr, dcsrRowPtrC, nullptr, &bufferSize)); void* dbuffer = nullptr; HIP_CHECK(hipMalloc((void**)&dbuffer, bufferSize)); int nnzC; HIPSPARSE_CHECK(hipsparseXcsrgeam2Nnz(handle, m, n, descrA, nnzA, dcsrRowPtrA, dcsrColIndA, descrB, nnzB, dcsrRowPtrB, dcsrColIndB, descrC, dcsrRowPtrC, &nnzC, dbuffer)); int* dcsrColIndC = nullptr; float* dcsrValC = nullptr; HIP_CHECK(hipMalloc((void**)&dcsrColIndC, sizeof(int) * nnzC)); HIP_CHECK(hipMalloc((void**)&dcsrValC, sizeof(float) * nnzC)); HIPSPARSE_CHECK(hipsparseScsrgeam2(handle, m, n, &alpha, descrA, nnzA, dcsrValA, dcsrRowPtrA, dcsrColIndA, &beta, descrB, nnzB, dcsrValB, dcsrRowPtrB, dcsrColIndB, descrC, dcsrValC, dcsrRowPtrC, dcsrColIndC, dbuffer)); std::vector hcsrRowPtrC(m + 1); std::vector hcsrColIndC(nnzC); std::vector hcsrValC(nnzC); // Copy back to the host HIP_CHECK( hipMemcpy(hcsrRowPtrC.data(), dcsrRowPtrC, sizeof(int) * (m + 1), hipMemcpyDeviceToHost)); HIP_CHECK( hipMemcpy(hcsrColIndC.data(), dcsrColIndC, sizeof(int) * nnzC, hipMemcpyDeviceToHost)); HIP_CHECK(hipMemcpy(hcsrValC.data(), dcsrValC, sizeof(float) * nnzC, hipMemcpyDeviceToHost)); std::cout << "C" << std::endl; for(int i = 0; i < m; i++) { int start = hcsrRowPtrC[i]; int end = hcsrRowPtrC[i + 1]; std::vector temp(n, 0.0f); for(int j = start; j < end; j++) { temp[hcsrColIndC[j]] = hcsrValC[j]; } for(int j = 0; j < n; j++) { std::cout << temp[j] << " "; } std::cout << "" << std::endl; } std::cout << "" << std::endl; HIP_CHECK(hipFree(dcsrRowPtrA)); HIP_CHECK(hipFree(dcsrColIndA)); HIP_CHECK(hipFree(dcsrValA)); HIP_CHECK(hipFree(dcsrRowPtrB)); HIP_CHECK(hipFree(dcsrColIndB)); HIP_CHECK(hipFree(dcsrValB)); HIP_CHECK(hipFree(dcsrRowPtrC)); HIP_CHECK(hipFree(dcsrColIndC)); HIP_CHECK(hipFree(dcsrValC)); HIP_CHECK(hipFree(dbuffer)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descrA)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descrB)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descrC)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); return 0; } //! [doc example] ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5763993 hipsparse/clients/samples/documentation_examples/extra/example_hipsparse_csrgemm.cpp0000664000175100017510000002054215206065364031747 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { const int m = 4; const int k = 3; const int n = 2; const int nnzA = 7; const int nnzB = 3; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; // A, B, and C are mxk, kxn, and m×n // A // 1 0 0 // 3 4 0 // 5 6 7 // 0 0 9 std::vector hcsrRowPtrA = {0, 1, 3, 6, 7}; std::vector hcsrColIndA = {0, 0, 1, 0, 1, 2, 2}; std::vector hcsrValA = {1.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 9.0f}; // B // 0 1 // 1 0 // 0 1 std::vector hcsrRowPtrB = {0, 1, 2, 3}; std::vector hcsrColIndB = {1, 0, 1}; std::vector hcsrValB = {1.0f, 1.0f, 1.0f}; // Device memory management: Allocate and copy A, B int* dcsrRowPtrA; int* dcsrColIndA; float* dcsrValA; int* dcsrRowPtrB; int* dcsrColIndB; float* dcsrValB; int* dcsrRowPtrC; HIP_CHECK(hipMalloc((void**)&dcsrRowPtrA, (m + 1) * sizeof(int))); HIP_CHECK(hipMalloc((void**)&dcsrColIndA, nnzA * sizeof(int))); HIP_CHECK(hipMalloc((void**)&dcsrValA, nnzA * sizeof(float))); HIP_CHECK(hipMalloc((void**)&dcsrRowPtrB, (m + 1) * sizeof(int))); HIP_CHECK(hipMalloc((void**)&dcsrColIndB, nnzB * sizeof(int))); HIP_CHECK(hipMalloc((void**)&dcsrValB, nnzB * sizeof(float))); HIP_CHECK(hipMalloc((void**)&dcsrRowPtrC, (m + 1) * sizeof(int))); HIP_CHECK( hipMemcpy(dcsrRowPtrA, hcsrRowPtrA.data(), (m + 1) * sizeof(int), hipMemcpyHostToDevice)); HIP_CHECK( hipMemcpy(dcsrColIndA, hcsrColIndA.data(), nnzA * sizeof(int), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrValA, hcsrValA.data(), nnzA * sizeof(float), hipMemcpyHostToDevice)); HIP_CHECK( hipMemcpy(dcsrRowPtrB, hcsrRowPtrB.data(), (m + 1) * sizeof(int), hipMemcpyHostToDevice)); HIP_CHECK( hipMemcpy(dcsrColIndB, hcsrColIndB.data(), nnzB * sizeof(int), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrValB, hcsrValB.data(), nnzB * sizeof(float), hipMemcpyHostToDevice)); hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); hipsparseMatDescr_t descrA; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descrA)); hipsparseMatDescr_t descrB; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descrB)); hipsparseMatDescr_t descrC; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descrC)); int nnzC; HIPSPARSE_CHECK(hipsparseXcsrgemmNnz(handle, transA, transB, m, n, k, descrA, nnzA, dcsrRowPtrA, dcsrColIndA, descrB, nnzB, dcsrRowPtrB, dcsrColIndB, descrC, dcsrRowPtrC, &nnzC)); int* dcsrColIndC = nullptr; float* dcsrValC = nullptr; HIP_CHECK(hipMalloc((void**)&dcsrColIndC, sizeof(int) * nnzC)); HIP_CHECK(hipMalloc((void**)&dcsrValC, sizeof(float) * nnzC)); HIPSPARSE_CHECK(hipsparseScsrgemm(handle, transA, transB, m, n, k, descrA, nnzA, dcsrValA, dcsrRowPtrA, dcsrColIndA, descrB, nnzB, dcsrValB, dcsrRowPtrB, dcsrColIndB, descrC, dcsrValC, dcsrRowPtrC, dcsrColIndC)); std::vector hcsrRowPtrC(m + 1); std::vector hcsrColIndC(nnzC); std::vector hcsrValC(nnzC); // Copy back to the host HIP_CHECK( hipMemcpy(hcsrRowPtrC.data(), dcsrRowPtrC, sizeof(int) * (m + 1), hipMemcpyDeviceToHost)); HIP_CHECK( hipMemcpy(hcsrColIndC.data(), dcsrColIndC, sizeof(int) * nnzC, hipMemcpyDeviceToHost)); HIP_CHECK(hipMemcpy(hcsrValC.data(), dcsrValC, sizeof(float) * nnzC, hipMemcpyDeviceToHost)); std::cout << "C" << std::endl; for(int i = 0; i < m; i++) { int start = hcsrRowPtrC[i]; int end = hcsrRowPtrC[i + 1]; std::vector temp(n, 0.0f); for(int j = start; j < end; j++) { temp[hcsrColIndC[j]] = hcsrValC[j]; } for(int j = 0; j < n; j++) { std::cout << temp[j] << " "; } std::cout << "" << std::endl; } std::cout << "" << std::endl; HIP_CHECK(hipFree(dcsrRowPtrA)); HIP_CHECK(hipFree(dcsrColIndA)); HIP_CHECK(hipFree(dcsrValA)); HIP_CHECK(hipFree(dcsrRowPtrB)); HIP_CHECK(hipFree(dcsrColIndB)); HIP_CHECK(hipFree(dcsrValB)); HIP_CHECK(hipFree(dcsrRowPtrC)); HIP_CHECK(hipFree(dcsrColIndC)); HIP_CHECK(hipFree(dcsrValC)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descrA)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descrB)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descrC)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); return 0; } //! [doc example] ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5763993 hipsparse/clients/samples/documentation_examples/extra/example_hipsparse_csrgemm2.cpp0000664000175100017510000002655515206065364032043 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { int m = 4; int k = 3; int n = 2; int nnzA = 7; int nnzB = 3; int nnzD = 6; float alpha{1.0f}; float beta{1.0f}; // A, B, and C are mxk, kxn, and m×n // A // 1 0 0 // 3 4 0 // 5 6 7 // 0 0 9 std::vector hcsrRowPtrA = {0, 1, 3, 6, 7}; std::vector hcsrColIndA = {0, 0, 1, 0, 1, 2, 2}; std::vector hcsrValA = {1.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 9.0f}; // B // 0 1 // 1 0 // 0 1 std::vector hcsrRowPtrB = {0, 1, 2, 3}; std::vector hcsrColIndB = {1, 0, 1}; std::vector hcsrValB = {1.0f, 1.0f, 1.0f}; // D // 0 1 // 2 3 // 4 5 // 0 6 std::vector hcsrRowPtrD = {0, 1, 3, 5, 6}; std::vector hcsrColIndD = {1, 0, 1, 0, 1, 1}; std::vector hcsrValD = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f}; // Device memory management: Allocate and copy A, B int* dcsrRowPtrA; int* dcsrColIndA; float* dcsrValA; int* dcsrRowPtrB; int* dcsrColIndB; float* dcsrValB; int* dcsrRowPtrD; int* dcsrColIndD; float* dcsrValD; int* dcsrRowPtrC; HIP_CHECK(hipMalloc((void**)&dcsrRowPtrA, (m + 1) * sizeof(int))); HIP_CHECK(hipMalloc((void**)&dcsrColIndA, nnzA * sizeof(int))); HIP_CHECK(hipMalloc((void**)&dcsrValA, nnzA * sizeof(float))); HIP_CHECK(hipMalloc((void**)&dcsrRowPtrB, (k + 1) * sizeof(int))); HIP_CHECK(hipMalloc((void**)&dcsrColIndB, nnzB * sizeof(int))); HIP_CHECK(hipMalloc((void**)&dcsrValB, nnzB * sizeof(float))); HIP_CHECK(hipMalloc((void**)&dcsrRowPtrD, (m + 1) * sizeof(int))); HIP_CHECK(hipMalloc((void**)&dcsrColIndD, nnzD * sizeof(int))); HIP_CHECK(hipMalloc((void**)&dcsrValD, nnzD * sizeof(float))); HIP_CHECK(hipMalloc((void**)&dcsrRowPtrC, (m + 1) * sizeof(int))); HIP_CHECK( hipMemcpy(dcsrRowPtrA, hcsrRowPtrA.data(), (m + 1) * sizeof(int), hipMemcpyHostToDevice)); HIP_CHECK( hipMemcpy(dcsrColIndA, hcsrColIndA.data(), nnzA * sizeof(int), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrValA, hcsrValA.data(), nnzA * sizeof(float), hipMemcpyHostToDevice)); HIP_CHECK( hipMemcpy(dcsrRowPtrB, hcsrRowPtrB.data(), (k + 1) * sizeof(int), hipMemcpyHostToDevice)); HIP_CHECK( hipMemcpy(dcsrColIndB, hcsrColIndB.data(), nnzB * sizeof(int), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrValB, hcsrValB.data(), nnzB * sizeof(float), hipMemcpyHostToDevice)); HIP_CHECK( hipMemcpy(dcsrRowPtrD, hcsrRowPtrD.data(), (m + 1) * sizeof(int), hipMemcpyHostToDevice)); HIP_CHECK( hipMemcpy(dcsrColIndD, hcsrColIndD.data(), nnzD * sizeof(int), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrValD, hcsrValD.data(), nnzD * sizeof(float), hipMemcpyHostToDevice)); hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); hipsparseMatDescr_t descrA; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descrA)); hipsparseMatDescr_t descrB; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descrB)); hipsparseMatDescr_t descrC; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descrC)); hipsparseMatDescr_t descrD; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descrD)); csrgemm2Info_t info; HIPSPARSE_CHECK(hipsparseCreateCsrgemm2Info(&info)); size_t bufferSize; HIPSPARSE_CHECK(hipsparseScsrgemm2_bufferSizeExt(handle, m, n, k, &alpha, descrA, nnzA, dcsrRowPtrA, dcsrColIndA, descrB, nnzB, dcsrRowPtrB, dcsrColIndB, &beta, descrD, nnzD, dcsrRowPtrD, dcsrColIndD, info, &bufferSize)); void* dbuffer = nullptr; HIP_CHECK(hipMalloc((void**)&dbuffer, bufferSize)); int nnzC; HIPSPARSE_CHECK(hipsparseXcsrgemm2Nnz(handle, m, n, k, descrA, nnzA, dcsrRowPtrA, dcsrColIndA, descrB, nnzB, dcsrRowPtrB, dcsrColIndB, descrD, nnzD, dcsrRowPtrD, dcsrColIndD, descrC, dcsrRowPtrC, &nnzC, info, dbuffer)); int* dcsrColIndC = nullptr; float* dcsrValC = nullptr; HIP_CHECK(hipMalloc((void**)&dcsrColIndC, sizeof(int) * nnzC)); HIP_CHECK(hipMalloc((void**)&dcsrValC, sizeof(float) * nnzC)); HIPSPARSE_CHECK(hipsparseScsrgemm2(handle, m, n, k, &alpha, descrA, nnzA, dcsrValA, dcsrRowPtrA, dcsrColIndA, descrB, nnzB, dcsrValB, dcsrRowPtrB, dcsrColIndB, &beta, descrD, nnzD, dcsrValD, dcsrRowPtrD, dcsrColIndD, descrC, dcsrValC, dcsrRowPtrC, dcsrColIndC, info, dbuffer)); std::vector hcsrRowPtrC(m + 1); std::vector hcsrColIndC(nnzC); std::vector hcsrValC(nnzC); // Copy back to the host HIP_CHECK( hipMemcpy(hcsrRowPtrC.data(), dcsrRowPtrC, sizeof(int) * (m + 1), hipMemcpyDeviceToHost)); HIP_CHECK( hipMemcpy(hcsrColIndC.data(), dcsrColIndC, sizeof(int) * nnzC, hipMemcpyDeviceToHost)); HIP_CHECK(hipMemcpy(hcsrValC.data(), dcsrValC, sizeof(float) * nnzC, hipMemcpyDeviceToHost)); std::cout << "C" << std::endl; for(int i = 0; i < m; i++) { int start = hcsrRowPtrC[i]; int end = hcsrRowPtrC[i + 1]; std::vector temp(n, 0.0f); for(int j = start; j < end; j++) { temp[hcsrColIndC[j]] = hcsrValC[j]; } for(int j = 0; j < n; j++) { std::cout << temp[j] << " "; } std::cout << "" << std::endl; } std::cout << "" << std::endl; HIP_CHECK(hipFree(dcsrRowPtrA)); HIP_CHECK(hipFree(dcsrColIndA)); HIP_CHECK(hipFree(dcsrValA)); HIP_CHECK(hipFree(dcsrRowPtrB)); HIP_CHECK(hipFree(dcsrColIndB)); HIP_CHECK(hipFree(dcsrValB)); HIP_CHECK(hipFree(dcsrRowPtrC)); HIP_CHECK(hipFree(dcsrColIndC)); HIP_CHECK(hipFree(dcsrValC)); HIP_CHECK(hipFree(dcsrRowPtrD)); HIP_CHECK(hipFree(dcsrColIndD)); HIP_CHECK(hipFree(dcsrValD)); HIP_CHECK(hipFree(dbuffer)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descrA)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descrB)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descrC)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descrD)); HIPSPARSE_CHECK(hipsparseDestroyCsrgemm2Info(info)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); return 0; } //! [doc example] ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5773993 hipsparse/clients/samples/documentation_examples/generic/0000775000175100017510000000000015206065364024303 5ustar00jenkinsjenkins././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5763993 hipsparse/clients/samples/documentation_examples/generic/example_hipsparse_axpby.cpp0000664000175100017510000001125415206065364031726 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // Number of non-zeros of the sparse vector int nnz = 3; // Size of sparse and dense vector int size = 9; // Sparse index vector std::vector hxInd = {0, 3, 5}; // Sparse value vector std::vector hxVal = {1.0f, 2.0f, 3.0f}; // Dense vector std::vector hy = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f}; // Scalar alpha float alpha = 3.7f; // Scalar beta float beta = 1.2f; // Offload data to device int* dxInd; float* dxVal; float* dy; HIP_CHECK(hipMalloc((void**)&dxInd, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dxVal, sizeof(float) * nnz)); HIP_CHECK(hipMalloc((void**)&dy, sizeof(float) * size)); HIP_CHECK(hipMemcpy(dxInd, hxInd.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dxVal, hxVal.data(), sizeof(float) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dy, hy.data(), sizeof(float) * size, hipMemcpyHostToDevice)); hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // Create sparse vector X hipsparseSpVecDescr_t vecX; HIPSPARSE_CHECK(hipsparseCreateSpVec( &vecX, size, nnz, dxInd, dxVal, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); // Create dense vector Y hipsparseDnVecDescr_t vecY; HIPSPARSE_CHECK(hipsparseCreateDnVec(&vecY, size, dy, HIP_R_32F)); // Call axpby to perform y = beta * y + alpha * x HIPSPARSE_CHECK(hipsparseAxpby(handle, &alpha, vecX, &beta, vecY)); HIPSPARSE_CHECK(hipsparseDnVecGetValues(vecY, (void**)&dy)); // Copy result back to host HIP_CHECK(hipMemcpy(hy.data(), dy, sizeof(float) * size, hipMemcpyDeviceToHost)); std::cout << "hy" << std::endl; for(size_t i = 0; i < hy.size(); i++) { std::cout << hy[i] << " "; } std::cout << "" << std::endl; // Clear hipSPARSE HIPSPARSE_CHECK(hipsparseDestroySpVec(vecX)); HIPSPARSE_CHECK(hipsparseDestroyDnVec(vecY)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); // Clear device memory HIP_CHECK(hipFree(dxInd)); HIP_CHECK(hipFree(dxVal)); HIP_CHECK(hipFree(dy)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5763993 hipsparse/clients/samples/documentation_examples/generic/example_hipsparse_dense_to_sparse.cpp0000664000175100017510000001425315206065364033762 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // 1 0 0 0 // A = 4 2 0 4 // 0 3 7 0 // 9 0 0 1 int m = 4; int n = 4; std::vector hdenseA = {1.0f, 4.0f, 0.0f, 9.0f, 0.0f, 2.0f, 3.0f, 0.0f, 0.0f, 0.0f, 7.0f, 0.0f, 0.0f, 4.0f, 0.0f, 1.0f}; float* ddenseA; HIP_CHECK(hipMalloc((void**)&ddenseA, sizeof(float) * m * n)); HIP_CHECK(hipMemcpy(ddenseA, hdenseA.data(), sizeof(float) * m * n, hipMemcpyHostToDevice)); int* dcsrRowPtrB; HIP_CHECK(hipMalloc((void**)&dcsrRowPtrB, sizeof(int) * (m + 1))); hipsparseHandle_t handle; hipsparseDnMatDescr_t matA; hipsparseSpMatDescr_t matB; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // Create dense matrix A HIPSPARSE_CHECK(hipsparseCreateDnMat(&matA, m, n, m, ddenseA, HIP_R_32F, HIPSPARSE_ORDER_COL)); hipsparseIndexType_t rowIdxTypeB = HIPSPARSE_INDEX_32I; hipsparseIndexType_t colIdxTypeB = HIPSPARSE_INDEX_32I; hipDataType dataTypeB = HIP_R_32F; hipsparseIndexBase_t idxBaseB = HIPSPARSE_INDEX_BASE_ZERO; // Create sparse matrix B HIPSPARSE_CHECK(hipsparseCreateCsr( &matB, m, n, 0, dcsrRowPtrB, NULL, NULL, rowIdxTypeB, colIdxTypeB, idxBaseB, dataTypeB)); hipsparseDenseToSparseAlg_t alg = HIPSPARSE_DENSETOSPARSE_ALG_DEFAULT; size_t bufferSize; HIPSPARSE_CHECK(hipsparseDenseToSparse_bufferSize(handle, matA, matB, alg, &bufferSize)); void* tempBuffer; HIP_CHECK(hipMalloc((void**)&tempBuffer, bufferSize)); // Perform analysis which will determine the number of non-zeros in the CSR matrix HIPSPARSE_CHECK(hipsparseDenseToSparse_analysis(handle, matA, matB, alg, tempBuffer)); // Grab the non-zero count from the B matrix decriptor int64_t rows; int64_t cols; int64_t nnz; HIPSPARSE_CHECK(hipsparseSpMatGetSize(matB, &rows, &cols, &nnz)); // Allocate the column indices and values arrays int* dcsrColIndB; float* dcsrValB; HIP_CHECK(hipMalloc((void**)&dcsrColIndB, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dcsrValB, sizeof(float) * nnz)); // Set the newly allocated arrays on the sparse matrix descriptor HIPSPARSE_CHECK(hipsparseCsrSetPointers(matB, dcsrRowPtrB, dcsrColIndB, dcsrValB)); // Complete the conversion HIPSPARSE_CHECK(hipsparseDenseToSparse_convert(handle, matA, matB, alg, tempBuffer)); // Copy result back to host std::vector hcsrRowPtrB(m + 1); std::vector hcsrColIndB(nnz); std::vector hcsrValB(nnz); HIP_CHECK( hipMemcpy(hcsrRowPtrB.data(), dcsrRowPtrB, sizeof(int) * (m + 1), hipMemcpyDeviceToHost)); HIP_CHECK(hipMemcpy(hcsrColIndB.data(), dcsrColIndB, sizeof(int) * nnz, hipMemcpyDeviceToHost)); HIP_CHECK(hipMemcpy(hcsrValB.data(), dcsrValB, sizeof(float) * nnz, hipMemcpyDeviceToHost)); // Clear hipSPARSE HIPSPARSE_CHECK(hipsparseDestroyMatDescr(matA)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(matB)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); // Clear device memory HIP_CHECK(hipFree(ddenseA)); HIP_CHECK(hipFree(dcsrRowPtrB)); HIP_CHECK(hipFree(dcsrColIndB)); HIP_CHECK(hipFree(dcsrValB)); HIP_CHECK(hipFree(tempBuffer)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5763993 hipsparse/clients/samples/documentation_examples/generic/example_hipsparse_gather.cpp0000664000175100017510000001041515206065364032053 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // Number of non-zeros of the sparse vector int nnz = 3; // Size of sparse and dense vector int size = 9; // Sparse index vector std::vector hxInd = {0, 3, 5}; // Dense vector std::vector hy = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f}; // Offload data to device int* dxInd; float* dxVal; float* dy; HIP_CHECK(hipMalloc((void**)&dxInd, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dxVal, sizeof(float) * nnz)); HIP_CHECK(hipMalloc((void**)&dy, sizeof(float) * size)); HIP_CHECK(hipMemcpy(dxInd, hxInd.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dy, hy.data(), sizeof(float) * size, hipMemcpyHostToDevice)); hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // Create sparse vector X hipsparseSpVecDescr_t vecX; HIPSPARSE_CHECK(hipsparseCreateSpVec( &vecX, size, nnz, dxInd, dxVal, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); // Create dense vector Y hipsparseDnVecDescr_t vecY; HIPSPARSE_CHECK(hipsparseCreateDnVec(&vecY, size, dy, HIP_R_32F)); // Perform gather HIPSPARSE_CHECK(hipsparseGather(handle, vecY, vecX)); HIPSPARSE_CHECK(hipsparseSpVecGetValues(vecX, (void**)&dxVal)); // Copy result back to host std::vector hxVal(nnz, 0.0f); HIP_CHECK(hipMemcpy(hxVal.data(), dxVal, sizeof(float) * nnz, hipMemcpyDeviceToHost)); // Clear hipSPARSE HIPSPARSE_CHECK(hipsparseDestroySpVec(vecX)); HIPSPARSE_CHECK(hipsparseDestroyDnVec(vecY)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); // Clear device memory HIP_CHECK(hipFree(dxInd)); HIP_CHECK(hipFree(dxVal)); HIP_CHECK(hipFree(dy)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5763993 hipsparse/clients/samples/documentation_examples/generic/example_hipsparse_rot.cpp0000664000175100017510000001117415206065364031410 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // Number of non-zeros of the sparse vector int nnz = 3; // Size of sparse and dense vector int size = 9; // Sparse index vector std::vector hxInd = {0, 3, 5}; // Sparse value vector std::vector hxVal = {1.0f, 2.0f, 3.0f}; // Dense vector std::vector hy = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f}; // Scalar c float c = 3.7f; // Scalar s float s = 1.2f; // Offload data to device int* dxInd; float* dxVal; float* dy; HIP_CHECK(hipMalloc((void**)&dxInd, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dxVal, sizeof(float) * nnz)); HIP_CHECK(hipMalloc((void**)&dy, sizeof(float) * size)); HIP_CHECK(hipMemcpy(dxInd, hxInd.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dxVal, hxVal.data(), sizeof(float) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dy, hy.data(), sizeof(float) * size, hipMemcpyHostToDevice)); hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // Create sparse vector X hipsparseSpVecDescr_t vecX; HIPSPARSE_CHECK(hipsparseCreateSpVec( &vecX, size, nnz, dxInd, dxVal, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); // Create dense vector Y hipsparseDnVecDescr_t vecY; HIPSPARSE_CHECK(hipsparseCreateDnVec(&vecY, size, dy, HIP_R_32F)); // Call rot HIPSPARSE_CHECK(hipsparseRot(handle, (void*)&c, (void*)&s, vecX, vecY)); HIPSPARSE_CHECK(hipsparseSpVecGetValues(vecX, (void**)&dxVal)); HIPSPARSE_CHECK(hipsparseDnVecGetValues(vecY, (void**)&dy)); // Copy result back to host HIP_CHECK(hipMemcpy(hxVal.data(), dxVal, sizeof(float) * nnz, hipMemcpyDeviceToHost)); HIP_CHECK(hipMemcpy(hy.data(), dy, sizeof(float) * size, hipMemcpyDeviceToHost)); // Clear hipSPARSE HIPSPARSE_CHECK(hipsparseDestroySpVec(vecX)); HIPSPARSE_CHECK(hipsparseDestroyDnVec(vecY)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); // Clear device memory HIP_CHECK(hipFree(dxInd)); HIP_CHECK(hipFree(dxVal)); HIP_CHECK(hipFree(dy)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5763993 hipsparse/clients/samples/documentation_examples/generic/example_hipsparse_scatter.cpp0000664000175100017510000001061015206065364032243 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // Number of non-zeros of the sparse vector int nnz = 3; // Size of sparse and dense vector int size = 9; // Sparse index vector std::vector hxInd = {0, 3, 5}; // Sparse value vector std::vector hxVal = {1.0f, 2.0f, 3.0f}; // Dense vector std::vector hy = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f}; // Offload data to device int* dxInd; float* dxVal; float* dy; HIP_CHECK(hipMalloc((void**)&dxInd, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dxVal, sizeof(float) * nnz)); HIP_CHECK(hipMalloc((void**)&dy, sizeof(float) * size)); HIP_CHECK(hipMemcpy(dxInd, hxInd.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dxVal, hxVal.data(), sizeof(float) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dy, hy.data(), sizeof(float) * size, hipMemcpyHostToDevice)); hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // Create sparse vector X hipsparseSpVecDescr_t vecX; HIPSPARSE_CHECK(hipsparseCreateSpVec( &vecX, size, nnz, dxInd, dxVal, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); // Create dense vector Y hipsparseDnVecDescr_t vecY; HIPSPARSE_CHECK(hipsparseCreateDnVec(&vecY, size, dy, HIP_R_32F)); // Perform scatter HIPSPARSE_CHECK(hipsparseScatter(handle, vecX, vecY)); HIPSPARSE_CHECK(hipsparseDnVecGetValues(vecY, (void**)&dy)); // Copy result back to host HIP_CHECK(hipMemcpy(hy.data(), dy, sizeof(float) * size, hipMemcpyDeviceToHost)); // Clear hipSPARSE HIPSPARSE_CHECK(hipsparseDestroySpVec(vecX)); HIPSPARSE_CHECK(hipsparseDestroyDnVec(vecY)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); // Clear device memory HIP_CHECK(hipFree(dxInd)); HIP_CHECK(hipFree(dxVal)); HIP_CHECK(hipFree(dy)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5763993 hipsparse/clients/samples/documentation_examples/generic/example_hipsparse_sddmm.cpp0000664000175100017510000002064215206065364031710 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); __half halpha = 1.0; __half hbeta = 0.0; // A, B, and C are mxk, kxn, and mxn int m = 4; int k = 3; int n = 2; int nnzC = 5; // 2 3 -1 // A = 0 2 1 // 0 0 5 // 0 -2 0.5 // 0 4 // B = 1 0 // -2 0.5 // 1 0 1 0 // C = 2 3 spy(C) = 1 1 // 0 0 0 0 // 4 5 1 1 std::vector<__half> hA = {2.0, 3.0, -1.0, 0.0, 2.0, 1.0, 0.0, 0.0, 5.0, 0.0, -2.0, 0.5}; std::vector<__half> hB = {0.0, 4.0, 1.0, 0.0, -2.0, 0.5}; std::vector hcsr_row_ptrC = {0, 1, 3, 3, 5}; std::vector hcsr_col_indC = {0, 0, 1, 0, 1}; std::vector<__half> hcsr_valC = {1.0, 2.0, 3.0, 4.0, 5.0}; __half* dA = nullptr; __half* dB = nullptr; HIP_CHECK(hipMalloc((void**)&dA, sizeof(__half) * m * k)); HIP_CHECK(hipMalloc((void**)&dB, sizeof(__half) * k * n)); int* dcsr_row_ptrC = nullptr; int* dcsr_col_indC = nullptr; __half* dcsr_valC = nullptr; HIP_CHECK(hipMalloc((void**)&dcsr_row_ptrC, sizeof(int) * (m + 1))); HIP_CHECK(hipMalloc((void**)&dcsr_col_indC, sizeof(int) * nnzC)); HIP_CHECK(hipMalloc((void**)&dcsr_valC, sizeof(__half) * nnzC)); HIP_CHECK(hipMemcpy(dA, hA.data(), sizeof(__half) * m * k, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dB, hB.data(), sizeof(__half) * k * n, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy( dcsr_row_ptrC, hcsr_row_ptrC.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); HIP_CHECK( hipMemcpy(dcsr_col_indC, hcsr_col_indC.data(), sizeof(int) * nnzC, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsr_valC, hcsr_valC.data(), sizeof(__half) * nnzC, hipMemcpyHostToDevice)); hipsparseDnMatDescr_t matA; HIPSPARSE_CHECK(hipsparseCreateDnMat(&matA, m, k, k, dA, HIP_R_16F, HIPSPARSE_ORDER_ROW)); hipsparseDnMatDescr_t matB; HIPSPARSE_CHECK(hipsparseCreateDnMat(&matB, k, n, n, dB, HIP_R_16F, HIPSPARSE_ORDER_ROW)); hipsparseSpMatDescr_t matC; HIPSPARSE_CHECK(hipsparseCreateCsr(&matC, m, n, nnzC, dcsr_row_ptrC, dcsr_col_indC, dcsr_valC, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_16F)); size_t buffer_size = 0; HIPSPARSE_CHECK(hipsparseSDDMM_bufferSize(handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_NON_TRANSPOSE, &halpha, matA, matB, &hbeta, matC, HIP_R_16F, HIPSPARSE_SDDMM_ALG_DEFAULT, &buffer_size)); void* dbuffer = nullptr; HIP_CHECK(hipMalloc((void**)&dbuffer, buffer_size)); HIPSPARSE_CHECK(hipsparseSDDMM_preprocess(handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_NON_TRANSPOSE, &halpha, matA, matB, &hbeta, matC, HIP_R_16F, HIPSPARSE_SDDMM_ALG_DEFAULT, dbuffer)); HIPSPARSE_CHECK(hipsparseSDDMM(handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_NON_TRANSPOSE, &halpha, matA, matB, &hbeta, matC, HIP_R_16F, HIPSPARSE_SDDMM_ALG_DEFAULT, dbuffer)); HIP_CHECK(hipMemcpy( hcsr_row_ptrC.data(), dcsr_row_ptrC, sizeof(int) * (m + 1), hipMemcpyDeviceToHost)); HIP_CHECK( hipMemcpy(hcsr_col_indC.data(), dcsr_col_indC, sizeof(int) * nnzC, hipMemcpyDeviceToHost)); HIP_CHECK(hipMemcpy(hcsr_valC.data(), dcsr_valC, sizeof(__half) * nnzC, hipMemcpyDeviceToHost)); std::cout << "C" << std::endl; for(int i = 0; i < m; i++) { int start = hcsr_row_ptrC[i]; int end = hcsr_row_ptrC[i + 1]; std::vector<__half> temp(n, 0.0); for(int j = start; j < end; j++) { temp[hcsr_col_indC[j]] = hcsr_valC[j]; } for(int j = 0; j < n; j++) { std::cout << temp[j] << " "; } std::cout << "" << std::endl; } std::cout << "" << std::endl; HIPSPARSE_CHECK(hipsparseDestroyMatDescr(matA)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(matB)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(matC)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); HIP_CHECK(hipFree(dA)); HIP_CHECK(hipFree(dB)); HIP_CHECK(hipFree(dcsr_row_ptrC)); HIP_CHECK(hipFree(dcsr_col_indC)); HIP_CHECK(hipFree(dcsr_valC)); HIP_CHECK(hipFree(dbuffer)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5763993 hipsparse/clients/samples/documentation_examples/generic/example_hipsparse_sparse_to_dense.cpp0000664000175100017510000001277615206065364033772 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // 1 0 0 0 // A = 4 2 0 4 // 0 3 7 0 // 9 0 0 1 int m = 4; int n = 4; int nnz = 8; std::vector hcsrRowPtrA = {0, 1, 4, 6, 8}; std::vector hcsrColIndA = {0, 0, 1, 3, 1, 2, 0, 3}; std::vector hcsrValA = {1.0f, 4.0f, 2.0f, 4.0f, 3.0f, 7.0f, 9.0f, 1.0f}; int* dcsrRowPtrA; int* dcsrColIndA; float* dcsrValA; HIP_CHECK(hipMalloc((void**)&dcsrRowPtrA, sizeof(int) * (m + 1))); HIP_CHECK(hipMalloc((void**)&dcsrColIndA, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dcsrValA, sizeof(float) * nnz)); HIP_CHECK( hipMemcpy(dcsrRowPtrA, hcsrRowPtrA.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrColIndA, hcsrColIndA.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrValA, hcsrValA.data(), sizeof(float) * nnz, hipMemcpyHostToDevice)); float* ddenseB; HIP_CHECK(hipMalloc((void**)&ddenseB, sizeof(float) * m * n)); hipsparseHandle_t handle; hipsparseSpMatDescr_t matA; hipsparseDnMatDescr_t matB; HIPSPARSE_CHECK(hipsparseCreate(&handle)); hipsparseIndexType_t rowIdxTypeA = HIPSPARSE_INDEX_32I; hipsparseIndexType_t colIdxTypeA = HIPSPARSE_INDEX_32I; hipDataType dataTypeA = HIP_R_32F; hipsparseIndexBase_t idxBaseA = HIPSPARSE_INDEX_BASE_ZERO; // Create sparse matrix A HIPSPARSE_CHECK(hipsparseCreateCsr(&matA, m, n, nnz, dcsrRowPtrA, dcsrColIndA, dcsrValA, rowIdxTypeA, colIdxTypeA, idxBaseA, dataTypeA)); // Create dense matrix B HIPSPARSE_CHECK(hipsparseCreateDnMat(&matB, m, n, m, ddenseB, HIP_R_32F, HIPSPARSE_ORDER_COL)); hipsparseSparseToDenseAlg_t alg = HIPSPARSE_SPARSETODENSE_ALG_DEFAULT; size_t bufferSize; HIPSPARSE_CHECK(hipsparseSparseToDense_bufferSize(handle, matA, matB, alg, &bufferSize)); void* tempBuffer; HIP_CHECK(hipMalloc((void**)&tempBuffer, bufferSize)); // Complete the conversion HIPSPARSE_CHECK(hipsparseSparseToDense(handle, matA, matB, alg, tempBuffer)); // Copy result back to host std::vector hdenseB(m * n); HIP_CHECK(hipMemcpy(hdenseB.data(), ddenseB, sizeof(float) * m * n, hipMemcpyDeviceToHost)); // Clear hipSPARSE HIPSPARSE_CHECK(hipsparseDestroyMatDescr(matA)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(matB)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); // Clear device memory HIP_CHECK(hipFree(dcsrRowPtrA)); HIP_CHECK(hipFree(dcsrColIndA)); HIP_CHECK(hipFree(dcsrValA)); HIP_CHECK(hipFree(ddenseB)); HIP_CHECK(hipFree(tempBuffer)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5763993 hipsparse/clients/samples/documentation_examples/generic/example_hipsparse_spgemm.cpp0000664000175100017510000003055015206065364032073 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { int m = 2; int k = 2; int n = 3; int nnzA = 4; int nnzB = 4; float alpha{1.0f}; float beta{0.0f}; hipsparseOperation_t opA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t opB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipDataType computeType = HIP_R_32F; // A, B, and C are m×k, k×n, and m×n // A std::vector hcsrRowPtrA = {0, 2, 4}; std::vector hcsrColIndA = {0, 1, 0, 1}; std::vector hcsrValA = {1.0f, 2.0f, 3.0f, 4.0f}; // B std::vector hcsrRowPtrB = {0, 2, 4}; std::vector hcsrColIndB = {1, 2, 0, 2}; std::vector hcsrValB = {5.0f, 6.0f, 7.0f, 8.0f}; // Device memory management: Allocate and copy A, B int* dcsrRowPtrA; int* dcsrColIndA; float* dcsrValA; int* dcsrRowPtrB; int* dcsrColIndB; float* dcsrValB; int* dcsrRowPtrC; int* dcsrColIndC; float* dcsrValC; HIP_CHECK(hipMalloc((void**)&dcsrRowPtrA, (m + 1) * sizeof(int))); HIP_CHECK(hipMalloc((void**)&dcsrColIndA, nnzA * sizeof(int))); HIP_CHECK(hipMalloc((void**)&dcsrValA, nnzA * sizeof(float))); HIP_CHECK(hipMalloc((void**)&dcsrRowPtrB, (k + 1) * sizeof(int))); HIP_CHECK(hipMalloc((void**)&dcsrColIndB, nnzB * sizeof(int))); HIP_CHECK(hipMalloc((void**)&dcsrValB, nnzB * sizeof(float))); HIP_CHECK(hipMalloc((void**)&dcsrRowPtrC, (m + 1) * sizeof(int))); HIP_CHECK( hipMemcpy(dcsrRowPtrA, hcsrRowPtrA.data(), (m + 1) * sizeof(int), hipMemcpyHostToDevice)); HIP_CHECK( hipMemcpy(dcsrColIndA, hcsrColIndA.data(), nnzA * sizeof(int), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrValA, hcsrValA.data(), nnzA * sizeof(float), hipMemcpyHostToDevice)); HIP_CHECK( hipMemcpy(dcsrRowPtrB, hcsrRowPtrB.data(), (k + 1) * sizeof(int), hipMemcpyHostToDevice)); HIP_CHECK( hipMemcpy(dcsrColIndB, hcsrColIndB.data(), nnzB * sizeof(int), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrValB, hcsrValB.data(), nnzB * sizeof(float), hipMemcpyHostToDevice)); hipsparseSpMatDescr_t matA, matB, matC; hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // Create sparse matrix A in CSR format HIPSPARSE_CHECK(hipsparseCreateCsr(&matA, m, k, nnzA, dcsrRowPtrA, dcsrColIndA, dcsrValA, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); HIPSPARSE_CHECK(hipsparseCreateCsr(&matB, k, n, nnzB, dcsrRowPtrB, dcsrColIndB, dcsrValB, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); HIPSPARSE_CHECK(hipsparseCreateCsr(&matC, m, n, 0, dcsrRowPtrC, NULL, NULL, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); hipsparseSpGEMMDescr_t spgemmDesc; HIPSPARSE_CHECK(hipsparseSpGEMM_createDescr(&spgemmDesc)); void* dBuffer1 = NULL; void* dBuffer2 = NULL; size_t bufferSize1 = 0; size_t bufferSize2 = 0; // Determine size of first user allocated buffer HIPSPARSE_CHECK(hipsparseSpGEMM_workEstimation(handle, opA, opB, &alpha, matA, matB, &beta, matC, computeType, HIPSPARSE_SPGEMM_DEFAULT, spgemmDesc, &bufferSize1, NULL)); HIP_CHECK(hipMalloc((void**)&dBuffer1, bufferSize1)); // Inspect the matrices A and B to determine the number of intermediate product in // C = alpha * A * B HIPSPARSE_CHECK(hipsparseSpGEMM_workEstimation(handle, opA, opB, &alpha, matA, matB, &beta, matC, computeType, HIPSPARSE_SPGEMM_DEFAULT, spgemmDesc, &bufferSize1, dBuffer1)); // Determine size of second user allocated buffer HIPSPARSE_CHECK(hipsparseSpGEMM_compute(handle, opA, opB, &alpha, matA, matB, &beta, matC, computeType, HIPSPARSE_SPGEMM_DEFAULT, spgemmDesc, &bufferSize2, NULL)); HIP_CHECK(hipMalloc((void**)&dBuffer2, bufferSize2)); // Compute C = alpha * A * B and store result in temporary buffers HIPSPARSE_CHECK(hipsparseSpGEMM_compute(handle, opA, opB, &alpha, matA, matB, &beta, matC, computeType, HIPSPARSE_SPGEMM_DEFAULT, spgemmDesc, &bufferSize2, dBuffer2)); // Get matrix C non-zero entries C_nnz1 int64_t C_num_rows1, C_num_cols1, C_nnz1; HIPSPARSE_CHECK(hipsparseSpMatGetSize(matC, &C_num_rows1, &C_num_cols1, &C_nnz1)); // Allocate the CSR structures for the matrix C HIP_CHECK(hipMalloc((void**)&dcsrColIndC, C_nnz1 * sizeof(int))); HIP_CHECK(hipMalloc((void**)&dcsrValC, C_nnz1 * sizeof(float))); // Update matC with the new pointers HIPSPARSE_CHECK(hipsparseCsrSetPointers(matC, dcsrRowPtrC, dcsrColIndC, dcsrValC)); // Copy the final products to the matrix C HIPSPARSE_CHECK(hipsparseSpGEMM_copy(handle, opA, opB, &alpha, matA, matB, &beta, matC, computeType, HIPSPARSE_SPGEMM_DEFAULT, spgemmDesc)); std::vector hcsrRowPtrC(m + 1); std::vector hcsrColIndC(C_nnz1); std::vector hcsrValC(C_nnz1); // Copy back to the host HIP_CHECK( hipMemcpy(hcsrRowPtrC.data(), dcsrRowPtrC, sizeof(int) * (m + 1), hipMemcpyDeviceToHost)); HIP_CHECK( hipMemcpy(hcsrColIndC.data(), dcsrColIndC, sizeof(int) * C_nnz1, hipMemcpyDeviceToHost)); HIP_CHECK(hipMemcpy(hcsrValC.data(), dcsrValC, sizeof(float) * C_nnz1, hipMemcpyDeviceToHost)); std::cout << "C" << std::endl; for(int i = 0; i < m; i++) { int start = hcsrRowPtrC[i]; int end = hcsrRowPtrC[i + 1]; std::vector temp(n, 0.0f); for(int j = start; j < end; j++) { temp[hcsrColIndC[j]] = hcsrValC[j]; } for(int j = 0; j < n; j++) { std::cout << temp[j] << " "; } std::cout << "" << std::endl; } std::cout << "" << std::endl; // Destroy matrix descriptors and handles HIPSPARSE_CHECK(hipsparseSpGEMM_destroyDescr(spgemmDesc)); HIPSPARSE_CHECK(hipsparseDestroySpMat(matA)); HIPSPARSE_CHECK(hipsparseDestroySpMat(matB)); HIPSPARSE_CHECK(hipsparseDestroySpMat(matC)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); // Free device memory HIP_CHECK(hipFree(dBuffer1)); HIP_CHECK(hipFree(dBuffer2)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5763993 hipsparse/clients/samples/documentation_examples/generic/example_hipsparse_spgemm_reuse.cpp0000664000175100017510000003713715206065364033306 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { int m = 2; int k = 2; int n = 3; int nnzA = 4; int nnzB = 4; float alpha{1.0f}; float beta{0.0f}; hipsparseOperation_t opA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t opB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipDataType computeType = HIP_R_32F; // A, B, and C are m×k, k×n, and m×n // A std::vector hcsrRowPtrA = {0, 2, 4}; std::vector hcsrColIndA = {0, 1, 0, 1}; std::vector hcsrValA = {1.0f, 2.0f, 3.0f, 4.0f}; // B std::vector hcsrRowPtrB = {0, 2, 4}; std::vector hcsrColIndB = {1, 2, 0, 2}; std::vector hcsrValB = {5.0f, 6.0f, 7.0f, 8.0f}; // Device memory management: Allocate and copy A, B int* dcsrRowPtrA; int* dcsrColIndA; float* dcsrValA; int* dcsrRowPtrB; int* dcsrColIndB; float* dcsrValB; int* dcsrRowPtrC; int* dcsrColIndC; float* dcsrValC; HIP_CHECK(hipMalloc((void**)&dcsrRowPtrA, (m + 1) * sizeof(int))); HIP_CHECK(hipMalloc((void**)&dcsrColIndA, nnzA * sizeof(int))); HIP_CHECK(hipMalloc((void**)&dcsrValA, nnzA * sizeof(float))); HIP_CHECK(hipMalloc((void**)&dcsrRowPtrB, (k + 1) * sizeof(int))); HIP_CHECK(hipMalloc((void**)&dcsrColIndB, nnzB * sizeof(int))); HIP_CHECK(hipMalloc((void**)&dcsrValB, nnzB * sizeof(float))); HIP_CHECK(hipMalloc((void**)&dcsrRowPtrC, (m + 1) * sizeof(int))); HIP_CHECK( hipMemcpy(dcsrRowPtrA, hcsrRowPtrA.data(), (m + 1) * sizeof(int), hipMemcpyHostToDevice)); HIP_CHECK( hipMemcpy(dcsrColIndA, hcsrColIndA.data(), nnzA * sizeof(int), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrValA, hcsrValA.data(), nnzA * sizeof(float), hipMemcpyHostToDevice)); HIP_CHECK( hipMemcpy(dcsrRowPtrB, hcsrRowPtrB.data(), (k + 1) * sizeof(int), hipMemcpyHostToDevice)); HIP_CHECK( hipMemcpy(dcsrColIndB, hcsrColIndB.data(), nnzB * sizeof(int), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrValB, hcsrValB.data(), nnzB * sizeof(float), hipMemcpyHostToDevice)); hipsparseHandle_t handle = NULL; hipsparseSpMatDescr_t matA, matB, matC; void* dBuffer1 = NULL; void* dBuffer2 = NULL; void* dBuffer3 = NULL; void* dBuffer4 = NULL; void* dBuffer5 = NULL; size_t bufferSize1 = 0; size_t bufferSize2 = 0; size_t bufferSize3 = 0; size_t bufferSize4 = 0; size_t bufferSize5 = 0; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // Create sparse matrix A in CSR format HIPSPARSE_CHECK(hipsparseCreateCsr(&matA, m, k, nnzA, dcsrRowPtrA, dcsrColIndA, dcsrValA, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); HIPSPARSE_CHECK(hipsparseCreateCsr(&matB, k, n, nnzB, dcsrRowPtrB, dcsrColIndB, dcsrValB, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); HIPSPARSE_CHECK(hipsparseCreateCsr(&matC, m, n, 0, dcsrRowPtrC, NULL, NULL, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); hipsparseSpGEMMDescr_t spgemmDesc; HIPSPARSE_CHECK(hipsparseSpGEMM_createDescr(&spgemmDesc)); // Determine size of first user allocated buffer HIPSPARSE_CHECK(hipsparseSpGEMMreuse_workEstimation(handle, opA, opB, matA, matB, matC, HIPSPARSE_SPGEMM_DEFAULT, spgemmDesc, &bufferSize1, NULL)); HIP_CHECK(hipMalloc((void**)&dBuffer1, bufferSize1)); // Inspect the matrices A and B to determine the number of intermediate product in // C = alpha * A * B HIPSPARSE_CHECK(hipsparseSpGEMMreuse_workEstimation(handle, opA, opB, matA, matB, matC, HIPSPARSE_SPGEMM_DEFAULT, spgemmDesc, &bufferSize1, dBuffer1)); // Determine size of second, third, and fourth user allocated buffer HIPSPARSE_CHECK(hipsparseSpGEMMreuse_nnz(handle, opA, opB, matA, matB, matC, HIPSPARSE_SPGEMM_DEFAULT, spgemmDesc, &bufferSize2, NULL, &bufferSize3, NULL, &bufferSize4, NULL)); HIP_CHECK(hipMalloc((void**)&dBuffer2, bufferSize2)); HIP_CHECK(hipMalloc((void**)&dBuffer3, bufferSize3)); HIP_CHECK(hipMalloc((void**)&dBuffer4, bufferSize4)); // Compute sparsity pattern of C matrix and store in temporary buffers HIPSPARSE_CHECK(hipsparseSpGEMMreuse_nnz(handle, opA, opB, matA, matB, matC, HIPSPARSE_SPGEMM_DEFAULT, spgemmDesc, &bufferSize2, dBuffer2, &bufferSize3, dBuffer3, &bufferSize4, dBuffer4)); // We can now free buffer 1 and 2 HIP_CHECK(hipFree(dBuffer1)); HIP_CHECK(hipFree(dBuffer2)); // Get matrix C non-zero entries nnzC int64_t rowsC, colsC, nnzC; HIPSPARSE_CHECK(hipsparseSpMatGetSize(matC, &rowsC, &colsC, &nnzC)); // Allocate matrix C HIP_CHECK(hipMalloc((void**)&dcsrColIndC, sizeof(int) * nnzC)); HIP_CHECK(hipMalloc((void**)&dcsrValC, sizeof(float) * nnzC)); // Update matC with the new pointers. The C values array can be filled with data here // which is used if beta != 0. HIPSPARSE_CHECK(hipsparseCsrSetPointers(matC, dcsrRowPtrC, dcsrColIndC, dcsrValC)); // Determine size of fifth user allocated buffer HIPSPARSE_CHECK(hipsparseSpGEMMreuse_copy(handle, opA, opB, matA, matB, matC, HIPSPARSE_SPGEMM_DEFAULT, spgemmDesc, &bufferSize5, NULL)); HIP_CHECK(hipMalloc((void**)&dBuffer5, bufferSize5)); // Copy data from temporary buffers to the newly allocated C matrix HIPSPARSE_CHECK(hipsparseSpGEMMreuse_copy(handle, opA, opB, matA, matB, matC, HIPSPARSE_SPGEMM_DEFAULT, spgemmDesc, &bufferSize5, dBuffer5)); // We can now free buffer 3 HIP_CHECK(hipFree(dBuffer3)); // Compute C' = alpha * A * B + beta * C HIPSPARSE_CHECK(hipsparseSpGEMMreuse_compute(handle, opA, opB, &alpha, matA, matB, &beta, matC, computeType, HIPSPARSE_SPGEMM_DEFAULT, spgemmDesc)); // Copy results back to host if required std::vector hcsrRowPtrC(m + 1); std::vector hcsrColIndC(nnzC); std::vector hcsrValC(nnzC); HIP_CHECK( hipMemcpy(hcsrRowPtrC.data(), dcsrRowPtrC, sizeof(int) * (m + 1), hipMemcpyDeviceToHost)); HIP_CHECK( hipMemcpy(hcsrColIndC.data(), dcsrColIndC, sizeof(int) * nnzC, hipMemcpyDeviceToHost)); HIP_CHECK(hipMemcpy(hcsrValC.data(), dcsrValC, sizeof(float) * nnzC, hipMemcpyDeviceToHost)); // Update dcsrValA, dcsrValB with new values for(size_t i = 0; i < hcsrValA.size(); i++) { hcsrValA[i] = 1.0f; } for(size_t i = 0; i < hcsrValB.size(); i++) { hcsrValB[i] = 2.0f; } HIP_CHECK(hipMemcpy(dcsrValA, hcsrValA.data(), sizeof(float) * nnzA, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrValB, hcsrValB.data(), sizeof(float) * nnzB, hipMemcpyHostToDevice)); // Compute C' = alpha * A * B + beta * C again with the new A and B values HIPSPARSE_CHECK(hipsparseSpGEMMreuse_compute(handle, opA, opB, &alpha, matA, matB, &beta, matC, computeType, HIPSPARSE_SPGEMM_DEFAULT, spgemmDesc)); // Copy results back to host if required HIP_CHECK( hipMemcpy(hcsrRowPtrC.data(), dcsrRowPtrC, sizeof(int) * (m + 1), hipMemcpyDeviceToHost)); HIP_CHECK( hipMemcpy(hcsrColIndC.data(), dcsrColIndC, sizeof(int) * nnzC, hipMemcpyDeviceToHost)); HIP_CHECK(hipMemcpy(hcsrValC.data(), dcsrValC, sizeof(float) * nnzC, hipMemcpyDeviceToHost)); // Destroy matrix descriptors and handles HIPSPARSE_CHECK(hipsparseSpGEMM_destroyDescr(spgemmDesc)); HIPSPARSE_CHECK(hipsparseDestroySpMat(matA)); HIPSPARSE_CHECK(hipsparseDestroySpMat(matB)); HIPSPARSE_CHECK(hipsparseDestroySpMat(matC)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); // Free device memory HIP_CHECK(hipFree(dBuffer4)); HIP_CHECK(hipFree(dBuffer5)); HIP_CHECK(hipFree(dcsrRowPtrA)); HIP_CHECK(hipFree(dcsrColIndA)); HIP_CHECK(hipFree(dcsrValA)); HIP_CHECK(hipFree(dcsrRowPtrB)); HIP_CHECK(hipFree(dcsrColIndB)); HIP_CHECK(hipFree(dcsrValB)); HIP_CHECK(hipFree(dcsrRowPtrC)); HIP_CHECK(hipFree(dcsrColIndC)); HIP_CHECK(hipFree(dcsrValC)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5763993 hipsparse/clients/samples/documentation_examples/generic/example_hipsparse_spmm.cpp0000664000175100017510000001706015206065364031560 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // A, B, and C are m×k, k×n, and m×n int m = 3, n = 5, k = 4; int ldb = n, ldc = n; int nnz_A = 8, nnz_B = 20, nnz_C = 15; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transC = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOrder_t order = HIPSPARSE_ORDER_ROW; // alpha and beta float alpha = 0.5f; float beta = 0.25f; std::vector hcsrRowPtr = {0, 3, 5, 8}; std::vector hcsrColInd = {0, 1, 3, 1, 2, 0, 2, 3}; std::vector hcsrVal = {1, 2, 3, 4, 5, 6, 7, 8}; std::vector hB(nnz_B, 1.0f); std::vector hC(nnz_C, 1.0f); int* dcsrRowPtr; int* dcsrColInd; float* dcsrVal; HIP_CHECK(hipMalloc((void**)&dcsrRowPtr, sizeof(int) * (m + 1))); HIP_CHECK(hipMalloc((void**)&dcsrColInd, sizeof(int) * nnz_A)); HIP_CHECK(hipMalloc((void**)&dcsrVal, sizeof(float) * nnz_A)); HIP_CHECK( hipMemcpy(dcsrRowPtr, hcsrRowPtr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrColInd, hcsrColInd.data(), sizeof(int) * nnz_A, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrVal, hcsrVal.data(), sizeof(float) * nnz_A, hipMemcpyHostToDevice)); hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); hipsparseSpMatDescr_t matA; HIPSPARSE_CHECK(hipsparseCreateCsr(&matA, m, k, nnz_A, dcsrRowPtr, dcsrColInd, dcsrVal, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); // Allocate memory for the matrix B float* dB; HIP_CHECK(hipMalloc((void**)&dB, sizeof(float) * nnz_B)); HIP_CHECK(hipMemcpy(dB, hB.data(), sizeof(float) * nnz_B, hipMemcpyHostToDevice)); hipsparseDnMatDescr_t matB; HIPSPARSE_CHECK(hipsparseCreateDnMat(&matB, k, n, ldb, dB, HIP_R_32F, order)); // Allocate memory for the resulting matrix C float* dC; HIP_CHECK(hipMalloc((void**)&dC, sizeof(float) * nnz_C)); HIP_CHECK(hipMemcpy(dC, hC.data(), sizeof(float) * nnz_C, hipMemcpyHostToDevice)); hipsparseDnMatDescr_t matC; HIPSPARSE_CHECK(hipsparseCreateDnMat(&matC, m, n, ldc, dC, HIP_R_32F, HIPSPARSE_ORDER_ROW)); // Compute buffersize size_t bufferSize; HIPSPARSE_CHECK(hipsparseSpMM_bufferSize(handle, transA, transB, &alpha, matA, matB, &beta, matC, HIP_R_32F, HIPSPARSE_MM_ALG_DEFAULT, &bufferSize)); void* buffer; HIP_CHECK(hipMalloc(&buffer, bufferSize)); // Preprocess operation (Optional) HIPSPARSE_CHECK(hipsparseSpMM_preprocess(handle, transA, transB, &alpha, matA, matB, &beta, matC, HIP_R_32F, HIPSPARSE_MM_ALG_DEFAULT, buffer)); // Perform operation HIPSPARSE_CHECK(hipsparseSpMM(handle, transA, transB, &alpha, matA, matB, &beta, matC, HIP_R_32F, HIPSPARSE_MM_ALG_DEFAULT, buffer)); // Copy device to host HIP_CHECK(hipMemcpy(hC.data(), dC, sizeof(float) * nnz_C, hipMemcpyDeviceToHost)); // Destroy matrix descriptors and handles HIPSPARSE_CHECK(hipsparseDestroySpMat(matA)); HIPSPARSE_CHECK(hipsparseDestroyDnMat(matB)); HIPSPARSE_CHECK(hipsparseDestroyDnMat(matC)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); HIP_CHECK(hipFree(buffer)); HIP_CHECK(hipFree(dcsrRowPtr)); HIP_CHECK(hipFree(dcsrColInd)); HIP_CHECK(hipFree(dcsrVal)); HIP_CHECK(hipFree(dB)); HIP_CHECK(hipFree(dC)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5773993 hipsparse/clients/samples/documentation_examples/generic/example_hipsparse_spmv.cpp0000664000175100017510000001611215206065364031566 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // A, x, and y are m×k, k×1, and m×1 int m = 3, k = 4; int nnz_A = 8; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; // alpha and beta float alpha = 0.5f; float beta = 0.25f; std::vector hcsrRowPtr = {0, 3, 5, 8}; std::vector hcsrColInd = {0, 1, 3, 1, 2, 0, 2, 3}; std::vector hcsrVal = {1, 2, 3, 4, 5, 6, 7, 8}; std::vector hx(k, 1.0f); std::vector hy(m, 1.0f); int* dcsrRowPtr; int* dcsrColInd; float* dcsrVal; HIP_CHECK(hipMalloc((void**)&dcsrRowPtr, sizeof(int) * (m + 1))); HIP_CHECK(hipMalloc((void**)&dcsrColInd, sizeof(int) * nnz_A)); HIP_CHECK(hipMalloc((void**)&dcsrVal, sizeof(float) * nnz_A)); HIP_CHECK( hipMemcpy(dcsrRowPtr, hcsrRowPtr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrColInd, hcsrColInd.data(), sizeof(int) * nnz_A, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrVal, hcsrVal.data(), sizeof(float) * nnz_A, hipMemcpyHostToDevice)); hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); hipsparseSpMatDescr_t matA; HIPSPARSE_CHECK(hipsparseCreateCsr(&matA, m, k, nnz_A, dcsrRowPtr, dcsrColInd, dcsrVal, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); // Allocate memory for the vector x float* dx; HIP_CHECK(hipMalloc((void**)&dx, sizeof(float) * k)); HIP_CHECK(hipMemcpy(dx, hx.data(), sizeof(float) * k, hipMemcpyHostToDevice)); hipsparseDnVecDescr_t vecX; HIPSPARSE_CHECK(hipsparseCreateDnVec(&vecX, k, dx, HIP_R_32F)); // Allocate memory for the resulting vector y float* dy; HIP_CHECK(hipMalloc((void**)&dy, sizeof(float) * m)); HIP_CHECK(hipMemcpy(dy, hy.data(), sizeof(float) * m, hipMemcpyHostToDevice)); hipsparseDnMatDescr_t vecY; HIPSPARSE_CHECK(hipsparseCreateDnVec(&vecY, m, dy, HIP_R_32F)); // Compute buffersize size_t bufferSize; HIPSPARSE_CHECK(hipsparseSpMV_bufferSize(handle, transA, &alpha, matA, vecX, &beta, vecY, HIP_R_32F, HIPSPARSE_MV_ALG_DEFAULT, &bufferSize)); void* buffer; HIP_CHECK(hipMalloc(&buffer, bufferSize)); // Preprocess operation (Optional) HIPSPARSE_CHECK(hipsparseSpMV_preprocess(handle, transA, &alpha, matA, vecX, &beta, vecY, HIP_R_32F, HIPSPARSE_MV_ALG_DEFAULT, buffer)); // Perform operation HIPSPARSE_CHECK(hipsparseSpMV(handle, transA, &alpha, matA, vecX, &beta, vecY, HIP_R_32F, HIPSPARSE_MV_ALG_DEFAULT, buffer)); // Copy device to host HIP_CHECK(hipMemcpy(hy.data(), dy, sizeof(float) * m, hipMemcpyDeviceToHost)); // Destroy matrix descriptors and handles HIPSPARSE_CHECK(hipsparseDestroySpMat(matA)); HIPSPARSE_CHECK(hipsparseDestroyDnVec(vecX)); HIPSPARSE_CHECK(hipsparseDestroyDnVec(vecY)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); HIP_CHECK(hipFree(buffer)); HIP_CHECK(hipFree(dcsrRowPtr)); HIP_CHECK(hipFree(dcsrColInd)); HIP_CHECK(hipFree(dcsrVal)); HIP_CHECK(hipFree(dx)); HIP_CHECK(hipFree(dy)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5773993 hipsparse/clients/samples/documentation_examples/generic/example_hipsparse_spsm.cpp0000664000175100017510000002001215206065364031555 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // 1 0 0 0 // A = 4 2 0 0 // 0 3 7 0 // 0 0 0 1 int m = 4; int n = 2; std::vector hcsr_row_ptr = {0, 1, 3, 5, 6}; std::vector hcsr_col_ind = {0, 0, 1, 1, 2, 3}; std::vector hcsr_val = {1, 4, 2, 3, 7, 1}; std::vector hB(m * n); std::vector hC(m * n); for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { hB[m * i + j] = static_cast(i + 1); } } // Scalar alpha float alpha = 1.0f; int nnz = hcsr_row_ptr[m] - hcsr_row_ptr[0]; // Offload data to device int* dcsr_row_ptr; int* dcsr_col_ind; float* dcsr_val; float* dB; float* dC; HIP_CHECK(hipMalloc((void**)&dcsr_row_ptr, sizeof(int) * (m + 1))); HIP_CHECK(hipMalloc((void**)&dcsr_col_ind, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dcsr_val, sizeof(float) * nnz)); HIP_CHECK(hipMalloc((void**)&dB, sizeof(float) * m * n)); HIP_CHECK(hipMalloc((void**)&dC, sizeof(float) * m * n)); HIP_CHECK( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); HIP_CHECK( hipMemcpy(dcsr_col_ind, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsr_val, hcsr_val.data(), sizeof(float) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dB, hB.data(), sizeof(float) * m * n, hipMemcpyHostToDevice)); hipsparseHandle_t handle; hipsparseSpMatDescr_t matA; hipsparseDnMatDescr_t matB; hipsparseDnMatDescr_t matC; hipsparseIndexType_t row_idx_type = HIPSPARSE_INDEX_32I; hipsparseIndexType_t col_idx_type = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; hipDataType computeType = HIP_R_32F; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // Create sparse matrix A HIPSPARSE_CHECK(hipsparseCreateCsr(&matA, m, m, nnz, dcsr_row_ptr, dcsr_col_ind, dcsr_val, row_idx_type, col_idx_type, idxBase, dataType)); // Create dense matrix B HIPSPARSE_CHECK(hipsparseCreateDnMat(&matB, m, n, m, dB, dataType, HIPSPARSE_ORDER_COL)); // Create dense matrix C HIPSPARSE_CHECK(hipsparseCreateDnMat(&matC, m, n, m, dC, dataType, HIPSPARSE_ORDER_COL)); hipsparseSpSMDescr_t descr; HIPSPARSE_CHECK(hipsparseSpSM_createDescr(&descr)); // Call SpSM to get buffer size size_t buffer_size; HIPSPARSE_CHECK(hipsparseSpSM_bufferSize(handle, transA, transB, &alpha, matA, matB, matC, computeType, HIPSPARSE_SPSM_ALG_DEFAULT, descr, &buffer_size)); void* temp_buffer; HIP_CHECK(hipMalloc((void**)&temp_buffer, buffer_size)); // Call SpSM to perform analysis HIPSPARSE_CHECK(hipsparseSpSM_analysis(handle, transA, transB, &alpha, matA, matB, matC, computeType, HIPSPARSE_SPSM_ALG_DEFAULT, descr, temp_buffer)); // Call SpSM to perform computation HIPSPARSE_CHECK(hipsparseSpSM_solve(handle, transA, transB, &alpha, matA, matB, matC, computeType, HIPSPARSE_SPSM_ALG_DEFAULT, descr, temp_buffer)); // Copy result back to host HIP_CHECK(hipMemcpy(hC.data(), dC, sizeof(float) * m * n, hipMemcpyDeviceToHost)); // Clear hipSPARSE HIPSPARSE_CHECK(hipsparseSpSM_destroyDescr(descr)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(matA)); HIPSPARSE_CHECK(hipsparseDestroyDnMat(matB)); HIPSPARSE_CHECK(hipsparseDestroyDnMat(matC)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); // Clear device memory HIP_CHECK(hipFree(dcsr_row_ptr)); HIP_CHECK(hipFree(dcsr_col_ind)); HIP_CHECK(hipFree(dcsr_val)); HIP_CHECK(hipFree(dB)); HIP_CHECK(hipFree(dC)); HIP_CHECK(hipFree(temp_buffer)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5773993 hipsparse/clients/samples/documentation_examples/generic/example_hipsparse_spsv.cpp0000664000175100017510000001632115206065364031576 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // 1 0 0 0 // A = 4 2 0 0 // 0 3 7 0 // 0 0 0 1 int m = 4; std::vector hcsr_row_ptr = {0, 1, 3, 5, 6}; std::vector hcsr_col_ind = {0, 0, 1, 1, 2, 3}; std::vector hcsr_val = {1, 4, 2, 3, 7, 1}; std::vector hx(m, 1.0f); std::vector hy(m, 0.0f); // Scalar alpha float alpha = 1.0f; int nnz = hcsr_row_ptr[m] - hcsr_row_ptr[0]; // Offload data to device int* dcsr_row_ptr; int* dcsr_col_ind; float* dcsr_val; float* dx; float* dy; HIP_CHECK(hipMalloc((void**)&dcsr_row_ptr, sizeof(int) * (m + 1))); HIP_CHECK(hipMalloc((void**)&dcsr_col_ind, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dcsr_val, sizeof(float) * nnz)); HIP_CHECK(hipMalloc((void**)&dx, sizeof(float) * m)); HIP_CHECK(hipMalloc((void**)&dy, sizeof(float) * m)); HIP_CHECK( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); HIP_CHECK( hipMemcpy(dcsr_col_ind, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsr_val, hcsr_val.data(), sizeof(float) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dx, hx.data(), sizeof(float) * m, hipMemcpyHostToDevice)); hipsparseHandle_t handle; hipsparseSpMatDescr_t matA; hipsparseDnVecDescr_t vecX; hipsparseDnVecDescr_t vecY; hipsparseIndexType_t row_idx_type = HIPSPARSE_INDEX_32I; hipsparseIndexType_t col_idx_type = HIPSPARSE_INDEX_32I; hipDataType data_type = HIP_R_32F; hipDataType computeType = HIP_R_32F; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseOperation_t trans = HIPSPARSE_OPERATION_NON_TRANSPOSE; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // Create sparse matrix A HIPSPARSE_CHECK(hipsparseCreateCsr(&matA, m, m, nnz, dcsr_row_ptr, dcsr_col_ind, dcsr_val, row_idx_type, col_idx_type, idx_base, data_type)); // Create dense vector X HIPSPARSE_CHECK(hipsparseCreateDnVec(&vecX, m, dx, data_type)); // Create dense vector Y HIPSPARSE_CHECK(hipsparseCreateDnVec(&vecY, m, dy, data_type)); hipsparseSpSVDescr_t descr; HIPSPARSE_CHECK(hipsparseSpSV_createDescr(&descr)); // Call spsv to get buffer size size_t buffer_size; HIPSPARSE_CHECK(hipsparseSpSV_bufferSize(handle, trans, &alpha, matA, vecX, vecY, computeType, HIPSPARSE_SPSV_ALG_DEFAULT, descr, &buffer_size)); void* temp_buffer; HIP_CHECK(hipMalloc((void**)&temp_buffer, buffer_size)); // Call spsv to perform analysis HIPSPARSE_CHECK(hipsparseSpSV_analysis(handle, trans, &alpha, matA, vecX, vecY, computeType, HIPSPARSE_SPSV_ALG_DEFAULT, descr, temp_buffer)); // Call spsv to perform computation HIPSPARSE_CHECK(hipsparseSpSV_solve( handle, trans, &alpha, matA, vecX, vecY, computeType, HIPSPARSE_SPSV_ALG_DEFAULT, descr)); // Copy result back to host HIP_CHECK(hipMemcpy(hy.data(), dy, sizeof(float) * m, hipMemcpyDeviceToHost)); // Clear hipSPARSE HIPSPARSE_CHECK(hipsparseSpSV_destroyDescr(descr)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(matA)); HIPSPARSE_CHECK(hipsparseDestroyDnVec(vecX)); HIPSPARSE_CHECK(hipsparseDestroyDnVec(vecY)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); // Clear device memory HIP_CHECK(hipFree(dcsr_row_ptr)); HIP_CHECK(hipFree(dcsr_col_ind)); HIP_CHECK(hipFree(dcsr_val)); HIP_CHECK(hipFree(dx)); HIP_CHECK(hipFree(dy)); HIP_CHECK(hipFree(temp_buffer)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5773993 hipsparse/clients/samples/documentation_examples/generic/example_hipsparse_spvv.cpp0000664000175100017510000001130015206065364031571 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // Number of non-zeros of the sparse vector int nnz = 3; // Size of sparse and dense vector int size = 9; // Sparse index vector std::vector hxInd = {0, 3, 5}; // Sparse value vector std::vector hxVal = {1.0f, 2.0f, 3.0f}; // Dense vector std::vector hy = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f}; // Offload data to device int* dxInd; float* dxVal; float* dy; HIP_CHECK(hipMalloc((void**)&dxInd, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dxVal, sizeof(float) * nnz)); HIP_CHECK(hipMalloc((void**)&dy, sizeof(float) * size)); HIP_CHECK(hipMemcpy(dxInd, hxInd.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dxVal, hxVal.data(), sizeof(float) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dy, hy.data(), sizeof(float) * size, hipMemcpyHostToDevice)); hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // Create sparse vector X hipsparseSpVecDescr_t vecX; HIPSPARSE_CHECK(hipsparseCreateSpVec( &vecX, size, nnz, dxInd, dxVal, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); // Create dense vector Y hipsparseDnVecDescr_t vecY; HIPSPARSE_CHECK(hipsparseCreateDnVec(&vecY, size, dy, HIP_R_32F)); // Obtain buffer size float hresult = 0.0f; size_t buffer_size; HIPSPARSE_CHECK(hipsparseSpVV_bufferSize( handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, vecX, vecY, &hresult, HIP_R_32F, &buffer_size)); void* temp_buffer; HIP_CHECK(hipMalloc(&temp_buffer, buffer_size)); // SpVV HIPSPARSE_CHECK(hipsparseSpVV( handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, vecX, vecY, &hresult, HIP_R_32F, temp_buffer)); HIP_CHECK(hipDeviceSynchronize()); std::cout << "hresult: " << hresult << std::endl; // Clear hipSPARSE HIPSPARSE_CHECK(hipsparseDestroySpVec(vecX)); HIPSPARSE_CHECK(hipsparseDestroyDnVec(vecY)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); // Clear device memory HIP_CHECK(hipFree(dxInd)); HIP_CHECK(hipFree(dxVal)); HIP_CHECK(hipFree(dy)); HIP_CHECK(hipFree(temp_buffer)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5773993 hipsparse/clients/samples/documentation_examples/level1/0000775000175100017510000000000015206065364024057 5ustar00jenkinsjenkins././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5773993 hipsparse/clients/samples/documentation_examples/level1/example_hipsparse_axpyi.cpp0000664000175100017510000001027215206065364031510 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // Number of non-zeros of the sparse vector const int nnz = 3; // Number of entries in the dense vector const int size = 9; // Sparse index vector int hxInd[nnz] = {0, 3, 5}; // Sparse value vector double hxVal[nnz] = {1.0, 2.0, 3.0}; // Dense vector double hy[size] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}; // Scalar alpha double alpha = 3.7; // Index base hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; // Offload data to device int* dxInd; double* dxVal; double* dy; HIP_CHECK(hipMalloc((void**)&dxInd, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dxVal, sizeof(double) * nnz)); HIP_CHECK(hipMalloc((void**)&dy, sizeof(double) * 9)); HIP_CHECK(hipMemcpy(dxInd, hxInd, sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dxVal, hxVal, sizeof(double) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dy, hy, sizeof(double) * size, hipMemcpyHostToDevice)); // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // Call daxpyi to perform y = y + alpha * x HIPSPARSE_CHECK(hipsparseDaxpyi(handle, nnz, &alpha, dxVal, dxInd, dy, idxBase)); // Copy result back to host HIP_CHECK(hipMemcpy(hy, dy, sizeof(double) * size, hipMemcpyDeviceToHost)); std::cout << "hy" << std::endl; for(int i = 0; i < size; i++) { std::cout << hy[i] << " "; } std::cout << "" << std::endl; // Clear hipSPARSE HIPSPARSE_CHECK(hipsparseDestroy(handle)); // Clear device memory HIP_CHECK(hipFree(dxInd)); HIP_CHECK(hipFree(dxVal)); HIP_CHECK(hipFree(dy)); return 0; } //! [doc example] ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5773993 hipsparse/clients/samples/documentation_examples/level1/example_hipsparse_doti.cpp0000664000175100017510000000770315206065364031322 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // Number of non-zeros of the sparse vector const int nnz = 3; // Number of entries in the dense vector const int size = 9; // Sparse index vector int hxInd[nnz] = {0, 3, 5}; // Sparse value vector float hxVal[nnz] = {1.0f, 2.0f, 3.0f}; // Dense vector float hy[size] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f}; // Index base hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; // Offload data to device int* dxInd; float* dxVal; float* dy; HIP_CHECK(hipMalloc((void**)&dxInd, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dxVal, sizeof(float) * nnz)); HIP_CHECK(hipMalloc((void**)&dy, sizeof(float) * size)); HIP_CHECK(hipMemcpy(dxInd, hxInd, sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dxVal, hxVal, sizeof(float) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dy, hy, sizeof(float) * size, hipMemcpyHostToDevice)); // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // Call sdoti to compute the dot product float dot; HIPSPARSE_CHECK(hipsparseSdoti(handle, nnz, dxVal, dxInd, dy, &dot, idxBase)); std::cout << "dot: " << dot << std::endl; // Clear hipSPARSE HIPSPARSE_CHECK(hipsparseDestroy(handle)); // Clear device memory HIP_CHECK(hipFree(dxInd)); HIP_CHECK(hipFree(dxVal)); HIP_CHECK(hipFree(dy)); return 0; } //! [doc example] ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5773993 hipsparse/clients/samples/documentation_examples/level1/example_hipsparse_gthr.cpp0000664000175100017510000001000415206065364031313 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // Number of non-zeros of the sparse vector const int nnz = 3; // Number of entries in the dense vector const int size = 9; // Sparse index vector int hxInd[nnz] = {0, 3, 5}; // Sparse value vector float hxVal[nnz]; // Dense vector float hy[size] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}; // Index base hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; // Offload data to device int* dxInd; float* dxVal; float* dy; HIP_CHECK(hipMalloc((void**)&dxInd, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dxVal, sizeof(float) * nnz)); HIP_CHECK(hipMalloc((void**)&dy, sizeof(float) * size)); HIP_CHECK(hipMemcpy(dxInd, hxInd, sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dy, hy, sizeof(float) * size, hipMemcpyHostToDevice)); // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // Call sgthr HIPSPARSE_CHECK(hipsparseSgthr(handle, nnz, dy, dxVal, dxInd, idxBase)); // Copy result back to host HIP_CHECK(hipMemcpy(hxVal, dxVal, sizeof(float) * nnz, hipMemcpyDeviceToHost)); std::cout << "hxVal" << std::endl; for(int i = 0; i < nnz; i++) { std::cout << hxVal[i] << " "; } std::cout << "" << std::endl; // Clear hipSPARSE HIPSPARSE_CHECK(hipsparseDestroy(handle)); // Clear device memory HIP_CHECK(hipFree(dxInd)); HIP_CHECK(hipFree(dxVal)); HIP_CHECK(hipFree(dy)); return 0; } //! [doc example] ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5773993 hipsparse/clients/samples/documentation_examples/level1/example_hipsparse_roti.cpp0000664000175100017510000001063315206065364031334 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // Number of non-zeros of the sparse vector const int nnz = 3; // Number of entries in the dense vector const int size = 9; // Sparse index vector int hxInd[nnz] = {0, 3, 5}; // Sparse value vector float hxVal[nnz] = {1.0f, 2.0f, 3.0f}; // Dense vector float hy[size] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f}; // c and s float c = 3.7; float s = 1.3; // Index base hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; // Offload data to device int* dxInd; float* dxVal; float* dy; HIP_CHECK(hipMalloc((void**)&dxInd, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dxVal, sizeof(float) * nnz)); HIP_CHECK(hipMalloc((void**)&dy, sizeof(float) * size)); HIP_CHECK(hipMemcpy(dxInd, hxInd, sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dxVal, hxVal, sizeof(float) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dy, hy, sizeof(float) * size, hipMemcpyHostToDevice)); // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // Call sroti HIPSPARSE_CHECK(hipsparseSroti(handle, nnz, dxVal, dxInd, dy, &c, &s, idxBase)); // Copy result back to host HIP_CHECK(hipMemcpy(hxVal, dxVal, sizeof(float) * nnz, hipMemcpyDeviceToHost)); HIP_CHECK(hipMemcpy(hy, dy, sizeof(float) * size, hipMemcpyDeviceToHost)); std::cout << "hxVal" << std::endl; for(int i = 0; i < nnz; i++) { std::cout << hxVal[i] << " "; } std::cout << "" << std::endl; std::cout << "hy" << std::endl; for(int i = 0; i < size; i++) { std::cout << hy[i] << " "; } std::cout << "" << std::endl; // Clear hipSPARSE HIPSPARSE_CHECK(hipsparseDestroy(handle)); // Clear device memory HIP_CHECK(hipFree(dxInd)); HIP_CHECK(hipFree(dxVal)); HIP_CHECK(hipFree(dy)); return 0; } //! [doc example] ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5773993 hipsparse/clients/samples/documentation_examples/level1/example_hipsparse_sctr.cpp0000664000175100017510000001014015206065364031323 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // Number of non-zeros of the sparse vector const int nnz = 3; // Number of entries in the dense vector const int size = 9; // Sparse index vector int hxInd[nnz] = {0, 3, 5}; // Sparse value vector float hxVal[nnz] = {9.0, 2.0, 3.0}; // Dense vector float hy[size] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}; // Index base hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; // Offload data to device int* dxInd; float* dxVal; float* dy; HIP_CHECK(hipMalloc((void**)&dxInd, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dxVal, sizeof(float) * nnz)); HIP_CHECK(hipMalloc((void**)&dy, sizeof(float) * size)); HIP_CHECK(hipMemcpy(dxInd, hxInd, sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dxVal, hxVal, sizeof(float) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dy, hy, sizeof(float) * size, hipMemcpyHostToDevice)); // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // Call ssctr HIPSPARSE_CHECK(hipsparseSsctr(handle, nnz, dxVal, dxInd, dy, idxBase)); // Copy result back to host HIP_CHECK(hipMemcpy(hy, dy, sizeof(float) * size, hipMemcpyDeviceToHost)); std::cout << "hy" << std::endl; for(int i = 0; i < size; i++) { std::cout << hy[i] << " "; } std::cout << "" << std::endl; // Clear hipSPARSE HIPSPARSE_CHECK(hipsparseDestroy(handle)); // Clear device memory HIP_CHECK(hipFree(dxInd)); HIP_CHECK(hipFree(dxVal)); HIP_CHECK(hipFree(dy)); return 0; } //! [doc example] ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5783992 hipsparse/clients/samples/documentation_examples/level2/0000775000175100017510000000000015206065364024060 5ustar00jenkinsjenkins././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5773993 hipsparse/clients/samples/documentation_examples/level2/example_hipsparse_bsrmv.cpp0000664000175100017510000001417715206065364031520 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // alpha * ( 1.0 0.0 2.0 ) * ( 1.0 ) + beta * ( 4.0 ) = ( 31.1 ) // ( 3.0 0.0 4.0 ) * ( 2.0 ) ( 5.0 ) = ( 62.0 ) // ( 5.0 6.0 0.0 ) * ( 3.0 ) ( 6.0 ) = ( 70.7 ) // ( 7.0 0.0 8.0 ) * ( 7.0 ) = ( 123.8 ) // BSR block dimension const int bsr_dim = 2; // Number of block rows and columns const int mb = 2; const int nb = 2; // Number of non-zero blocks const int nnzb = 4; // Number of rows and columns const int m = mb * bsr_dim; const int n = nb * bsr_dim; // BSR row pointers int hbsrRowPtr[mb + 1] = {0, 2, 4}; // BSR column indices int hbsrColInd[nnzb] = {0, 1, 0, 1}; // BSR values double hbsrVal[nnzb * bsr_dim * bsr_dim] = {1.0, 3.0, 0.0, 0.0, 2.0, 4.0, 0.0, 0.0, 5.0, 7.0, 6.0, 0.0, 0.0, 8.0, 0.0, 0.0}; // Block storage in column major hipsparseDirection_t dir = HIPSPARSE_DIRECTION_COLUMN; // Transposition of the matrix hipsparseOperation_t trans = HIPSPARSE_OPERATION_NON_TRANSPOSE; // Scalar alpha and beta double alpha = 3.7; double beta = 1.3; // x and y double hx[n] = {1.0, 2.0, 3.0, 0.0}; double hy[m] = {4.0, 5.0, 6.0, 7.0}; // Matrix descriptor hipsparseMatDescr_t descr; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descr)); // Offload data to device int* dbsrRowPtr; int* dbsrColInd; double* dbsrVal; double* dx; double* dy; HIP_CHECK(hipMalloc((void**)&dbsrRowPtr, sizeof(int) * (mb + 1))); HIP_CHECK(hipMalloc((void**)&dbsrColInd, sizeof(int) * nnzb)); HIP_CHECK(hipMalloc((void**)&dbsrVal, sizeof(double) * nnzb * bsr_dim * bsr_dim)); HIP_CHECK(hipMalloc((void**)&dx, sizeof(double) * n)); HIP_CHECK(hipMalloc((void**)&dy, sizeof(double) * m)); HIP_CHECK(hipMemcpy(dbsrRowPtr, hbsrRowPtr, sizeof(int) * (mb + 1), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dbsrColInd, hbsrColInd, sizeof(int) * nnzb, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy( dbsrVal, hbsrVal, sizeof(double) * nnzb * bsr_dim * bsr_dim, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dx, hx, sizeof(double) * n, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dy, hy, sizeof(double) * m, hipMemcpyHostToDevice)); // Call dbsrmv to perform y = alpha * A x + beta * y HIPSPARSE_CHECK(hipsparseDbsrmv(handle, dir, trans, mb, nb, nnzb, &alpha, descr, dbsrVal, dbsrRowPtr, dbsrColInd, bsr_dim, dx, &beta, dy)); // Copy result back to host HIP_CHECK(hipMemcpy(hy, dy, sizeof(double) * m, hipMemcpyDeviceToHost)); std::cout << "hy" << std::endl; for(int i = 0; i < m; i++) { std::cout << hy[i] << " "; } std::cout << "" << std::endl; // Clear hipSPARSE HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descr)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); // Clear device memory HIP_CHECK(hipFree(dbsrRowPtr)); HIP_CHECK(hipFree(dbsrColInd)); HIP_CHECK(hipFree(dbsrVal)); HIP_CHECK(hipFree(dx)); HIP_CHECK(hipFree(dy)); return 0; } //! [doc example] ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5773993 hipsparse/clients/samples/documentation_examples/level2/example_hipsparse_bsrsv2.cpp0000664000175100017510000002104315206065364031576 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // A = ( 1.0 0.0 0.0 0.0 ) // ( 2.0 3.0 0.0 0.0 ) // ( 4.0 5.0 6.0 0.0 ) // ( 7.0 0.0 8.0 9.0 ) // // with bsr_dim = 2 // // ------------------- // = | 1.0 0.0 | 0.0 0.0 | // | 2.0 3.0 | 0.0 0.0 | // ------------------- // | 4.0 5.0 | 6.0 0.0 | // | 7.0 0.0 | 8.0 9.0 | // ------------------- // Number of rows (matrix must be square) const int m = 4; // Number of block rows and block columns const int mb = 2; const int nb = 2; // BSR block dimension const int bsr_dim = 2; // Number of non-zero blocks const int nnzb = 3; // BSR row pointers int hbsrRowPtr[mb + 1] = {0, 1, 3}; // BSR column indices int hbsrColInd[nnzb] = {0, 0, 1}; // BSR values double hbsrVal[nnzb * bsr_dim * bsr_dim] = {1.0, 2.0, 0.0, 3.0, 4.0, 7.0, 5.0, 0.0, 6.0, 8.0, 0.0, 9.0}; // Storage scheme of the BSR blocks hipsparseDirection_t dir = HIPSPARSE_DIRECTION_COLUMN; // Transposition of the matrix and rhs matrix hipsparseOperation_t trans = HIPSPARSE_OPERATION_NON_TRANSPOSE; // Solve policy hipsparseSolvePolicy_t solve_policy = HIPSPARSE_SOLVE_POLICY_USE_LEVEL; // Scalar alpha and beta double alpha = 3.7; double hx[m] = {1, 2, 3, 4}; double hy[m]; // Offload data to device int* dbsrRowPtr; int* dbsrColInd; double* dbsrVal; double* dx; double* dy; HIP_CHECK(hipMalloc((void**)&dbsrRowPtr, sizeof(int) * (mb + 1))); HIP_CHECK(hipMalloc((void**)&dbsrColInd, sizeof(int) * nnzb)); HIP_CHECK(hipMalloc((void**)&dbsrVal, sizeof(double) * nnzb * bsr_dim * bsr_dim)); HIP_CHECK(hipMalloc((void**)&dx, sizeof(double) * m)); HIP_CHECK(hipMalloc((void**)&dy, sizeof(double) * m)); HIP_CHECK(hipMemcpy(dbsrRowPtr, hbsrRowPtr, sizeof(int) * (mb + 1), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dbsrColInd, hbsrColInd, sizeof(int) * nnzb, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy( dbsrVal, hbsrVal, sizeof(double) * nnzb * bsr_dim * bsr_dim, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dx, hx, sizeof(double) * m, hipMemcpyHostToDevice)); // Matrix descriptor hipsparseMatDescr_t descr; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descr)); // Matrix fill mode HIPSPARSE_CHECK(hipsparseSetMatFillMode(descr, HIPSPARSE_FILL_MODE_LOWER)); // Matrix diagonal type HIPSPARSE_CHECK(hipsparseSetMatDiagType(descr, HIPSPARSE_DIAG_TYPE_UNIT)); // Matrix info structure bsrsv2Info_t info; HIPSPARSE_CHECK(hipsparseCreateBsrsv2Info(&info)); // Obtain required buffer size int buffer_size; HIPSPARSE_CHECK(hipsparseDbsrsv2_bufferSize(handle, dir, trans, mb, nnzb, descr, dbsrVal, dbsrRowPtr, dbsrColInd, bsr_dim, info, &buffer_size)); // Allocate temporary buffer void* dbuffer; HIP_CHECK(hipMalloc(&dbuffer, buffer_size)); // Perform analysis step HIPSPARSE_CHECK(hipsparseDbsrsv2_analysis(handle, dir, trans, mb, nnzb, descr, dbsrVal, dbsrRowPtr, dbsrColInd, bsr_dim, info, solve_policy, dbuffer)); // Call dbsrsm to perform lower triangular solve LX = B HIPSPARSE_CHECK(hipsparseDbsrsv2_solve(handle, dir, trans, mb, nnzb, &alpha, descr, dbsrVal, dbsrRowPtr, dbsrColInd, bsr_dim, info, dx, dy, solve_policy, dbuffer)); // Check for zero pivots int pivot; hipsparseStatus_t status = hipsparseXbsrsv2_zeroPivot(handle, info, &pivot); if(status == HIPSPARSE_STATUS_ZERO_PIVOT) { std::cout << "Found zero pivot in matrix row " << pivot << std::endl; } // Copy results back to the host HIP_CHECK(hipMemcpy(hy, dy, sizeof(double) * m, hipMemcpyDeviceToHost)); std::cout << "hy" << std::endl; for(int i = 0; i < m; i++) { std::cout << hy[i] << " "; } std::cout << "" << std::endl; // Clear hipSPARSE HIPSPARSE_CHECK(hipsparseDestroyBsrsv2Info(info)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descr)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); // Clear device memory HIP_CHECK(hipFree(dbsrRowPtr)); HIP_CHECK(hipFree(dbsrColInd)); HIP_CHECK(hipFree(dbsrVal)); HIP_CHECK(hipFree(dx)); HIP_CHECK(hipFree(dy)); HIP_CHECK(hipFree(dbuffer)); return 0; } //! [doc example] ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5773993 hipsparse/clients/samples/documentation_examples/level2/example_hipsparse_csrmv.cpp0000664000175100017510000001231215206065364031506 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // alpha * ( 1.0 0.0 2.0 ) * ( 1.0 ) + beta * ( 4.0 ) = ( 31.1 ) // ( 3.0 0.0 4.0 ) * ( 2.0 ) ( 5.0 ) = ( 62.0 ) // ( 5.0 6.0 0.0 ) * ( 3.0 ) ( 6.0 ) = ( 70.7 ) // ( 7.0 0.0 8.0 ) * ( 7.0 ) = ( 123.8 ) const int m = 4; const int n = 3; const int nnz = 8; // CSR row pointers int hcsrRowPtr[m + 1] = {0, 2, 4, 6, 8}; // CSR column indices int hcsrColInd[nnz] = {0, 2, 0, 2, 0, 1, 0, 2}; // CSR values double hcsrVal[nnz] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0}; // Transposition of the matrix hipsparseOperation_t trans = HIPSPARSE_OPERATION_NON_TRANSPOSE; // Scalar alpha and beta double alpha = 3.7; double beta = 1.3; // x and y double hx[n] = {1.0, 2.0, 3.0}; double hy[m] = {4.0, 5.0, 6.0, 7.0}; // Matrix descriptor hipsparseMatDescr_t descr; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descr)); // Offload data to device int* dcsrRowPtr; int* dcsrColInd; double* dcsrVal; double* dx; double* dy; HIP_CHECK(hipMalloc((void**)&dcsrRowPtr, sizeof(int) * (m + 1))); HIP_CHECK(hipMalloc((void**)&dcsrColInd, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dcsrVal, sizeof(double) * nnz)); HIP_CHECK(hipMalloc((void**)&dx, sizeof(double) * n)); HIP_CHECK(hipMalloc((void**)&dy, sizeof(double) * m)); HIP_CHECK(hipMemcpy(dcsrRowPtr, hcsrRowPtr, sizeof(int) * (m + 1), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrColInd, hcsrColInd, sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrVal, hcsrVal, sizeof(double) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dx, hx, sizeof(double) * n, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dy, hy, sizeof(double) * m, hipMemcpyHostToDevice)); // Call dcsrmv to perform y = alpha * A x + beta * y HIPSPARSE_CHECK(hipsparseDcsrmv( handle, trans, m, n, nnz, &alpha, descr, dcsrVal, dcsrRowPtr, dcsrColInd, dx, &beta, dy)); // Copy result back to host HIP_CHECK(hipMemcpy(hy, dy, sizeof(double) * m, hipMemcpyDeviceToHost)); std::cout << "hy" << std::endl; for(int i = 0; i < m; i++) { std::cout << hy[i] << " "; } std::cout << "" << std::endl; // Clear hipSPARSE HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descr)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); // Clear device memory HIP_CHECK(hipFree(dcsrRowPtr)); HIP_CHECK(hipFree(dcsrColInd)); HIP_CHECK(hipFree(dcsrVal)); HIP_CHECK(hipFree(dx)); HIP_CHECK(hipFree(dy)); return 0; } //! [doc example] ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5773993 hipsparse/clients/samples/documentation_examples/level2/example_hipsparse_csrsv2.cpp0000664000175100017510000001511215206065364031577 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // alpha * ( 1.0 0.0 2.0 0.0 ) * ( x_0 ) = ( 32.0 ) // ( 3.0 2.0 4.0 1.0 ) * ( x_1 ) = ( 14.7 ) // ( 5.0 6.0 1.0 3.0 ) * ( x_2 ) = ( 33.6 ) // ( 7.0 0.0 8.0 0.6 ) * ( x_3 ) = ( 10.0 ) const int m = 4; const int nnz = 13; // CSR row pointers int hcsrRowPtr[m + 1] = {0, 2, 6, 10, 13}; // CSR column indices int hcsrColInd[nnz] = {0, 2, 0, 1, 2, 3, 0, 1, 2, 3, 0, 2, 3}; // CSR values double hcsrVal[nnz] = {1.0, 2.0, 3.0, 2.0, 4.0, 1.0, 5.0, 6.0, 1.0, 3.0, 7.0, 8.0, 0.6}; // Transposition of the matrix hipsparseOperation_t trans = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseSolvePolicy_t policy = HIPSPARSE_SOLVE_POLICY_USE_LEVEL; // Scalar alpha double alpha = 1.0; // f and x double hf[m] = {32.0, 14.7, 33.6, 10.0}; double hx[m]; // Matrix descriptor hipsparseMatDescr_t descr; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descr)); // Set index base on descriptor HIPSPARSE_CHECK(hipsparseSetMatIndexBase(descr, HIPSPARSE_INDEX_BASE_ZERO)); // Set fill mode on descriptor HIPSPARSE_CHECK(hipsparseSetMatFillMode(descr, HIPSPARSE_FILL_MODE_LOWER)); // Set diag type on descriptor HIPSPARSE_CHECK(hipsparseSetMatDiagType(descr, HIPSPARSE_DIAG_TYPE_UNIT)); // Csrsv info csrsv2Info_t info; HIPSPARSE_CHECK(hipsparseCreateCsrsv2Info(&info)); // Offload data to device int* dcsrRowPtr; int* dcsrColInd; double* dcsrVal; double* df; double* dx; HIP_CHECK(hipMalloc((void**)&dcsrRowPtr, sizeof(int) * (m + 1))); HIP_CHECK(hipMalloc((void**)&dcsrColInd, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dcsrVal, sizeof(double) * nnz)); HIP_CHECK(hipMalloc((void**)&df, sizeof(double) * m)); HIP_CHECK(hipMalloc((void**)&dx, sizeof(double) * m)); HIP_CHECK(hipMemcpy(dcsrRowPtr, hcsrRowPtr, sizeof(int) * (m + 1), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrColInd, hcsrColInd, sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrVal, hcsrVal, sizeof(double) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(df, hf, sizeof(double) * m, hipMemcpyHostToDevice)); int bufferSize = 0; HIPSPARSE_CHECK(hipsparseDcsrsv2_bufferSize( handle, trans, m, nnz, descr, dcsrVal, dcsrRowPtr, dcsrColInd, info, &bufferSize)); void* dbuffer = nullptr; HIP_CHECK(hipMalloc((void**)&dbuffer, bufferSize)); HIPSPARSE_CHECK(hipsparseDcsrsv2_analysis( handle, trans, m, nnz, descr, dcsrVal, dcsrRowPtr, dcsrColInd, info, policy, dbuffer)); // Call dcsrsv to perform alpha * A * x = f HIPSPARSE_CHECK(hipsparseDcsrsv2_solve(handle, trans, m, nnz, &alpha, descr, dcsrVal, dcsrRowPtr, dcsrColInd, info, df, dx, policy, dbuffer)); // Copy result back to host HIP_CHECK(hipMemcpy(hx, dx, sizeof(double) * m, hipMemcpyDeviceToHost)); std::cout << "hx" << std::endl; for(int i = 0; i < m; i++) { std::cout << hx[i] << " "; } std::cout << "" << std::endl; // Clear hipSPARSE HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descr)); HIPSPARSE_CHECK(hipsparseDestroyCsrsv2Info(info)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); // Clear device memory HIP_CHECK(hipFree(dcsrRowPtr)); HIP_CHECK(hipFree(dcsrColInd)); HIP_CHECK(hipFree(dcsrVal)); HIP_CHECK(hipFree(df)); HIP_CHECK(hipFree(dx)); HIP_CHECK(hipFree(dbuffer)); return 0; } //! [doc example] ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5783992 hipsparse/clients/samples/documentation_examples/level2/example_hipsparse_gemvi.cpp0000664000175100017510000001272615206065364031474 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { hipsparseOperation_t opA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; // Scalar alpha and beta float alpha = 1.0f; float beta = 1.0f; const int m = 4; // Number of rows of A const int n = 4; // Number of columns of A const int lda = m; // leading dimension of A // A = 1 2 3 4 // 5 6 7 8 // 2 4 6 8 // 4 3 2 1 std::vector hA = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 2.0f, 4.0f, 6.0f, 8.0f, 4.0f, 3.0f, 2.0f, 1.0f}; // Sparse vector x int nnz = 2; std::vector hxInd = {0, 2}; std::vector hx = {10.0f, 11.0f}; // Dense vector y std::vector hy = {1.0f, 2.0f, 3.0f, 4.0f}; // Device data float* dA = nullptr; HIP_CHECK(hipMalloc((void**)&dA, sizeof(float) * m * n)); int* dxInd = nullptr; float* dx = nullptr; HIP_CHECK(hipMalloc((void**)&dxInd, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dx, sizeof(float) * nnz)); float* dy = nullptr; HIP_CHECK(hipMalloc((void**)&dy, sizeof(float) * m)); // Copy data from host to device HIP_CHECK(hipMemcpy(dA, hA.data(), sizeof(float) * m * n, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dxInd, hxInd.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dx, hx.data(), sizeof(float) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dy, hy.data(), sizeof(float) * m, hipMemcpyHostToDevice)); // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // Call hipsparseSgemvi to perform y = alpha * A * x + beta * y int bufferSize = 0; HIPSPARSE_CHECK(hipsparseSgemvi_bufferSize(handle, opA, m, n, nnz, &bufferSize)); void* dbuffer = nullptr; HIP_CHECK(hipMalloc((void**)&dbuffer, bufferSize)); HIPSPARSE_CHECK(hipsparseSgemvi( handle, opA, m, n, &alpha, dA, lda, nnz, dx, dxInd, &beta, dy, idxBase, dbuffer)); // Copy result back to host HIP_CHECK(hipMemcpy(hy.data(), dy, sizeof(float) * m, hipMemcpyDeviceToHost)); // Print the result (optional) std::cout << "hy" << std::endl; for(int i = 0; i < m; i++) { std::cout << hy[i] << " "; } std::cout << "" << std::endl; // Clear hipSPARSE HIPSPARSE_CHECK(hipsparseDestroy(handle)); // Clear device memory HIP_CHECK(hipFree(dA)); HIP_CHECK(hipFree(dxInd)); HIP_CHECK(hipFree(dx)); HIP_CHECK(hipFree(dy)); HIP_CHECK(hipFree(dbuffer)); return 0; } //! [doc example] ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5783992 hipsparse/clients/samples/documentation_examples/level2/example_hipsparse_hybmv.cpp0000664000175100017510000001164715206065364031513 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // A sparse matrix // 1 0 3 4 // 0 0 5 1 // 0 2 0 0 // 4 0 0 8 int hAptr[5] = {0, 3, 5, 6, 8}; int hAcol[8] = {0, 2, 3, 2, 3, 1, 0, 3}; double hAval[8] = {1.0, 3.0, 4.0, 5.0, 1.0, 2.0, 4.0, 8.0}; int m = 4; int n = 4; int nnz = 8; double halpha = 1.0; double hbeta = 0.0; double hx[4] = {1.0, 2.0, 3.0, 4.0}; double hy[4] = {4.0, 5.0, 6.0, 7.0}; // Matrix descriptor hipsparseMatDescr_t descrA; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descrA)); // Offload data to device int* dAptr = NULL; int* dAcol = NULL; double* dAval = NULL; double* dx = NULL; double* dy = NULL; HIP_CHECK(hipMalloc((void**)&dAptr, sizeof(int) * (m + 1))); HIP_CHECK(hipMalloc((void**)&dAcol, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dAval, sizeof(double) * nnz)); HIP_CHECK(hipMalloc((void**)&dx, sizeof(double) * n)); HIP_CHECK(hipMalloc((void**)&dy, sizeof(double) * m)); HIP_CHECK(hipMemcpy(dAptr, hAptr, sizeof(int) * (m + 1), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dAcol, hAcol, sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dAval, hAval, sizeof(double) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dx, hx, sizeof(double) * n, hipMemcpyHostToDevice)); // Convert CSR matrix to HYB format hipsparseHybMat_t hybA; HIPSPARSE_CHECK(hipsparseCreateHybMat(&hybA)); HIPSPARSE_CHECK(hipsparseDcsr2hyb( handle, m, n, descrA, dAval, dAptr, dAcol, hybA, 0, HIPSPARSE_HYB_PARTITION_AUTO)); // Clean up CSR structures HIP_CHECK(hipFree(dAptr)); HIP_CHECK(hipFree(dAcol)); HIP_CHECK(hipFree(dAval)); // Call hipsparse hybmv HIPSPARSE_CHECK(hipsparseDhybmv( handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, &halpha, descrA, hybA, dx, &hbeta, dy)); // Copy result back to host HIP_CHECK(hipMemcpy(hy, dy, sizeof(double) * m, hipMemcpyDeviceToHost)); std::cout << "hy" << std::endl; for(int i = 0; i < m; i++) { std::cout << hy[i] << " "; } std::cout << "" << std::endl; // Clear up on device HIPSPARSE_CHECK(hipsparseDestroyHybMat(hybA)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descrA)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); HIP_CHECK(hipFree(dx)); HIP_CHECK(hipFree(dy)); return 0; } //! [doc example] ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5783992 hipsparse/clients/samples/documentation_examples/level3/0000775000175100017510000000000015206065364024061 5ustar00jenkinsjenkins././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5783992 hipsparse/clients/samples/documentation_examples/level3/example_hipsparse_bsrmm.cpp0000664000175100017510000001440215206065364031477 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // 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 const int blockDim = 2; const int mb = 2; const int kb = 3; const int nnzb = 4; const hipsparseDirection_t dir = HIPSPARSE_DIRECTION_ROW; int hbsrRowPtr[mb + 1] = {0, 2, 4}; int hbsrColInd[nnzb] = {0, 1, 1, 2}; float hbsrVal[nnzb * blockDim * blockDim] = {1, 2, 0, 4, 0, 3, 5, 0, 0, 7, 1, 2, 8, 0, 4, 1}; // Set dimension n of B const int n = 3; const int m = mb * blockDim; const int k = kb * blockDim; // Allocate and generate dense matrix B (k x n) float hB[k * n] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f}; int* dbsrRowPtr = NULL; int* dbsrColInd = NULL; float* dbsrVal = NULL; HIP_CHECK(hipMalloc((void**)&dbsrRowPtr, sizeof(int) * (mb + 1))); HIP_CHECK(hipMalloc((void**)&dbsrColInd, sizeof(int) * nnzb)); HIP_CHECK(hipMalloc((void**)&dbsrVal, sizeof(float) * nnzb * blockDim * blockDim)); HIP_CHECK(hipMemcpy(dbsrRowPtr, hbsrRowPtr, sizeof(int) * (mb + 1), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dbsrColInd, hbsrColInd, sizeof(int) * nnzb, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy( dbsrVal, hbsrVal, sizeof(float) * nnzb * blockDim * blockDim, hipMemcpyHostToDevice)); // Copy B to the device float* dB; HIP_CHECK(hipMalloc((void**)&dB, sizeof(float) * k * n)); HIP_CHECK(hipMemcpy(dB, hB, sizeof(float) * k * n, hipMemcpyHostToDevice)); // alpha and beta float alpha = 1.0f; float beta = 0.0f; // Allocate memory for the resulting matrix C float* dC; HIP_CHECK(hipMalloc((void**)&dC, sizeof(float) * m * n)); // Matrix descriptor hipsparseMatDescr_t descr; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descr)); // Perform the matrix multiplication HIPSPARSE_CHECK(hipsparseSbsrmm(handle, dir, HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_NON_TRANSPOSE, mb, n, kb, nnzb, &alpha, descr, dbsrVal, dbsrRowPtr, dbsrColInd, blockDim, dB, k, &beta, dC, m)); // Copy results to host float hC[m * n]; HIP_CHECK(hipMemcpy(hC, dC, sizeof(float) * m * n, hipMemcpyDeviceToHost)); std::cout << "hC" << std::endl; for(int i = 0; i < m * n; i++) { std::cout << hC[i] << " "; } std::cout << "" << std::endl; HIP_CHECK(hipFree(dbsrRowPtr)); HIP_CHECK(hipFree(dbsrColInd)); HIP_CHECK(hipFree(dbsrVal)); HIP_CHECK(hipFree(dB)); HIP_CHECK(hipFree(dC)); return 0; } //! [doc example] ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5783992 hipsparse/clients/samples/documentation_examples/level3/example_hipsparse_bsrsm.cpp0000664000175100017510000002241715206065364031512 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // A = ( 1.0 0.0 0.0 0.0 ) // ( 2.0 3.0 0.0 0.0 ) // ( 4.0 5.0 6.0 0.0 ) // ( 7.0 0.0 8.0 9.0 ) // // with bsr_dim = 2 // // ------------------- // = | 1.0 0.0 | 0.0 0.0 | // | 2.0 3.0 | 0.0 0.0 | // ------------------- // | 4.0 5.0 | 6.0 0.0 | // | 7.0 0.0 | 8.0 9.0 | // ------------------- // Number of rows and columns const int m = 4; // Number of block rows and block columns const int mb = 2; const int nb = 2; // BSR block dimension const int bsr_dim = 2; // Number of right-hand-sides const int nrhs = 4; // Number of non-zero blocks const int nnzb = 3; // BSR row pointers int hbsrRowPtr[mb + 1] = {0, 1, 3}; // BSR column indices int hbsrColInd[nnzb] = {0, 0, 1}; // BSR values double hbsrVal[nnzb * bsr_dim * bsr_dim] = {1.0, 2.0, 0.0, 3.0, 4.0, 7.0, 5.0, 0.0, 6.0, 8.0, 0.0, 9.0}; // Storage scheme of the BSR blocks hipsparseDirection_t dir = HIPSPARSE_DIRECTION_COLUMN; // Transposition of the matrix and rhs matrix hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transX = HIPSPARSE_OPERATION_NON_TRANSPOSE; // Solve policy hipsparseSolvePolicy_t solve_policy = HIPSPARSE_SOLVE_POLICY_NO_LEVEL; // Scalar alpha and beta double alpha = 1.0; // rhs and solution matrix const int ldb = nb * bsr_dim; const int ldx = mb * bsr_dim; double hB[ldb * nrhs] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; double hX[ldx * nrhs]; // Offload data to device int* dbsrRowPtr; int* dbsrColInd; double* dbsrVal; double* dB; double* dX; HIP_CHECK(hipMalloc((void**)&dbsrRowPtr, sizeof(int) * (mb + 1))); HIP_CHECK(hipMalloc((void**)&dbsrColInd, sizeof(int) * nnzb)); HIP_CHECK(hipMalloc((void**)&dbsrVal, sizeof(double) * nnzb * bsr_dim * bsr_dim)); HIP_CHECK(hipMalloc((void**)&dB, sizeof(double) * nb * bsr_dim * nrhs)); HIP_CHECK(hipMalloc((void**)&dX, sizeof(double) * mb * bsr_dim * nrhs)); HIP_CHECK(hipMemcpy(dbsrRowPtr, hbsrRowPtr, sizeof(int) * (mb + 1), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dbsrColInd, hbsrColInd, sizeof(int) * nnzb, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy( dbsrVal, hbsrVal, sizeof(double) * nnzb * bsr_dim * bsr_dim, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dB, hB, sizeof(double) * nb * bsr_dim * nrhs, hipMemcpyHostToDevice)); // Matrix descriptor hipsparseMatDescr_t descr; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descr)); // Matrix fill mode HIPSPARSE_CHECK(hipsparseSetMatFillMode(descr, HIPSPARSE_FILL_MODE_LOWER)); // Matrix diagonal type HIPSPARSE_CHECK(hipsparseSetMatDiagType(descr, HIPSPARSE_DIAG_TYPE_NON_UNIT)); // Matrix info structure bsrsm2Info_t info; HIPSPARSE_CHECK(hipsparseCreateBsrsm2Info(&info)); // Obtain required buffer size int buffer_size; HIPSPARSE_CHECK(hipsparseDbsrsm2_bufferSize(handle, dir, transA, transX, mb, nrhs, nnzb, descr, dbsrVal, dbsrRowPtr, dbsrColInd, bsr_dim, info, &buffer_size)); // Allocate temporary buffer void* dbuffer; HIP_CHECK(hipMalloc(&dbuffer, buffer_size)); // Perform analysis step HIPSPARSE_CHECK(hipsparseDbsrsm2_analysis(handle, dir, transA, transX, mb, nrhs, nnzb, descr, dbsrVal, dbsrRowPtr, dbsrColInd, bsr_dim, info, solve_policy, dbuffer)); // Call dbsrsm to perform lower triangular solve LX = B HIPSPARSE_CHECK(hipsparseDbsrsm2_solve(handle, dir, transA, transX, mb, nrhs, nnzb, &alpha, descr, dbsrVal, dbsrRowPtr, dbsrColInd, bsr_dim, info, dB, ldb, dX, ldx, solve_policy, dbuffer)); // Check for zero pivots int pivot; hipsparseStatus_t status = hipsparseXbsrsm2_zeroPivot(handle, info, &pivot); if(status == HIPSPARSE_STATUS_ZERO_PIVOT) { std::cout << "Found zero pivot in matrix row " << pivot << std::endl; } // Copy result back to host HIP_CHECK(hipMemcpy(hX, dX, sizeof(double) * mb * bsr_dim * nrhs, hipMemcpyDeviceToHost)); std::cout << "hX" << std::endl; for(int i = 0; i < ldx * nrhs; i++) { std::cout << hX[i] << " "; } std::cout << "" << std::endl; // Clear hipSPARSE HIPSPARSE_CHECK(hipsparseDestroyBsrsm2Info(info)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descr)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); // Clear device memory HIP_CHECK(hipFree(dbsrRowPtr)); HIP_CHECK(hipFree(dbsrColInd)); HIP_CHECK(hipFree(dbsrVal)); HIP_CHECK(hipFree(dB)); HIP_CHECK(hipFree(dX)); HIP_CHECK(hipFree(dbuffer)); return 0; } //! [doc example] ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5783992 hipsparse/clients/samples/documentation_examples/level3/example_hipsparse_csrmm.cpp0000664000175100017510000001365315206065364031507 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // 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 const int m = 4; const int k = 6; const int nnz = 11; const hipsparseDirection_t dir = HIPSPARSE_DIRECTION_ROW; int hcsrRowPtr[m + 1] = {0, 3, 5, 7, 11}; int hcsrColInd[nnz] = {0, 1, 3, 1, 2, 3, 4, 2, 3, 4, 5}; float hcsrVal[nnz] = {1, 2, 3, 4, 5, 7, 8, 1, 2, 4, 1}; // Set dimension n of B const int n = 3; // Allocate and generate dense matrix B (k x n) float hB[k * n] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f}; int* dcsrRowPtr = NULL; int* dcsrColInd = NULL; float* dcsrVal = NULL; HIP_CHECK(hipMalloc((void**)&dcsrRowPtr, sizeof(int) * (m + 1))); HIP_CHECK(hipMalloc((void**)&dcsrColInd, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dcsrVal, sizeof(float) * nnz)); HIP_CHECK(hipMemcpy(dcsrRowPtr, hcsrRowPtr, sizeof(int) * (m + 1), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrColInd, hcsrColInd, sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrVal, hcsrVal, sizeof(float) * nnz, hipMemcpyHostToDevice)); // Copy B to the device float* dB; HIP_CHECK(hipMalloc((void**)&dB, sizeof(float) * k * n)); HIP_CHECK(hipMemcpy(dB, hB, sizeof(float) * k * n, hipMemcpyHostToDevice)); // alpha and beta float alpha = 1.0f; float beta = 0.0f; // Allocate memory for the resulting matrix C float* dC; HIP_CHECK(hipMalloc((void**)&dC, sizeof(float) * m * n)); // Matrix descriptor hipsparseMatDescr_t descr; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descr)); // Perform the matrix multiplication HIPSPARSE_CHECK(hipsparseScsrmm(handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, m, n, k, nnz, &alpha, descr, dcsrVal, dcsrRowPtr, dcsrColInd, dB, k, &beta, dC, m)); // Copy results to host float hC[6 * 3]; HIP_CHECK(hipMemcpy(hC, dC, sizeof(float) * m * n, hipMemcpyDeviceToHost)); std::cout << "hC" << std::endl; for(int i = 0; i < m * n; i++) { std::cout << hC[i] << " "; } std::cout << "" << std::endl; HIP_CHECK(hipFree(dcsrRowPtr)); HIP_CHECK(hipFree(dcsrColInd)); HIP_CHECK(hipFree(dcsrVal)); HIP_CHECK(hipFree(dB)); HIP_CHECK(hipFree(dC)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); return 0; } //! [doc example] ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5783992 hipsparse/clients/samples/documentation_examples/level3/example_hipsparse_csrsm2.cpp0000664000175100017510000002070215206065364031570 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // A = ( 1.0 0.0 0.0 0.0 ) // ( 2.0 3.0 0.0 0.0 ) // ( 4.0 5.0 6.0 0.0 ) // ( 7.0 0.0 8.0 9.0 ) // Number of rows and columns int m = 4; int n = 4; // Number of right-hand-sides int nrhs = 4; // Number of non-zeros int nnz = 9; // CSR row pointers int hcsrRowPtr[5] = {0, 1, 3, 6, 9}; // CSR column indices int hcsrColInd[9] = {0, 0, 1, 0, 1, 2, 0, 2, 3}; // CSR values double hcsrVal[9] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}; // Transposition of the matrix and rhs matrix hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; // Solve policy hipsparseSolvePolicy_t solve_policy = HIPSPARSE_SOLVE_POLICY_NO_LEVEL; // Scalar alpha and beta double alpha = 1.0; // rhs and solution matrix int ldb = n; double hB[16] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; // Offload data to device int* dcsrRowPtr; int* dcsrColInd; double* dcsrVal; double* dB; HIP_CHECK(hipMalloc((void**)&dcsrRowPtr, sizeof(int) * (m + 1))); HIP_CHECK(hipMalloc((void**)&dcsrColInd, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dcsrVal, sizeof(double) * nnz)); HIP_CHECK(hipMalloc((void**)&dB, sizeof(double) * n * nrhs)); HIP_CHECK(hipMemcpy(dcsrRowPtr, hcsrRowPtr, sizeof(int) * (m + 1), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrColInd, hcsrColInd, sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrVal, hcsrVal, sizeof(double) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dB, hB, sizeof(double) * n * nrhs, hipMemcpyHostToDevice)); // Matrix descriptor hipsparseMatDescr_t descr; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descr)); // Matrix fill mode HIPSPARSE_CHECK(hipsparseSetMatFillMode(descr, HIPSPARSE_FILL_MODE_LOWER)); // Matrix diagonal type HIPSPARSE_CHECK(hipsparseSetMatDiagType(descr, HIPSPARSE_DIAG_TYPE_NON_UNIT)); // Matrix info structure csrsm2Info_t info; HIPSPARSE_CHECK(hipsparseCreateCsrsm2Info(&info)); // Obtain required buffer size size_t buffer_size; HIPSPARSE_CHECK(hipsparseDcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, &alpha, descr, dcsrVal, dcsrRowPtr, dcsrColInd, dB, ldb, info, solve_policy, &buffer_size)); // Allocate temporary buffer void* dbuffer; HIP_CHECK(hipMalloc(&dbuffer, buffer_size)); // Perform analysis step HIPSPARSE_CHECK(hipsparseDcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, &alpha, descr, dcsrVal, dcsrRowPtr, dcsrColInd, dB, ldb, info, solve_policy, dbuffer)); // Call dcsrsm to perform lower triangular solve LB = B HIPSPARSE_CHECK(hipsparseDcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &alpha, descr, dcsrVal, dcsrRowPtr, dcsrColInd, dB, ldb, info, solve_policy, dbuffer)); // Check for zero pivots int pivot; hipsparseStatus_t status = hipsparseXcsrsm2_zeroPivot(handle, info, &pivot); if(status == HIPSPARSE_STATUS_ZERO_PIVOT) { std::cout << "Found zero pivot in matrix row " << pivot << std::endl; } // Copy result back to host HIP_CHECK(hipMemcpy(hB, dB, sizeof(double) * m * nrhs, hipMemcpyDeviceToHost)); // Clear hipSPARSE HIPSPARSE_CHECK(hipsparseDestroyCsrsm2Info(info)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descr)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); // Clear device memory HIP_CHECK(hipFree(dcsrRowPtr)); HIP_CHECK(hipFree(dcsrColInd)); HIP_CHECK(hipFree(dcsrVal)); HIP_CHECK(hipFree(dB)); HIP_CHECK(hipFree(dbuffer)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5783992 hipsparse/clients/samples/documentation_examples/level3/example_hipsparse_gemmi.cpp0000664000175100017510000001140615206065364031456 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // A, B, and C are m×k, k×n, and m×n const int m = 3, n = 5, k = 4; const int lda = m, ldc = m; const int nnz_A = m * k, nnz_B = 10, nnz_C = m * n; // alpha and beta float alpha = 0.5f; float beta = 0.25f; std::vector hcscColPtr = {0, 2, 5, 7, 8, 10}; std::vector hcscRowInd = {0, 2, 0, 1, 3, 1, 3, 2, 0, 2}; std::vector hcsc_val = {1, 6, 2, 4, 9, 5, 2, 7, 3, 8}; std::vector hA(nnz_A, 1.0f); std::vector hC(nnz_C, 1.0f); int* dcscColPtr; int* dcscRowInd; float* dcsc_val; HIP_CHECK(hipMalloc((void**)&dcscColPtr, sizeof(int) * (n + 1))); HIP_CHECK(hipMalloc((void**)&dcscRowInd, sizeof(int) * nnz_B)); HIP_CHECK(hipMalloc((void**)&dcsc_val, sizeof(float) * nnz_B)); HIP_CHECK( hipMemcpy(dcscColPtr, hcscColPtr.data(), sizeof(int) * (n + 1), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcscRowInd, hcscRowInd.data(), sizeof(int) * nnz_B, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsc_val, hcsc_val.data(), sizeof(float) * nnz_B, hipMemcpyHostToDevice)); hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // Allocate memory for the matrix A float* dA; HIP_CHECK(hipMalloc((void**)&dA, sizeof(float) * nnz_A)); HIP_CHECK(hipMemcpy(dA, hA.data(), sizeof(float) * nnz_A, hipMemcpyHostToDevice)); // Allocate memory for the resulting matrix C float* dC; HIP_CHECK(hipMalloc((void**)&dC, sizeof(float) * nnz_C)); HIP_CHECK(hipMemcpy(dC, hC.data(), sizeof(float) * nnz_C, hipMemcpyHostToDevice)); // Perform operation HIPSPARSE_CHECK(hipsparseSgemmi( handle, m, n, k, nnz_B, &alpha, dA, lda, dcsc_val, dcscColPtr, dcscRowInd, &beta, dC, ldc)); // Copy device to host HIP_CHECK(hipMemcpy(hC.data(), dC, sizeof(float) * nnz_C, hipMemcpyDeviceToHost)); std::cout << "hC" << std::endl; for(int i = 0; i < nnz_C; i++) { std::cout << hC[i] << " "; } std::cout << "" << std::endl; // Destroy matrix descriptors and handles HIPSPARSE_CHECK(hipsparseDestroy(handle)); HIP_CHECK(hipFree(dcscColPtr)); HIP_CHECK(hipFree(dcscRowInd)); HIP_CHECK(hipFree(dcsc_val)); HIP_CHECK(hipFree(dA)); HIP_CHECK(hipFree(dC)); return 0; } //! [doc example] ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5793993 hipsparse/clients/samples/documentation_examples/precond/0000775000175100017510000000000015206065364024321 5ustar00jenkinsjenkins././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5783992 hipsparse/clients/samples/documentation_examples/precond/example_hipsparse_bsric02.cpp0000664000175100017510000002005215206065364032061 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // A sample symmetric positive definite matrix A (4x4) // with a block size of 1. This example effectively uses BSR format // for a CSR-like matrix. // Matrix A: // ( 4 1 0 0 ) // ( 1 5 2 0 ) // ( 0 2 3 1 ) // ( 0 0 1 2 ) const int m = 4; // Number of rows const int n = 4; // Number of columns const int bs = 1; // Block size const int mb = m / bs; // Number of block rows const int nb = n / bs; // Number of block columns const int nnzb = 10; // Number of non-zero blocks // BSR row pointers int hbsrRowPtr[mb + 1] = {0, 2, 5, 8, 10}; // BSR column indices int hbsrColInd[nnzb] = {0, 1, 0, 1, 2, 1, 2, 3, 2, 3}; // BSR values (single precision float for 'S'bsric02) // Values are stored column-major within each block, but with bs=1, this is simple. // The values correspond to the upper triangular part of the matrix. float hbsrVal[nnzb * bs * bs] = {4.0f, 1.0f, 1.0f, 5.0f, 2.0f, 2.0f, 3.0f, 1.0f, 1.0f, 2.0f}; // Matrix descriptor hipsparseMatDescr_t descr; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descr)); // Set index base on descriptor HIPSPARSE_CHECK(hipsparseSetMatIndexBase(descr, HIPSPARSE_INDEX_BASE_ZERO)); // Set fill mode to lower and diagonal type to unit (required for IC02) HIPSPARSE_CHECK(hipsparseSetMatFillMode(descr, HIPSPARSE_FILL_MODE_LOWER)); HIPSPARSE_CHECK(hipsparseSetMatDiagType(descr, HIPSPARSE_DIAG_TYPE_UNIT)); // BSRIC02 info bsric02Info_t info; HIPSPARSE_CHECK(hipsparseCreateBsric02Info(&info)); // Offload data to device int* dbsrRowPtr; int* dbsrColInd; float* dbsrVal; HIP_CHECK(hipMalloc((void**)&dbsrRowPtr, sizeof(int) * (mb + 1))); HIP_CHECK(hipMalloc((void**)&dbsrColInd, sizeof(int) * nnzb)); HIP_CHECK(hipMalloc((void**)&dbsrVal, sizeof(float) * nnzb * bs * bs)); HIP_CHECK(hipMemcpy(dbsrRowPtr, hbsrRowPtr, sizeof(int) * (mb + 1), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dbsrColInd, hbsrColInd, sizeof(int) * nnzb, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dbsrVal, hbsrVal, sizeof(float) * nnzb * bs * bs, hipMemcpyHostToDevice)); // 1. Get buffer size int bufferSize = 0; HIPSPARSE_CHECK(hipsparseSbsric02_bufferSize(handle, HIPSPARSE_DIRECTION_COLUMN, mb, nnzb, descr, dbsrVal, dbsrRowPtr, dbsrColInd, bs, info, &bufferSize)); void* dbuffer = nullptr; HIP_CHECK(hipMalloc((void**)&dbuffer, bufferSize)); // 2. Perform analysis (symbolic factorization) HIPSPARSE_CHECK(hipsparseSbsric02_analysis(handle, HIPSPARSE_DIRECTION_COLUMN, mb, nnzb, descr, dbsrVal, dbsrRowPtr, dbsrColInd, bs, info, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer)); // 3. Perform factorization (numerical computation) HIPSPARSE_CHECK(hipsparseSbsric02(handle, HIPSPARSE_DIRECTION_COLUMN, mb, nnzb, descr, dbsrVal, dbsrRowPtr, dbsrColInd, bs, info, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer)); // 4. Check for zero pivots int zeroPivot = 0; HIPSPARSE_CHECK(hipsparseXbsric02_zeroPivot(handle, info, &zeroPivot)); if(zeroPivot != -1) { printf("Error: Zero pivot detected at index %d\n", zeroPivot); // Handle error, e.g., by returning an error code } // Copy the factorized values back to host float* hbsrVal_result = new float[nnzb * bs * bs]; HIP_CHECK( hipMemcpy(hbsrVal_result, dbsrVal, sizeof(float) * nnzb * bs * bs, hipMemcpyDeviceToHost)); // Print the result (the values of the factorized matrix) printf("Successfully computed incomplete Cholesky factorization.\n"); printf("Factorized BSR values:\n"); for(int i = 0; i < nnzb * bs * bs; ++i) { printf("val[%d] = %f\n", i, hbsrVal_result[i]); } // Clean up delete[] hbsrVal_result; HIPSPARSE_CHECK(hipsparseDestroyBsric02Info(info)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descr)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); HIP_CHECK(hipFree(dbsrRowPtr)); HIP_CHECK(hipFree(dbsrColInd)); HIP_CHECK(hipFree(dbsrVal)); HIP_CHECK(hipFree(dbuffer)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5783992 hipsparse/clients/samples/documentation_examples/precond/example_hipsparse_bsrilu02.cpp0000664000175100017510000002027615206065364032267 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // A sample square matrix A (4x4) in BSR format for ILU(0) factorization. // The 'S' in Sbsrilu02 indicates single precision float. // We'll use a block size of 1 for simplicity, making it behave like CSR ILU. // Matrix A: // ( 1 2 0 0 ) // ( 3 4 5 0 ) // ( 0 6 7 8 ) // ( 0 0 9 10 ) int m = 4; // Number of rows int n = 4; // Number of columns int bs = 1; // Block size int mb = m / bs; // Number of block rows int nb = n / bs; // Number of block columns int nnzb = 10; // Number of non-zero blocks // BSR row pointers int hbsrRowPtr[5] = {0, 2, 5, 8, 10}; // BSR column indices int hbsrColInd[10] = {0, 1, 0, 1, 2, 1, 2, 3, 2, 3}; // BSR values (single precision float) float hbsrVal[10] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f}; // Matrix descriptor hipsparseMatDescr_t descr; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descr)); // Set index base on descriptor HIPSPARSE_CHECK(hipsparseSetMatIndexBase(descr, HIPSPARSE_INDEX_BASE_ZERO)); // For ILU(0), the L factor often has a unit diagonal. HIPSPARSE_CHECK(hipsparseSetMatDiagType(descr, HIPSPARSE_DIAG_TYPE_UNIT)); // BSRILU02 info bsrilu02Info_t info; HIPSPARSE_CHECK(hipsparseCreateBsrilu02Info(&info)); // Offload data to device int* dbsrRowPtr; int* dbsrColInd; float* dbsrVal; // This will store the factorized L and U values HIP_CHECK(hipMalloc((void**)&dbsrRowPtr, sizeof(int) * (mb + 1))); HIP_CHECK(hipMalloc((void**)&dbsrColInd, sizeof(int) * nnzb)); HIP_CHECK(hipMalloc((void**)&dbsrVal, sizeof(float) * nnzb * bs * bs)); HIP_CHECK(hipMemcpy(dbsrRowPtr, hbsrRowPtr, sizeof(int) * (mb + 1), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dbsrColInd, hbsrColInd, sizeof(int) * nnzb, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dbsrVal, hbsrVal, sizeof(float) * nnzb * bs * bs, hipMemcpyHostToDevice)); // 1. Get buffer size int bufferSize = 0; HIPSPARSE_CHECK( hipsparseSbsrilu02_bufferSize(handle, HIPSPARSE_DIRECTION_COLUMN, // Block storage direction mb, nnzb, descr, dbsrVal, dbsrRowPtr, dbsrColInd, bs, info, &bufferSize)); void* dbuffer = nullptr; HIP_CHECK(hipMalloc((void**)&dbuffer, bufferSize)); // 2. Perform analysis (symbolic factorization) // This step analyzes the sparsity pattern of A to determine the structure of L and U. HIPSPARSE_CHECK( hipsparseSbsrilu02_analysis(handle, HIPSPARSE_DIRECTION_COLUMN, mb, nnzb, descr, dbsrVal, dbsrRowPtr, dbsrColInd, bs, info, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, // Policy for analysis dbuffer)); // 3. Perform factorization (numerical computation) // This step computes the actual numerical values of L and U, stored in dbsrVal. HIPSPARSE_CHECK(hipsparseSbsrilu02(handle, HIPSPARSE_DIRECTION_COLUMN, mb, nnzb, descr, dbsrVal, dbsrRowPtr, dbsrColInd, bs, info, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, // Policy for factorization dbuffer)); // 4. Check for zero pivots // A zero pivot can occur during factorization, indicating a numerical breakdown. int zeroPivot = 0; // -1 if no zero pivot, otherwise the block row index of the first zero pivot HIPSPARSE_CHECK(hipsparseXbsrilu02_zeroPivot(handle, info, &zeroPivot)); if(zeroPivot != -1) { printf("Error: Zero pivot detected during ILU0 factorization at block row index %d\n", zeroPivot); // Handle the error (e.g., return, use a different preconditioner, etc.) } else { printf("BSRILU0 factorization completed successfully (no zero pivots detected).\n"); } // Copy the factorized values (L and U combined) back to host float* hbsrVal_result = new float[nnzb * bs * bs]; HIP_CHECK( hipMemcpy(hbsrVal_result, dbsrVal, sizeof(float) * nnzb * bs * bs, hipMemcpyDeviceToHost)); // Print the result (the values of the factorized L and U combined) printf("\nFactorized BSR values (L and U combined):\n"); for(int i = 0; i < nnzb * bs * bs; ++i) { printf("val[%d] = %f\n", i, hbsrVal_result[i]); } // Clean up delete[] hbsrVal_result; HIPSPARSE_CHECK(hipsparseDestroyBsrilu02Info(info)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descr)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); HIP_CHECK(hipFree(dbsrRowPtr)); HIP_CHECK(hipFree(dbsrColInd)); HIP_CHECK(hipFree(dbsrVal)); HIP_CHECK(hipFree(dbuffer)); return 0; } //! [doc example] ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5783992 hipsparse/clients/samples/documentation_examples/precond/example_hipsparse_csric02.cpp0000664000175100017510000002053615206065364032071 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // A sample symmetric positive definite matrix A (4x4) in CSR format. // The 'S' in Scsric02 indicates single precision float. // Matrix A: // ( 4 1 0 0 ) // ( 1 5 2 0 ) // ( 0 2 3 1 ) // ( 0 0 1 2 ) // This matrix is symmetric. For IC02, we typically provide the full matrix // or just the lower/upper part if using `HIPSPARSE_MATRIX_TYPE_SYMMETRIC` // with the descriptor. Here, we provide elements for both lower and upper parts // for simplicity, but the factorization will operate on the implicitly // symmetric matrix and produce the lower triangular factor L. int m = 4; // Number of rows int n = 4; // Number of columns (equal to m for Cholesky) int nnz = 10; // Number of non-zero elements (counting only one side for symmetric) // CSR row pointers int hcsrRowPtr[5] = {0, 2, 5, 8, 10}; // CSR column indices // These indices correspond to the non-zero values used below. // For a symmetric matrix A, we implicitly work with A_lower. // The output will be L. int hcsrColInd[10] = {0, 1, 0, 1, 2, 1, 2, 3, 2, 3}; // CSR values (single precision float for 'S'csric02) // The factorization computes the lower triangular L factor. // The input values represent the entries of A that correspond to the non-zero pattern. float hcsrVal[10] = {4.0f, 1.0f, 1.0f, 5.0f, 2.0f, 2.0f, 3.0f, 1.0f, 1.0f, 2.0f}; // Matrix descriptor hipsparseMatDescr_t descr; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descr)); // Set index base on descriptor HIPSPARSE_CHECK(hipsparseSetMatIndexBase(descr, HIPSPARSE_INDEX_BASE_ZERO)); // For incomplete Cholesky, the L factor is computed. // L is lower triangular with a unit diagonal. HIPSPARSE_CHECK(hipsparseSetMatFillMode(descr, HIPSPARSE_FILL_MODE_LOWER)); HIPSPARSE_CHECK(hipsparseSetMatDiagType(descr, HIPSPARSE_DIAG_TYPE_UNIT)); // Optionally set matrix type to symmetric if only storing one triangle of A // HIPSPARSE_CHECK(hipsparseSetMatType(descr, HIPSPARSE_MATRIX_TYPE_SYMMETRIC)); // CSRIC02 info csric02Info_t info; HIPSPARSE_CHECK(hipsparseCreateCsric02Info(&info)); // Offload data to device int* dcsrRowPtr; int* dcsrColInd; float* dcsrVal; // This will store the factorized L values HIP_CHECK(hipMalloc((void**)&dcsrRowPtr, sizeof(int) * (m + 1))); HIP_CHECK(hipMalloc((void**)&dcsrColInd, sizeof(int) * nnz)); HIP_CHECK( hipMalloc((void**)&dcsrVal, sizeof(float) * nnz)); // Note: Same size as input, values will be overwritten HIP_CHECK(hipMemcpy(dcsrRowPtr, hcsrRowPtr, sizeof(int) * (m + 1), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrColInd, hcsrColInd, sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrVal, hcsrVal, sizeof(float) * nnz, hipMemcpyHostToDevice)); // 1. Get buffer size int bufferSize = 0; HIPSPARSE_CHECK(hipsparseScsric02_bufferSize( handle, m, nnz, descr, dcsrVal, dcsrRowPtr, dcsrColInd, info, &bufferSize)); void* dbuffer = nullptr; HIP_CHECK(hipMalloc((void**)&dbuffer, bufferSize)); // 2. Perform analysis (symbolic factorization) // This step analyzes the sparsity pattern of A to determine the structure of L. HIPSPARSE_CHECK( hipsparseScsric02_analysis(handle, m, nnz, descr, dcsrVal, dcsrRowPtr, dcsrColInd, info, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, // Policy for analysis dbuffer)); // 3. Perform factorization (numerical computation) // This step computes the actual numerical values of L, stored in dcsrVal. HIPSPARSE_CHECK(hipsparseScsric02(handle, m, nnz, descr, dcsrVal, dcsrRowPtr, dcsrColInd, info, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, // Policy for factorization dbuffer)); // 4. Check for zero pivots // A zero pivot can occur during factorization, indicating a numerical breakdown. int zeroPivot = 0; // -1 if no zero pivot, otherwise the row index of the first zero pivot HIPSPARSE_CHECK(hipsparseXcsric02_zeroPivot(handle, info, &zeroPivot)); if(zeroPivot != -1) { printf("Error: Zero pivot detected during IC02 factorization at row index %d\n", zeroPivot); // Depending on your application, you might want to handle this error // or switch to a different preconditioner. } else { printf("CSRIC02 factorization completed successfully (no zero pivots detected).\n"); } // Copy the factorized values (L) back to host float* hcsrVal_result = new float[nnz]; HIP_CHECK(hipMemcpy(hcsrVal_result, dcsrVal, sizeof(float) * nnz, hipMemcpyDeviceToHost)); // Print the result (the values of the factorized L) printf("\nFactorized CSR values (L factor):\n"); for(int i = 0; i < nnz; ++i) { printf("val[%d] = %f\n", i, hcsrVal_result[i]); } // Clean up delete[] hcsrVal_result; HIPSPARSE_CHECK(hipsparseDestroyCsric02Info(info)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descr)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); HIP_CHECK(hipFree(dcsrRowPtr)); HIP_CHECK(hipFree(dcsrColInd)); HIP_CHECK(hipFree(dcsrVal)); HIP_CHECK(hipFree(dbuffer)); return 0; } //! [doc example] ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5783992 hipsparse/clients/samples/documentation_examples/precond/example_hipsparse_csrilu02.cpp0000664000175100017510000001664115206065364032271 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // A sample square matrix A (4x4) in CSR format for ILU(0) factorization. // The 'S' in Scsrilu02 indicates single precision float. // Matrix A: // ( 1 2 0 0 ) // ( 3 4 5 0 ) // ( 0 6 7 8 ) // ( 0 0 9 10 ) int m = 4; // Number of rows int n = 4; // Number of columns (equal to m for ILU) int nnz = 10; // Number of non-zero elements // CSR row pointers int hcsrRowPtr[5] = {0, 2, 5, 8, 10}; // CSR column indices int hcsrColInd[10] = {0, 1, 0, 1, 2, 1, 2, 3, 2, 3}; // CSR values float hcsrVal[10] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f}; // Matrix descriptor hipsparseMatDescr_t descr; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descr)); // Set index base on descriptor HIPSPARSE_CHECK(hipsparseSetMatIndexBase(descr, HIPSPARSE_INDEX_BASE_ZERO)); // For incomplete LU, the L factor often has a unit diagonal. HIPSPARSE_CHECK(hipsparseSetMatDiagType(descr, HIPSPARSE_DIAG_TYPE_UNIT)); // CSRILU02 info (for incomplete LU factorization) csrilu02Info_t info; HIPSPARSE_CHECK(hipsparseCreateCsrilu02Info(&info)); // Offload data to device int* dcsrRowPtr; int* dcsrColInd; float* dcsrVal; // This will store the factorized L and U values HIP_CHECK(hipMalloc((void**)&dcsrRowPtr, sizeof(int) * (m + 1))); HIP_CHECK(hipMalloc((void**)&dcsrColInd, sizeof(int) * nnz)); HIP_CHECK( hipMalloc((void**)&dcsrVal, sizeof(float) * nnz)); // Note: Same size as input, values will be overwritten HIP_CHECK(hipMemcpy(dcsrRowPtr, hcsrRowPtr, sizeof(int) * (m + 1), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrColInd, hcsrColInd, sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dcsrVal, hcsrVal, sizeof(float) * nnz, hipMemcpyHostToDevice)); // 1. Get buffer size int bufferSize = 0; HIPSPARSE_CHECK(hipsparseScsrilu02_bufferSize( handle, m, nnz, descr, dcsrVal, dcsrRowPtr, dcsrColInd, info, &bufferSize)); void* dbuffer = nullptr; HIP_CHECK(hipMalloc((void**)&dbuffer, bufferSize)); // 2. Perform analysis (symbolic factorization) // This step analyzes the sparsity pattern of A to determine the structure of L and U. HIPSPARSE_CHECK( hipsparseScsrilu02_analysis(handle, m, nnz, descr, dcsrVal, dcsrRowPtr, dcsrColInd, info, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, // Policy for analysis dbuffer)); // 3. Perform factorization (numerical computation) // This step computes the actual numerical values of L and U, stored in dcsrVal. HIPSPARSE_CHECK(hipsparseScsrilu02(handle, m, nnz, descr, dcsrVal, dcsrRowPtr, dcsrColInd, info, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, // Policy for factorization dbuffer)); // 4. Check for zero pivots // A zero pivot can occur during factorization, indicating a numerical breakdown. int zeroPivot = 0; // -1 if no zero pivot, otherwise the row index of the first zero pivot HIPSPARSE_CHECK(hipsparseXcsrilu02_zeroPivot(handle, info, &zeroPivot)); if(zeroPivot != -1) { printf("Error: Zero pivot detected during ILU0 factorization at row index %d\n", zeroPivot); // Depending on your application, you might want to handle this error // or switch to a different preconditioner. } else { printf("CSRILU0 factorization completed successfully (no zero pivots detected).\n"); } // Copy the factorized values (L and U combined) back to host float* hcsrVal_result = new float[nnz]; HIP_CHECK(hipMemcpy(hcsrVal_result, dcsrVal, sizeof(float) * nnz, hipMemcpyDeviceToHost)); // Print the result (the values of the factorized L and U combined) printf("\nFactorized CSR values (L and U combined):\n"); for(int i = 0; i < nnz; ++i) { printf("val[%d] = %f\n", i, hcsrVal_result[i]); } // Clean up delete[] hcsrVal_result; HIPSPARSE_CHECK(hipsparseDestroyCsrilu02Info(info)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descr)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); HIP_CHECK(hipFree(dcsrRowPtr)); HIP_CHECK(hipFree(dcsrColInd)); HIP_CHECK(hipFree(dcsrVal)); HIP_CHECK(hipFree(dbuffer)); return 0; } //! [doc example] ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5783992 hipsparse/clients/samples/documentation_examples/precond/example_hipsparse_gtsv.cpp0000664000175100017510000001170115206065364031601 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" // Assuming this provides basic utility functions, remove if not needed for standalone example #include #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // Size of square tridiagonal matrix int m = 5; // Number of columns in right-hand side (column ordered) matrix int n = 3; // Leading dimension of right-hand side (column ordered) matrix int ldb = m; // Host tri-diagonal matrix // 2 3 0 0 0 // 2 4 2 0 0 // 0 1 1 1 0 // 0 0 1 3 1 // 0 0 0 1 4 std::vector hdl = {0.0f, 2.0f, 1.0f, 1.0f, 1.0f}; std::vector hd = {2.0f, 4.0f, 1.0f, 3.0f, 4.0f}; std::vector hdu = {3.0f, 2.0f, 1.0f, 1.0f, 0.0f}; // Host right-hand side column vectors std::vector hB(ldb * n, 2.0f); float* ddl = nullptr; float* dd = nullptr; float* ddu = nullptr; float* dB = nullptr; HIP_CHECK(hipMalloc((void**)&ddl, sizeof(float) * m)); HIP_CHECK(hipMalloc((void**)&dd, sizeof(float) * m)); HIP_CHECK(hipMalloc((void**)&ddu, sizeof(float) * m)); HIP_CHECK(hipMalloc((void**)&dB, sizeof(float) * ldb * n)); HIP_CHECK(hipMemcpy(ddl, hdl.data(), sizeof(float) * m, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dd, hd.data(), sizeof(float) * m, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(ddu, hdu.data(), sizeof(float) * m, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dB, hB.data(), sizeof(float) * ldb * n, hipMemcpyHostToDevice)); // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // 1. Get buffer size size_t bufferSize = 0; HIPSPARSE_CHECK( hipsparseSgtsv2_bufferSizeExt(handle, m, m, ddl, dd, ddu, dB, ldb, &bufferSize)); void* dbuffer = nullptr; HIP_CHECK(hipMalloc((void**)&dbuffer, bufferSize)); // 2. Perform tridiagonal solve with pivoting // The solution is computed and stored in the dB vector. HIPSPARSE_CHECK(hipsparseSgtsv2(handle, m, m, ddl, dd, ddu, dB, ldb, dbuffer)); // Copy solution back to host from dB HIP_CHECK(hipMemcpy(hB.data(), dB, sizeof(float) * m, hipMemcpyDeviceToHost)); // Print the solution printf("Solution for the tridiagonal system:\n"); for(int i = 0; i < m; ++i) { printf(" x[%d] = %f\n", i, hB[i]); } // Clean up HIP_CHECK(hipFree(ddl)); HIP_CHECK(hipFree(dd)); HIP_CHECK(hipFree(ddu)); HIP_CHECK(hipFree(dB)); HIP_CHECK(hipFree(dbuffer)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); return 0; } //! [doc example] ././@PaxHeader0000000000000000000000000000021300000000000010211 xustar00111 path=hipsparse/clients/samples/documentation_examples/precond/example_hipsparse_gtsv_interleaved_batch.cpp 28 mtime=1779985139.5783992 hipsparse/clients/samples/documentation_examples/precond/example_hipsparse_gtsv_interleaved_batch.cp0000664000175100017510000001414715206065364035153 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // Size of each square tridiagonal matrix int m = 6; // Number of batches int batchCount = 4; // Can be Thomas algorithm (0), LU (1), or QR (2) int algo = 1; // Host tridiagonal matrix std::vector hdl(m * batchCount); std::vector hd(m * batchCount); std::vector hdu(m * batchCount); // Solve multiple tridiagonal matrix systems by interleaving matrices for better memory access: // // 4 2 0 0 0 0 5 3 0 0 0 0 6 4 0 0 0 0 7 5 0 0 0 0 // 2 4 2 0 0 0 3 5 3 0 0 0 4 6 4 0 0 0 5 7 5 0 0 0 // A1 = 0 2 4 2 0 0 A2 = 0 3 5 3 0 0 A3 = 0 4 6 4 0 0 A4 = 0 5 7 5 0 0 // 0 0 2 4 2 0 0 0 3 5 3 0 0 0 4 6 4 0 0 0 5 7 5 0 // 0 0 0 2 4 2 0 0 0 3 5 3 0 0 0 4 6 4 0 0 0 5 7 5 // 0 0 0 0 2 4 0 0 0 0 3 5 0 0 0 0 4 6 0 0 0 0 5 7 // // hdl = 0 0 0 0 2 3 4 5 2 3 4 5 2 3 4 5 2 3 4 5 2 3 4 5 // hd = 4 5 6 7 4 5 6 7 4 5 6 7 4 5 6 7 4 5 6 7 4 5 6 7 // hdu = 2 3 4 5 2 3 4 5 2 3 4 5 2 3 4 5 2 3 4 5 0 0 0 0 for(int b = 0; b < batchCount; ++b) { for(int i = 0; i < m; ++i) { hdl[batchCount * i + b] = 2 + b; hd[batchCount * i + b] = 4 + b; hdu[batchCount * i + b] = 2 + b; } hdl[batchCount * 0 + b] = 0.0f; hdu[batchCount * (m - 1) + b] = 0.0f; } // Host dense rhs std::vector hx(m * batchCount); for(int b = 0; b < batchCount; ++b) { for(int i = 0; i < m; ++i) { hx[batchCount * i + b] = static_cast(b + 1); } } float* ddl = nullptr; float* dd = nullptr; float* ddu = nullptr; float* dx = nullptr; HIP_CHECK(hipMalloc((void**)&ddl, sizeof(float) * m * batchCount)); HIP_CHECK(hipMalloc((void**)&dd, sizeof(float) * m * batchCount)); HIP_CHECK(hipMalloc((void**)&ddu, sizeof(float) * m * batchCount)); HIP_CHECK(hipMalloc((void**)&dx, sizeof(float) * m * batchCount)); HIP_CHECK(hipMemcpy(ddl, hdl.data(), sizeof(float) * m * batchCount, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dd, hd.data(), sizeof(float) * m * batchCount, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(ddu, hdu.data(), sizeof(float) * m * batchCount, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dx, hx.data(), sizeof(float) * m * batchCount, hipMemcpyHostToDevice)); // 1. Get buffer size size_t bufferSize = 0; HIPSPARSE_CHECK(hipsparseSgtsvInterleavedBatch_bufferSizeExt( handle, algo, m, ddl, dd, ddu, dx, batchCount, &bufferSize)); void* dbuffer = nullptr; HIP_CHECK(hipMalloc((void**)&dbuffer, bufferSize)); // 2. Perform batched tridiagonal solve HIPSPARSE_CHECK( hipsparseSgtsvInterleavedBatch(handle, algo, m, ddl, dd, ddu, dx, batchCount, dbuffer)); // Copy solution back to host HIP_CHECK(hipMemcpy(hx.data(), dx, sizeof(float) * m * batchCount, hipMemcpyDeviceToHost)); // Print the solutions printf("Solutions for batched tridiagonal systems:\n"); for(int b = 0; b < batchCount; ++b) { printf(" Batch %d:\n", b); for(int i = 0; i < m; ++i) { printf(" x[%d] = %f\n", i, hx[i * batchCount + b]); } } // Clean up HIP_CHECK(hipFree(ddl)); HIP_CHECK(hipFree(dd)); HIP_CHECK(hipFree(ddu)); HIP_CHECK(hipFree(dx)); HIP_CHECK(hipFree(dbuffer)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); return 0; } //! [doc example]././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5793993 hipsparse/clients/samples/documentation_examples/precond/example_hipsparse_gtsv_no_pivot.cpp0000664000175100017510000001156615206065364033527 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "utility.hpp" // Assuming this provides basic utility functions, remove if not needed for standalone example #include #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } //! [doc example] int main(int argc, char* argv[]) { // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // Size of square tridiagonal matrix int m = 5; // Number of columns in right-hand side (column ordered) matrix int n = 3; // Leading dimension of right-hand side (column ordered) matrix int ldb = m; // Host tri-diagonal matrix // 2 -1 0 0 0 // -1 2 -1 0 0 // 0 -1 2 -1 0 // 0 0 -1 2 -1 // 0 0 0 -1 2 std::vector hdl = {0.0f, -1.0f, -1.0f, -1.0f, -1.0f}; std::vector hd = {2.0f, 2.0f, 2.0f, 2.0f, 2.0f}; std::vector hdu = {-1.0f, -1.0f, -1.0f, -1.0f, 0.0f}; // Host right-hand side column vectors std::vector hB(ldb * n, 1.0f); float* ddl = nullptr; float* dd = nullptr; float* ddu = nullptr; float* dB = nullptr; HIP_CHECK(hipMalloc((void**)&ddl, sizeof(float) * m)); HIP_CHECK(hipMalloc((void**)&dd, sizeof(float) * m)); HIP_CHECK(hipMalloc((void**)&ddu, sizeof(float) * m)); HIP_CHECK(hipMalloc((void**)&dB, sizeof(float) * ldb * n)); HIP_CHECK(hipMemcpy(ddl, hdl.data(), sizeof(float) * m, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dd, hd.data(), sizeof(float) * m, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(ddu, hdu.data(), sizeof(float) * m, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dB, hB.data(), sizeof(float) * ldb * n, hipMemcpyHostToDevice)); // Obtain required buffer size size_t bufferSize; HIPSPARSE_CHECK( hipsparseSgtsv2_nopivot_bufferSizeExt(handle, m, n, ddl, dd, ddu, dB, ldb, &bufferSize)); void* dbuffer; HIP_CHECK(hipMalloc(&dbuffer, bufferSize)); HIPSPARSE_CHECK(hipsparseSgtsv2_nopivot(handle, m, n, ddl, dd, ddu, dB, ldb, dbuffer)); // Copy right-hand side to host HIP_CHECK(hipMemcpy(hB.data(), dB, sizeof(float) * ldb * n, hipMemcpyDeviceToHost)); // Print the solution printf("Solution for the tridiagonal system:\n"); for(int i = 0; i < m; ++i) { printf(" x[%d] = %f\n", i, hB[i]); } // Clean up HIP_CHECK(hipFree(ddl)); HIP_CHECK(hipFree(dd)); HIP_CHECK(hipFree(ddu)); HIP_CHECK(hipFree(dB)); HIP_CHECK(hipFree(dbuffer)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); return 0; } //! [doc example] ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5793993 hipsparse/clients/samples/example_axpyi.c0000664000175100017510000000760315206065364021137 0ustar00jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include #include #include #include #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } int main() { // Number of non-zeros of the sparse vector int nnz = 3; // Sparse index vector int hxInd[3] = {0, 3, 5}; // Sparse value vector double hxVal[3] = {1.0, 2.0, 3.0}; // Dense vector double hy[9] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}; // Scalar alpha double alpha = 3.7; // Index base hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; // Offload data to device int* dxInd; double* dxVal; double* dy; HIP_CHECK(hipMalloc((void**)&dxInd, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dxVal, sizeof(double) * nnz)); HIP_CHECK(hipMalloc((void**)&dy, sizeof(double) * 9)); HIP_CHECK(hipMemcpy(dxInd, hxInd, sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dxVal, hxVal, sizeof(double) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dy, hy, sizeof(double) * 9, hipMemcpyHostToDevice)); // hipSPARSE handle hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); // Call daxpyi to perform y = y + alpha * x HIPSPARSE_CHECK(hipsparseDaxpyi(handle, nnz, &alpha, dxVal, dxInd, dy, idxBase)); // Copy result back to host HIP_CHECK(hipMemcpy(hy, dy, sizeof(double) * 9, hipMemcpyDeviceToHost)); // Clear hipSPARSE HIPSPARSE_CHECK(hipsparseDestroy(handle)); // Clear device memory HIP_CHECK(hipFree(dxInd)); HIP_CHECK(hipFree(dxVal)); HIP_CHECK(hipFree(dy)); return 0; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5793993 hipsparse/clients/samples/example_c_headers.c0000664000175100017510000000265115206065364021720 0ustar00jenkinsjenkins/* ************************************************************************ * 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 // This file is to make sure including hipsparse C headers // are C-compilable. int main() { return 0; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5793993 hipsparse/clients/samples/example_csrmv.cpp0000664000175100017510000001621015206065364021471 0ustar00jenkinsjenkins/* ************************************************************************ * 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 #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } 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; HIPSPARSE_CHECK(hipsparseCreate(&handle)); hipDeviceProp_t devProp; int device_id = 0; HIP_CHECK(hipGetDevice(&device_id)); HIP_CHECK(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; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descrA)); // Offload data to device int* dAptr = NULL; int* dAcol = NULL; double* dAval = NULL; double* dx = NULL; double* dy = NULL; HIP_CHECK(hipMalloc((void**)&dAptr, sizeof(int) * (m + 1))); HIP_CHECK(hipMalloc((void**)&dAcol, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dAval, sizeof(double) * nnz)); HIP_CHECK(hipMalloc((void**)&dx, sizeof(double) * n)); HIP_CHECK(hipMalloc((void**)&dy, sizeof(double) * m)); HIP_CHECK(hipMemcpy(dAptr, hAptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dAcol, hAcol.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dAval, hAval.data(), sizeof(double) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dx, hx.data(), sizeof(double) * n, hipMemcpyHostToDevice)); // Warm up for(int i = 0; i < 10; ++i) { // Call hipsparse csrmv HIPSPARSE_CHECK(hipsparseDcsrmv(handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, m, n, nnz, &halpha, descrA, dAval, dAptr, dAcol, dx, &hbeta, dy)); } // Device synchronization HIP_CHECK(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 HIPSPARSE_CHECK(hipsparseDcsrmv(handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, m, n, nnz, &halpha, descrA, dAval, dAptr, dAcol, dx, &hbeta, dy)); } // Device synchronization HIP_CHECK(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 HIP_CHECK(hipFree(dAptr)); HIP_CHECK(hipFree(dAcol)); HIP_CHECK(hipFree(dAval)); HIP_CHECK(hipFree(dx)); HIP_CHECK(hipFree(dy)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descrA)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); return 0; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5793993 hipsparse/clients/samples/example_fortran_auxiliary.f900000664000175100017510000001346315206065364023724 0ustar00jenkinsjenkins!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5793993 hipsparse/clients/samples/example_fortran_bsric02.f900000664000175100017510000002421615206065364023157 0ustar00jenkinsjenkins!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5793993 hipsparse/clients/samples/example_fortran_bsrilu02.f900000664000175100017510000002424115206065364023353 0ustar00jenkinsjenkins!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5803993 hipsparse/clients/samples/example_fortran_bsrmm.f900000664000175100017510000002053515206065364023033 0ustar00jenkinsjenkins!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5803993 hipsparse/clients/samples/example_fortran_csric02.f900000664000175100017510000002154015206065364023155 0ustar00jenkinsjenkins!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5803993 hipsparse/clients/samples/example_fortran_csrilu02.f900000664000175100017510000002141515206065364023354 0ustar00jenkinsjenkins!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5803993 hipsparse/clients/samples/example_fortran_csrsm2.f900000664000175100017510000002470215206065364023124 0ustar00jenkinsjenkins!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5803993 hipsparse/clients/samples/example_fortran_csrsv2.f900000664000175100017510000002240215206065364023130 0ustar00jenkinsjenkins!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5803993 hipsparse/clients/samples/example_fortran_dotci.f900000664000175100017510000001352515206065364023016 0ustar00jenkinsjenkins!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5803993 hipsparse/clients/samples/example_fortran_roti.f900000664000175100017510000001355215206065364022671 0ustar00jenkinsjenkins!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5803993 hipsparse/clients/samples/example_fortran_spmv.f900000664000175100017510000004261115206065364022677 0ustar00jenkinsjenkins!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5803993 hipsparse/clients/samples/example_handle.cpp0000664000175100017510000000454315206065364021600 0ustar00jenkinsjenkins/* ************************************************************************ * 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 #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } int main(int argc, char* argv[]) { hipsparseHandle_t handle; HIPSPARSE_CHECK(hipsparseCreate(&handle)); int version; HIPSPARSE_CHECK(hipsparseGetVersion(handle, &version)); char rev[256]; HIPSPARSE_CHECK(hipsparseGetGitRevision(handle, rev)); printf("hipSPARSE version %d.%d.%d-%s\n", version / 100000, version / 100 % 1000, version % 100, rev); HIPSPARSE_CHECK(hipsparseDestroy(handle)); return 0; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5803993 hipsparse/clients/samples/example_hybmv.cpp0000664000175100017510000001473515206065364021476 0ustar00jenkinsjenkins/* ************************************************************************ * 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 #define HIP_CHECK(stat) \ { \ if(stat != hipSuccess) \ { \ fprintf(stderr, "Error: hip error in line %d", __LINE__); \ return -1; \ } \ } #define HIPSPARSE_CHECK(stat) \ { \ if(stat != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "Error: hipsparse error in line %d", __LINE__); \ return -1; \ } \ } 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; HIPSPARSE_CHECK(hipsparseCreate(&handle)); hipDeviceProp_t devProp; int device_id = 0; HIP_CHECK(hipGetDevice(&device_id)); HIP_CHECK(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; HIPSPARSE_CHECK(hipsparseCreateMatDescr(&descrA)); // Offload data to device int* dAptr = NULL; int* dAcol = NULL; double* dAval = NULL; double* dx = NULL; double* dy = NULL; HIP_CHECK(hipMalloc((void**)&dAptr, sizeof(int) * (m + 1))); HIP_CHECK(hipMalloc((void**)&dAcol, sizeof(int) * nnz)); HIP_CHECK(hipMalloc((void**)&dAval, sizeof(double) * nnz)); HIP_CHECK(hipMalloc((void**)&dx, sizeof(double) * n)); HIP_CHECK(hipMalloc((void**)&dy, sizeof(double) * m)); HIP_CHECK(hipMemcpy(dAptr, hAptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dAcol, hAcol.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dAval, hAval.data(), sizeof(double) * nnz, hipMemcpyHostToDevice)); HIP_CHECK(hipMemcpy(dx, hx.data(), sizeof(double) * n, hipMemcpyHostToDevice)); // Convert CSR matrix to HYB format hipsparseHybMat_t hybA; HIPSPARSE_CHECK(hipsparseCreateHybMat(&hybA)); HIPSPARSE_CHECK(hipsparseDcsr2hyb( handle, m, n, descrA, dAval, dAptr, dAcol, hybA, 0, HIPSPARSE_HYB_PARTITION_AUTO)); // Clean up CSR structures HIP_CHECK(hipFree(dAptr)); HIP_CHECK(hipFree(dAcol)); HIP_CHECK(hipFree(dAval)); // Warm up for(int i = 0; i < 10; ++i) { // Call hipsparse hybmv HIPSPARSE_CHECK(hipsparseDhybmv( handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, &halpha, descrA, hybA, dx, &hbeta, dy)); } // Device synchronization HIP_CHECK(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 HIPSPARSE_CHECK(hipsparseDhybmv( handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, &halpha, descrA, hybA, dx, &hbeta, dy)); } // Device synchronization HIP_CHECK(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 HIPSPARSE_CHECK(hipsparseDestroyHybMat(hybA)); HIPSPARSE_CHECK(hipsparseDestroyMatDescr(descrA)); HIPSPARSE_CHECK(hipsparseDestroy(handle)); // Clean up HIP_CHECK(hipFree(dx)); HIP_CHECK(hipFree(dy)); return 0; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5903993 hipsparse/clients/tests/0000775000175100017510000000000015206065364015616 5ustar00jenkinsjenkins././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5803993 hipsparse/clients/tests/CMakeLists.txt0000664000175100017510000002236715206065364020370 0ustar00jenkinsjenkins# ######################################################################## # 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_parse_data.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 $) if (BUILD_CLIENTS_ONLY) target_include_directories(hipsparse-test PRIVATE ${hipsparse_INCLUDE_DIRS}/hipsparse) endif() # Target link libraries target_link_libraries(hipsparse-test PRIVATE GTest::gtest roc::hipsparse) # Add OpenMP if available if(OPENMP_FOUND AND THREADS_FOUND) target_link_libraries(hipsparse-test PRIVATE OpenMP::OpenMP_CXX ${OpenMP_CXX_FLAGS}) endif() if(NOT USE_CUDA) target_link_libraries(hipsparse-test PRIVATE hip::host) else() target_compile_definitions(hipsparse-test PRIVATE __HIP_PLATFORM_NVIDIA__) target_include_directories(hipsparse-test PRIVATE ${HIP_INCLUDE_DIRS}) target_link_libraries(hipsparse-test PRIVATE ${CUDA_LIBRARIES}) endif() set_target_properties(hipsparse-test PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/staging") rocm_install(TARGETS hipsparse-test COMPONENT tests) set(HIPSPARSE_TEST_YAMLS test_axpyi.yaml test_doti.yaml test_dotci.yaml test_sctr.yaml test_roti.yaml test_gthr.yaml test_gthrz.yaml test_bsrmv.yaml test_csrmv.yaml test_bsrsv2.yaml test_csrsv2.yaml test_gemvi.yaml test_hybmv.yaml test_bsrmm.yaml test_bsrsm2.yaml test_csrmm.yaml test_csrsm2.yaml test_gemmi.yaml test_bsr2csr.yaml test_coo2csr.yaml test_csc2dense.yaml test_csr2bsr.yaml test_csr2coo.yaml test_csr2csc.yaml test_csr2csc_ex2.yaml test_csr2csr_compress.yaml test_csr2dense.yaml test_csr2gebsr.yaml test_csr2hyb.yaml test_csru2csr.yaml test_dense2csc.yaml test_dense2csr.yaml test_gebsr2csr.yaml test_gebsr2gebsc.yaml test_gebsr2gebsr.yaml test_hyb2csr.yaml test_prune_csr2csr.yaml test_prune_csr2csr_by_percentage.yaml test_prune_dense2csr.yaml test_prune_dense2csr_by_percentage.yaml) # Prepare testing data set(HIPSPARSE_TEST_DATA "${PROJECT_BINARY_DIR}/staging/hipsparse_test.data") add_custom_command(OUTPUT "${HIPSPARSE_TEST_DATA}" COMMAND ${python} ../common/hipsparse_gentest.py -m ${PROJECT_BINARY_DIR}/matrices -I ../include hipsparse_test.yaml -o "${HIPSPARSE_TEST_DATA}" DEPENDS ../common/hipsparse_gentest.py hipsparse_test.yaml ../include/hipsparse_common.yaml ${HIPSPARSE_TEST_YAMLS} WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") add_custom_target(hipsparse-test-data DEPENDS "${HIPSPARSE_TEST_DATA}" ) add_dependencies(hipsparse-test hipsparse-test-data hipsparse-common) rocm_install(FILES ${HIPSPARSE_TEST_DATA} DESTINATION "${CMAKE_INSTALL_DATADIR}/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) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5813992 hipsparse/clients/tests/hipsparse_gtest_main.cpp0000664000175100017510000002013515206065364022533 0ustar00jenkinsjenkins/* ************************************************************************ * 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 #include "hipsparse_parse_data.hpp" 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[512]; 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); std::string datapath = hipsparse_datapath(); // Print test data path being used std::cout << "hipSPARSE data path: " << datapath << std::endl; // Set data file path hipsparse_parse_data(argc, argv, datapath + "hipsparse_test.data"); // 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 (void)hipDeviceReset(); return ret; } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5813992 hipsparse/clients/tests/hipsparse_test.yaml0000664000175100017510000000463115206065364021543 0ustar00jenkinsjenkins# ######################################################################## # Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # # ######################################################################## # level1 include: test_axpyi.yaml include: test_doti.yaml include: test_dotci.yaml include: test_roti.yaml include: test_sctr.yaml include: test_gthr.yaml include: test_gthrz.yaml #level2 include: test_bsrmv.yaml include: test_bsrsv2.yaml include: test_csrmv.yaml include: test_csrsv2.yaml include: test_gemvi.yaml include: test_hybmv.yaml # level3 include: test_bsrmm.yaml include: test_bsrsm2.yaml include: test_csrmm.yaml include: test_csrsm2.yaml include: test_gemmi.yaml # conversion include: test_bsr2csr.yaml include: test_coo2csr.yaml include: test_csc2dense.yaml include: test_csr2bsr.yaml include: test_csr2coo.yaml include: test_csr2csc.yaml include: test_csr2csc_ex2.yaml include: test_csr2csr_compress.yaml include: test_csr2dense.yaml include: test_csr2gebsr.yaml include: test_csr2hyb.yaml include: test_csru2csr.yaml include: test_dense2csc.yaml include: test_dense2csr.yaml include: test_gebsr2csr.yaml include: test_gebsr2gebsc.yaml include: test_gebsr2gebsr.yaml include: test_hyb2csr.yaml include: test_prune_csr2csr.yaml include: test_prune_csr2csr_by_percentage.yaml include: test_prune_dense2csr.yaml include: test_prune_dense2csr_by_percentage.yaml ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5813992 hipsparse/clients/tests/hipsparse_test_call.hpp0000664000175100017510000000314315206065364022360 0ustar00jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #include "hipsparse_test_enum.hpp" namespace temp { template struct hipsparse_test_call { template static void testing_bad_arg(const Arguments& arg); template static void testing(const Arguments& arg); }; }././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5813992 hipsparse/clients/tests/hipsparse_test_check.hpp0000664000175100017510000000477315206065364022534 0ustar00jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2022-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #include "hipsparse_test_traits.hpp" template struct hipsparse_test_check { public: template static constexpr bool is_valid_type() { switch(hipsparse_test_traits::s_numeric_types) { case hipsparse_test_numeric_types_enum::all: { return std::is_same{} || std::is_same{} || std::is_same{} || std::is_same{}; } case hipsparse_test_numeric_types_enum::real_only: { return std::is_same{} || std::is_same{}; } case hipsparse_test_numeric_types_enum::complex_only: { return std::is_same{} || std::is_same{}; } } return false; }; template static constexpr bool is_valid_type() { return std::is_integral::value && is_valid_type(); }; template static constexpr bool is_valid_type() { return std::is_integral::value && std::is_integral::value && is_valid_type(); }; }; ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5813992 hipsparse/clients/tests/hipsparse_test_config.hpp0000664000175100017510000000675115206065364022722 0ustar00jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #include "hipsparse_test_dispatch_enum.hpp" #include "hipsparse_test_numeric_types_enum.hpp" template struct hipsparse_test_config_template { static constexpr hipsparse_test_dispatch_enum::value_type s_dispatch = DISPATCH; static constexpr hipsparse_test_numeric_types_enum::value_type s_numeric_types = NUMERIC_TYPES; }; struct hipsparse_test_config : hipsparse_test_config_template { }; struct hipsparse_test_config_real_only : hipsparse_test_config_template { }; struct hipsparse_test_config_complex_only : hipsparse_test_config_template { }; struct hipsparse_test_config_it : hipsparse_test_config_template { }; struct hipsparse_test_config_it_real_only : hipsparse_test_config_template { }; struct hipsparse_test_config_it_complex_only : hipsparse_test_config_template { }; struct hipsparse_test_config_ijt : hipsparse_test_config_template { }; struct hipsparse_test_config_ijt_real_only : hipsparse_test_config_template { }; struct hipsparse_test_config_ijt_complex_only : hipsparse_test_config_template { };././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779985139.5813992 hipsparse/clients/tests/hipsparse_test_dispatch.hpp0000664000175100017510000000435115206065364023246 0ustar00jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #include "hipsparse_test.hpp" #include "hipsparse_test_dispatch_enum.hpp" #include "hipsparse_type_dispatch.hpp" template struct hipsparse_test_dispatch; template <> struct hipsparse_test_dispatch { template