pax_global_header00006660000000000000000000000064150737733250014526gustar00rootroot0000000000000052 comment=b0adf826d3ea50e695a4a0425f74fd85c17fa931 rocALUTION-rocm-7.1.0/000077500000000000000000000000001507377332500143105ustar00rootroot00000000000000rocALUTION-rocm-7.1.0/.azuredevops/000077500000000000000000000000001507377332500167355ustar00rootroot00000000000000rocALUTION-rocm-7.1.0/.azuredevops/rocm-ci.yml000066400000000000000000000012441507377332500210120ustar00rootroot00000000000000resources: 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 }}/rocALUTION.yml@pipelines_repo rocALUTION-rocm-7.1.0/.clang-format000066400000000000000000000065421507377332500166720ustar00rootroot00000000000000# 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 --- rocALUTION-rocm-7.1.0/.githooks/000077500000000000000000000000001507377332500162155ustar00rootroot00000000000000rocALUTION-rocm-7.1.0/.githooks/install000077500000000000000000000002231507377332500176060ustar00rootroot00000000000000#!/usr/bin/env bash cd $(git rev-parse --git-dir) cd hooks echo "Installing hooks..." ln -fs ../../.githooks/pre-commit pre-commit echo "Done!" rocALUTION-rocm-7.1.0/.githooks/pre-commit000077500000000000000000000041201507377332500202140ustar00rootroot00000000000000#!/bin/bash # # 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. export PATH=/usr/bin:/bin set -x format=/opt/rocm/llvm/bin/clang-format # Redirect stdout to stderr. exec >&2 # 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 if [[ "$1" == "--reformat" ]]; then files=$(git ls-files --exclude-standard) else files=$(git diff-index --cached --name-only $against) fi [[ -z "$files" ]] && exit # Change the copyright date at the top of any text files for file in $files; do if [[ -e $file ]]; then /usr/bin/perl -pi -e 'INIT { exit 1 if !-f $ARGV[0] || -B $ARGV[0]; $year = (localtime)[5] + 1900 } s/^([*\/#[:space:]]*)Copyright\s+(?:\(C\)\s*)?(\d+)(?:\s*-\s*\d+)?/qq($1Copyright (C) $2@{[$year != $2 ? "-$year" : ""]})/ie if $. < 10' "$file" && git add -u "$file" fi done # do the formatting for file in $files; do if [[ -e $file ]] && echo $file | grep -Eq '\.c$|\.h$|\.hpp$|\.cpp$|\.cl$|\.in$|\.txt$|\.yaml$|\.sh$|\.py$|\.pl$|\.cmake$|\.md$|\.rst$|\.groovy$'; then sed -i -e 's/[[:space:]]*$//' "$file" # Remove whitespace at end of lines sed -i -e '$a\' "$file" # Add missing newline to end of file # Convert UTF8 non-ASCII to ASCII temp=$(mktemp) [[ -w $temp ]] || exit iconv -s -f utf-8 -t ascii//TRANSLIT "$file" > "$temp" || exit chmod --reference="$file" "$temp" || exit mv -f "$temp" "$file" || exit git add -u "$file" fi done # if clang-format exists, run it on C/C++ files if [[ -x $format ]]; then for file in $files; do if [[ -e $file ]] && echo $file | grep -Eq '\.c$|\.h$|\.hpp$|\.cpp$|\.cl$|\.h\.in$|\.hpp\.in$|\.cpp\.in$'; then echo "$format $file" "$format" -i -style=file "$file" git add -u "$file" fi done fi rocALUTION-rocm-7.1.0/.github/000077500000000000000000000000001507377332500156505ustar00rootroot00000000000000rocALUTION-rocm-7.1.0/.github/CODEOWNERS000077500000000000000000000003161507377332500172460ustar00rootroot00000000000000* @ntrost57 @YvanMokwinski @jsandham @kliegeois # Documentation files docs/* @ROCm/rocm-documentation *.md @ROCm/rocm-documentation *.rst @ROCm/rocm-documentation .readthedocs.yaml @ROCm/rocm-documentation rocALUTION-rocm-7.1.0/.github/CONTRIBUTING.md000066400000000000000000000224541507377332500201100ustar00rootroot00000000000000 # Contributing to rocALUTION # AMD welcomes contributions to rocALUTION 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 ## rocALUTION is a sparse linear algebra library with focus on exploring fine-grained parallelism on top of the AMD ROCm runtime and toolchains, targeting modern CPU and GPU platforms. Based on C++ and HIP, it provides a portable, generic and flexible design that allows seamless integration with other scientific software packages. In rocALUTION we are interested in contributions that: * Fix bugs, improve documentation, enhance testing, reduce complexity. * Improve the performance of existing routines. * Add missing functionality such as new multigrid solvers, iterative solvers, direct solvers, or preconditioners. * Extending new or existing functionality to work with MPI or accelerators (such as GPU devices). We encourage contributors to leverage the GitHub "Issues" tab to discuss possible additions they would like to add. ### Exceptions ### rocALUTION places a heavy emphasis on being high performance. Because of this, contributions that add new routines (or that modify existing routines) must do so from the perspective that they offer high performance in relation to the hardware they are run on. Furthermore, all routines added to rocalution must have at a minimum a host solution as all routines must have the ability to fall back to a host solution if a GPU accelerator is not avaiable. Because compile times, binary sizes, and general library complexity are important considerations, we reserve the right to make decisions on whether a proposed routine is too niche or specialized to be worth including. ## Code Structure ## The following is the structure of the rocALUTION library in the GitHub repository. A more detailed description of the directory structure can be found in the rocALUTION [documentation](https://rocm.docs.amd.com/projects/rocALUTION/en/latest/design/orga.html). The `src/` directory contains the library source code. This is broken up into three sub-directories: * `src/base` * `src/solvers` * `src/utils` The `src/base` Contains source code related to rocALUTION's vector, matrix, and stencil operator types as well as classes related to parallel management. This directory is further broken up into: * `src/base/hip` Contains HIP implementations of vector, matrix, and stencil operators. * `src/base/host` Contains host implementations of vector, matrix, and stencil operators. The `src/solvers` directory contains all the source code related to direct (`src/solvers/direct`), krylov (`src/solvers/krylov`), and multigrid solvers `src/solvers/multigrid`. The `src/utils` directory contains source code related to logging, memory allocation, math and timing functions. The `clients/` directory contains the testing and benchmarking code as well as all the samples demonstrating rocALUTION 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 rocALUTION 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. By submitting a pull request, you acknowlege and agree with the CLA below: Contribution License Agreement 1. The code I am contributing is mine, and I have the right to license it. 2. By submitting a pull request for this project I am granting you a license to distribute said code under the MIT License for the project. ### Deliverables ### When raising a PR in rocALUTION 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. 5. At a minimum, rocALUTION must have a host solution for each direct, iterative, multigrid, or preconditioner. If you add a accelerator solution (say using HIP targetting GPU devices) please also add a fall back host solution. 6. Ensure code builds successfully. This includes making sure that the code can compile, that the code is properly formatted, and that all tests pass. 7. Do not break existing test cases ### Process ### When a PR is raised targetting the develop branch in rocALUTION, 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 * Ensure that all tests pass on different OS and GPU device architecture combinations Feel free to ask questions on your PR regarding any CI failures you encounter. * Reviewers are listed in the CODEOWNERS file rocALUTION-rocm-7.1.0/.github/dependabot.yml000066400000000000000000000012601507377332500204770ustar00rootroot00000000000000# 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" rocALUTION-rocm-7.1.0/.gitignore000066400000000000000000000006101507377332500162750ustar00rootroot00000000000000# 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 build # Visual Studio stuff *.vcxproj.user *.suo *.sdf *.pdb *.opensdf rocALUTION-rocm-7.1.0/.jenkins/000077500000000000000000000000001507377332500160275ustar00rootroot00000000000000rocALUTION-rocm-7.1.0/.jenkins/codecov.groovy000066400000000000000000000045411507377332500207240ustar00rootroot00000000000000#!/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('rocALUTION', 'CodeCov') // customize for project prj.paths.build_command = './install.sh -cg --codecoverage' prj.compiler.compiler_name = 'c++' prj.compiler.compiler_path = 'c++' prj.libraryDependencies = ['rocPRIM', 'hipBLAS-common', 'hipBLASLt', 'rocBLAS', 'rocSPARSE', 'rocRAND'] prj.defaults.ccache = false // Define test architectures, optional rocm version argument is available def nodes = new dockerNodes(nodeDetails, jobName, prj) def commonGroovy boolean formatCheck = false def compileCommand = { platform, project-> project.paths.construct_build_prefix() 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, "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)) } jobNameList.each { jobName, nodeDetails-> if (urlJobName == jobName) stage(jobName) { runCI(nodeDetails, jobName) } } // For url job names that are not listed by the jobNameList i.e. compute-rocm-dkms-no-npi-1901 if(!jobNameList.keySet().contains(urlJobName)) { properties(auxiliary.addCommonProperties([pipelineTriggers([cron('0 1 * * *')])])) stage(urlJobName) { runCI([], urlJobName) } } } rocALUTION-rocm-7.1.0/.jenkins/common.groovy000066400000000000000000000122751507377332500205750ustar00rootroot00000000000000// This file is for internal AMD use. // If you are interested in running your own Jenkins, please raise a github issue for assistance. import static groovy.io.FileType.FILES def runCompileCommand(platform, project, boolean sameOrg=false) { project.paths.construct_build_prefix() String centos7devtoolset = platform.jenkinsLabel.contains('centos7') ? 'source /etc/profile.d/modules.sh && source scl_source enable devtoolset-7 && module load mpi/openmpi-x86_64' : '' def getDependenciesCommand = "" if (project.installLibraryDependenciesFromCI) { project.libraryDependencies.each { libraryName -> getDependenciesCommand += auxiliary.getLibrary(libraryName, platform.jenkinsLabel, 'develop', sameOrg) } } def command = """#!/usr/bin/env bash set -x cd ${project.paths.project_build_prefix} ${getDependenciesCommand} ${centos7devtoolset} ${project.paths.build_command} """ platform.runCommand(this, command) } def runTestCommand (platform, project, gfilter) { def hmmTestCommand= '' if (platform.jenkinsLabel.contains('gfx90a')) { hmmTestCommand = """ HSA_XNACK=0 GTEST_LISTENER=NO_PASS_LINE_IN_LOG ./rocalution-test --gtest_output=xml:test_detail_hmm_xnack_off.xml --gtest_color=yes --gtest_filter=** HSA_XNACK=1 GTEST_LISTENER=NO_PASS_LINE_IN_LOG ./rocalution-test --gtest_output=xml:test_detail_hmm_xnack_on.xml --gtest_color=yes --gtest_filter=** """ } 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} LD_LIBRARY_PATH=/opt/rocm/hcc/lib GTEST_LISTENER=NO_PASS_LINE_IN_LOG ./rocalution-test --gtest_output=xml --gtest_color=yes #--gtest_filter=${gfilter}-*known_bug* ${hmmTestCommand} """ 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-rocalution", 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/ export ROCALUTION_CODE_COVERAGE=1 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 rocALUTION --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, jobName, label='') { def command label = label != '' ? '-' + label.toLowerCase() : '' if(platform.jenkinsLabel.contains('centos') || platform.jenkinsLabel.contains('sles')) { command = """ set -x cd ${project.paths.project_build_prefix}/build/release make package mkdir -p package if [ ! -z "$label" ] then for f in rocalution*.rpm do echo f mv "\$f" "rocalution${label}-\${f#*-}" ls done fi mv *.rpm package/ rpm -qlp package/*.rpm """ platform.runCommand(this, command) platform.archiveArtifacts(this, """${project.paths.project_build_prefix}/build/release/package/*.rpm""") } else { command = """ set -x cd ${project.paths.project_build_prefix}/build/release make package mkdir -p package if [ ! -z "$label" ] then for f in rocalution*.deb do echo f mv "\$f" "rocalution${label}-\${f#*-}" ls done fi mv *.deb package/ for pkg in package/*.deb; do dpkg -c \$pkg done """ platform.runCommand(this, command) platform.archiveArtifacts(this, """${project.paths.project_build_prefix}/build/release/package/*.deb""") } } return this rocALUTION-rocm-7.1.0/.jenkins/debug.groovy000066400000000000000000000062461507377332500203740ustar00rootroot00000000000000#!/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, buildCommand -> def prj = new rocProject('rocALUTION', 'Debug') // customize for project prj.paths.build_command = buildCommand prj.compiler.compiler_name = 'c++' prj.compiler.compiler_path = 'c++' prj.libraryDependencies = ['rocPRIM', 'hipBLAS-common', 'hipBLASLt', 'rocBLAS', 'rocSPARSE', 'rocRAND'] // Define test architectures, optional rocm version argument is available def nodes = new dockerNodes(nodeDetails, jobName, prj) def commonGroovy boolean formatCheck = false def compileCommand = { platform, project-> project.paths.construct_build_prefix() commonGroovy = load "${project.paths.project_src_prefix}/.jenkins/common.groovy" commonGroovy.runCompileCommand(platform, project) } buildProject(prj, formatCheck, nodes.dockerArray, compileCommand, null, null) } def setupCI(urlJobName, jobNameList, buildCommand, runCI, label) { jobNameList = auxiliary.appendJobNameList(jobNameList) jobNameList.each { jobName, nodeDetails-> if (urlJobName == jobName) stage(label + ' ' + jobName) { runCI(nodeDetails, jobName, buildCommand) } } // 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 * * *')])])) stage(label + ' ' + urlJobName) { runCI([ubuntu18:['any']], urlJobName, buildCommand) } } } ci: { String urlJobName = auxiliary.getTopJobName(env.BUILD_URL) def propertyList = ["compute-rocm-dkms-no-npi":[pipelineTriggers([cron('0 1 * * 0')])], "rocm-docker":[]] propertyList = auxiliary.appendPropertyList(propertyList) propertyList.each { jobName, property-> if (urlJobName == jobName) properties(auxiliary.addCommonProperties(property)) } def defaultJobNameList = ["compute-rocm-dkms-no-npi":([ubuntu18:['any']]), "rocm-docker":([ubuntu18:['any']])] def hostJobNameList = ["compute-rocm-dkms-no-npi":([ubuntu18:['any']]), "rocm-docker":([ubuntu18:['any']])] def mpiJobNameList = ["compute-rocm-dkms-no-npi":([ubuntu18:['any']]), "rocm-docker":([ubuntu18:['any']])] String defaultBuildCommand = './install.sh -c' String hostBuildCommand = './install.sh -c --host' String mpiBuildCommand = './install.sh -c --host --mpi=on --no-openmp' setupCI(urlJobName, defaultJobNameList, defaultBuildCommand, runCI, '') setupCI(urlJobName, hostJobNameList, hostBuildCommand, runCI, 'Host') setupCI(urlJobName, mpiJobNameList, mpiBuildCommand, runCI, 'MPI') } rocALUTION-rocm-7.1.0/.jenkins/extended.groovy000066400000000000000000000071621507377332500211040ustar00rootroot00000000000000#!/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, buildCommand -> def prj = new rocProject('rocALUTION', 'Extended') // customize for project prj.paths.build_command = buildCommand prj.compiler.compiler_name = 'c++' prj.compiler.compiler_path = 'c++' prj.libraryDependencies = ['rocPRIM', 'hipBLAS-common', 'hipBLASLt', 'rocBLAS', 'rocSPARSE', 'rocRAND'] // Define test architectures, optional rocm version argument is available def nodes = new dockerNodes(nodeDetails, jobName, prj) def commonGroovy boolean formatCheck = false def compileCommand = { platform, project-> project.paths.construct_build_prefix() 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, jobName) } buildProject(prj, formatCheck, nodes.dockerArray, compileCommand, testCommand, packageCommand) } def setupCI(urlJobName, jobNameList, buildCommand, runCI, label) { jobNameList = auxiliary.appendJobNameList(jobNameList) jobNameList.each { jobName, nodeDetails-> if (urlJobName == jobName) stage(label + ' ' + jobName) { runCI(nodeDetails, jobName, buildCommand) } } // 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 * * *')])])) stage(label + ' ' + urlJobName) { runCI([ubuntu18:['gfx906']], urlJobName, buildCommand) } } } ci: { String urlJobName = auxiliary.getTopJobName(env.BUILD_URL) def propertyList = ["compute-rocm-dkms-no-npi":[pipelineTriggers([cron('0 1 * * 0')])], "rocm-docker":[]] propertyList = auxiliary.appendPropertyList(propertyList) propertyList.each { jobName, property-> if (urlJobName == jobName) properties(auxiliary.addCommonProperties(property)) } def defaultJobNameList = ["compute-rocm-dkms-no-npi-hipclang":([ubuntu18:['gfx900'],centos7:['gfx906'],centos8:['any'],sles15sp1:['gfx908']]), "rocm-docker":([ubuntu18:['gfx900'],centos7:['gfx906'],sles15sp1:['gfx908']])] def hostJobNameList = ["compute-rocm-dkms-no-npi-hipclang":([ubuntu18:['gfx900']]), "rocm-docker":([ubuntu18:['gfx900']])] def mpiJobNameList = ["compute-rocm-dkms-no-npi-hipclang":([ubuntu18:['gfx900']]), "rocm-docker":([ubuntu18:['gfx900']])] String defaultBuildCommand = './install.sh -c' String hostBuildCommand = './install.sh -c --host' String mpiBuildCommand = './install.sh -c --host --mpi=on --no-openmp' setupCI(urlJobName, defaultJobNameList, defaultBuildCommand, runCI, '') setupCI(urlJobName, hostJobNameList, hostBuildCommand, runCI, 'Host') setupCI(urlJobName, mpiJobNameList, mpiBuildCommand, runCI, 'MPI') } rocALUTION-rocm-7.1.0/.jenkins/precheckin.groovy000066400000000000000000000071761507377332500214240ustar00rootroot00000000000000#!/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, buildCommand, label -> def prj = new rocProject('rocALUTION', 'PreCheckin') // customize for project prj.paths.build_command = buildCommand prj.compiler.compiler_name = 'c++' prj.compiler.compiler_path = 'c++' prj.libraryDependencies = ['rocPRIM', 'hipBLAS-common', 'hipBLASLt', 'rocBLAS', 'rocSPARSE', 'rocRAND'] // Define test architectures, optional rocm version argument is available def nodes = new dockerNodes(nodeDetails, jobName, prj) def commonGroovy boolean formatCheck = false def compileCommand = { platform, project-> project.paths.construct_build_prefix() 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, jobName, label) } buildProject(prj, formatCheck, nodes.dockerArray, compileCommand, testCommand, packageCommand) } def setupCI(urlJobName, jobNameList, buildCommand, runCI, label) { jobNameList = auxiliary.appendJobNameList(jobNameList) jobNameList.each { jobName, nodeDetails-> if (urlJobName == jobName) stage(label + ' ' + jobName) { runCI(nodeDetails, jobName, buildCommand, label) } } // 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 * * *')])])) stage(label + ' ' + urlJobName) { runCI([ubuntu18:['gfx906']], urlJobName, buildCommand, label) } } } ci: { String urlJobName = auxiliary.getTopJobName(env.BUILD_URL) def propertyList = ["compute-rocm-dkms-no-npi":[pipelineTriggers([cron('0 1 * * 0')])], "rocm-docker":[]] propertyList = auxiliary.appendPropertyList(propertyList) propertyList.each { jobName, property-> if (urlJobName == jobName) properties(auxiliary.addCommonProperties(property)) } def defaultJobNameList = ["compute-rocm-dkms-no-npi-hipclang":([ubuntu18:['gfx900'],centos7:['gfx906'],centos8:['any'],sles15sp1:['gfx908']]), "rocm-docker":([ubuntu18:['gfx900'],centos7:['gfx906'],sles15sp1:['gfx908']])] def hostJobNameList = ["compute-rocm-dkms-no-npi":([ubuntu18:['gfx900']]), "rocm-docker":([ubuntu18:['gfx900']])] def mpiJobNameList = ["compute-rocm-dkms-no-npi":([ubuntu18:['gfx900']]), "rocm-docker":([ubuntu18:['gfx900']])] String defaultBuildCommand = './install.sh -c' String hostBuildCommand = './install.sh -c --host' String mpiBuildCommand = './install.sh -c --host --mpi=on --no-openmp' setupCI(urlJobName, defaultJobNameList, defaultBuildCommand, runCI, '') setupCI(urlJobName, hostJobNameList, hostBuildCommand, runCI, 'Host') setupCI(urlJobName, mpiJobNameList, mpiBuildCommand, runCI, 'MPI') } rocALUTION-rocm-7.1.0/.jenkins/staticanalysis.groovy000066400000000000000000000033551507377332500223370ustar00rootroot00000000000000#!/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 runCompileCommand(platform, project, jobName, boolean debug=false) { project.paths.construct_build_prefix() } def runCI = { nodeDetails, jobName-> def prj = new rocProject('rocALUTION-internal', 'StaticAnalysis') // Define test architectures, optional rocm version argument is available def nodes = new dockerNodes(nodeDetails, jobName, prj) boolean formatCheck = true boolean staticAnalysis = true def compileCommand = { platform, project-> runCompileCommand(platform, project, jobName, false) } buildProject(prj , formatCheck, nodes.dockerArray, compileCommand, null, null, staticAnalysis) } ci: { String urlJobName = auxiliary.getTopJobName(env.BUILD_URL) def propertyList = ["compute-rocm-dkms-no-npi-hipclang":[pipelineTriggers([cron('0 1 * * 0')])], "rocm-docker":[]] propertyList = auxiliary.appendPropertyList(propertyList) def jobNameList = ["compute-rocm-dkms-no-npi-hipclang":[]] jobNameList = auxiliary.appendJobNameList(jobNameList) propertyList.each { jobName, property-> if (urlJobName == jobName) properties(auxiliary.addCommonProperties(property)) } jobNameList.each { jobName, nodeDetails-> if (urlJobName == jobName) stage(jobName) { runCI(nodeDetails, jobName) } } } rocALUTION-rocm-7.1.0/.jenkins/staticlibrary.groovy000066400000000000000000000072571507377332500221650ustar00rootroot00000000000000#!/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, buildCommand, label -> def prj = new rocProject('rocALUTION', 'Static Library PreCheckin') // customize for project prj.paths.build_command = buildCommand prj.compiler.compiler_name = 'amdclang++' prj.compiler.compiler_path = '/opt/rocm/bin/amdclang++' prj.libraryDependencies = ['rocPRIM', 'hipBLAS-common', 'hipBLASLt', 'rocBLAS', 'rocSPARSE', 'rocRAND'] // Define test architectures, optional rocm version argument is available def nodes = new dockerNodes(nodeDetails, jobName, prj) def commonGroovy boolean formatCheck = true def compileCommand = { platform, project-> project.paths.construct_build_prefix() 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, jobName, label) } buildProject(prj, formatCheck, nodes.dockerArray, compileCommand, testCommand, packageCommand) } def setupCI(urlJobName, jobNameList, buildCommand, runCI, label) { jobNameList = auxiliary.appendJobNameList(jobNameList) jobNameList.each { jobName, nodeDetails-> if (urlJobName == jobName) stage(label + ' ' + jobName) { runCI(nodeDetails, jobName, buildCommand, label) } } // 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 * * *')])])) stage(label + ' ' + urlJobName) { runCI([ubuntu18:['gfx906']], urlJobName, buildCommand, label) } } } ci: { String urlJobName = auxiliary.getTopJobName(env.BUILD_URL) def propertyList = ["compute-rocm-dkms-no-npi":[pipelineTriggers([cron('0 1 * * 0')])], "rocm-docker":[]] propertyList = auxiliary.appendPropertyList(propertyList) propertyList.each { jobName, property-> if (urlJobName == jobName) properties(auxiliary.addCommonProperties(property)) } def defaultJobNameList = ["compute-rocm-dkms-no-npi":([ubuntu18:['gfx900'],centos7:['gfx906'],sles15sp1:['gfx908']]), "rocm-docker":([ubuntu18:['gfx900'],centos7:['gfx906'],sles15sp1:['gfx908']])] def hostJobNameList = ["compute-rocm-dkms-no-npi":([ubuntu18:['gfx900']]), "rocm-docker":([ubuntu18:['gfx900']])] def mpiJobNameList = ["compute-rocm-dkms-no-npi":([ubuntu18:['gfx900']]), "rocm-docker":([ubuntu18:['gfx900']])] String defaultBuildCommand = './install.sh -c --static' String hostBuildCommand = './install.sh -c --host --static' String mpiBuildCommand = './install.sh -c --host --mpi=on --no-openmp --static' setupCI(urlJobName, defaultJobNameList, defaultBuildCommand, runCI, '') setupCI(urlJobName, hostJobNameList, hostBuildCommand, runCI, 'Host') setupCI(urlJobName, mpiJobNameList, mpiBuildCommand, runCI, 'MPI') } rocALUTION-rocm-7.1.0/.readthedocs.yaml000066400000000000000000000004751507377332500175450ustar00rootroot00000000000000# 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, epub] python: install: - requirements: docs/sphinx/requirements.txt build: os: ubuntu-22.04 tools: python: "3.10" rocALUTION-rocm-7.1.0/CHANGELOG.md000066400000000000000000000207211507377332500161230ustar00rootroot00000000000000# Changelog for rocALUTION Full documentation forrocALUTION is available at [https://rocm.docs.amd.com/projects/rocALUTION/en/latest/](https://rocm.docs.amd.com/projects/rocALUTION/en/latest/). ## rocALUTION 4.0.1 for ROCm 7.1.0 ### Added * Added support for gfx950. ### Changed * Updated the default build standard to C++17 when compiling rocALUTION from source (previously C++14). ### Optimized * Improved and expanded user documentation. ### Resolved issues * Fixed a bug in the GPU hashing algorithm that occurred when not compiling with -O2/-O3. * Fixed an issue with the SPAI preconditioner when using complex numbers. ## rocALUTION 3.2.3 for ROCm 6.4.1 ### Added * The `-a` option has been added to the `rmake.py` build script. This option provides a way to select specific architectures when building on Windows. ### Resolved issues * Fixed an issue where the `HIP_PATH` environment variable was being ignored when compiling on Windows. ## rocALUTION 3.2.2 for ROCm 6.4.0 ### Changed * Improved documentation ## rocALUTION 3.2.1 for ROCm 6.3.0 ### Added * Support for gfx1200, gfx1201, and gfx1151. ### Changed * Changed the default compiler from `hipcc` to `amdclang` in the installation script and cmake files. * Changed the address sanitizer build targets. Now only `gfx908:xnack+`, `gfx90a:xnack+`, `gfx940:xnack+`, `gfx941:xnack+`, and `gfx942:xnack+` are built with `BUILD_ADDRESS_SANITIZER=ON`. ### Resolved issues * Fix hang in `RS-AMG` for Navi on some specific matrix sparsity patterns. * Fix wrong results in `Apply` on multi-GPU setups. ## rocALUTION 3.2.0 for ROCm 6.2.0 ### Additions * New file I/O based on rocsparse I/O format * `GetConvergenceHistory` for ItILU0 preconditioner ### Deprecations * `LocalMatrix::ReadFileCSR` * `LocalMatrix::WriteFileCSR` * `GlobalMatrix::ReadFileCSR` * `GlobalMatrix::WriteFileCSR` ## rocALUTION 3.1.1 for ROCm 6.1.0 ### Additions * `TripleMatrixProduct` functionality for `GlobalMatrix` * Multi-Node/GPU support for `UA-AMG`, `SA-AMG` and `RS-AMG` * Iterative ILU0 preconditioner `ItILU0` * Iterative triangular solve, selectable via `SolverDecr` class ### Deprecations * `LocalMatrix::AMGConnect` * `LocalMatrix::AMGAggregate` * `LocalMatrix::AMGPMISAggregate` * `LocalMatrix::AMGSmoothedAggregation` * `LocalMatrix::AMGAggregation` * `PairwiseAMG` ### Known Issues * `PairwiseAMG` does currently not support matrix sizes that exceed int32 range * `PairwiseAMG` might fail building the hierarchy on certain input matrices ## rocALUTION 3.0.3 for ROCm 6.0.0 ### Additions * Support for 64bit integer vectors * Inclusive and exclusive sum functionality for vector classes * Transpose functionality for `GlobalMatrix` and `LocalMatrix` * `TripleMatrixProduct` functionality for `LocalMatrix` * `Sort()` function for `LocalVector` class * Multiple stream support to the HIP backend ### Optimizations * `GlobalMatrix::Apply()` now uses multiple streams to better hide communication ### Changes * Matrix dimensions and number of non-zeros are now stored using 64-bit integers * Improved the ILUT preconditioner ### Deprecations * `LocalVector::GetIndexValues(ValueType*)` * `LocalVector::SetIndexValues(const ValueType*)` * `LocalMatrix::RSDirectInterpolation(const LocalVector&, const LocalVector&, LocalMatrix*, LocalMatrix*)` * `LocalMatrix::RSExtPIInterpolation(const LocalVector&, const LocalVector&, bool, float, LocalMatrix*, LocalMatrix*)` * `LocalMatrix::RugeStueben()` * `LocalMatrix::AMGSmoothedAggregation(ValueType, const LocalVector&, const LocalVector&, LocalMatrix*, LocalMatrix*, int)` * `LocalMatrix::AMGAggregation(const LocalVector&, LocalMatrix*, LocalMatrix*)` ### Fixes * Unit tests no longer ignore BCSR block dimension * Fixed documentation typos * Bug in multi-coloring for non-symmetric matrix patterns ## rocALUTION 2.1.11 for ROCm 5.7.0 ### Additions * Support for gfx940, gfx941, and gfx942 ### Fixes * OpenMP runtime issue with Windows toolchain ## rocALUTION 2.1.9 for ROCm 5.6.0 ### Fixes * Synchronization issues in level 1 routines ## rocALUTION 2.1.8 for ROCm 5.5.0 ### Additions * Build support for Navi32 ### Fixes * Typo in MPI backend * Bug with the backend when HIP support is disabled * Bug in SAAMG hierarchy building on the HIP backend * Improved SAAMG hierarchy build performance on the HIP backend ### Deprecations * `LocalVector::GetIndexValues(ValueType*)`: use `LocalVector::GetIndexValues(const LocalVector&, LocalVector*)` instead * `LocalVector::SetIndexValues(const ValueType*)`: use `LocalVector::SetIndexValues(const LocalVector&, const LocalVector&)` instead * `LocalMatrix::RSDirectInterpolation(const LocalVector&, const LocalVector&, LocalMatrix*, LocalMatrix*)`: use `LocalMatrix::RSDirectInterpolation(const LocalVector&, const LocalVector&, LocalMatrix*)` instead * `LocalMatrix::RSExtPIInterpolation(const LocalVector&, const LocalVector&, bool, float, LocalMatrix*, LocalMatrix*)`: use `LocalMatrix::RSExtPIInterpolation(const LocalVector&, const LocalVector&, bool, LocalMatrix*)` instead * `LocalMatrix::RugeStueben()` * `LocalMatrix::AMGSmoothedAggregation(ValueType, const LocalVector&, const LocalVector&, LocalMatrix*, LocalMatrix*, int)`: use `LocalMatrix::AMGAggregation(ValueType, const LocalVector&, const LocalVector&, LocalMatrix*, int)` instead * `LocalMatrix::AMGAggregation(const LocalVector&, LocalMatrix*, LocalMatrix*)`: use `LocalMatrix::AMGAggregation(const LocalVector&, LocalMatrix*)` instead ## rocALUTION 2.1.3 for ROCm 5.4.0 ### Additions * Build support for Navi31 and Navi33 * Support for non-squared global matrices ### Fixes * Memory leak in MatrixMult on HIP backend * Global structures can now be used with a single process ### Changes * Switched GTest death test style to 'threadsafe' * Removed the native compiler option that was used during default library compilation ### Deprecations * `GlobalVector::GetGhostSize()` * `ParallelManager::GetGlobalSize(), ParallelManager::GetLocalSize()`, `ParallelManager::SetGlobalSize()`, and `ParallelManager::SetLocalSize()` * `Vector::GetGhostSize()` * `Multigrid::SetOperatorFormat(unsigned int)`: use `Multigrid::SetOperatorFormat(unsigned int, int)` instead * `RugeStuebenAMG::SetCouplingStrength(ValueType)`: use `SetStrengthThreshold(float)` instead ## rocALUTION 2.1.0 for ROCm 5.3.0 ### Additions * Benchmarking tool * Ext+I Interpolation with sparsify strategies added for RS-AMG ### Optimizations * ParallelManager ## rocALUTION 2.0.3 for ROCm 5.2.0 ### Additions * New packages for test and benchmark executables on all supported operating systems using CPack ## rocALUTION 2.0.2 for ROCm 5.1.0 ### Additions * Added out-of-place matrix transpose functionality * Added LocalVector ## rocALUTION 2.0.1 for ROCm 5.0.0 ### Changes * Changed to C++ 14 Standard * Added sanitizer option * Improved documentation ### Deprecations * `GlobalPairwiseAMG` class: use `PairwiseAMG` instead ## rocALUTION 1.13.2 for ROCm 4.5.0 ### Additions * AddressSanitizer build option * Enabled beta support for Windows 10 ### Changes * Packaging has been split into a runtime package (`rocalution`) and a development package (`rocalution-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. ### Deprecations * `GlobalPairwiseAMG`: use `PairwiseAMG` instead ### Optimizations * Improved (A)MG smoothing and convergence rate * Improved IDR Gram-Schmidt process * Optimized (A)MG solving phase ## rocALUTION 1.12.1 for ROCm 4.3.0 ### Additions * Support for gfx90a target * Support for gfx1030 target ### Optimizations * Install script ## rocALUTION 1.11.5 for ROCm 4.0.0 ### Additions * Changelog * Block compressed sparse row (BCSRR) format support ### Changes * Update to the Debian package name * CMake file adjustments ### Fixes * NaN issues ## rocALUTION 1.10 for ROCm 3.9 ### Additions * rocRAND support for GPU sampling of random data ## rocALUTION 1.9.3 for ROCm 3.8 ### Additions * `csr2dense` and `dense2csr` to HIP backend ## rocALUTION 1.9.1 for ROCm 3.5 ### Additions * Static build * BCSR matrix format for SpMV ### Fixes * Bug in conversion from CSR to HYB format rocALUTION-rocm-7.1.0/CMakeLists.txt000066400000000000000000000220621507377332500170520ustar00rootroot00000000000000# ######################################################################## # 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. # # ######################################################################## 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 ${ROCM_PATH} CACHE PATH "Install path prefix, prepended onto install directories") endif() # Needed to pickup static library files list(APPEND CMAKE_PREFIX_PATH ${ROCM_PATH}/llvm ${ROCM_PATH}) # CMake modules list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${ROCM_PATH}/lib/cmake/hip ${ROCM_PATH}/hip/cmake ${ROCM_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() # rocALUTION project project(rocalution LANGUAGES CXX) # Build flags set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_HIP_STANDARD 17) set(CMAKE_HIP_STANDARD_REQUIRED ON) set(CMAKE_HIP_EXTENSIONS OFF) # Build options option(BUILD_SHARED_LIBS "Build rocALUTION as a shared library" ON) option(BUILD_CLIENTS_TESTS "Build tests (requires googletest)" OFF) option(BUILD_CLIENTS_BENCHMARKS "Build benchmarks (requires boost)" OFF) option(BUILD_CLIENTS_SAMPLES "Build examples" ON) option(BUILD_VERBOSE "Output additional build information" OFF) option(BUILD_CODE_COVERAGE "Build with code coverage enabled" OFF) option(BUILD_ADDRESS_SANITIZER "Build with address sanitizer enabled" OFF) option(BUILD_GLOBALTYPE_64 "Support global number of rows / columns exceeding 32 bits" OFF) option(BUILD_LOCALTYPE_64 "Support local number of rows / columns exceeding 32 bits" OFF) option(BUILD_PTRTYPE_64 "Support local number of non-zeros exceeding 32 bits" OFF) option(BUILD_OPTCPU "Enable all instruction subsets supported by the local machine" OFF) option(BUILD_SUPPORT_COMPLEX "Enable complex number support" ON) # Dependencies include(cmake/Dependencies.cmake) if(BUILD_ADDRESS_SANITIZER) set(DEFAULT_AMDGPU_TARGETS gfx908:xnack+ gfx90a:xnack+ gfx942:xnack+ ) else() set(DEFAULT_AMDGPU_TARGETS gfx803 gfx900:xnack- gfx906:xnack- gfx908:xnack- gfx90a:xnack- gfx90a:xnack+ gfx942 gfx950 gfx1030 gfx1100 gfx1101 gfx1102 gfx1151 gfx1200 gfx1201 ) endif() if(AMDGPU_TARGETS AND NOT GPU_TARGETS) message( DEPRECATION "AMDGPU_TARGETS use is deprecated. Use GPU_TARGETS." ) endif() set(AMDGPU_TARGETS "${DEFAULT_AMDGPU_TARGETS}" CACHE STRING "Target default GPUs if AMDGPU_TARGETS is not defined. (Deprecated, prefer GPU_TARGETS)") # Don't force, users should be able to override GPU_TARGETS at the command line if desired set(GPU_TARGETS "${AMDGPU_TARGETS}" CACHE STRING "GPU architectures to build for") include(CheckLanguage) include(CMakeDependentOption) check_language(HIP) cmake_dependent_option(USE_HIPCXX "Use CMake HIP language support" OFF CMAKE_HIP_COMPILER OFF) if(USE_HIPCXX) enable_language(HIP) else() find_package(HIP MODULE) # hip_add_library is only provided by the find module if(NOT HIP_FOUND) message("-- HIP not found. Compiling WITHOUT HIP support.") endif() endif() cmake_dependent_option(SUPPORT_HIP "Compile WITH HIP support" ON "USE_HIPCXX OR HIP_FOUND" OFF) # HIP related library dependencies if(SUPPORT_HIP) if( CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) find_package( hip REQUIRED CONFIG PATHS ${HIP_DIR} ${ROCM_PATH} /opt/rocm ) endif( ) find_package(rocblas REQUIRED) find_package(rocsparse REQUIRED) find_package(rocprim REQUIRED) find_package(rocrand REQUIRED) endif() if(BUILD_CODE_COVERAGE) add_compile_options(-fprofile-arcs -ftest-coverage) add_link_options(--coverage -lgcov) 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() # Setup version rocm_setup_version(VERSION "4.0.1") if(BUILD_CLIENTS_SAMPLES OR BUILD_CLIENTS_BENCHMARKS OR BUILD_CLIENTS_TESTS) set( BUILD_CLIENTS ON ) rocm_package_setup_component(clients) if(BUILD_CLIENTS_TESTS) rocm_package_setup_client_component(tests) endif() if(BUILD_CLIENTS_BENCHMARKS) rocm_package_setup_client_component(benchmarks) endif() endif() # rocALUTION library add_subdirectory(src) # Trigger client builds if selected if(BUILD_CLIENTS) add_subdirectory(clients) endif() # Package specific CPACK vars if(SUPPORT_HIP) if(BUILD_ADDRESS_SANITIZER) set(DEPENDS_HIP_RUNTIME "hip-runtime-amd-asan >= 4.5.0" ) else() set(DEPENDS_HIP_RUNTIME "hip-runtime-amd >= 4.5.0" ) endif() rocm_package_add_dependencies(DEPENDS "${DEPENDS_HIP_RUNTIME}" "rocsparse >= 1.12.10" "rocblas >= 2.22.0" "rocrand >= 2.1.0") endif() set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.md") if(WIN32) set(CPACK_SOURCE_GENERATOR "ZIP") set(CPACK_GENERATOR "ZIP") set(CMAKE_INSTALL_PREFIX "C:/hipSDK" CACHE PATH "Install path" FORCE) set(INSTALL_PREFIX "C:/hipSDK") set(CPACK_SET_DESTDIR OFF) set(CPACK_PACKAGE_INSTALL_DIRECTORY "C:/hipSDK") set(CPACK_PACKAGING_INSTALL_PREFIX "") set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF) else() if(NOT CPACK_PACKAGING_INSTALL_PREFIX) set(CPACK_PACKAGING_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") endif() endif() set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "\${CPACK_PACKAGING_INSTALL_PREFIX}" ) # Package name set(package_name rocalution) set(ROCALUTION_CONFIG_DIR "\${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" CACHE PATH "Path placed into ldconfig file") rocm_create_package( NAME ${package_name} DESCRIPTION "ROCm library for sparse linear systems" MAINTAINER "rocALUTION Maintainer " LDCONFIG LDCONFIG_DIR ${ROCALUTION_CONFIG_DIR} ) # # ADDITIONAL TARGETS FOR CODE COVERAGE # if(BUILD_CODE_COVERAGE) # # > make coverage_cleanup (clean coverage related files.) # > make coverage GTEST_FILTER=<> # will run: # > make coverage_analysis GTEST_FILTER=<> (analyze tests) # > make coverage_output (generate html documentation) # # # Run coverage analysis # add_custom_target(coverage_analysis COMMAND echo Coverage GTEST_FILTER=\${GTEST_FILTER} COMMAND ./clients/staging/rocalution-test --gtest_filter=\"\${GTEST_FILTER}\" WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) add_dependencies(coverage_analysis rocalution) # # 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 "'${CMAKE_SOURCE_DIR}/src/utils/*'" "'${CMAKE_SOURCE_DIR}/src/base/host/host_io.*'" "'${CMAKE_SOURCE_DIR}/clients/*'" "'${CMAKE_SOURCE_DIR}/build/*'" "'/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() rocALUTION-rocm-7.1.0/LICENSE.md000066400000000000000000000021221507377332500157110ustar00rootroot00000000000000MIT License 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. rocALUTION-rocm-7.1.0/README.md000066400000000000000000000114661507377332500155770ustar00rootroot00000000000000# rocALUTION > [!NOTE] > The published documentation is available at [rocALUTION](https://rocm.docs.amd.com/projects/rocALUTION/en/latest/) in an organized, easy-to-read format, with search and a table of contents. The documentation source files reside in the `docs` folder of this repository. As with all ROCm projects, the documentation is open source. For more information on contributing to the documentation, see [Contribute to ROCm documentation](https://rocm.docs.amd.com/en/latest/contribute/contributing.html). rocALUTION is a sparse linear algebra library that can be used to explore fine-grained parallelism on top of the [ROCm](https://github.com/ROCm/ROCm) platform runtime and toolchains. Based on C++ and [HIP](https://github.com/ROCm/HIP/), rocALUTION provides a portable, generic, and flexible design that allows seamless integration with other scientific software packages. rocALUTION offers various backends for different (parallel) hardware: * Host * [OpenMP](http://www.openmp.org/): Designed for multi-core CPUs * [HIP](https://github.com/ROCm/HIP/): Designed for ROCm-compatible devices * [MPI](https://www.open-mpi.org/): Designed for multi-node clusters and multi-GPU setups ## Requirements To use rocALUTION on GPU devices, you must first install the [rocBLAS](https://github.com/ROCm/rocBLAS), [rocSPARSE](https://github.com/ROCm/rocSPARSE), and [rocRAND](https://github.com/ROCm/rocRAND) libraries. You can install these from the ROCm repository, the GitHub 'releases' tab, or you can manually compile them. ## Documentation Documentation for rocALUTION is available at [https://rocm.docs.amd.com/projects/rocALUTION/en/latest/](https://rocm.docs.amd.com/projects/rocALUTION/en/latest/). To build our documentation locally, use 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 ``` ## Build You can compile rocALUTION using CMake 3.5 or later. Note that all compiler specifications are determined automatically. ```bash # Clone rocALUTION using git git clone https://github.com/ROCm/rocALUTION.git # Go to rocALUTION directory, create and change to build directory cd rocALUTION; mkdir build; cd build # Configure rocALUTION # Build options: # SUPPORT_HIP - build rocALUTION with HIP support (ON) # SUPPORT_OMP - build rocALUTION with OpenMP support (ON) # SUPPORT_MPI - build rocALUTION with MPI (multi-node) support (OFF) # BUILD_SHARED_LIBS - build rocALUTION as shared library (ON, recommended) # BUILD_EXAMPLES - build rocALUTION examples (ON) cmake .. -DSUPPORT_HIP=ON -DROCM_PATH=/opt/rocm/ # Build make ``` To test your installation, run a CG solver on a Laplacian matrix: ```bash cd rocALUTION; cd build wget ftp://math.nist.gov/pub/MatrixMarket2/Harwell-Boeing/laplace/gr_30_30.mtx.gz gzip -d gr_30_30.mtx.gz ./clients/staging/cg gr_30_30.mtx ``` ## General information rocALUTION is based on a generic and robust design that allows expansion in the direction of new solvers and preconditioners with support for various hardware types. The library's design allows the use of all solvers as preconditioners in other solvers. For example, you can define a CG solver with a multi-elimination preconditioner, in which the last-block is preconditioned with another Chebyshev iteration method that itself is preconditioned with a multi-colored symmetric Gauss-Seidel scheme. ### Iterative solvers * Fixed-point iteration schemes: Jacobi, (Symmetric) Gauss-Seidel, SOR, SSOR * Krylov subspace methods: CR, CG, BiCGStab, BiCGStab(*l*), GMRES, IDR, QMRCGSTAB, Flexible CG/GMRES * Mixed-precision defect correction scheme * Chebyshev iteration scheme * Multigrid: Geometric and algebraic ### Preconditioners * Matrix splitting schemes: Jacobi, (multi-colored) (symmetric) Gauss-Seidel, SOR, SSOR * Factorization schemes: ILU(*0*), ILU(*p*) (based on levels), ILU(*p,q*) (power(*q*)-pattern method), multi-elimination ILU (nested/recursive), ILUT (based on threshold), IC(*0*) * Approximate Inverses: Chebyshev matrix-valued polynomial, SPAI, FSAI, TNS * Diagonal-based preconditioner for Saddle-point problems * Block-type of sub-preconditioners/solvers * Additive Schwarz (restricted) * Variable type of preconditioners ### Sparse matrix formats * Compressed Sparse Row (CSR) * Modified Compressed Sparse Row (MCSR) * Dense (DENSE) * Coordinate (COO) * ELL * Diagonal (DIA) * Hybrid ELL+COO (HYB) ## Portability All code based on rocALUTION is portable and hardware-independent. It compiles and runs on any supported platform. All solvers and preconditioners are based on a single source code implementation that delivers portable results across all backends (note that variations are possible due to different hardware rounding modes). The only visible difference between hardware is performance variation. rocALUTION-rocm-7.1.0/clients/000077500000000000000000000000001507377332500157515ustar00rootroot00000000000000rocALUTION-rocm-7.1.0/clients/CMakeLists.txt000066400000000000000000000064661507377332500205250ustar00rootroot00000000000000# ######################################################################## # 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. # # ######################################################################## # 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 ${ROCM_PATH} 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 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) # Build flags set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) if(NOT TARGET rocalution) # This project may compile dependencies for clients project(rocalution-clients LANGUAGES CXX) find_package(rocalution REQUIRED CONFIG PATHS ${ROCM_PATH}/rocalution) get_target_property(depends roc::rocalution INTERFACE_LINK_LIBRARIES) # Check for MPI build foreach(i ${depends}) if("MPI::MPI_CXX" STREQUAL ${i}) set(SUPPORT_MPI ON) find_package(MPI REQUIRED) endif() endforeach() option(BUILD_CLIENTS_SAMPLES "Build examples." ON) option(BUILD_CLIENTS_BENCHMARKS "Build benchmarks." OFF) option(BUILD_CLIENTS_TESTS "Build tests." OFF) 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) endif() rocALUTION-rocm-7.1.0/clients/benchmarks/000077500000000000000000000000001507377332500200665ustar00rootroot00000000000000rocALUTION-rocm-7.1.0/clients/benchmarks/CMakeLists.txt000066400000000000000000000047111507377332500226310ustar00rootroot00000000000000# ######################################################################## # Copyright (C) 2022-2023 Advanced Micro Devices, Inc. All rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # # ######################################################################## set(ROCALUTION_BENCHMARK_SOURCES client.cpp rocalution_arguments_config.cpp rocalution_bench.cpp rocalution_bench_solver_parameters.cpp rocalution_bench_solver_results.cpp rocalution_enum_coarsening_strategy.cpp rocalution_enum_directsolver.cpp rocalution_enum_itilu0_alg.cpp rocalution_enum_itsolver.cpp rocalution_enum_matrix_init.cpp rocalution_enum_preconditioner.cpp rocalution_enum_smoother.cpp rocalution_bench_cmdlines.cpp rocalution_bench_app.cpp ) add_executable(rocalution-bench ${ROCALUTION_BENCHMARK_SOURCES} ${ROCALUTION_CLIENTS_COMMON}) # Target compile options target_compile_options(rocalution-bench PRIVATE -Wall) # Internal common header target_include_directories(rocalution-bench PRIVATE $) # Target link libraries target_link_libraries(rocalution-bench PRIVATE roc::rocalution) if(NOT TARGET rocalution) set_target_properties(rocalution-bench PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/staging") else() set_target_properties(rocalution-bench PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/clients/staging") endif() rocm_install(TARGETS rocalution-bench COMPONENT benchmarks) rocALUTION-rocm-7.1.0/clients/benchmarks/client.cpp000066400000000000000000000075541507377332500220630ustar00rootroot00000000000000/*! \file */ /* ************************************************************************ * 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 "rocalution/rocalution.hpp" #include "rocalution_bench.hpp" #include "utility.hpp" #include #include "rocalution_bench_app.hpp" // // REQUIRED ROUTINES: // bool rocalution_bench_record_results(const rocalution_bench_solver_parameters& params, const rocalution_bench_solver_results& results) { auto* s_bench_app = rocalution_bench_app::instance(); if(s_bench_app) { return s_bench_app->record_results(params, results); } else { params.WriteNicely(std::cout); results.WriteNicely(std::cout); return true; } } int device = 0; int main(int argc, char* argv[]) { if(rocalution_bench_app::applies(argc, argv)) { std::cout << "main " << std::endl; try { auto* s_bench_app = rocalution_bench_app::instance(argc, argv); // // RUN CASES. // bool success = s_bench_app->run_cases(); if(!success) { std::cout << "ERROR SUCCESS FAILURE client.cpp line " << __LINE__ << std::endl; return !success; } // // EXPORT FILE. // success = s_bench_app->export_file(); if(!success) { std::cout << "ERROR SUCCESS FAILURE client.cpp line " << __LINE__ << std::endl; return !success; } return !success; } catch(const bool& success) { std::cout << "ERROR SUCCESS EXCEPTION FAILURE client.cpp line " << __LINE__ << std::endl; return !success; } catch(const std::exception&) { std::cout << "ERROR UNKNOWN EXCEPTION FAILURE client.cpp line " << __LINE__ << std::endl; throw; } } else { try { rocalution_bench bench(argc, argv); // // Print info devices. // bench.info_devices(std::cout); // // Run benchmark. // bool success = bench.run(); if(!success) { std::cout << "ERROR SUCCESS FAILURE client.cpp line " << __LINE__ << std::endl; return !success; } return !success; } catch(const std::exception&) { std::cout << "ERROR UNKNOWN EXCEPTION FAILURE client.cpp line " << __LINE__ << std::endl; throw; } } return 0; } rocALUTION-rocm-7.1.0/clients/benchmarks/program_options.hpp000066400000000000000000000302341507377332500240230ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2022 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 // 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: // 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&) {} rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_arguments_config.cpp000066400000000000000000000312371507377332500263710ustar00rootroot00000000000000/*! \file */ /* ************************************************************************ * Copyright (C) 2022-2023 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "rocalution_arguments_config.hpp" #include "rocalution_bench_solver.hpp" // // // rocalution_arguments_config::rocalution_arguments_config() {} std::string make_option(const char* name) { std::string s(name); for(size_t i = 0; i < s.length(); ++i) { if(s[i] == '_') s[i] = '-'; } return s; } // // // void rocalution_arguments_config::set_description(options_description& desc) { desc.add_options()("help,h", "produces this help message"); #define ADD_OPTION(type_, e_, x_default_, x_desc_) \ desc.add_options()(make_option(rocalution_bench_solver_parameters::GetName(e_)), \ value(this->GetPointer(e_))->default_value(x_default_), \ x_desc_) for(auto e : rocalution_bench_solver_parameters::e_double_all) { switch(e) { case rocalution_bench_solver_parameters::abs_tol: { ADD_OPTION(double, e, 1.0e-6, "absolute tolerance"); break; } case rocalution_bench_solver_parameters::rel_tol: { ADD_OPTION(double, e, 0.0, "relative tolerance"); break; } case rocalution_bench_solver_parameters::div_tol: { ADD_OPTION(double, e, 1e+8, "divide tolerance"); break; } case rocalution_bench_solver_parameters::residual_tol: { ADD_OPTION(double, e, 1.0e-8, "residual tolerance"); break; } case rocalution_bench_solver_parameters::ilut_tol: { ADD_OPTION(double, e, 0.05, "ilut tolerance"); break; } case rocalution_bench_solver_parameters::itsolve_tol: { ADD_OPTION(double, e, 1e-03, "iterative solve tolerance (see --iterative_solve)."); break; } case rocalution_bench_solver_parameters::itilu0_tol: { ADD_OPTION(double, e, 2e-07, "itilu0 tolerance"); break; } case rocalution_bench_solver_parameters::mcgs_relax: { ADD_OPTION(double, e, 1.0, "relaxation coefficient"); break; } case rocalution_bench_solver_parameters::solver_over_interp: { ADD_OPTION(double, e, 1.2, "over interp coefficient for multigrid"); break; } case rocalution_bench_solver_parameters::solver_coupling_strength: { ADD_OPTION(double, e, 0.005, "coupling strength coefficient for multigrid"); break; } } } for(auto e : rocalution_bench_solver_parameters::e_int_all) { switch(e) { case rocalution_bench_solver_parameters::krylov_basis: { ADD_OPTION(int, e, 30, "dimension of the Krylov basis."); break; } case rocalution_bench_solver_parameters::max_iter: { ADD_OPTION(int, e, 2000, "default maximum number of iterations."); break; } case rocalution_bench_solver_parameters::ndim: { ADD_OPTION(int, e, 200, "dimension"); break; } case rocalution_bench_solver_parameters::solver_pre_smooth: { ADD_OPTION(int, e, 2, "number of iteration of pre-smoother"); break; } case rocalution_bench_solver_parameters::solver_post_smooth: { ADD_OPTION(int, e, 2, "number of iteration of post-smoother"); break; } case rocalution_bench_solver_parameters::solver_ordering: { ADD_OPTION(int, e, 1, "ordering type"); break; } case rocalution_bench_solver_parameters::rebuild_numeric: { ADD_OPTION(int, e, 0, "rebuild numeric"); break; } case rocalution_bench_solver_parameters::cycle: { ADD_OPTION(int, e, 0, "Number of cycle"); break; } case rocalution_bench_solver_parameters::ilut_n: { ADD_OPTION(int, e, 4, "number of elements per row kept"); break; } case rocalution_bench_solver_parameters::itsolve_max_iter: { ADD_OPTION(int, e, 30, "iterative solve maximum number of iterations (see " "--iterative_solve)."); break; } case rocalution_bench_solver_parameters::itilu0_max_iter: { ADD_OPTION(int, e, 1000, "itilu0 maximum number of iterations."); break; } case rocalution_bench_solver_parameters::itilu0_options: { ADD_OPTION(int, e, 1000, "itilu0 combination of options."); break; } case rocalution_bench_solver_parameters::mcilu_p: { ADD_OPTION(int, e, 0, "multicolored ilu parameter p."); break; } case rocalution_bench_solver_parameters::mcilu_q: { ADD_OPTION(int, e, 0, "multicolored ilu parameter q."); break; } case rocalution_bench_solver_parameters::solver_coarsest_level: { ADD_OPTION(int, e, 200, "multigrid coarsest_level."); break; } case rocalution_bench_solver_parameters::blockdim: { ADD_OPTION(int, e, 3, "block dimension."); break; } } } for(auto e : rocalution_bench_solver_parameters::e_string_all) { switch(e) { case rocalution_bench_solver_parameters::matrix_filename: { ADD_OPTION(std::string, e, "", "read from matrix " "market (.mtx) format. This will override parameters -m, -n, and -z."); break; } case rocalution_bench_solver_parameters::smoother: { ADD_OPTION(std::string, e, "", "solver smoother"); break; } case rocalution_bench_solver_parameters::iterative_solver: { ADD_OPTION(std::string, e, "", "iterative solver"); break; } case rocalution_bench_solver_parameters::direct_solver: { ADD_OPTION(std::string, e, "", "direct solver"); break; } case rocalution_bench_solver_parameters::preconditioner: { ADD_OPTION(std::string, e, "", "preconditioner"); break; } case rocalution_bench_solver_parameters::coarsening_strategy: { ADD_OPTION(std::string, e, "", "coarsening strategy"); break; } case rocalution_bench_solver_parameters::itilu0_alg: { ADD_OPTION(std::string, e, "Default", "ItILU0 algorithm"); break; } case rocalution_bench_solver_parameters::matrix: { ADD_OPTION(std::string, e, "", "matrix initialization"); break; } } } for(auto e : rocalution_bench_solver_parameters::e_uint_all) { switch(e) { case rocalution_bench_solver_parameters::format: { ADD_OPTION(unsigned int, e, CSR, "matrix format"); break; } } } for(auto e : rocalution_bench_solver_parameters::e_bool_all) { switch(e) { case rocalution_bench_solver_parameters::iterative_solve: { ADD_OPTION(bool, e, false, "perform triangular iterative solve during solving step."); break; } case rocalution_bench_solver_parameters::verbose: { ADD_OPTION(bool, e, false, "verbose"); break; } case rocalution_bench_solver_parameters::mcilu_use_level: { ADD_OPTION(bool, e, false, "use level in mcilu"); break; } } } } // // // int rocalution_arguments_config::parse(int& argc, char**& argv, options_description& desc) { variables_map vm; store(parse_command_line(argc, argv, desc, sizeof(rocalution_arguments_config)), vm); notify(vm); if(vm.count("help")) { std::cout << desc << std::endl; return 0; } // // Init enums. // for(auto e : rocalution_bench_solver_parameters::e_string_all) { switch(e) { case rocalution_bench_solver_parameters::matrix_filename: { break; } case rocalution_bench_solver_parameters::smoother: { auto smoother_string = this->Get(rocalution_bench_solver_parameters::smoother); if(smoother_string != "") { this->m_enum_smoother(smoother_string.c_str()); } break; } case rocalution_bench_solver_parameters::iterative_solver: { auto iterative_solver_string = this->Get(rocalution_bench_solver_parameters::iterative_solver); if(iterative_solver_string != "") { this->m_enum_itsolver(iterative_solver_string.c_str()); } break; } case rocalution_bench_solver_parameters::direct_solver: { auto direct_solver_string = this->Get(rocalution_bench_solver_parameters::direct_solver); if(direct_solver_string != "") { this->m_enum_directsolver(direct_solver_string.c_str()); } break; } case rocalution_bench_solver_parameters::preconditioner: { auto preconditioner_string = this->Get(rocalution_bench_solver_parameters::preconditioner); if(preconditioner_string != "") { this->m_enum_preconditioner(preconditioner_string.c_str()); } break; } case rocalution_bench_solver_parameters::coarsening_strategy: { auto coarsening_strategy_string = this->Get(rocalution_bench_solver_parameters::coarsening_strategy); if(coarsening_strategy_string != "") { this->m_enum_coarsening_strategy(coarsening_strategy_string.c_str()); } break; } case rocalution_bench_solver_parameters::itilu0_alg: { auto itilu0_alg_string = this->Get(rocalution_bench_solver_parameters::itilu0_alg); if(itilu0_alg_string != "") { this->m_enum_itilu0_alg(itilu0_alg_string.c_str()); } break; } case rocalution_bench_solver_parameters::matrix: { auto matrix_init_string = this->Get(rocalution_bench_solver_parameters::matrix); if(matrix_init_string != "") { this->m_enum_matrix_init(matrix_init_string.c_str()); } break; } } } return 0; } // // // int rocalution_arguments_config::parse_no_default(int& argc, char**& argv, options_description& desc) { variables_map vm; store(parse_command_line(argc, argv, desc), vm); notify(vm); if(vm.count("help")) { std::cout << desc << std::endl; return 0; } return 0; } rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_arguments_config.hpp000066400000000000000000000042311507377332500263700ustar00rootroot00000000000000/*! \file */ /* ************************************************************************ * 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 #include #include #include "program_options.hpp" #include "utility.hpp" #include "rocalution_bench_solver_parameters.hpp" // // @brief Class as an extension of Arguments to deal with the rocalution_bench. // struct rocalution_arguments_config : rocalution_bench_solver_parameters { char precision; char indextype; std::string function; int device_id; // // @brief Default constructor. // rocalution_arguments_config(); // // @brief Set the description. // void set_description(options_description& desc); // // @brief Parse command line arguments. // int parse(int& argc, char**& argv, options_description& desc); // // @brief Parse command line arguments with no default value. // int parse_no_default(int& argc, char**& argv, options_description& desc); }; rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_bench.cpp000066400000000000000000000063461507377332500241210ustar00rootroot00000000000000/*! \file */ /* ************************************************************************ * 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 "rocalution_bench.hpp" #include "rocalution_bench_template.hpp" #define TO_STR2(x) #x #define TO_STR(x) TO_STR2(x) std::string rocalution_get_version() { int rocalution_ver = __ROCALUTION_VER; char rocalution_rev[64]; static constexpr char v[] = TO_STR(__ROCALUTION_VER_TWEAK); memcpy(rocalution_rev, v, sizeof(v)); std::ostringstream os; os << rocalution_ver / 100000 << "." << rocalution_ver / 100 % 1000 << "." << rocalution_ver % 100 << "-" << rocalution_rev; return os.str(); } // // // void rocalution_bench::parse(int& argc, char**& argv, rocalution_arguments_config& config) { config.set_description(this->desc); config.precision = 's'; config.indextype = 's'; config.parse(argc, argv, this->desc); } // // // rocalution_bench::rocalution_bench() : desc("rocalution client command line options") { } // // Execute the benchmark. // bool rocalution_bench::execute() { // // Set up rocalution. // set_device_rocalution(device); init_rocalution(); // // Run the benchmark. // bool success; success = rocalution_bench_template(this->config); if(!success) { rocalution_bench_errmsg << "rocalution_bench_template failed." << std::endl; } // // Stop rocalution. // stop_rocalution(); return success; } // // // rocalution_bench::rocalution_bench(int& argc, char**& argv) : desc("rocalution client command line options") { // // Parse the command line for configuration. // this->parse(argc, argv, this->config); } rocalution_bench& rocalution_bench::operator()(int& argc, char**& argv) { this->parse(argc, argv, this->config); return *this; } // // Run (execute). // bool rocalution_bench::run() { return this->execute(); } int rocalution_bench::get_device_id() const { return this->config.device_id; } void rocalution_bench::info_devices(std::ostream& out_) const {} rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_bench.hpp000066400000000000000000000051261507377332500241210ustar00rootroot00000000000000/*! \file */ /* ************************************************************************ * 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 #include "rocalution_arguments_config.hpp" #include "rocalution_enum_itsolver.hpp" // // @brief Class responsible of configuring the benchmark from parsing command line arguments // and execute it. // class rocalution_bench { public: // // @brief Default contructor. // rocalution_bench(); // // @brief Contructor with command line arguments. // rocalution_bench(int& argc, char**& argv); // // @brief Parenthesis operator equivalent to the contructor. // rocalution_bench& operator()(int& argc, char**& argv); // // @brief Run the benchmark. // bool run(); // // @brief Execute the benchmark. // bool execute(); // // @brief Get device id. // int get_device_id() const; // // @brief Get info devices. // void info_devices(std::ostream& out_) const; private: // // @brief Convert the command line arguments to rocalution_arguments_config. // void parse(int& argc, char**& argv, rocalution_arguments_config& config); // // @brief Description of the command line options. // options_description desc; // // @brief Configuration of the benchmark. // rocalution_arguments_config config; }; // // @brief Get rocalution version. // std::string rocalution_get_version(); rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_bench_app.cpp000066400000000000000000000363241507377332500247600ustar00rootroot00000000000000/*! \file */ /* ************************************************************************ * 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 "rocalution_bench_app.hpp" #include "rocalution_bench.hpp" #include #include #include rocalution_bench_app* rocalution_bench_app::s_instance = nullptr; rocalution_bench_app_base::rocalution_bench_app_base(int argc, char** argv) : m_initial_argc(rocalution_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()) {}; bool rocalution_bench_app_base::run_case(int isample, int irun, int argc, char** argv) { rocalution_bench bench(argc, argv); return bench.run(); } bool rocalution_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(); this->m_stdout_skip_legend = false; if(is_stdout_disabled()) { printf("// start benchmarking ... (nsamples = %d, nruns = %d)\n", nsamples, nruns); } bool status = true; for(int isample = 0; isample < nsamples; ++isample) { this->m_isample = isample; // // Add an item to collect data through rocalution_record_timing // for(int irun = 0; irun < nruns; ++irun) { this->m_irun = irun; if(false == this->m_stdout_skip_legend) { this->m_stdout_skip_legend = (irun > 0 && isample == 0); } // // 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. // status &= this->run_case(this->m_isample, this->m_irun, sample_argc, sample_argv); if(!status) { rocalution_bench_errmsg << "run_cases::run_case failed at line " << __LINE__ << std::endl; break; } 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 status; }; rocalution_bench_app::rocalution_bench_app(int argc, char** argv) : rocalution_bench_app_base(argc, argv) { } rocalution_bench_app::~rocalution_bench_app() {} void rocalution_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(); 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]) std::srand(0); for(int iboot = 0; iboot < nboots; ++iboot) { for(int i = 0; i < resize; ++i) { const int j = (std::rand() % size); 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 rocalution_bench_app::series_lower_upper(int N, const std::vector& r, rocalution_bench_solver_results::e_double e, double& median, double& lower, double& upper) { static constexpr double alpha = 0.95; std::vector s(N); for(int i = 0; i < N; ++i) { s[i] = r[i].Get(e); } std::sort(s.begin(), s.end()); double interval[2]; static constexpr int nboots = 200; confidence_interval(alpha, 10, nboots, s, interval); median = (N % 2 == 0) ? (s[N / 2 - 1] + s[N / 2]) * 0.5 : s[N / 2]; lower = interval[0]; upper = interval[1]; } void rocalution_bench_app::export_item(std::ostream& out, rocalution_bench_timing_t::item_t& item) { out << " \"setup\" : { "; item.m_parameters.WriteJson(out); out << " }," << std::endl; // // // auto N = item.m_nruns; if(N > 1) { rocalution_bench_solver_results res; rocalution_bench_solver_results res_low; rocalution_bench_solver_results res_up; for(auto e : rocalution_bench_solver_results::e_bool_all) { for(int i = 0; i < N; ++i) { if(item.m_results[i].Get(e) != item.m_results[0].Get(e)) { std::cerr << "WARNING/ERROR Boolean result '" << rocalution_bench_solver_results::Name(e) << "' is not constant over runs." << std::endl; } } res.Set(e, item.m_results[0].Get(e)); res_low.Set(e, item.m_results[0].Get(e)); res_up.Set(e, item.m_results[0].Get(e)); } for(auto e : rocalution_bench_solver_results::e_int_all) { for(int i = 0; i < N; ++i) { if(item.m_results[i].Get(e) != item.m_results[0].Get(e)) { std::cerr << "WARNING/ERROR Integer result '" << rocalution_bench_solver_results::Name(e) << "' is not constant over runs." << std::endl; } } res.Set(e, item.m_results[0].Get(e)); res_low.Set(e, item.m_results[0].Get(e)); res_up.Set(e, item.m_results[0].Get(e)); } for(auto e : rocalution_bench_solver_results::e_double_all) { double median; double lower; double upper; series_lower_upper(N, item.m_results, e, median, lower, upper); res.Set(e, median); res_low.Set(e, lower); res_up.Set(e, upper); } out << " \"nsamples\": \"" << N << "\"," << std::endl; out << " \"median\" : { "; res.WriteJson(out); out << " }," << std::endl; out << " \"low\" : { "; res_low.WriteJson(out); out << " }," << std::endl; out << " \"up\" : { "; res_up.WriteJson(out); out << " }" << std::endl; } else { out << " \"nsamples\": \"" << N << "\"," << std::endl; out << " \"median\" : { "; item.m_results[0].WriteJson(out); out << " }," << std::endl; out << " \"low\" : { "; item.m_results[0].WriteJson(out); out << " }," << std::endl; out << " \"up\" : { "; item.m_results[0].WriteJson(out); out << " }" << std::endl; } } bool rocalution_bench_app::export_file() { const char* ofilename = this->m_bench_cmdlines.get_ofilename(); if(ofilename == nullptr) { std::cerr << "//" << std::endl; std::cerr << "// rocalution_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]; bool status; // // Write header. // status = define_results_json(out); if(!status) { rocalution_bench_errmsg << "run_cases failed at line " << __LINE__ << std::endl; return status; } // // Loop over cases. // const int nsamples = m_bench_cmdlines.get_nsamples(); const int bench_timing_size = m_bench_timing.size(); if(nsamples != bench_timing_size) { rocalution_bench_errmsg << "incompatible sizes at line " << __LINE__ << " " << nsamples << " " << bench_timing_size << std::endl; if(bench_timing_size == 0) { rocalution_bench_errmsg << "No data has been harvested from running case" << std::endl; } exit(1); } for(int isample = 0; isample < nsamples; ++isample) { this->m_bench_cmdlines.get(isample, sample_argc, sample_argv); this->define_case_json(out, isample, sample_argc, sample_argv); out << "{ "; { this->export_item(out, this->m_bench_timing[isample]); } out << " }"; this->close_case_json(out, isample, sample_argc, sample_argv); } // // Write footer. // status = this->close_results_json(out); if(!status) { rocalution_bench_errmsg << "run_cases failed at line " << __LINE__ << std::endl; return status; } out.close(); return true; } bool rocalution_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 true; } bool rocalution_bench_app::close_case_json(std::ostream& out, int isample, int argc, char** argv) { out << " }"; return true; } bool rocalution_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 << 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; int option_index_x = this->m_bench_cmdlines.get_option_index_x(); out << std::endl << "\"xargs\": \["; for(int j = 0; j < this->m_bench_cmdlines.get_option_nargs(option_index_x); ++j) { auto arg = this->m_bench_cmdlines.get_option_arg(option_index_x, j); if(j > 0) out << ", "; out << "\"" << arg << "\""; } out << "]," << std::endl; out << std::endl << "\"yargs\":"; // // Harvest expanded options. // std::vector y_options_size; std::vector y_options_index; for(int k = 0; k < this->m_bench_cmdlines.get_noptions(); ++k) { if(k != option_index_x) { if(this->m_bench_cmdlines.get_option_nargs(k) > 1) { y_options_index.push_back(k); y_options_size.push_back(this->m_bench_cmdlines.get_option_nargs(k)); } } } const int num_y_options = y_options_index.size(); if(num_y_options > 0) { std::vector> indices(num_y_options); for(int k = 0; k < num_y_options; ++k) { indices[k].resize(y_options_size[k], 0); } } int nplots = this->m_bench_cmdlines.get_nsamples() / this->m_bench_cmdlines.get_option_nargs(option_index_x); std::vector plot_titles(nplots); if(plot_titles.size() == 1) { plot_titles.push_back(""); } else { int n = y_options_size[0]; auto argname0 = this->m_bench_cmdlines.get_option_name(y_options_index[0]); for(int iplot = 0; iplot < nplots; ++iplot) { std::string title(""); int p = n; { int jref = iplot % p; auto arg0 = this->m_bench_cmdlines.get_option_arg(y_options_index[0], jref); title += std::string(argname0 + ((argname0[1] == '-') ? 2 : 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]); title += std::string(",") + std::string(argname + ((argname[1] == '-') ? 2 : 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 true; } bool rocalution_bench_app::close_results_json(std::ostream& out) { out << "]" << std::endl; out << "}" << std::endl; return true; } rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_bench_app.hpp000066400000000000000000000203631507377332500247610ustar00rootroot00000000000000/*! \file */ /* ************************************************************************ * 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 #include "rocalution_arguments_config.hpp" #include "rocalution_bench_cmdlines.hpp" // // only for status // #include "rocalution_bench_solver_results.hpp" struct rocalution_benchfile_format { typedef enum value_type_ : int { json = 0, yaml } value_type; protected: value_type value{json}; public: inline constexpr operator value_type() const { return this->value; }; inline constexpr rocalution_benchfile_format(){}; inline constexpr rocalution_benchfile_format(int ival) : value((value_type)ival) { } static constexpr value_type all[2] = {rocalution_benchfile_format::json, rocalution_benchfile_format::yaml}; inline bool is_invalid() const { switch(this->value) { case json: case yaml: { return false; } } return true; }; inline rocalution_benchfile_format(const char* ext) { if(!strcmp(ext, ".json")) { value = json; } else if(!strcmp(ext, ".JSON")) { value = json; } else if(!strcmp(ext, ".yaml")) { value = yaml; } else if(!strcmp(ext, ".YAML")) { value = yaml; } else value = (value_type)-1; }; inline const char* to_string() const { switch(this->value) { #define CASE(case_name) \ case case_name: \ { \ return #case_name; \ } CASE(json); CASE(yaml); #undef CASE } return "unknown"; } }; // // Struct collecting benchmark timing results. // struct rocalution_bench_timing_t { // // Local item. // struct item_t { int m_nruns{}; std::vector m_results; rocalution_bench_solver_parameters m_parameters{}; item_t(){}; item_t(int nruns_) : m_nruns(nruns_) , m_results(nruns_){}; item_t& operator()(int nruns_) { this->m_nruns = nruns_; this->m_results.resize(nruns_); return *this; }; bool record(const rocalution_bench_solver_parameters& parameters) { m_parameters = parameters; return true; } bool record(int irun, const rocalution_bench_solver_results& results) { if(irun >= 0 && irun < m_nruns) { this->m_results[irun] = results; return true; } else { rocalution_bench_errmsg << "out of bounds from item_t::record " << std::endl; return false; } } }; 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]; } rocalution_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 rocalution_bench_app_base { protected: // // Record initial command line. // int m_initial_argc; char** m_initial_argv; // // Set of command lines. // rocalution_bench_cmdlines m_bench_cmdlines; // // // rocalution_bench_timing_t m_bench_timing; bool m_stdout_skip_legend{}; 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. // rocalution_bench_app_base(int argc, char** argv); // // @brief Run case. // bool 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 stdout_skip_legend() const { return this->m_stdout_skip_legend; } // // @brief Run cases. // bool run_cases(); }; class rocalution_bench_app : public rocalution_bench_app_base { private: static rocalution_bench_app* s_instance; public: static rocalution_bench_app* instance(int argc, char** argv) { s_instance = new rocalution_bench_app(argc, argv); return s_instance; } static rocalution_bench_app* instance() { return s_instance; } rocalution_bench_app(const rocalution_bench_app&) = delete; rocalution_bench_app& operator=(const rocalution_bench_app&) = delete; static bool applies(int argc, char** argv) { return rocalution_bench_cmdlines::applies(argc, argv); } rocalution_bench_app(int argc, char** argv); ~rocalution_bench_app(); bool export_file(); bool record_results(const rocalution_bench_solver_parameters& parameters, const rocalution_bench_solver_results& results) { if(this->m_irun == 0) { this->m_bench_timing[this->m_isample].record(parameters); } return this->m_bench_timing[this->m_isample].record(this->m_irun, results); } protected: void export_item(std::ostream& out, rocalution_bench_timing_t::item_t& item); bool define_case_json(std::ostream& out, int isample, int argc, char** argv); bool close_case_json(std::ostream& out, int isample, int argc, char** argv); bool define_results_json(std::ostream& out); bool close_results_json(std::ostream& out); static void confidence_interval(const double alpha, const int resize, const int nboots, const std::vector& v, double interval[2]); static void series_lower_upper(int N, const std::vector& r, rocalution_bench_solver_results::e_double e, double& median, double& lower, double& upper); }; rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_bench_cmdlines.cpp000066400000000000000000000054321507377332500257720ustar00rootroot00000000000000#include "rocalution_bench_cmdlines.hpp" // // @brief Get the output filename. // const char* rocalution_bench_cmdlines::get_ofilename() const { return this->m_cmd.get_ofilename(); } // // @brief Get the number of samples.. // int rocalution_bench_cmdlines::get_nsamples() const { return this->m_cmd.get_nsamples(); }; int rocalution_bench_cmdlines::get_option_index_x() const { return this->m_cmd.get_option_index_x(); }; int rocalution_bench_cmdlines::get_option_nargs(int i) { return this->m_cmd.get_option_nargs(i); } const char* rocalution_bench_cmdlines::get_option_arg(int i, int j) { return this->m_cmd.get_option_arg(i, j); } const char* rocalution_bench_cmdlines::get_option_name(int i) { return this->m_cmd.get_option_name(i); } int rocalution_bench_cmdlines::get_noptions_x() const { return this->m_cmd.get_noptions_x(); }; int rocalution_bench_cmdlines::get_noptions() const { return this->m_cmd.get_noptions(); }; bool rocalution_bench_cmdlines::is_stdout_disabled() const { return this->m_cmd.is_stdout_disabled(); }; // // @brief Get the number of runs per sample. // int rocalution_bench_cmdlines::get_nruns() const { return this->m_cmd.get_nruns(); }; // // @brief Copy the command line arguments corresponding to a given sample. // void rocalution_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 rocalution_bench_cmdlines::get_argc(int isample, int& argc_) const { argc_ = this->m_cmdset[isample].argc; } // // @brief Constructor. // rocalution_bench_cmdlines::rocalution_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 rocalution_bench_cmdlines::applies(int argc, char** argv) { for(int i = 1; i < argc; ++i) { if(!strcmp(argv[i], "--bench-x") || !strcmp(argv[i], "--bench-o") || !strcmp(argv[i], "--bench-n") || !strcmp(argv[i], "--bench-std")) { return true; } } return false; } void rocalution_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; } } rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_bench_cmdlines.hpp000066400000000000000000000442411507377332500260000ustar00rootroot00000000000000/*! \file */ /* ************************************************************************ * 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 #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 rocalution_bench_cmdlines { private: struct val { // // Everything is public. // public: int argc{}; char** argv{}; ~val() { if(this->argv != nullptr) { delete[] this->argv; this->argv = nullptr; } } val(){}; 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; } int 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; } // // 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_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 int 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(int 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{}; cmdline_arg(char* name_) : name(name_){}; }; // // argument option. // struct cmdline_option { char* name{}; std::vector args{}; 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}; int m_option_index_x; int m_nsamples; bool m_is_stdout_disabled{true}; const char* m_ofilename{}; }; private: cmdline m_cmd; val* m_cmdset{}; public: // // @brief Get the output filename. // const char* get_ofilename() const; // // @brief Get the number of samples.. // int get_nsamples() const; int 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; // // @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; // // @brief Constructor. // rocalution_bench_cmdlines(int argc, char** argv); static bool applies(int argc, char** argv); // // @brief Some info. // void info() const; }; rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_bench_itsolver.hpp000066400000000000000000000200251507377332500260430ustar00rootroot00000000000000/* ************************************************************************ * 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 #include "rocalution_bench_solver_results.hpp" #include // // @brief Simple struct to hold the definition of a linear system. // template struct rocalution_linear_system { LocalMatrix A{}; LocalVector B{}; LocalVector X{}; LocalVector S{}; }; // // @brief Base struct for rocalution_bench. // @details This structure is a base structure that contains the linear system to solve. template struct rocalution_bench_itsolver { public: using results_t = rocalution_bench_solver_results; private: rocalution_linear_system m_linsys; protected: static constexpr bool s_verbose = false; // // @brief Import the linear system Ax=b // @param[out] // A matrix to import. // @param[out] // B right-hand-side to import. // @param[out] // S solution to import. // @return true if successful, false otherwise. // virtual bool ImportLinearSystem(LocalMatrix& A, LocalVector& B, LocalVector& S) = 0; // // @brief Presolve the linear system. // @note This should only be call once. // virtual bool AnalyzeLinearSystem(LocalMatrix& A, LocalVector& B, LocalVector& X) = 0; // // @brief Solve the linear system. // virtual bool SolveLinearSystem(LocalMatrix& A, LocalVector& B, LocalVector& X, results_t& results) = 0; // // @brief Log bench results. // virtual bool LogBenchResults(LocalMatrix& A, LocalVector& B, LocalVector& X, LocalVector& S, results_t& results) = 0; // // Compute error approximation. // bool ComputeErrorApproximation(const LocalVector& X, const LocalVector& S, LocalVector& E, results_t& results) { const auto N = X.GetSize(); E.CopyFrom(X, 0, 0, N); E.ScaleAdd(-1.0, S); const T nrm2 = E.Norm(); results.Set(results_t::norm_residual, nrm2); // // Compute some statistics about the error distribution. // { E.MoveToHost(); T* v = new T[N]; for(auto i = 0; i < N; ++i) { v[i] = T(std::abs(E[i])); } std::sort(v, v + N); results.Set(results_t::nrmmax_err, v[N - 1]); results.Set(results_t::nrmmax95_err, v[((N - 1) * 95) / 100]); results.Set(results_t::nrmmax75_err, v[((N - 1) * 75) / 100]); results.Set(results_t::nrmmax50_err, v[((N - 1) * 50) / 100]); delete[] v; E.MoveToAccelerator(); } return true; }; public: virtual ~rocalution_bench_itsolver(){}; bool Run(results_t& results) { #define TIC(var_) double var_ = rocalution_time() #define TAC(var_) var_ = ((rocalution_time() - var_) / 1e3) TIC(t_run); // // Import the linear system. // if(s_verbose) { std::cout << "Import linear system ..." << std::endl; } TIC(t_import_linear_system); { bool success = this->ImportLinearSystem(this->m_linsys.A, this->m_linsys.B, this->m_linsys.S); if(!success) { rocalution_bench_errmsg << "ImportLinearSystem failed." << std::endl; return false; } } TAC(t_import_linear_system); if(s_verbose) { std::cout << "Import linear system done." << std::endl; } // // Create unknown vector. // this->m_linsys.X.MoveToAccelerator(); this->m_linsys.X.Allocate("x", this->m_linsys.A.GetN()); this->m_linsys.X.Zeros(); // // Analyze the linear system. // if(s_verbose) { std::cout << "Analyze linear system ..." << std::endl; } TIC(t_analyze_linear_system); { bool success = this->AnalyzeLinearSystem(this->m_linsys.A, this->m_linsys.B, this->m_linsys.X); if(!success) { rocalution_bench_errmsg << "AnalyzeLinearSystem failed." << std::endl; return false; } } TAC(t_analyze_linear_system); if(s_verbose) { std::cout << "Analyze linear system done." << std::endl; } // // Solve the linear system. // if(s_verbose) { std::cout << "Solve linear system ..." << std::endl; } TIC(t_solve_linear_system); { bool success = this->SolveLinearSystem( this->m_linsys.A, this->m_linsys.B, this->m_linsys.X, results); if(!success) { rocalution_bench_errmsg << "SolveLinearSystem failed." << std::endl; return false; } } TAC(t_solve_linear_system); if(s_verbose) { std::cout << "Solve linear system done." << std::endl; } // // Compute Error Approximation. // if(s_verbose) { std::cout << "Compute error approximation ..." << std::endl; } { LocalVector E; E.MoveToAccelerator(); E.Allocate("e", this->m_linsys.X.GetSize()); bool success = this->ComputeErrorApproximation(this->m_linsys.X, this->m_linsys.S, E, results); if(!success) { rocalution_bench_errmsg << "ComputeErrorApproximation failed." << std::endl; return false; } } if(s_verbose) { std::cout << "Compute error approximation done." << std::endl; } TAC(t_run); // // LOG RESULTS. // results.Set(results_t::time_import, t_import_linear_system); results.Set(results_t::time_analyze, t_analyze_linear_system); results.Set(results_t::time_solve, t_solve_linear_system); results.Set(results_t::time_global, t_run); { bool success = this->LogBenchResults( this->m_linsys.A, this->m_linsys.B, this->m_linsys.X, this->m_linsys.S, results); if(!success) { rocalution_bench_errmsg << "LogBenchResults failed." << std::endl; return false; } } return true; } }; rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_bench_itsolver_impl.hpp000066400000000000000000000166421507377332500270760ustar00rootroot00000000000000/* ************************************************************************ * 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 #include using namespace rocalution; #include "rocalution_bench_itsolver.hpp" #include "rocalution_driver_itsolver_fgmres.hpp" #include "rocalution_driver_itsolver_gmres.hpp" #include "rocalution_driver_itsolver_uaamg.hpp" static constexpr bool s_verbose = true; bool rocalution_bench_record_results(const rocalution_bench_solver_parameters&, const rocalution_bench_solver_results&); // // @brief This structure is an implementation of \ref rocalution_bench_itsolver. // template struct rocalution_bench_itsolver_impl : public rocalution_bench_itsolver { using driver_traits_t = rocalution_driver_itsolver_traits; using solver_t = typename driver_traits_t::solver_t; using results_t = rocalution_bench_solver_results; using params_t = rocalution_bench_solver_parameters; private: // // @brief Input parameters. // const rocalution_bench_solver_parameters* m_params{}; // // @brief Output results. // results_t* m_results{}; // // @brief Solver. // solver_t m_solver{}; // // @brief Iterative Driver. // rocalution_driver_itsolver m_driver{}; public: rocalution_bench_itsolver_impl(const params_t* parameters, results_t* results) : m_params(parameters) , m_results(results){}; virtual ~rocalution_bench_itsolver_impl() { this->m_solver.Clear(); }; // // @copydoc rocalution_bench_itsolver::ImportLinearSystem // virtual bool ImportLinearSystem(LocalMatrix& A, LocalVector& B, LocalVector& S) override { // // Import linear system. // bool success = this->m_driver.ImportLinearSystem(A, B, S, *this->m_params); if(!success) { rocalution_bench_errmsg << "import linear system failed." << std::endl; return false; } // // Move to accelerator. // A.MoveToAccelerator(); S.MoveToAccelerator(); B.MoveToAccelerator(); // // Finalize the import. // success = this->m_driver.PostprocessImportLinearSystem(A, B, S, *this->m_params); if(!success) { rocalution_bench_errmsg << "post process Import linear system failed." << std::endl; return false; } return true; } // // @copydoc rocalution_bench_itsolver::LogBenchResults // virtual bool LogBenchResults(LocalMatrix& A, LocalVector& B, LocalVector& X, LocalVector& S, results_t& results) override { return rocalution_bench_record_results(*this->m_params, results); } // // @copydoc rocalution_bench_itsolver::AnalyzeLinearSystem // virtual bool AnalyzeLinearSystem(LocalMatrix& A, LocalVector& B, LocalVector& X) override { // // Configure linear solver. // { if(s_verbose) { std::cout << "AnalyzeLinearSystem ConfigureLinearSolver ..." << std::endl; std::cout << "A.M = " << A.GetM() << std::endl; std::cout << "A.N = " << A.GetN() << std::endl; std::cout << "A.NNZ = " << A.GetNnz() << std::endl; } { bool success = this->m_driver.ConfigureLinearSolver( A, B, X, this->m_solver, *this->m_params); if(!success) { rocalution_bench_errmsg << "configure linear solver failed." << std::endl; return false; } } if(s_verbose) { std::cout << "AnalyzeLinearSystem ConfigureLinearSolver done." << std::endl; } } // // Convert the matrix to the required format. // { if(s_verbose) { std::cout << "AnalyzeLinearSystem ConvertTo..." << std::endl; } { auto format = this->m_params->Get(params_t::format); if(s_verbose) { std::cout << "AnalyzeLinearSystem ConvertTo ... format = " << format << " ... " << std::endl; } const auto blockdim = this->m_params->Get(params_t::blockdim); A.ConvertTo(format, format == BCSR ? blockdim : 1); } if(s_verbose) { std::cout << "AnalyzeLinearSystem ConvertTo done." << std::endl; } } return true; } // // @copydoc rocalution_bench_itsolver::SolveLinearSystem // virtual bool SolveLinearSystem(LocalMatrix& A, LocalVector& B, LocalVector& X, results_t& results) override { // // Pre-solve. // if(!this->m_driver.PreprocessLinearSolve(A, B, X, this->m_solver, *this->m_params)) { rocalution_bench_errmsg << "preprocess linear solve failed." << std::endl; return false; } // // Solve // this->m_solver.Solve(B, &X); // // Post solve. // if(!this->m_driver.PostprocessLinearSolve(A, B, X, this->m_solver, *this->m_params)) { rocalution_bench_errmsg << "postprocess linear solve failed." << std::endl; return false; } // // Record results. // results.Set(results_t::iter, this->m_solver.GetIterationCount()); results.Set(results_t::norm_residual, this->m_solver.GetCurrentResidual()); { auto status = this->m_solver.GetSolverStatus(); results.Set(results_t::convergence, (status == 1) ? true : false); } return true; } }; rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_bench_solver.hpp000066400000000000000000000072241507377332500255140ustar00rootroot00000000000000/* ************************************************************************ * 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 #include "rocalution_bench_itsolver_impl.hpp" // // @brief Core structure responsible of configuring the benchmark from parsing command line arguments // and execute it. // template struct rocalution_bench_solver { private: rocalution_bench_itsolver* m_itsolver{}; rocalution_bench_solver_results m_output_results{}; const rocalution_bench_solver_parameters* m_input_parameters{}; public: ~rocalution_bench_solver() { if(this->m_itsolver) { delete this->m_itsolver; this->m_itsolver = nullptr; } } rocalution_bench_solver(const rocalution_bench_solver_parameters* config) : m_input_parameters(config) { // // Try to config iterative solver. // const rocalution_enum_itsolver enum_itsolver = this->m_input_parameters->GetEnumIterativeSolver(); if(enum_itsolver.is_invalid()) { rocalution_bench_errmsg << "invalid iterative solver." << std::endl; throw false; } this->m_itsolver = nullptr; switch(enum_itsolver.value) { // // Define cases. // #define ROCALUTION_ENUM_ITSOLVER_TRANSFORM(x_) \ case rocalution_enum_itsolver::x_: \ { \ this->m_itsolver = new rocalution_bench_itsolver_impl( \ this->m_input_parameters, &this->m_output_results); \ break; \ } // // Generate cases. // ROCALUTION_ENUM_ITSOLVER_TRANSFORM_EACH; // // Undefine cases. // #undef ROCALUTION_ENUM_ITSOLVER_TRANSFORM } if(this->m_itsolver == nullptr) { rocalution_bench_errmsg << "iterative solver instantiation failed." << std::endl; throw false; } } bool Run() { if(this->m_itsolver != nullptr) { return this->m_itsolver->Run(this->m_output_results); } return false; } }; rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_bench_solver_parameters.cpp000066400000000000000000000152411507377332500277300ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2022-2023 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "rocalution_bench_solver_parameters.hpp" rocalution_enum_smoother rocalution_bench_solver_parameters::GetEnumSmoother() const { return this->m_enum_smoother; }; rocalution_enum_coarsening_strategy rocalution_bench_solver_parameters::GetEnumCoarseningStrategy() const { return this->m_enum_coarsening_strategy; }; rocalution_enum_preconditioner rocalution_bench_solver_parameters::GetEnumPreconditioner() const { return this->m_enum_preconditioner; }; rocalution_enum_itilu0_alg rocalution_bench_solver_parameters::GetEnumItILU0Algorithm() const { return this->m_enum_itilu0_alg; }; rocalution_enum_itsolver rocalution_bench_solver_parameters::GetEnumIterativeSolver() const { return this->m_enum_itsolver; }; rocalution_enum_directsolver rocalution_bench_solver_parameters::GetEnumDirectSolver() const { return this->m_enum_directsolver; }; rocalution_enum_matrix_init rocalution_bench_solver_parameters::GetEnumMatrixInit() const { return this->m_enum_matrix_init; }; constexpr rocalution_bench_solver_parameters::e_bool rocalution_bench_solver_parameters::e_bool_all[]; constexpr rocalution_bench_solver_parameters::e_int rocalution_bench_solver_parameters::e_int_all[]; constexpr rocalution_bench_solver_parameters::e_string rocalution_bench_solver_parameters::e_string_all[]; constexpr rocalution_bench_solver_parameters::e_uint rocalution_bench_solver_parameters::e_uint_all[]; constexpr rocalution_bench_solver_parameters::e_double rocalution_bench_solver_parameters::e_double_all[]; constexpr const char* rocalution_bench_solver_parameters::e_bool_names[]; constexpr const char* rocalution_bench_solver_parameters::e_int_names[]; constexpr const char* rocalution_bench_solver_parameters::e_string_names[]; constexpr const char* rocalution_bench_solver_parameters::e_uint_names[]; constexpr const char* rocalution_bench_solver_parameters::e_double_names[]; bool rocalution_bench_solver_parameters::Get(e_bool v) const { return this->bool_values[v]; } void rocalution_bench_solver_parameters::Set(e_bool v, bool s) { this->bool_values[v] = s; } std::string rocalution_bench_solver_parameters::Get(e_string v) const { return this->string_values[v]; } void rocalution_bench_solver_parameters::Set(e_string v, const std::string& s) { this->string_values[v] = s; } unsigned int rocalution_bench_solver_parameters::Get(e_uint v) const { return this->uint_values[v]; } void rocalution_bench_solver_parameters::Set(e_uint v, unsigned int s) { this->uint_values[v] = s; } int rocalution_bench_solver_parameters::Get(e_int v) const { return this->int_values[v]; } void rocalution_bench_solver_parameters::Set(e_int v, int s) { this->int_values[v] = s; } double rocalution_bench_solver_parameters::Get(e_double v) const { return this->double_values[v]; } void rocalution_bench_solver_parameters::Set(e_double v, double s) { this->double_values[v] = s; } bool* rocalution_bench_solver_parameters::GetPointer(e_bool v) { return &this->bool_values[v]; } std::string* rocalution_bench_solver_parameters::GetPointer(e_string v) { return &this->string_values[v]; } unsigned int* rocalution_bench_solver_parameters::GetPointer(e_uint v) { return &this->uint_values[v]; } int* rocalution_bench_solver_parameters::GetPointer(e_int v) { return &this->int_values[v]; } double* rocalution_bench_solver_parameters::GetPointer(e_double v) { return &this->double_values[v]; } void rocalution_bench_solver_parameters::WriteNicely(std::ostream& out) const { out.precision(2); out.setf(std::ios::fixed); out.setf(std::ios::left); out << std::scientific; for(auto e : e_bool_all) { out << std::setw(20) << e_bool_names[e] << " " << std::setw(20) << bool_values[e]; out << std::endl; } for(auto e : e_int_all) { out << std::setw(20) << e_int_names[e] << " " << std::setw(20) << int_values[e]; out << std::endl; } for(auto e : e_double_all) { out << std::setw(20) << e_double_names[e] << " " << std::setw(20) << double_values[e]; out << std::endl; } for(auto e : e_uint_all) { out << std::setw(20) << e_uint_names[e] << " " << std::setw(20) << uint_values[e]; out << std::endl; } for(auto e : e_string_all) { out << std::setw(20) << e_string_names[e] << " " << std::setw(20) << string_values[e]; out << std::endl; } } void rocalution_bench_solver_parameters::WriteJson(std::ostream& out) const { bool first = false; for(auto e : e_bool_all) { if(!first) first = true; else out << "," << std::endl; out << "\"" << e_bool_names[e] << "\" : " << "\"" << bool_values[e] << "\""; } for(auto e : e_int_all) { out << "," << std::endl; out << "\"" << e_int_names[e] << "\" : " << "\"" << int_values[e] << "\""; } for(auto e : e_double_all) { out << "," << std::endl; out << "\"" << e_double_names[e] << "\" : " << "\"" << double_values[e] << "\""; } for(auto e : e_uint_all) { out << "," << std::endl; out << "\"" << e_uint_names[e] << "\" : " << "\"" << uint_values[e] << "\""; } for(auto e : e_string_all) { out << "," << std::endl; out << "\"" << e_string_names[e] << "\" : " << "\"" << string_values[e] << "\""; } } rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_bench_solver_parameters.hpp000066400000000000000000000271531507377332500277420ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2022-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 #include "rocalution_enum_coarsening_strategy.hpp" #include "rocalution_enum_directsolver.hpp" #include "rocalution_enum_itilu0_alg.hpp" #include "rocalution_enum_itsolver.hpp" #include "rocalution_enum_matrix_init.hpp" #include "rocalution_enum_preconditioner.hpp" #include "rocalution_enum_smoother.hpp" #include // // @brief Structure responsible of the parameter definitions and values. // struct rocalution_bench_solver_parameters { protected: // // @brief Which matrix initialization. // rocalution_enum_matrix_init m_enum_matrix_init{}; // // @brief Which ItILU0 algorithm. // rocalution_enum_itilu0_alg m_enum_itilu0_alg{}; // // @brief Which iterative solver. // rocalution_enum_itsolver m_enum_itsolver{}; // // @brief Which preconditioner. // rocalution_enum_preconditioner m_enum_preconditioner{}; // // @brief Which smoother. // rocalution_enum_smoother m_enum_smoother{}; // // @brief Which direct solver. // rocalution_enum_directsolver m_enum_directsolver{}; // // @brief Which coarsening_strategy. // rocalution_enum_coarsening_strategy m_enum_coarsening_strategy{}; public: // // @brief Get which direct solver. // rocalution_enum_directsolver GetEnumDirectSolver() const; // // @brief Get which smoother. // rocalution_enum_smoother GetEnumSmoother() const; // // @brief Get which coarsening_strategy. // rocalution_enum_coarsening_strategy GetEnumCoarseningStrategy() const; // // @brief Get which preconditioner // rocalution_enum_preconditioner GetEnumPreconditioner() const; // // @brief Get which iterative solver. // rocalution_enum_itsolver GetEnumIterativeSolver() const; // // @brief Get which ItILU0 algorithm. // rocalution_enum_itilu0_alg GetEnumItILU0Algorithm() const; // // @brief Get which matrix initialization // rocalution_enum_matrix_init GetEnumMatrixInit() const; // // @brief Define Boolean parameters // // clang-format off #define PBOOL_TRANSFORM_EACH \ PBOOL_TRANSFORM(iterative_solve) \ PBOOL_TRANSFORM(verbose) \ PBOOL_TRANSFORM(mcilu_use_level) // clang-format on #define PBOOL_TRANSFORM(x_) x_, typedef enum e_bool_ : int { PBOOL_TRANSFORM_EACH } e_bool; static constexpr e_bool e_bool_all[] = {PBOOL_TRANSFORM_EACH}; #undef PBOOL_TRANSFORM // // @brief Define Integer parameters // // clang-format off #define PINT_TRANSFORM_EACH \ PINT_TRANSFORM(krylov_basis) \ PINT_TRANSFORM(ndim) \ PINT_TRANSFORM(ilut_n) \ PINT_TRANSFORM(itsolve_max_iter) \ PINT_TRANSFORM(itilu0_max_iter) \ PINT_TRANSFORM(itilu0_options) \ PINT_TRANSFORM(mcilu_p) \ PINT_TRANSFORM(mcilu_q) \ PINT_TRANSFORM(max_iter) \ PINT_TRANSFORM(solver_pre_smooth) \ PINT_TRANSFORM(solver_post_smooth) \ PINT_TRANSFORM(solver_ordering) \ PINT_TRANSFORM(rebuild_numeric) \ PINT_TRANSFORM(cycle) \ PINT_TRANSFORM(solver_coarsest_level) \ PINT_TRANSFORM(blockdim) // clang-format on #define PINT_TRANSFORM(x_) x_, typedef enum e_int_ : int { PINT_TRANSFORM_EACH } e_int; static constexpr e_int e_int_all[] = {PINT_TRANSFORM_EACH}; #undef PINT_TRANSFORM // // @brief Define String parameters // // clang-format off #define PSTRING_TRANSFORM_EACH \ PSTRING_TRANSFORM(coarsening_strategy) \ PSTRING_TRANSFORM(direct_solver) \ PSTRING_TRANSFORM(iterative_solver) \ PSTRING_TRANSFORM(itilu0_alg) \ PSTRING_TRANSFORM(matrix) \ PSTRING_TRANSFORM(matrix_filename) \ PSTRING_TRANSFORM(preconditioner) \ PSTRING_TRANSFORM(smoother) // clang-format on #define PSTRING_TRANSFORM(x_) x_, typedef enum e_string_ : int { PSTRING_TRANSFORM_EACH } e_string; static constexpr e_string e_string_all[] = {PSTRING_TRANSFORM_EACH}; #undef PSTRING_TRANSFORM // // @brief Define Unsigned integer parameters // // clang-format off #define PUINT_TRANSFORM_EACH \ PUINT_TRANSFORM(format) // clang-format on #define PUINT_TRANSFORM(x_) x_, typedef enum e_uint_ : int { PUINT_TRANSFORM_EACH } e_uint; static constexpr e_uint e_uint_all[] = {PUINT_TRANSFORM_EACH}; #undef PUINT_TRANSFORM // // @brief Define Double parameters // // clang-format off #define PDOUBLE_TRANSFORM_EACH \ PDOUBLE_TRANSFORM(abs_tol) \ PDOUBLE_TRANSFORM(rel_tol) \ PDOUBLE_TRANSFORM(div_tol) \ PDOUBLE_TRANSFORM(residual_tol) \ PDOUBLE_TRANSFORM(ilut_tol) \ PDOUBLE_TRANSFORM(itsolve_tol) \ PDOUBLE_TRANSFORM(itilu0_tol) \ PDOUBLE_TRANSFORM(mcgs_relax) \ PDOUBLE_TRANSFORM(solver_over_interp) \ PDOUBLE_TRANSFORM(solver_coupling_strength) \ // clang-format on #define PDOUBLE_TRANSFORM(x_) x_, typedef enum e_double_ : int { PDOUBLE_TRANSFORM_EACH } e_double; static constexpr e_double e_double_all[] = {PDOUBLE_TRANSFORM_EACH}; #undef PDOUBLE_TRANSFORM private: // // @brief Number of string parameters // static constexpr std::size_t e_string_size = countof(e_string_all); // // @brief Number of unsigned integer parameters // static constexpr std::size_t e_uint_size = countof(e_uint_all); // // @brief Number of Boolean parameters // static constexpr std::size_t e_bool_size = countof(e_bool_all); // // @brief Number of integer parameters // static constexpr std::size_t e_int_size = countof(e_int_all); // // @brief Number of double parameters // static constexpr std::size_t e_double_size = countof(e_double_all); // // @brief Array of Boolean parameter names. // #define PBOOL_TRANSFORM(x_) #x_, static constexpr const char* e_bool_names[e_bool_size]{PBOOL_TRANSFORM_EACH}; #undef PBOOL_TRANSFORM // // @brief Array of unsigned integer parameter names. // #define PUINT_TRANSFORM(x_) #x_, static constexpr const char* e_uint_names[e_uint_size]{PUINT_TRANSFORM_EACH}; #undef PUINT_TRANSFORM // // @brief Array of string parameter names. // #define PSTRING_TRANSFORM(x_) #x_, static constexpr const char* e_string_names[e_string_size]{PSTRING_TRANSFORM_EACH}; #undef PSTRING_TRANSFORM // // @brief Array of integer parameter names. // #define PINT_TRANSFORM(x_) #x_, static constexpr const char* e_int_names[e_int_size]{PINT_TRANSFORM_EACH}; #undef PINT_TRANSFORM // // @brief Array of Double parameter names. // #define PDOUBLE_TRANSFORM(x_) #x_, static constexpr const char* e_double_names[e_double_size]{PDOUBLE_TRANSFORM_EACH}; #undef PDOUBLE_TRANSFORM // // @brief Array of Boolean parameter values. // bool bool_values[e_bool_size]{}; // // @brief Array of Unsigned integer parameter values. // unsigned int uint_values[e_uint_size]{}; // // @brief Array of Integer parameter values. // int int_values[e_int_size]{}; // // @brief Array of string parameter values. // std::string string_values[e_string_size]{}; // // @brief Array of Double parameter values. // double double_values[e_double_size]{}; public: static const char* GetName(e_bool v) { return e_bool_names[v]; } static const char* GetName(e_int v) { return e_int_names[v]; } static const char* GetName(e_uint v) { return e_uint_names[v]; } static const char* GetName(e_double v) { return e_double_names[v]; } static const char* GetName(e_string v) { return e_string_names[v]; } // // @brief Get pointer to string parameter value. // std::string* GetPointer(e_string v); // // @brief Get string parameter value. // std::string Get(e_string v) const; // // @brief Set string parameter value. // void Set(e_string v, const std::string& s); // // @brief Get unsigned int parameter value. // unsigned int Get(e_uint v) const; // // @brief Get pointer to unsigned int parameter value. // unsigned int* GetPointer(e_uint v); // // @brief Set unsigned int parameter value. // void Set(e_uint v, unsigned int s); // // @brief Get Boolean parameter value. // bool Get(e_bool v) const; // // @brief Get pointer to Boolean parameter value. // bool* GetPointer(e_bool v); // // @brief Set Boolean parameter value. // void Set(e_bool v, bool s); // // @brief Get integer parameter value. // int Get(e_int v) const; // // @brief Get pointer to integer parameter value. // int* GetPointer(e_int v); // // @brief Set integer parameter value. // void Set(e_int v, int s); // // @brief Get double parameter value. // double Get(e_double v) const; // // @brief Get pointer to double parameter value. // double* GetPointer(e_double v); // // @brief Set double parameter value. // void Set(e_double v, double s); // // @brief Write information // void Info(std::ostream& out) const { out.setf(std::ios::left); out << "bool: " << std::endl; for(auto e : e_bool_all) { out << std::setw(20) << e_bool_names[e] << std::setw(20) << bool_values[e] << std::endl; } out << "int: " << std::endl; for(auto e : e_int_all) { out << std::setw(20) << e_int_names[e] << std::setw(20) << int_values[e] << std::endl; } out << "uint: " << std::endl; for(auto e : e_uint_all) { out << std::setw(20) << e_uint_names[e] << std::setw(20) << uint_values[e] << std::endl; } out << "double: " << std::endl; for(auto e : e_double_all) { out << std::setw(20) << e_double_names[e] << std::setw(20) << double_values[e] << std::endl; } out << "string: " << std::endl; for(auto e : e_string_all) { out << std::setw(20) << e_string_names[e] << "'" << string_values[e] << "'" << std::endl; } } void WriteJson(std::ostream& out) const; void WriteNicely(std::ostream& out) const; }; rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_bench_solver_results.cpp000066400000000000000000000075541507377332500272760ustar00rootroot00000000000000/* ************************************************************************ * 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 "rocalution_bench_solver_results.hpp" constexpr rocalution_bench_solver_results::e_bool rocalution_bench_solver_results::e_bool_all[]; constexpr rocalution_bench_solver_results::e_int rocalution_bench_solver_results::e_int_all[]; constexpr rocalution_bench_solver_results::e_double rocalution_bench_solver_results::e_double_all[]; constexpr const char* rocalution_bench_solver_results::e_bool_names[]; constexpr const char* rocalution_bench_solver_results::e_int_names[]; constexpr const char* rocalution_bench_solver_results::e_double_names[]; bool rocalution_bench_solver_results::Get(e_bool v) const { return bool_values[v]; } void rocalution_bench_solver_results::Set(e_bool v, bool s) { bool_values[v] = s; } int rocalution_bench_solver_results::Get(e_int v) const { return int_values[v]; } void rocalution_bench_solver_results::Set(e_int v, int s) { int_values[v] = s; } double rocalution_bench_solver_results::Get(e_double v) const { return double_values[v]; } void rocalution_bench_solver_results::Set(e_double v, double s) { double_values[v] = s; } void rocalution_bench_solver_results::WriteJson(std::ostream& out) const { bool first = false; for(auto e : e_bool_all) { if(!first) first = true; else out << ","; out << "\"" << e_bool_names[e] << "\" : " << "\"" << bool_values[e] << "\""; } for(auto e : e_int_all) { if(!first) first = true; else out << ","; out << "\"" << e_int_names[e] << "\" : " << "\"" << int_values[e] << "\""; } for(auto e : e_double_all) { if(!first) first = true; else out << ","; out << "\"" << e_double_names[e] << "\" : " << "\"" << double_values[e] << "\""; } } void rocalution_bench_solver_results::WriteNicely(std::ostream& out) const { out.precision(2); out.setf(std::ios::fixed); out.setf(std::ios::left); out << std::scientific; for(auto e : e_bool_all) { out << std::setw(14) << e_bool_names[e]; } for(auto e : e_int_all) { out << std::setw(14) << e_int_names[e]; } for(auto e : e_double_all) { out << std::setw(14) << e_double_names[e]; } out << std::endl; for(auto e : e_bool_all) { out << std::setw(14) << bool_values[e]; } for(auto e : e_int_all) { out << std::setw(14) << int_values[e]; } for(auto e : e_double_all) { out << std::setw(14) << double_values[e]; } out << std::endl; } rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_bench_solver_results.hpp000066400000000000000000000113111507377332500272650ustar00rootroot00000000000000/* ************************************************************************ * 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 #include "rocalution_enum_itsolver.hpp" #include "rocalution_enum_preconditioner.hpp" #include "rocalution_enum_smoother.hpp" #include struct rocalution_bench_solver_results { // clang-format off #define RESBOOL_TRANSFORM_EACH \ RESBOOL_TRANSFORM(convergence) // clang-format on #define RESBOOL_TRANSFORM(x_) x_, typedef enum e_bool_ : int { RESBOOL_TRANSFORM_EACH } e_bool; static constexpr e_bool e_bool_all[] = {RESBOOL_TRANSFORM_EACH}; #undef RESBOOL_TRANSFORM // clang-format off #define RESINT_TRANSFORM_EACH \ RESINT_TRANSFORM(iter) // clang-format on #define RESINT_TRANSFORM(x_) x_, typedef enum e_int_ : int { RESINT_TRANSFORM_EACH } e_int; static constexpr e_int e_int_all[] = {RESINT_TRANSFORM_EACH}; #undef RESINT_TRANSFORM // clang-format off #define RESDOUBLE_TRANSFORM_EACH \ RESDOUBLE_TRANSFORM(time_import) \ RESDOUBLE_TRANSFORM(time_analyze) \ RESDOUBLE_TRANSFORM(time_solve) \ RESDOUBLE_TRANSFORM(time_global) \ RESDOUBLE_TRANSFORM(norm_residual) \ RESDOUBLE_TRANSFORM(nrmmax_err) \ RESDOUBLE_TRANSFORM(nrmmax95_err) \ RESDOUBLE_TRANSFORM(nrmmax75_err) \ RESDOUBLE_TRANSFORM(nrmmax50_err) // clang-format on #define RESDOUBLE_TRANSFORM(x_) x_, typedef enum e_double_ : int { RESDOUBLE_TRANSFORM_EACH } e_double; static constexpr e_double e_double_all[] = {RESDOUBLE_TRANSFORM_EACH}; #undef RESDOUBLE_TRANSFORM private: static constexpr std::size_t e_bool_size = countof(e_bool_all); static constexpr std::size_t e_int_size = countof(e_int_all); static constexpr std::size_t e_double_size = countof(e_double_all); #define RESBOOL_TRANSFORM(x_) #x_, static constexpr const char* e_bool_names[e_bool_size]{RESBOOL_TRANSFORM_EACH}; #undef RESBOOL_TRANSFORM #define RESINT_TRANSFORM(x_) #x_, static constexpr const char* e_int_names[e_int_size]{RESINT_TRANSFORM_EACH}; #undef RESINT_TRANSFORM #define RESDOUBLE_TRANSFORM(x_) #x_, static constexpr const char* e_double_names[e_double_size]{RESDOUBLE_TRANSFORM_EACH}; #undef RESDOUBLE_TRANSFORM bool bool_values[e_bool_size]{}; int int_values[e_int_size]{}; double double_values[e_double_size]{}; public: static const char* Name(e_bool v) { return e_bool_names[v]; }; static const char* Name(e_double v) { return e_double_names[v]; }; static const char* Name(e_int v) { return e_int_names[v]; }; bool Get(e_bool v) const; void Set(e_bool v, bool s); int Get(e_int v) const; void Set(e_int v, int s); double Get(e_double v) const; void Set(e_double v, double s); void Info(std::ostream& out) const { out << "bool: " << std::endl; for(auto e : e_bool_all) { out << std::setw(20) << e_bool_names[e] << std::setw(20) << bool_values[e] << std::endl; } out << "int: " << std::endl; for(auto e : e_int_all) { out << std::setw(20) << e_int_names[e] << std::setw(20) << int_values[e] << std::endl; } out << "double: " << std::endl; for(auto e : e_double_all) { out << std::setw(20) << e_double_names[e] << std::setw(20) << double_values[e] << std::endl; } } void WriteJson(std::ostream& out) const; void WriteNicely(std::ostream& out) const; }; rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_bench_template.hpp000066400000000000000000000037121507377332500260130ustar00rootroot00000000000000/* ************************************************************************ * 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 #include "rocalution_bench_solver.hpp" // // @brief One function to call the bench execution. // template bool rocalution_bench_template(const rocalution_arguments_config& config) { try { rocalution_bench_solver bench_solver(&config); bool success = bench_solver.Run(); return success; } catch(bool) { rocalution_bench_errmsg << "rocalution_bench_template failure" << std::endl; ; return false; } catch(std::exception&) { rocalution_bench_errmsg << "rocalution_bench_template unknown failure" << std::endl; ; return false; } } rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_driver_itsolver.hpp000066400000000000000000000355031507377332500262660ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2022-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 #include "rocalution_driver_itsolver_template.hpp" // // @brief This structure is responsible of providing a base implementation // of \ref rocalution_driver_itsolver_template. // template struct rocalution_driver_itsolver_base : rocalution_driver_itsolver_template { protected: using traits_t = rocalution_driver_itsolver_traits; using solver_t = typename traits_t::solver_t; using preconditioner_t = typename traits_t::preconditioner_t; using params_t = rocalution_bench_solver_parameters; protected: T* cache_csr_val{}; preconditioner_t* m_preconditioner{}; // // Option for caching. // void Cache(int m, int n, int nnz, const int* csr_ptr, const int* csr_ind, const T* csr_val, const params_t& parameters) { this->cache_csr_val = new T[nnz]; for(int i = 0; i < nnz; i++) { this->cache_csr_val[i] = csr_val[i]; } } public: // // @brief Destructor. // ~rocalution_driver_itsolver_base() { if(this->cache_csr_val != nullptr) { delete[] this->cache_csr_val; this->cache_csr_val = nullptr; } if(this->m_preconditioner != nullptr) { delete m_preconditioner; m_preconditioner = nullptr; } } virtual const preconditioner_t* GetPreconditioner() const override { return this->m_preconditioner; }; virtual preconditioner_t* GetPreconditioner() override { return this->m_preconditioner; }; virtual void SetPreconditioner(preconditioner_t* preconditioner) override { this->m_preconditioner = preconditioner; }; // @brief Import matrix. // @param[in] // A local matrix. // @param[in] // parameters parameters to configure the operation. // @return true if successful, false otherwise. virtual bool ImportMatrix(LocalMatrix& A, const params_t& parameters) { auto matrix_init = parameters.GetEnumMatrixInit(); if(matrix_init.is_invalid()) { rocalution_bench_errmsg << "matrix initialization is invalid" << std::endl; return false; } const auto rebuild_numeric = parameters.Get(params_t::rebuild_numeric); switch(matrix_init.value) { case rocalution_enum_matrix_init::laplacian: { int* csr_ptr = NULL; int* csr_col = NULL; T* csr_val = NULL; const int ndim = parameters.Get(params_t::ndim); auto nrow = gen_2d_laplacian(ndim, &csr_ptr, &csr_col, &csr_val); if(rebuild_numeric) { this->Cache(nrow, nrow, csr_ptr[nrow], csr_ptr, csr_col, csr_val, parameters); } A.SetDataPtrCSR(&csr_ptr, &csr_col, &csr_val, "A", csr_ptr[nrow], nrow, nrow); return true; } case rocalution_enum_matrix_init::permuted_identity: { int* csr_ptr = NULL; int* csr_col = NULL; T* csr_val = NULL; const int ndim = parameters.Get(params_t::ndim); auto nrow = gen_permuted_identity(ndim, &csr_ptr, &csr_col, &csr_val); if(rebuild_numeric) { this->Cache(nrow, nrow, csr_ptr[nrow], csr_ptr, csr_col, csr_val, parameters); } A.SetDataPtrCSR(&csr_ptr, &csr_col, &csr_val, "A", csr_ptr[nrow], nrow, nrow); return true; } case rocalution_enum_matrix_init::file: { const std::string matrix_filename = parameters.Get(params_t::matrix_filename); if(matrix_filename == "") { rocalution_bench_errmsg << "no filename for matrix file initialization." << std::endl; return false; } else { A.ReadFileMTX(matrix_filename); // Apply reordering ? // LocalVector rcmk; // A.RCMK(&rcmk); // A.Permute(rcmk); if(rebuild_numeric) { // // Since we want to cache // // Convert to csr format. // A.ConvertTo(1); // // Grab csr data. // int* csr_ptr = NULL; int* csr_col = NULL; T* csr_val = NULL; auto nrow = A.GetM(); auto ncol = A.GetN(); auto nnz = A.GetNnz(); // // Leave pointers, A is not usable after this until we re-set the pointers. // A.LeaveDataPtrCSR(&csr_ptr, &csr_col, &csr_val); // // Cache. // this->Cache(nrow, ncol, nnz, csr_ptr, csr_col, csr_val, parameters); // // Re-set the pointers. // A.SetDataPtrCSR(&csr_ptr, &csr_col, &csr_val, "A", nnz, nrow, nrow); } return true; } } } return true; } virtual bool ImportLinearSystem(LocalMatrix& A, LocalVector& B, LocalVector& X, const params_t& parameters) override { // // Import matrix. // this->ImportMatrix(A, parameters); return true; } }; // // @Brief Default implementation. // template struct rocalution_driver_itsolver_default : rocalution_driver_itsolver_base { using params_t = rocalution_bench_solver_parameters; virtual bool CreatePreconditioner(LocalMatrix& A, LocalVector& B, LocalVector& X, const params_t& parameters) override { auto enum_preconditioner = parameters.GetEnumPreconditioner(); if(enum_preconditioner.is_invalid()) { rocalution_bench_errmsg << "enum preconditioner is invalid." << std::endl; return false; } this->m_preconditioner = nullptr; switch(enum_preconditioner.value) { case rocalution_enum_preconditioner::none: { return true; } case rocalution_enum_preconditioner::chebyshev: { // Chebyshev preconditioner // Determine min and max eigenvalues T lambda_min; T lambda_max; A.Gershgorin(lambda_min, lambda_max); auto* p = new rocalution:: AIChebyshev, rocalution::LocalVector, T>; p->Set(3, lambda_max / 7.0, lambda_max); this->m_preconditioner = p; break; } case rocalution_enum_preconditioner::FSAI: { auto* p = new rocalution::FSAI, rocalution::LocalVector, T>; this->m_preconditioner = p; break; } case rocalution_enum_preconditioner::SPAI: { auto* p = new rocalution::SPAI, rocalution::LocalVector, T>; this->m_preconditioner = p; break; } case rocalution_enum_preconditioner::TNS: { auto* p = new rocalution::TNS, rocalution::LocalVector, T>; this->m_preconditioner = p; break; } case rocalution_enum_preconditioner::Jacobi: { auto* p = new rocalution::Jacobi, rocalution::LocalVector, T>; // // no specific parameters // this->m_preconditioner = p; break; } case rocalution_enum_preconditioner::GS: { auto* p = new rocalution::GS, rocalution::LocalVector, T>; // // no specific parameters // this->m_preconditioner = p; break; } case rocalution_enum_preconditioner::SGS: { auto* p = new rocalution::SGS, rocalution::LocalVector, T>; // // no specific parameters // this->m_preconditioner = p; break; } case rocalution_enum_preconditioner::ILU: { auto* p = new rocalution::ILU, rocalution::LocalVector, T>; // // no specific parameters // this->m_preconditioner = p; break; } case rocalution_enum_preconditioner::ItILU0: { auto enum_itilu0_alg = parameters.GetEnumItILU0Algorithm(); if(enum_itilu0_alg.is_invalid()) { rocalution_bench_errmsg << "enum_itilu0_alg is invalid." << std::endl; return false; } auto* p = new rocalution::ItILU0, rocalution::LocalVector, T>; p->SetMaxIter(parameters.Get(params_t::itilu0_max_iter)); p->SetTolerance(parameters.Get(params_t::itilu0_tol)); p->SetOptions(parameters.Get(params_t::itilu0_options)); switch(enum_itilu0_alg.value) { case rocalution_enum_itilu0_alg::Default: { p->SetAlgorithm(ItILU0Algorithm::Default); break; } case rocalution_enum_itilu0_alg::AsyncInPlace: { p->SetAlgorithm(ItILU0Algorithm::AsyncInPlace); break; } case rocalution_enum_itilu0_alg::AsyncSplit: { p->SetAlgorithm(ItILU0Algorithm::AsyncSplit); break; } case rocalution_enum_itilu0_alg::SyncSplit: { p->SetAlgorithm(ItILU0Algorithm::SyncSplit); break; } case rocalution_enum_itilu0_alg::SyncSplitFusion: { p->SetAlgorithm(ItILU0Algorithm::SyncSplitFusion); break; } } this->m_preconditioner = p; return true; } case rocalution_enum_preconditioner::ILUT: { auto* p = new rocalution::ILUT, rocalution::LocalVector, T>; p->Set(parameters.Get(params_t::ilut_tol), parameters.Get(params_t::ilut_n)); this->m_preconditioner = p; break; } case rocalution_enum_preconditioner::IC: { auto* p = new rocalution::IC, rocalution::LocalVector, T>; // // no specific parameters // this->m_preconditioner = p; break; } case rocalution_enum_preconditioner::MCGS: { auto* p = new rocalution:: MultiColoredGS, rocalution::LocalVector, T>; p->SetRelaxation(parameters.Get(params_t::mcgs_relax)); this->m_preconditioner = p; break; } case rocalution_enum_preconditioner::MCSGS: { auto* p = new rocalution:: MultiColoredSGS, rocalution::LocalVector, T>; // // no specific parameters // this->m_preconditioner = p; break; } case rocalution_enum_preconditioner::MCILU: { auto* p = new rocalution:: MultiColoredILU, rocalution::LocalVector, T>; p->Set(parameters.Get(params_t::mcilu_p), parameters.Get(params_t::mcilu_q), parameters.Get(params_t::mcilu_use_level)); this->m_preconditioner = p; break; } } if(this->m_preconditioner != nullptr) { const auto itsolve = parameters.Get(params_t::iterative_solve); rocalution::SolverDescr descr; if(itsolve) { descr.SetTriSolverAlg(TriSolverAlg_Iterative); descr.SetIterativeSolverMaxIteration(parameters.Get(params_t::itsolve_max_iter)); descr.SetIterativeSolverTolerance(parameters.Get(params_t::itsolve_tol)); } else { descr.SetTriSolverAlg(TriSolverAlg_Default); } this->m_preconditioner->SetSolverDescriptor(descr); return true; } return false; } }; // // @Brief Default definition. // template struct rocalution_driver_itsolver : rocalution_driver_itsolver_default { }; rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_driver_itsolver_fgmres.hpp000066400000000000000000000043731507377332500276320ustar00rootroot00000000000000/* ************************************************************************ * 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 #include "rocalution_driver_itsolver.hpp" template struct rocalution_driver_itsolver : rocalution_driver_itsolver_default { static constexpr auto ITSOLVER = rocalution_enum_itsolver::fgmres; using traits_t = rocalution_driver_itsolver_traits; using solver_t = typename traits_t::solver_t; using params_t = rocalution_bench_solver_parameters; virtual bool PreprocessSolverBuild(LocalMatrix& A, LocalVector& B, LocalVector& X, solver_t& solver, const params_t& parameters) override { const auto krylov_basis = parameters.Get(params_t::krylov_basis); solver.SetBasisSize(krylov_basis); return true; }; }; rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_driver_itsolver_gmres.hpp000066400000000000000000000043671507377332500274670ustar00rootroot00000000000000/* ************************************************************************ * 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 #include "rocalution_driver_itsolver.hpp" template struct rocalution_driver_itsolver : rocalution_driver_itsolver_default { static constexpr auto ITSOLVER = rocalution_enum_itsolver::gmres; using traits_t = rocalution_driver_itsolver_traits; using solver_t = typename traits_t::solver_t; using params_t = rocalution_bench_solver_parameters; virtual bool PreprocessSolverBuild(LocalMatrix& A, LocalVector& B, LocalVector& X, solver_t& solver, const params_t& parameters) override { const auto krylov_basis = parameters.Get(params_t::krylov_basis); solver.SetBasisSize(krylov_basis); return true; }; }; rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_driver_itsolver_template.hpp000066400000000000000000000270761507377332500301670ustar00rootroot00000000000000/* ************************************************************************ * 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 #include "rocalution_bench_solver_parameters.hpp" #include "rocalution_driver_itsolver_traits.hpp" // // @brief This structure is responsible of defining a driver to configure an iterative linear solver. // template struct rocalution_driver_itsolver_template { protected: static constexpr bool s_verbose = true; using traits_t = rocalution_driver_itsolver_traits; using solver_t = typename traits_t::solver_t; using preconditioner_t = typename traits_t::preconditioner_t; using params_t = rocalution_bench_solver_parameters; // // Pure protected virtual methods. // ______________________________ protected: // @brief Get the preconditioner. // @return constant pointer to the preconditioner. virtual const preconditioner_t* GetPreconditioner() const = 0; // @brief Get the preconditioner. // @return pointer to the preconditioner. virtual preconditioner_t* GetPreconditioner() = 0; // @brief Set the preconditioner. // @param[in] // preconditioner pointer to the preconditioner. virtual void SetPreconditioner(preconditioner_t* preconditioner) = 0; // @brief Create preconditioner. // @param[in] // A matrix of the linear system. // @param[in] // B right-hand-side vector of the linear system. // @param[in] // X unknown vector of the linear system. // @param[in] // parameters parameters to configure the operation. // @return true if successful, false otherwise. virtual bool CreatePreconditioner(LocalMatrix& A, LocalVector& B, LocalVector& X, const params_t& parameters) = 0; // // Protected virtual methods. // _________________________ protected: // // @brief Method called before the Build method from the solver being called. // @param[inout] // A matrix of the linear system. // @param[inout] // B right-hand-side vector of the linear system. // @param[inout] // X unknown vector of the linear system. // @param[inout] // solver linear solver. // @param[inout] // parameters parameters to configure the operation. // @return true if successful, false otherwise. // virtual bool PreprocessSolverBuild(LocalMatrix& A, LocalVector& B, LocalVector& X, solver_t& solver, const params_t& parameters) { // // by default do nothing. // return true; } // // @brief Method called after the Build method from the solver being called. // @param[inout] // A matrix of the linear system. // @param[inout] // B right-hand-side vector of the linear system. // @param[inout] // X unknown vector of the linear system. // @param[inout] // solver linear solver. // @param[inout] // parameters parameters to configure the operation. // @return true if successful, false otherwise. // virtual bool PostprocessSolverBuild(LocalMatrix& A, LocalVector& B, LocalVector& X, solver_t& solver, const params_t& parameters) { // // by default do nothing. // return true; } // // Public pure virtual methods. // ______________________ public: // // @brief Import the linear system Ax=b // @param[out] // A matrix to import. // @param[out] // B right-hand-side to import. // @param[out] // S solution to import. // @param[in] // parameters parameters to set up the import. // @return true if successful, false otherwise. // virtual bool ImportLinearSystem(LocalMatrix& A, LocalVector& B, LocalVector& S, const params_t& parameters) = 0; // // Public virtual methods. // ______________________ public: // // @brief Method called before the execution linear solver. // @param[inout] // A matrix of the linear system. // @param[inout] // B right-hand-side vector of the linear system. // @param[inout] // X unknown vector of the linear system. // @param[inout] // solver linear solver. // @param[inout] // parameters parameters to configure the operation. // @return true if successful, false otherwise. // virtual bool PreprocessLinearSolve(LocalMatrix& A, LocalVector& B, LocalVector& X, solver_t& solver, const params_t& parameters) { return true; } // // @brief Method called after the execution linear solver. // @param[inout] // A matrix of the linear system. // @param[inout] // B right-hand-side vector of the linear system. // @param[inout] // X unknown vector of the linear system. // @param[inout] // solver linear solver. // @param[inout] // parameters parameters to configure the operation. // @return true if successful, false otherwise. // virtual bool PostprocessLinearSolve(LocalMatrix& A, LocalVector& B, LocalVector& X, solver_t& solver, const params_t& parameters) { return true; } // // @brief Postprocess the import, A, B and X are moved to accelerator. // @param[inout] // A matrix of the linear system. // @param[inout] // B right-hand-side vector of the linear system. // @param[inout] // S solution vector of the linear system. // @param[inout] // solver parameters to set up the import. // @param[inout] // parameters parameters to configure the operation. // @return true if successful, false otherwise. // virtual bool PostprocessImportLinearSystem(LocalMatrix& A, LocalVector& B, LocalVector& S, const params_t& parameters) { S.Allocate("s", A.GetN()); B.Allocate("b", A.GetM()); // // Get a temp vector and set it to one. // S.Ones(); // // Matrix vector product to build B. // A.Apply(S, &B); return true; } // // @brief Configure the linear solver. // // @param[inout] // A matrix of the linear system. // @param[inout] // B right-hand-side vector of the linear system. // @param[inout] // X unknown vector of the linear system. // @param[inout] // solver linear solver // @param[inout] // parameters parameters to configure the operation. // @return true if successful, false otherwise. // bool ConfigureLinearSolver(LocalMatrix& A, LocalVector& B, LocalVector& X, solver_t& solver, const params_t& parameters) { // // Get parameters. // const auto abs_tol = parameters.Get(params_t::abs_tol); const auto rel_tol = parameters.Get(params_t::rel_tol); const auto div_tol = parameters.Get(params_t::div_tol); const auto max_iter = parameters.Get(params_t::max_iter); // // Create preconditioner. // if(s_verbose) { std::cout << "ConfigureLinearSolver CreatePreconditioner ..." << std::endl; } bool success = this->CreatePreconditioner(A, B, X, parameters); if(!success) { rocalution_bench_errmsg << "create preconditioner failed.." << std::endl; return false; } if(s_verbose) { std::cout << "ConfigureLinearSolver CreatePreconditioner done." << std::endl; } // // Initialize the solver. // solver.Verbose(0); solver.SetOperator(A); solver.Init(abs_tol, rel_tol, div_tol, max_iter); // // Get preconditioner. // auto* preconditioner = this->GetPreconditioner(); if(preconditioner != nullptr) { solver.SetPreconditioner(*preconditioner); } // // Preprocess solver build. // if(s_verbose) { std::cout << "ConfigureLinearSolver PreprocessSolverBuild ..." << std::endl; } success = this->PreprocessSolverBuild(A, B, X, solver, parameters); if(!success) { rocalution_bench_errmsg << "preprocess solver build failed.." << std::endl; return false; } if(s_verbose) { std::cout << "ConfigureLinearSolver PreprocessSolverBuild done." << std::endl; } // // solver build. // solver.Build(); // // Postprocess solver build. // if(s_verbose) { std::cout << "ConfigureLinearSolver PostprocessSolverBuild ..." << std::endl; } success = this->PostprocessSolverBuild(A, B, X, solver, parameters); if(!success) { rocalution_bench_errmsg << "postprocess solver build failed.." << std::endl; return false; } if(s_verbose) { std::cout << "ConfigureLinearSolver PostprocessSolverBuild ..." << std::endl; } return success; } }; rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_driver_itsolver_traits.hpp000066400000000000000000000110211507377332500276410ustar00rootroot00000000000000/* ************************************************************************ * 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 #include "rocalution_bench_itsolver.hpp" #include "rocalution_bench_solver_parameters.hpp" using namespace rocalution; template struct rocalution_driver_itsolver_traits; template struct rocalution_driver_itsolver_traits { using solver_t = BiCGStab, LocalVector, T>; using preconditioner_t = Preconditioner, LocalVector, T>; }; template struct rocalution_driver_itsolver_traits { using solver_t = FCG, LocalVector, T>; using preconditioner_t = Preconditioner, LocalVector, T>; }; template struct rocalution_driver_itsolver_traits { using solver_t = FCG, LocalVector, T>; using preconditioner_t = UAAMG, LocalVector, T>; }; template struct rocalution_driver_itsolver_traits { using solver_t = QMRCGStab, LocalVector, T>; using preconditioner_t = Preconditioner, LocalVector, T>; }; template struct rocalution_driver_itsolver_traits { using solver_t = CG, LocalVector, T>; using preconditioner_t = Preconditioner, LocalVector, T>; }; template struct rocalution_driver_itsolver_traits { using solver_t = IDR, LocalVector, T>; using preconditioner_t = Preconditioner, LocalVector, T>; }; template struct rocalution_driver_itsolver_traits { using solver_t = FCG, LocalVector, T>; using preconditioner_t = Preconditioner, LocalVector, T>; }; template struct rocalution_driver_itsolver_traits { using solver_t = CR, LocalVector, T>; using preconditioner_t = Preconditioner, LocalVector, T>; }; template struct rocalution_driver_itsolver_traits { using solver_t = CG, LocalVector, T>; using preconditioner_t = Preconditioner, LocalVector, T>; }; template struct rocalution_driver_itsolver_traits { using solver_t = GMRES, LocalVector, T>; using preconditioner_t = Preconditioner, LocalVector, T>; }; template struct rocalution_driver_itsolver_traits { using solver_t = FGMRES, LocalVector, T>; using preconditioner_t = Preconditioner, LocalVector, T>; }; template struct rocalution_driver_itsolver_traits { using solver_t = BiCGStab, LocalVector, T>; using preconditioner_t = Preconditioner, LocalVector, T>; }; rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_driver_itsolver_uaamg.hpp000066400000000000000000000172011507377332500274330ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2022-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 #include "rocalution_driver_itsolver.hpp" template struct rocalution_driver_itsolver : rocalution_driver_itsolver_base { static constexpr auto ITSOLVER = rocalution_enum_itsolver::uaamg; using params_t = rocalution_bench_solver_parameters; using traits_t = rocalution_driver_itsolver_traits; using solver_t = typename traits_t::solver_t; LocalVector b2; LocalVector e; FCG, LocalVector, T> cgs; IterativeLinearSolver, LocalVector, T>** sm; Preconditioner, LocalVector, T>** smooth; virtual bool PreprocessLinearSolve(LocalMatrix& A, LocalVector& B, LocalVector& X, solver_t& solver, const rocalution_bench_solver_parameters& parameters) override { const auto rebuild_numeric = parameters.Get(params_t::rebuild_numeric); const auto format = parameters.Get(params_t::format); if(rebuild_numeric) { b2.MoveToAccelerator(); e.MoveToAccelerator(); b2.Allocate("b2", A.GetM()); e.Allocate("e", A.GetN()); if(this->cache_csr_val) { A.UpdateValuesCSR(this->cache_csr_val); delete[] this->cache_csr_val; this->cache_csr_val = nullptr; } // b2 = A * 1 e.Ones(); A.Apply(e, &b2); solver.ReBuildNumeric(); } // Matrix format const auto blockdim = parameters.Get(params_t::blockdim); A.ConvertTo(format, format == BCSR ? blockdim : 1); return true; } virtual bool PostprocessLinearSolve(LocalMatrix& A, LocalVector& B, LocalVector& X, solver_t& solver, const rocalution_bench_solver_parameters& parameters) override { return true; } virtual bool CreatePreconditioner(LocalMatrix& A, LocalVector& B, LocalVector& X, const rocalution_bench_solver_parameters& parameters) override { const auto pre_smooth = parameters.Get(params_t::solver_pre_smooth); const auto post_smooth = parameters.Get(params_t::solver_post_smooth); const auto cycle = parameters.Get(params_t::cycle); const auto scaling = parameters.Get(params_t::solver_ordering); const auto format = parameters.Get(params_t::format); const auto couplingStrength = parameters.Get(params_t::solver_coupling_strength); const auto overInterp = parameters.Get(params_t::solver_over_interp); const auto coarsestLevel = parameters.Get(params_t::solver_coarsest_level); const auto enum_coarsening_strategy = parameters.GetEnumCoarseningStrategy(); if(enum_coarsening_strategy.is_invalid()) { rocalution_bench_errmsg << "coarsening strategy is invalid" << std::endl; return false; } const auto enum_smoother = parameters.GetEnumSmoother(); if(enum_smoother.is_invalid()) { rocalution_bench_errmsg << "smoother is invalid" << std::endl; return false; } auto* preconditioner = new UAAMG, LocalVector, T>(); preconditioner->SetCoarsestLevel(coarsestLevel); preconditioner->SetCycle(cycle); preconditioner->SetOperator(A); preconditioner->SetManualSmoothers(true); preconditioner->SetManualSolver(true); preconditioner->SetScaling(scaling); switch(enum_coarsening_strategy.value) { case rocalution_enum_coarsening_strategy::Greedy: { preconditioner->SetCoarseningStrategy(CoarseningStrategy::Greedy); break; } case rocalution_enum_coarsening_strategy::PMIS: { preconditioner->SetCoarseningStrategy(CoarseningStrategy::PMIS); break; } } preconditioner->SetCouplingStrength(couplingStrength); preconditioner->SetOverInterp(overInterp); preconditioner->BuildHierarchy(); // Get number of hierarchy levels int levels = preconditioner->GetNumLevels(); // Coarse grid solver this->cgs.Verbose(0); // Smoother for each level this->sm = new IterativeLinearSolver, LocalVector, T>*[levels - 1]; this->smooth = new Preconditioner, LocalVector, T>*[levels - 1]; for(int i = 0; i < levels - 1; ++i) { this->sm[i] = new FixedPoint, LocalVector, T>; switch(enum_smoother.value) { case rocalution_enum_smoother::FSAI: { this->smooth[i] = new FSAI, LocalVector, T>; break; } case rocalution_enum_smoother::ILU: { this->smooth[i] = new ILU, LocalVector, T>; break; } } this->sm[i]->SetPreconditioner(*(this->smooth[i])); this->sm[i]->Verbose(0); } preconditioner->SetSmoother(sm); preconditioner->SetSolver(cgs); preconditioner->SetSmootherPreIter(pre_smooth); preconditioner->SetSmootherPostIter(post_smooth); preconditioner->SetOperatorFormat(format, parameters.Get(params_t::blockdim)); preconditioner->InitMaxIter(1); preconditioner->Verbose(0); this->SetPreconditioner(preconditioner); return true; } }; rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_enum_coarsening_strategy.cpp000066400000000000000000000061121507377332500301270ustar00rootroot00000000000000/*! \file */ /* ************************************************************************ * 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 "rocalution_enum_coarsening_strategy.hpp" constexpr const char* rocalution_enum_coarsening_strategy::names[rocalution_enum_coarsening_strategy::size]; constexpr rocalution_enum_coarsening_strategy::value_type rocalution_enum_coarsening_strategy::all[rocalution_enum_coarsening_strategy::size]; #include bool rocalution_enum_coarsening_strategy::is_invalid() const { for(auto v : all) { if(this->value == v) { return false; } } return true; } rocalution_enum_coarsening_strategy::rocalution_enum_coarsening_strategy(const char* name_) { for(auto v : all) { if(!strcmp(name_, names[v])) { this->value = v; return; } } rocalution_bench_errmsg << "coarsening_strategy '" << name_ << "' is invalid, the list of valid coarsening_strategys is" << std::endl; for(auto v : all) { rocalution_bench_errmsg << " - '" << names[v] << "'" << std::endl; } throw false; }; // // Default contructor. // rocalution_enum_coarsening_strategy::rocalution_enum_coarsening_strategy() : value((value_type)-1){}; // // // rocalution_enum_coarsening_strategy& rocalution_enum_coarsening_strategy::operator()(const char* name_) { this->value = (value_type)-1; for(auto v : all) { if(!strcmp(name_, names[v])) { this->value = v; return *this; } } rocalution_bench_errmsg << "coarsening_strategy '" << name_ << "' is invalid, the list of valid coarsening_strategys is" << std::endl; for(auto v : all) { rocalution_bench_errmsg << " - '" << names[v] << "'" << std::endl; } throw false; } rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_enum_coarsening_strategy.hpp000066400000000000000000000045021507377332500301350ustar00rootroot00000000000000/* ************************************************************************ * 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 #include "rocalution/rocalution.hpp" #include "utility.hpp" #include struct rocalution_enum_coarsening_strategy { #define LIST_ROCALUTION_ENUM_COARSENING_STRATEGY \ ENUM_COARSENING_STRATEGY(Greedy) \ ENUM_COARSENING_STRATEGY(PMIS) // // // #define ENUM_COARSENING_STRATEGY(x_) x_, typedef enum rocalution_enum_coarsening_strategy__ : int { LIST_ROCALUTION_ENUM_COARSENING_STRATEGY } value_type; static constexpr value_type all[]{LIST_ROCALUTION_ENUM_COARSENING_STRATEGY}; static constexpr std::size_t size = countof(all); #undef ENUM_COARSENING_STRATEGY // // // #define ENUM_COARSENING_STRATEGY(x_) #x_, static constexpr const char* names[size]{LIST_ROCALUTION_ENUM_COARSENING_STRATEGY}; #undef ENUM_COARSENING_STRATEGY bool is_invalid() const; rocalution_enum_coarsening_strategy(); rocalution_enum_coarsening_strategy& operator()(const char* name_); rocalution_enum_coarsening_strategy(const char* name_); value_type value{}; }; rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_enum_directsolver.cpp000066400000000000000000000055441507377332500265720ustar00rootroot00000000000000/*! \file */ /* ************************************************************************ * 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 "rocalution_enum_directsolver.hpp" #include constexpr const char* rocalution_enum_directsolver::names[rocalution_enum_directsolver::size]; constexpr rocalution_enum_directsolver::value_type rocalution_enum_directsolver::all[]; const char* rocalution_enum_directsolver::to_string() const { return rocalution_enum_directsolver::to_string(this->value); } bool rocalution_enum_directsolver::is_invalid() const { for(auto v : all) { if(this->value == v) { return false; } } return true; } rocalution_enum_directsolver::rocalution_enum_directsolver(const char* name) { this->value = (value_type)-1; for(auto v : all) { const char* str = names[v]; if(!strcmp(name, str)) { this->value = v; break; } } rocalution_bench_errmsg << "direct solver '" << name << "' is invalid, the list of valid direct solvers is" << std::endl; for(auto v : all) { const char* str = names[v]; rocalution_bench_errmsg << " - '" << str << "'" << std::endl; } throw false; } // // Default contructor. // rocalution_enum_directsolver::rocalution_enum_directsolver() : value((value_type)-1){}; // // // rocalution_enum_directsolver& rocalution_enum_directsolver::operator()(const char* function) { this->value = (value_type)-1; for(auto v : all) { const char* str = names[v]; if(!strcmp(function, str)) { this->value = v; break; } } return *this; } rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_enum_directsolver.hpp000066400000000000000000000064321507377332500265740ustar00rootroot00000000000000/*! \file */ /* ************************************************************************ * 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 #include "utility.hpp" #include // // List the enumeration values. // // clang-format off #define ROCALUTION_ENUM_DIRECTSOLVER_TRANSFORM_EACH \ ROCALUTION_ENUM_DIRECTSOLVER_TRANSFORM(inversion) \ ROCALUTION_ENUM_DIRECTSOLVER_TRANSFORM(lu) \ ROCALUTION_ENUM_DIRECTSOLVER_TRANSFORM(qr) // clang-format on struct rocalution_enum_directsolver { private: public: #define ROCALUTION_ENUM_DIRECTSOLVER_TRANSFORM(x_) x_, typedef enum rocalution_enum_directsolver__ : int { ROCALUTION_ENUM_DIRECTSOLVER_TRANSFORM_EACH } value_type; static constexpr value_type all[] = {ROCALUTION_ENUM_DIRECTSOLVER_TRANSFORM_EACH}; #undef ROCALUTION_ENUM_DIRECTSOLVER_TRANSFORM static constexpr std::size_t size = countof(all); value_type value{}; private: #define ROCALUTION_ENUM_DIRECTSOLVER_TRANSFORM(x_) #x_, static constexpr const char* names[size]{ROCALUTION_ENUM_DIRECTSOLVER_TRANSFORM_EACH}; #undef ROCALUTION_ENUM_DIRECTSOLVER_TRANSFORM public: operator value_type() const { return this->value; }; rocalution_enum_directsolver(); rocalution_enum_directsolver& operator()(const char* function); rocalution_enum_directsolver(const char* function); const char* to_string() const; bool is_invalid() const; static inline const char* to_string(rocalution_enum_directsolver::value_type value) { // // switch for checking inconsistency. // switch(value) { /// #define ROCALUTION_ENUM_DIRECTSOLVER_TRANSFORM(x_) \ case x_: \ { \ if(strcmp(#x_, names[value])) \ return nullptr; \ break; \ } ROCALUTION_ENUM_DIRECTSOLVER_TRANSFORM_EACH; #undef ROCALUTION_ENUM_DIRECTSOLVER_TRANSFORM /// } return names[value]; } }; rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_enum_directsolver_traits.hpp000066400000000000000000000040461507377332500301610ustar00rootroot00000000000000/* ************************************************************************ * 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 #include "rocalution_bench_solver_template_base.hpp" #include "rocalution_enum_directsolver.hpp" using namespace rocalution; template struct rocalution_enum_directsolver_traits; template struct rocalution_enum_directsolver_traits { using solver_t = LU, LocalVector, T>; }; template struct rocalution_enum_directsolver_traits { using solver_t = QR, LocalVector, T>; }; template struct rocalution_enum_directsolver_traits { using solver_t = Inversion, LocalVector, T>; }; rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_enum_itilu0_alg.cpp000066400000000000000000000063001507377332500261050ustar00rootroot00000000000000/*! \file */ /* ************************************************************************ * Copyright (C) 2023 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "rocalution_enum_itilu0_alg.hpp" #include constexpr const char* rocalution_enum_itilu0_alg::names[rocalution_enum_itilu0_alg::size]; constexpr rocalution_enum_itilu0_alg::value_type rocalution_enum_itilu0_alg::all[]; const char* rocalution_enum_itilu0_alg::to_string() const { return rocalution_enum_itilu0_alg::to_string(this->value); } bool rocalution_enum_itilu0_alg::is_invalid() const { for(auto v : all) { if(this->value == v) { return false; } } return true; } rocalution_enum_itilu0_alg::rocalution_enum_itilu0_alg(const char* itilu0_alg_name) { this->value = (value_type)-1; for(auto v : all) { const char* str = names[v]; if(!strcmp(itilu0_alg_name, str)) { this->value = v; return; } } rocalution_bench_errmsg << "ItILU0 algorithm '" << itilu0_alg_name << "' is invalid, the list of valid ItILU0 algorithms is" << std::endl; for(auto v : all) { const char* str = names[v]; rocalution_bench_errmsg << " - '" << str << "'" << std::endl; } throw false; } // // Default contructor. // rocalution_enum_itilu0_alg::rocalution_enum_itilu0_alg() : value((value_type)-1){}; // // // rocalution_enum_itilu0_alg& rocalution_enum_itilu0_alg::operator()(const char* itilu0_alg_name) { this->value = (value_type)-1; for(auto v : all) { const char* str = names[v]; if(!strcmp(itilu0_alg_name, str)) { this->value = v; return *this; } } rocalution_bench_errmsg << "ItILU0 algorithm '" << itilu0_alg_name << "' is invalid, the list of valid ItILU0 algorithms is" << std::endl; for(auto v : all) { const char* str = names[v]; rocalution_bench_errmsg << " - '" << str << "'" << std::endl; } throw false; } rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_enum_itilu0_alg.hpp000066400000000000000000000065441507377332500261240ustar00rootroot00000000000000/*! \file */ /* ************************************************************************ * 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 #include "utility.hpp" #include // // List the enumeration values. // // clang-format off #define ROCALUTION_ENUM_ITILU0_ALG_TRANSFORM_EACH \ ROCALUTION_ENUM_ITILU0_ALG_TRANSFORM(Default) \ ROCALUTION_ENUM_ITILU0_ALG_TRANSFORM(AsyncInPlace) \ ROCALUTION_ENUM_ITILU0_ALG_TRANSFORM(AsyncSplit) \ ROCALUTION_ENUM_ITILU0_ALG_TRANSFORM(SyncSplit) \ ROCALUTION_ENUM_ITILU0_ALG_TRANSFORM(SyncSplitFusion) // clang-format on struct rocalution_enum_itilu0_alg { public: #define ROCALUTION_ENUM_ITILU0_ALG_TRANSFORM(x_) x_, typedef enum rocalution_enum_itilu0_alg__ : int { ROCALUTION_ENUM_ITILU0_ALG_TRANSFORM_EACH } value_type; static constexpr value_type all[] = {ROCALUTION_ENUM_ITILU0_ALG_TRANSFORM_EACH}; #undef ROCALUTION_ENUM_ITILU0_ALG_TRANSFORM static constexpr std::size_t size = countof(all); value_type value{}; private: #define ROCALUTION_ENUM_ITILU0_ALG_TRANSFORM(x_) #x_, static constexpr const char* names[size]{ROCALUTION_ENUM_ITILU0_ALG_TRANSFORM_EACH}; #undef ROCALUTION_ENUM_ITILU0_ALG_TRANSFORM public: operator value_type() const { return this->value; }; rocalution_enum_itilu0_alg(); rocalution_enum_itilu0_alg& operator()(const char* function); rocalution_enum_itilu0_alg(const char* function); const char* to_string() const; bool is_invalid() const; static inline const char* to_string(rocalution_enum_itilu0_alg::value_type value) { // // switch for checking inconsistency. // switch(value) { /// #define ROCALUTION_ENUM_ITILU0_ALG_TRANSFORM(x_) \ case x_: \ { \ if(strcmp(#x_, names[value])) \ return nullptr; \ break; \ } ROCALUTION_ENUM_ITILU0_ALG_TRANSFORM_EACH; #undef ROCALUTION_ENUM_ITILU0_ALG_TRANSFORM /// } return names[value]; } }; rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_enum_itsolver.cpp000066400000000000000000000062301507377332500257250ustar00rootroot00000000000000/*! \file */ /* ************************************************************************ * 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 "rocalution_enum_itsolver.hpp" #include constexpr const char* rocalution_enum_itsolver::names[rocalution_enum_itsolver::size]; constexpr rocalution_enum_itsolver::value_type rocalution_enum_itsolver::all[]; const char* rocalution_enum_itsolver::to_string() const { return rocalution_enum_itsolver::to_string(this->value); } bool rocalution_enum_itsolver::is_invalid() const { for(auto v : all) { if(this->value == v) { return false; } } return true; } rocalution_enum_itsolver::rocalution_enum_itsolver(const char* itsolver_name) { this->value = (value_type)-1; for(auto v : all) { const char* str = names[v]; if(!strcmp(itsolver_name, str)) { this->value = v; return; } } rocalution_bench_errmsg << "iterative solver '" << itsolver_name << "' is invalid, the list of valid iterative solvers is" << std::endl; for(auto v : all) { const char* str = names[v]; rocalution_bench_errmsg << " - '" << str << "'" << std::endl; } throw false; } // // Default contructor. // rocalution_enum_itsolver::rocalution_enum_itsolver() : value((value_type)-1){}; // // // rocalution_enum_itsolver& rocalution_enum_itsolver::operator()(const char* itsolver_name) { this->value = (value_type)-1; for(auto v : all) { const char* str = names[v]; if(!strcmp(itsolver_name, str)) { this->value = v; return *this; } } rocalution_bench_errmsg << "iterative solver '" << itsolver_name << "' is invalid, the list of valid iterative solvers is" << std::endl; for(auto v : all) { const char* str = names[v]; rocalution_bench_errmsg << " - '" << str << "'" << std::endl; } throw false; } rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_enum_itsolver.hpp000066400000000000000000000072021507377332500257320ustar00rootroot00000000000000/*! \file */ /* ************************************************************************ * 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 #include "utility.hpp" #include // // List the enumeration values. // // clang-format off #define ROCALUTION_ENUM_ITSOLVER_TRANSFORM_EACH \ ROCALUTION_ENUM_ITSOLVER_TRANSFORM(gmres) \ ROCALUTION_ENUM_ITSOLVER_TRANSFORM(bicgstab) \ ROCALUTION_ENUM_ITSOLVER_TRANSFORM(fgmres) \ ROCALUTION_ENUM_ITSOLVER_TRANSFORM(cg) \ ROCALUTION_ENUM_ITSOLVER_TRANSFORM(cr) \ ROCALUTION_ENUM_ITSOLVER_TRANSFORM(fcg) \ ROCALUTION_ENUM_ITSOLVER_TRANSFORM(idr) \ ROCALUTION_ENUM_ITSOLVER_TRANSFORM(pairwise_amg) \ ROCALUTION_ENUM_ITSOLVER_TRANSFORM(qmrcgstab) \ ROCALUTION_ENUM_ITSOLVER_TRANSFORM(ruge_stueben_amg) \ ROCALUTION_ENUM_ITSOLVER_TRANSFORM(saamg) \ ROCALUTION_ENUM_ITSOLVER_TRANSFORM(uaamg) // clang-format on struct rocalution_enum_itsolver { private: public: #define ROCALUTION_ENUM_ITSOLVER_TRANSFORM(x_) x_, typedef enum rocalution_enum_itsolver__ : int { ROCALUTION_ENUM_ITSOLVER_TRANSFORM_EACH } value_type; static constexpr value_type all[] = {ROCALUTION_ENUM_ITSOLVER_TRANSFORM_EACH}; #undef ROCALUTION_ENUM_ITSOLVER_TRANSFORM static constexpr std::size_t size = countof(all); value_type value{}; private: #define ROCALUTION_ENUM_ITSOLVER_TRANSFORM(x_) #x_, static constexpr const char* names[size]{ROCALUTION_ENUM_ITSOLVER_TRANSFORM_EACH}; #undef ROCALUTION_ENUM_ITSOLVER_TRANSFORM public: operator value_type() const { return this->value; }; rocalution_enum_itsolver(); rocalution_enum_itsolver& operator()(const char* function); rocalution_enum_itsolver(const char* function); const char* to_string() const; bool is_invalid() const; static inline const char* to_string(rocalution_enum_itsolver::value_type value) { // // switch for checking inconsistency. // switch(value) { /// #define ROCALUTION_ENUM_ITSOLVER_TRANSFORM(x_) \ case x_: \ { \ if(strcmp(#x_, names[value])) \ return nullptr; \ break; \ } ROCALUTION_ENUM_ITSOLVER_TRANSFORM_EACH; #undef ROCALUTION_ENUM_ITSOLVER_TRANSFORM /// } return names[value]; } }; rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_enum_matrix_init.cpp000066400000000000000000000057371507377332500264200ustar00rootroot00000000000000/*! \file */ /* ************************************************************************ * 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 "rocalution_enum_matrix_init.hpp" constexpr const char* rocalution_enum_matrix_init::names[rocalution_enum_matrix_init::size]; constexpr rocalution_enum_matrix_init::value_type rocalution_enum_matrix_init::all[rocalution_enum_matrix_init::size]; #include bool rocalution_enum_matrix_init::is_invalid() const { for(auto v : all) { if(this->value == v) { return false; } } return true; } rocalution_enum_matrix_init::rocalution_enum_matrix_init(const char* name_) { for(auto v : all) { if(!strcmp(name_, names[v])) { this->value = v; return; } } rocalution_bench_errmsg << "matrix initialization '" << name_ << "' is invalid, the list of valid matrix initialization is" << std::endl; for(auto v : all) { rocalution_bench_errmsg << " - '" << names[v] << "'" << std::endl; } throw false; }; // // Default contructor. // rocalution_enum_matrix_init::rocalution_enum_matrix_init() : value((value_type)-1){}; // // // rocalution_enum_matrix_init& rocalution_enum_matrix_init::operator()(const char* name_) { this->value = (value_type)-1; for(auto v : all) { if(!strcmp(name_, names[v])) { this->value = v; return *this; } } rocalution_bench_errmsg << "matrix initialization '" << name_ << "' is invalid, the list of valid matrix initialization is" << std::endl; for(auto v : all) { rocalution_bench_errmsg << " - '" << names[v] << "'" << std::endl; } throw false; } rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_enum_matrix_init.hpp000066400000000000000000000043651507377332500264210ustar00rootroot00000000000000/* ************************************************************************ * 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 #include "rocalution/rocalution.hpp" #include "utility.hpp" #include struct rocalution_enum_matrix_init { #define LIST_ROCALUTION_ENUM_MATRIX_INIT \ ENUM_MATRIX_INIT(laplacian) \ ENUM_MATRIX_INIT(permuted_identity) \ ENUM_MATRIX_INIT(file) // // // #define ENUM_MATRIX_INIT(x_) x_, typedef enum rocalution_enum_matrix_init__ : int { LIST_ROCALUTION_ENUM_MATRIX_INIT } value_type; static constexpr value_type all[]{LIST_ROCALUTION_ENUM_MATRIX_INIT}; static constexpr std::size_t size = countof(all); #undef ENUM_MATRIX_INIT // // // #define ENUM_MATRIX_INIT(x_) #x_, static constexpr const char* names[size]{LIST_ROCALUTION_ENUM_MATRIX_INIT}; #undef ENUM_MATRIX_INIT bool is_invalid() const; rocalution_enum_matrix_init(); rocalution_enum_matrix_init& operator()(const char* name_); rocalution_enum_matrix_init(const char* name_); value_type value{}; }; rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_enum_preconditioner.cpp000066400000000000000000000056651507377332500271150ustar00rootroot00000000000000/*! \file */ /* ************************************************************************ * 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 "rocalution_enum_preconditioner.hpp" constexpr const char* rocalution_enum_preconditioner::names[rocalution_enum_preconditioner::size]; constexpr rocalution_enum_preconditioner::value_type rocalution_enum_preconditioner::all[rocalution_enum_preconditioner::size]; #include bool rocalution_enum_preconditioner::is_invalid() const { for(auto v : all) { if(this->value == v) { return false; } } return true; } rocalution_enum_preconditioner::rocalution_enum_preconditioner(const char* name_) { for(auto v : all) { if(!strcmp(name_, names[v])) { this->value = v; return; } } rocalution_bench_errmsg << "preconditioner '" << name_ << "' is invalid, the list of valid preconditioners is" << std::endl; for(auto v : all) { rocalution_bench_errmsg << " - '" << names[v] << "'" << std::endl; } throw false; }; // // Default contructor. // rocalution_enum_preconditioner::rocalution_enum_preconditioner() : value((value_type)-1){}; // // // rocalution_enum_preconditioner& rocalution_enum_preconditioner::operator()(const char* name_) { this->value = (value_type)-1; for(auto v : all) { if(!strcmp(name_, names[v])) { this->value = v; return *this; } } rocalution_bench_errmsg << "preconditioner '" << name_ << "' is invalid, the list of valid preconditioners is" << std::endl; for(auto v : all) { rocalution_bench_errmsg << " - '" << names[v] << "'" << std::endl; } throw false; } rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_enum_preconditioner.hpp000066400000000000000000000060761507377332500271170ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2022-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 #include "rocalution/rocalution.hpp" #include "utility.hpp" #include struct rocalution_enum_preconditioner { #define LIST_ROCALUTION_ENUM_PRECONDITIONER \ ENUM_PRECONDITIONER(none) \ ENUM_PRECONDITIONER(chebyshev) \ ENUM_PRECONDITIONER(FSAI) \ ENUM_PRECONDITIONER(SPAI) \ ENUM_PRECONDITIONER(TNS) \ ENUM_PRECONDITIONER(Jacobi) \ ENUM_PRECONDITIONER(GS) \ ENUM_PRECONDITIONER(SGS) \ ENUM_PRECONDITIONER(ILU) \ ENUM_PRECONDITIONER(ItILU0) \ ENUM_PRECONDITIONER(ILUT) \ ENUM_PRECONDITIONER(IC) \ ENUM_PRECONDITIONER(MCGS) \ ENUM_PRECONDITIONER(MCSGS) \ ENUM_PRECONDITIONER(MCILU) // // // #define ENUM_PRECONDITIONER(x_) x_, typedef enum rocalution_enum_preconditioner__ : int { LIST_ROCALUTION_ENUM_PRECONDITIONER } value_type; static constexpr value_type all[]{LIST_ROCALUTION_ENUM_PRECONDITIONER}; static constexpr std::size_t size = countof(all); #undef ENUM_PRECONDITIONER // // // #define ENUM_PRECONDITIONER(x_) #x_, static constexpr const char* names[size]{LIST_ROCALUTION_ENUM_PRECONDITIONER}; #undef ENUM_PRECONDITIONER bool is_invalid() const; rocalution_enum_preconditioner(); rocalution_enum_preconditioner& operator()(const char* name_); rocalution_enum_preconditioner(const char* name_); value_type value{}; }; // constexpr const char * rocalution_enum_preconditioner::names[rocalution_enum_preconditioner::size]; // constexpr rocalution_enum_preconditioner::value_type rocalution_enum_preconditioner::all[rocalution_enum_preconditioner::size]; rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_enum_smoother.cpp000066400000000000000000000055171507377332500257250ustar00rootroot00000000000000/*! \file */ /* ************************************************************************ * 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 "rocalution_enum_smoother.hpp" constexpr const char* rocalution_enum_smoother::names[rocalution_enum_smoother::size]; constexpr rocalution_enum_smoother::value_type rocalution_enum_smoother::all[rocalution_enum_smoother::size]; #include bool rocalution_enum_smoother::is_invalid() const { for(auto v : all) { if(this->value == v) { return false; } } return true; } rocalution_enum_smoother::rocalution_enum_smoother(const char* name_) { for(auto v : all) { if(!strcmp(name_, names[v])) { this->value = v; return; } } rocalution_bench_errmsg << "smoother '" << name_ << "' is invalid, the list of valid smoothers is" << std::endl; for(auto v : all) { rocalution_bench_errmsg << " - '" << names[v] << "'" << std::endl; } throw false; }; // // Default contructor. // rocalution_enum_smoother::rocalution_enum_smoother() : value((value_type)-1){}; // // // rocalution_enum_smoother& rocalution_enum_smoother::operator()(const char* name_) { this->value = (value_type)-1; for(auto v : all) { if(!strcmp(name_, names[v])) { this->value = v; return *this; } } rocalution_bench_errmsg << "smoother '" << name_ << "' is invalid, the list of valid smoothers is" << std::endl; for(auto v : all) { rocalution_bench_errmsg << " - '" << names[v] << "'" << std::endl; } throw false; } rocALUTION-rocm-7.1.0/clients/benchmarks/rocalution_enum_smoother.hpp000066400000000000000000000042341507377332500257250ustar00rootroot00000000000000/* ************************************************************************ * 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 #include "rocalution/rocalution.hpp" #include "utility.hpp" #include struct rocalution_enum_smoother { #define LIST_ROCALUTION_ENUM_SMOOTHER \ ENUM_SMOOTHER(FSAI) \ ENUM_SMOOTHER(ILU) // // // #define ENUM_SMOOTHER(x_) x_, typedef enum rocalution_enum_smoother__ : int { LIST_ROCALUTION_ENUM_SMOOTHER } value_type; static constexpr value_type all[]{LIST_ROCALUTION_ENUM_SMOOTHER}; static constexpr std::size_t size = countof(all); #undef ENUM_SMOOTHER // // // #define ENUM_SMOOTHER(x_) #x_, static constexpr const char* names[size]{LIST_ROCALUTION_ENUM_SMOOTHER}; #undef ENUM_SMOOTHER bool is_invalid() const; rocalution_enum_smoother(); rocalution_enum_smoother& operator()(const char* name_); rocalution_enum_smoother(const char* name_); value_type value{}; }; rocALUTION-rocm-7.1.0/clients/include/000077500000000000000000000000001507377332500173745ustar00rootroot00000000000000rocALUTION-rocm-7.1.0/clients/include/common.hpp000066400000000000000000001170231507377332500214010ustar00rootroot00000000000000/* ************************************************************************ * 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. * * ************************************************************************ */ #include #include #include #include #include using namespace rocalution; static void my_irecv(int* buf, int count, int source, int tag, MPI_Comm comm, MPI_Request* request) { MPI_Irecv(buf, count, MPI_INT, source, tag, comm, request); } static void my_irecv(int64_t* buf, int count, int source, int tag, MPI_Comm comm, MPI_Request* request) { MPI_Irecv(buf, count, MPI_INT64_T, source, tag, comm, request); } static void my_isend(const int* buf, int count, int dest, int tag, MPI_Comm comm, MPI_Request* request) { MPI_Isend(buf, count, MPI_INT, dest, tag, comm, request); } static void my_isend(const int64_t* buf, int count, int dest, int tag, MPI_Comm comm, MPI_Request* request) { MPI_Isend(buf, count, MPI_INT64_T, dest, tag, comm, request); } template void distribute_matrix(const MPI_Comm* comm, LocalMatrix* lmat, GlobalMatrix* gmat, ParallelManager* pm) { int rank; int num_procs; MPI_Comm_rank(*comm, &rank); MPI_Comm_size(*comm, &num_procs); int64_t global_nrow = lmat->GetM(); int64_t global_ncol = lmat->GetN(); int64_t global_nnz = lmat->GetNnz(); PtrType* global_row_offset = NULL; int* global_col = NULL; ValueType* global_val = NULL; lmat->LeaveDataPtrCSR(&global_row_offset, &global_col, &global_val); // If we have only a single MPI rank, we are done if(num_procs == 1) { pm->SetMPICommunicator(comm); pm->SetGlobalNrow(global_nrow); pm->SetGlobalNcol(global_ncol); pm->SetLocalNrow(global_nrow); pm->SetLocalNcol(global_ncol); gmat->SetParallelManager(*pm); gmat->SetLocalDataPtrCSR(&global_row_offset, &global_col, &global_val, "mat", global_nnz); return; } // Compute local matrix sizes std::vector local_size(num_procs); for(int i = 0; i < num_procs; ++i) { local_size[i] = global_nrow / num_procs; } if(global_nrow % num_procs != 0) { for(int i = 0; i < global_nrow % num_procs; ++i) { ++local_size[i]; } } // Compute index offsets std::vector index_offset(num_procs + 1); index_offset[0] = 0; for(int i = 0; i < num_procs; ++i) { index_offset[i + 1] = index_offset[i] + local_size[i]; } // Read sub matrix - row_offset int local_nrow = local_size[rank]; std::vector local_row_offset(local_nrow + 1); for(PtrType i = index_offset[rank], k = 0; k < local_nrow + 1; ++i, ++k) { local_row_offset[k] = global_row_offset[i]; } free_host(&global_row_offset); // Read sub matrix - col and val PtrType local_nnz = local_row_offset[local_nrow] - local_row_offset[0]; std::vector local_col(local_nnz); std::vector local_val(local_nnz); for(PtrType i = local_row_offset[0], k = 0; k < local_nnz; ++i, ++k) { local_col[k] = global_col[i]; local_val[k] = global_val[i]; } free_host(&global_col); free_host(&global_val); // Shift row_offset entries int shift = local_row_offset[0]; for(int i = 0; i < local_nrow + 1; ++i) { local_row_offset[i] -= shift; } PtrType interior_nnz = 0; PtrType ghost_nnz = 0; int boundary_nnz = 0; int neighbors = 0; std::vector> boundary(num_procs, std::vector()); std::vector neighbor(num_procs, false); std::vector> checked(num_procs, std::map()); for(int i = 0; i < local_nrow; ++i) { for(PtrType j = local_row_offset[i]; j < local_row_offset[i + 1]; ++j) { // Interior point if(local_col[j] >= index_offset[rank] && local_col[j] < index_offset[rank + 1]) { ++interior_nnz; } else { // Boundary point above current process if(local_col[j] < index_offset[rank]) { // Loop over ranks above current process for(int r = rank - 1; r >= 0; --r) { // Check if boundary belongs to rank r if(local_col[j] >= index_offset[r] && local_col[j] < index_offset[r + 1]) { // Add boundary point to rank r if it has not been added yet if(!checked[r][i + index_offset[rank]]) { boundary[r].push_back(i + index_offset[rank]); neighbor[r] = true; ++boundary_nnz; checked[r][i + index_offset[rank]] = true; } ++ghost_nnz; // Rank for current boundary point local_col[j] has been found // Continue with next boundary point break; } } } // boundary point below current process if(local_col[j] >= index_offset[rank + 1]) { // Loop over ranks above current process for(int r = rank + 1; r < num_procs; ++r) { // Check if boundary belongs to rank r if(local_col[j] >= index_offset[r] && local_col[j] < index_offset[r + 1]) { // Add boundary point to rank r if it has not been added yet if(!checked[r][i + index_offset[rank]]) { boundary[r].push_back(i + index_offset[rank]); neighbor[r] = true; ++boundary_nnz; checked[r][i + index_offset[rank]] = true; } ++ghost_nnz; // Rank for current boundary point local_col[j] has been found // Continue with next boundary point break; } } } } } } for(int i = 0; i < num_procs; ++i) { if(neighbor[i] == true) { ++neighbors; } } std::vector mpi_req(neighbors * 2); int n = 0; // Array to hold boundary size for each interface std::vector boundary_size(neighbors); // MPI receive boundary sizes for(int i = 0; i < num_procs; ++i) { // If neighbor receive from rank i is expected... if(neighbor[i] == true) { // Receive size of boundary from rank i to current rank my_irecv(&(boundary_size[n]), 1, i, 0, *comm, &mpi_req[n]); ++n; } } // MPI send boundary sizes for(int i = 0; i < num_procs; ++i) { // Send required if boundary for rank i available if(boundary[i].size() > 0) { int size = boundary[i].size(); // Send size of boundary from current rank to rank i my_isend(&size, 1, i, 0, *comm, &mpi_req[n]); ++n; } } // Wait to finish communication MPI_Waitall(n - 1, &(mpi_req[0]), MPI_STATUSES_IGNORE); n = 0; // Array to hold boundary offset for each interface int k = 0; std::vector recv_offset(neighbors + 1); std::vector send_offset(neighbors + 1); recv_offset[0] = 0; send_offset[0] = 0; for(int i = 0; i < neighbors; ++i) { recv_offset[i + 1] = recv_offset[i] + boundary_size[i]; } for(int i = 0; i < num_procs; ++i) { if(neighbor[i] == true) { send_offset[k + 1] = send_offset[k] + boundary[i].size(); ++k; } } // Array to hold boundary for each interface std::vector> local_boundary(neighbors); for(int i = 0; i < neighbors; ++i) { local_boundary[i].resize(boundary_size[i]); } // MPI receive boundary for(int i = 0; i < num_procs; ++i) { // If neighbor receive from rank i is expected... if(neighbor[i] == true) { // Receive boundary from rank i to current rank my_irecv(local_boundary[n].data(), boundary_size[n], i, 0, *comm, &mpi_req[n]); ++n; } } // MPI send boundary for(int i = 0; i < num_procs; ++i) { // Send required if boundary for rank i is available if(boundary[i].size() > 0) { // Send boundary from current rank to rank i my_isend(&(boundary[i][0]), boundary[i].size(), i, 0, *comm, &mpi_req[n]); ++n; } } // Wait to finish communication MPI_Waitall(n - 1, &(mpi_req[0]), MPI_STATUSES_IGNORE); // Total boundary size int nnz_boundary = 0; for(int i = 0; i < neighbors; ++i) { nnz_boundary += boundary_size[i]; } // Create local boundary index array k = 0; std::vector bnd(boundary_nnz); for(int i = 0; i < num_procs; ++i) { for(unsigned int j = 0; j < boundary[i].size(); ++j) { bnd[k] = static_cast(boundary[i][j] - index_offset[rank]); ++k; } } // Create boundary index array std::vector boundary_index(nnz_boundary); k = 0; for(int i = 0; i < neighbors; ++i) { for(int j = 0; j < boundary_size[i]; ++j) { boundary_index[k] = local_boundary[i][j]; ++k; } } // Create map with boundary index relations std::map boundary_map; for(int i = 0; i < nnz_boundary; ++i) { boundary_map[boundary_index[i]] = i; } // Build up ghost and interior matrix int* ghost_row = new int[ghost_nnz]; int* ghost_col = new int[ghost_nnz]; ValueType* ghost_val = new ValueType[ghost_nnz]; memset(ghost_row, 0, sizeof(int) * ghost_nnz); memset(ghost_col, 0, sizeof(int) * ghost_nnz); memset(ghost_val, 0, sizeof(ValueType) * ghost_nnz); PtrType* row_offset = new PtrType[local_nrow + 1]; int* col = new int[interior_nnz]; ValueType* val = new ValueType[interior_nnz]; memset(row_offset, 0, sizeof(PtrType) * (local_nrow + 1)); memset(col, 0, sizeof(int) * interior_nnz); memset(val, 0, sizeof(ValueType) * interior_nnz); row_offset[0] = 0; k = 0; int l = 0; for(int i = 0; i < local_nrow; ++i) { for(PtrType j = local_row_offset[i]; j < local_row_offset[i + 1]; ++j) { // Boundary point -- create ghost part if(local_col[j] < index_offset[rank] || local_col[j] >= index_offset[rank + 1]) { ghost_row[k] = i; ghost_col[k] = boundary_map[local_col[j]]; ghost_val[k] = local_val[j]; ++k; } else { // Interior point -- create interior part int c = local_col[j] - index_offset[rank]; col[l] = c; val[l] = local_val[j]; ++l; } } row_offset[i + 1] = l; } std::vector recv(neighbors); std::vector sender(neighbors); int nbc = 0; for(int i = 0; i < num_procs; ++i) { if(neighbor[i] == true) { recv[nbc] = i; sender[nbc] = i; ++nbc; } } pm->SetMPICommunicator(comm); pm->SetGlobalNrow(global_nrow); pm->SetGlobalNcol(global_nrow); pm->SetLocalNrow(local_size[rank]); pm->SetLocalNcol(local_size[rank]); pm->SetBoundaryIndex(boundary_nnz, bnd.data()); pm->SetReceivers(neighbors, recv.data(), recv_offset.data()); pm->SetSenders(neighbors, sender.data(), send_offset.data()); gmat->SetParallelManager(*pm); gmat->SetLocalDataPtrCSR(&row_offset, &col, &val, "mat", interior_nnz); gmat->SetGhostDataPtrCOO(&ghost_row, &ghost_col, &ghost_val, "ghost", ghost_nnz); gmat->Sort(); } // This function computes all prime factors of a given number n static void compute_prime_factors(int n, std::vector& p) { int factor = 2; // Factorize while(n > 1) { while(n % factor == 0) { p.push_back(factor); n /= factor; } ++factor; } } // This function computes the process distribution for each dimension static void compute_2d_process_distribution(int nprocs, int& nprocx, int& nprocy) { // Compute prime factors std::vector p; compute_prime_factors(nprocs, p); // Compute number of processes in each dimension nprocx = 1; nprocy = 1; if(p.size() == 0) { // No entry, this means we have exactly one process } else if(p.size() == 1) { // If we have a single prime number, this is going to be our x dimension nprocx = p[0]; } else if(p.size() == 2) { // For two prime numbers, setup x and y nprocx = p[1]; nprocy = p[0]; } else { // More than two prime numbers // #prime numbers int idx = 0; size_t nprime = p.size(); // cubic root double sqroot = std::sqrt(nprocs); // Determine x dimension nprocx = p[nprime-- - 1]; while(nprocx < sqroot && idx < nprime) { nprocx *= p[idx++]; } // Determine y dimension while(idx < nprime) { nprocy *= p[idx++]; } } // Number of processes must match assert(nprocx * nprocy == nprocs); } // This function computes the process distribution for each dimension static void compute_3d_process_distribution(int nprocs, int& nprocx, int& nprocy, int& nprocz) { // Compute prime factors std::vector p; compute_prime_factors(nprocs, p); // Compute number of processes in each dimension nprocx = 1; nprocy = 1; nprocz = 1; if(p.size() == 0) { // No entry, this means we have exactly one process } else if(p.size() == 1) { // If we have a single prime number, this is going to be our x dimension nprocx = p[0]; } else if(p.size() == 2) { // For two prime numbers, setup x and y nprocx = p[1]; nprocy = p[0]; } else if(p.size() == 3) { // Three prime numbers nprocx = p[2]; nprocy = p[1]; nprocz = p[0]; } else { // More than three prime numbers // #prime numbers int idx = 0; size_t nprime = p.size(); // cubic root double qroot = std::cbrt(nprocs); // Determine x dimension nprocx = p[nprime-- - 1]; while(nprocx < qroot && idx < nprime) { nprocx *= p[idx++]; } // Determine y dimension double sqroot = std::sqrt(nprocs / nprocx); nprocy = p[nprime-- - 1]; while(nprocy < sqroot && idx < nprime) { nprocy *= p[idx++]; } // Determine z dimension while(idx < nprime) { nprocz *= p[idx++]; } } // Number of processes must match assert(nprocx * nprocy * nprocz == nprocs); } template void generate_2d_laplacian(int local_dimx, int local_dimy, const MPI_Comm* comm, GlobalMatrix* mat, ParallelManager* pm, int rank, int nprocs, int nsten = 9) { assert(nsten == 5 || nsten == 9); // First, we need to determine process pattern for the unit square int nproc_x; int nproc_y; compute_2d_process_distribution(nprocs, nproc_x, nproc_y); // Next, determine process index into the unit square int iproc_y = rank / nproc_x; int iproc_x = rank % nproc_x; // Global sizes int64_t global_dimx = static_cast(nproc_x) * local_dimx; int64_t global_dimy = static_cast(nproc_y) * local_dimy; // Global process entry points int64_t global_iproc_x = iproc_x * local_dimx; int64_t global_iproc_y = iproc_y * local_dimy; // Number of rows (global and local) int64_t local_nrow = local_dimx * local_dimy; int64_t global_nrow = global_dimx * global_dimy; // Assemble local CSR matrix row offset pointers PtrType* global_csr_row_ptr = NULL; int64_t* global_csr_col_ind = NULL; int64_t* local2global = NULL; allocate_host(local_nrow + 1, &global_csr_row_ptr); allocate_host(local_nrow * nsten, &global_csr_col_ind); allocate_host(local_nrow, &local2global); std::map global2local; PtrType nnz = 0; global_csr_row_ptr[0] = 0; // Loop over y dimension for(int local_y = 0; local_y < local_dimy; ++local_y) { // Global index into y int64_t global_y = global_iproc_y + local_y; // Loop over x dimension for(int local_x = 0; local_x < local_dimx; ++local_x) { // Global index into x int64_t global_x = global_iproc_x + local_x; // Local row int local_row = local_y * local_dimx + local_x; // Global row int64_t global_row = global_y * global_dimx + global_x; // Fill l2g and g2l map local2global[local_row] = global_row; global2local[global_row] = local_row; // 5pt stencil if(nsten == 5) { // Fixed x (leaving out i == j) for(int by = -1; by <= 1; ++by) { if(global_y + by > -1 && global_y + by < global_dimy && by != 0) { // Global column int64_t global_col = global_row + by * global_dimx; // Fill global CSR column indices global_csr_col_ind[nnz++] = global_col; } } // Fixed y for(int bx = -1; bx <= 1; ++bx) { if(global_x + bx > -1 && global_x + bx < global_dimx) { // Global column int64_t global_col = global_row + bx; // Fill global CSR column indices global_csr_col_ind[nnz++] = global_col; } } } // 9 pt stencil if(nsten == 9) { // Check if current y vertex is on the boundary for(int by = -1; by <= 1; ++by) { if(global_y + by > -1 && global_y + by < global_dimy) { // Check if current x vertex is on the boundary for(int bx = -1; bx <= 1; ++bx) { if(global_x + bx > -1 && global_x + bx < global_dimx) { // Global column int64_t global_col = global_row + by * global_dimx + bx; // Fill global CSR column indices global_csr_col_ind[nnz++] = global_col; } } } } } global_csr_row_ptr[local_row + 1] = nnz; } } // Local number of non-zero entries - need to use long long int to make the communication work int64_t local_nnz = global_csr_row_ptr[local_nrow]; // Total number of non-zeros int64_t global_nnz; MPI_Allreduce(&local_nnz, &global_nnz, 1, MPI_INT64_T, MPI_SUM, *comm); // Now, we need to setup the communication pattern std::map> recv_indices; std::map> send_indices; // CSR matrix row pointers PtrType* int_csr_row_ptr = NULL; PtrType* gst_csr_row_ptr = NULL; allocate_host(local_nrow + 1, &int_csr_row_ptr); allocate_host(local_nrow + 1, &gst_csr_row_ptr); int_csr_row_ptr[0] = 0; gst_csr_row_ptr[0] = 0; // Determine, which vertices need to be sent / received for(int i = 0; i < local_nrow; ++i) { int_csr_row_ptr[i + 1] = int_csr_row_ptr[i]; gst_csr_row_ptr[i + 1] = gst_csr_row_ptr[i]; int64_t global_row = local2global[i]; for(PtrType j = global_csr_row_ptr[i]; j < global_csr_row_ptr[i + 1]; ++j) { int64_t global_col = global_csr_col_ind[j]; // Determine which process owns the vertex int64_t idx_y = global_col / global_dimx; int64_t idx_x = global_col % global_dimx; int idx_proc_y = idx_y / local_dimy; int idx_proc_x = idx_x / local_dimx; int owner = idx_proc_x + idx_proc_y * nproc_x; // If we do not own it, we need to receive it from our neighbor // and also send the current vertex to this neighbor if(owner != rank) { // Store the global column and row id that we have to receive / send from / to a neighbor // We need a set here to eliminate duplicates recv_indices[owner].insert(global_col); send_indices[owner].insert(global_row); ++gst_csr_row_ptr[i + 1]; } else { ++int_csr_row_ptr[i + 1]; } } } // Number of processes we communicate with int nrecv = recv_indices.size(); int nsend = send_indices.size(); // Process ids we communicate with std::vector recvs; std::vector sends; recvs.reserve(nrecv); sends.reserve(nsend); // Index offsets for each neighbor std::vector recv_index_offset; std::vector send_index_offset; recv_index_offset.reserve(nrecv + 1); send_index_offset.reserve(nsend + 1); recv_index_offset.push_back(0); send_index_offset.push_back(0); int cnt = 0; std::map global2ghost; // Go through the recv data for(std::map>::iterator it = recv_indices.begin(); it != recv_indices.end(); ++it) { recvs.push_back(it->first); recv_index_offset.push_back(it->second.size()); for(std::set::iterator iit = it->second.begin(); iit != it->second.end(); ++iit) { global2ghost[*iit] = cnt++; } } // Go through the send data int boundary_nnz = 0; for(std::map>::iterator it = send_indices.begin(); it != send_indices.end(); ++it) { sends.push_back(it->first); send_index_offset.push_back(it->second.size()); boundary_nnz += it->second.size(); } // Exclusive sum for(int i = 0; i < nrecv; ++i) { recv_index_offset[i + 1] += recv_index_offset[i]; } for(int i = 0; i < nsend; ++i) { send_index_offset[i + 1] += send_index_offset[i]; } // Boundary indices std::vector boundary; boundary.reserve(boundary_nnz); for(std::map>::iterator it = send_indices.begin(); it != send_indices.end(); ++it) { for(std::set::iterator iit = it->second.begin(); iit != it->second.end(); ++iit) { boundary.push_back(global2local[*iit]); } } // Initialize manager pm->SetMPICommunicator(comm); pm->SetGlobalNrow(global_nrow); pm->SetGlobalNcol(global_nrow); pm->SetLocalNrow(local_nrow); pm->SetLocalNcol(local_nrow); if(nprocs > 1) { pm->SetBoundaryIndex(boundary_nnz, boundary.data()); pm->SetReceivers(nrecv, recvs.data(), recv_index_offset.data()); pm->SetSenders(nsend, sends.data(), send_index_offset.data()); } mat->SetParallelManager(*pm); // Generate local and ghost matrices local_nnz = int_csr_row_ptr[local_nrow]; int64_t ghost_nnz = gst_csr_row_ptr[local_nrow]; int* int_csr_col_ind = NULL; int* gst_csr_col_ind = NULL; ValueType* int_csr_val = NULL; ValueType* gst_csr_val = NULL; allocate_host(local_nnz, &int_csr_col_ind); allocate_host(local_nnz, &int_csr_val); allocate_host(ghost_nnz, &gst_csr_col_ind); allocate_host(ghost_nnz, &gst_csr_val); // Convert global matrix columns to local columns for(int i = 0; i < local_nrow; ++i) { PtrType local_idx = int_csr_row_ptr[i]; PtrType ghost_idx = gst_csr_row_ptr[i]; int64_t global_row = local2global[i]; for(PtrType j = global_csr_row_ptr[i]; j < global_csr_row_ptr[i + 1]; ++j) { int64_t global_col = global_csr_col_ind[j]; // Determine which process owns the vertex int64_t idx_y = global_col / global_dimx; int64_t idx_x = global_col % global_dimx; int idx_proc_y = idx_y / local_dimy; int idx_proc_x = idx_x / local_dimx; int owner = idx_proc_x + idx_proc_y * nproc_x; // If we do not own it, we need to receive it from our neighbor // and also send the current vertex to this neighbor if(owner != rank) { // Store the global column and row id that we have to receive / send from / to a neighbor // We need a set here to eliminate duplicates recv_indices[owner].insert(global_col); send_indices[owner].insert(global_row); gst_csr_col_ind[ghost_idx] = global2ghost[global_col]; gst_csr_val[ghost_idx] = -1.0; ++ghost_idx; } else { // This is our part int_csr_col_ind[local_idx] = global2local[global_col]; int_csr_val[local_idx] = (global_col == global_row) ? (nsten - 1.0) : -1.0; ++local_idx; } } } free_host(&global_csr_row_ptr); free_host(&global_csr_col_ind); free_host(&local2global); mat->SetLocalDataPtrCSR(&int_csr_row_ptr, &int_csr_col_ind, &int_csr_val, "mat", local_nnz); mat->SetGhostDataPtrCSR(&gst_csr_row_ptr, &gst_csr_col_ind, &gst_csr_val, "gst", ghost_nnz); mat->Sort(); } template void generate_3d_laplacian(int local_dimx, int local_dimy, int local_dimz, const MPI_Comm* comm, GlobalMatrix* mat, ParallelManager* pm, int rank, int nprocs) { // First, we need to determine process pattern for the unit cube int nproc_x; int nproc_y; int nproc_z; compute_3d_process_distribution(nprocs, nproc_x, nproc_y, nproc_z); // Next, determine process index into the unit cube int iproc_z = rank / (nproc_x * nproc_y); int iproc_y = (rank - iproc_z * nproc_x * nproc_y) / nproc_x; int iproc_x = rank % nproc_x; // Global sizes int64_t global_dimx = static_cast(nproc_x) * local_dimx; int64_t global_dimy = static_cast(nproc_y) * local_dimy; int64_t global_dimz = static_cast(nproc_z) * local_dimz; // Global process entry points int64_t global_iproc_x = iproc_x * local_dimx; int64_t global_iproc_y = iproc_y * local_dimy; int64_t global_iproc_z = iproc_z * local_dimz; // Number of rows (global and local) int64_t local_nrow = local_dimx * local_dimy * local_dimz; int64_t global_nrow = global_dimx * global_dimy * global_dimz; // Assemble local CSR matrix row offset pointers std::vector global_csr_row_ptr(local_nrow + 1); std::vector global_csr_col_ind(local_nrow * 27); std::vector local2global(local_nrow); std::map global2local; PtrType nnz = 0; global_csr_row_ptr[0] = 0; // Loop over z dimension for(int local_z = 0; local_z < local_dimz; ++local_z) { // Global index into z int64_t global_z = global_iproc_z + local_z; // Loop over y dimension for(int local_y = 0; local_y < local_dimy; ++local_y) { // Global index into y int64_t global_y = global_iproc_y + local_y; // Loop over x dimension for(int local_x = 0; local_x < local_dimx; ++local_x) { // Global index into x int64_t global_x = global_iproc_x + local_x; // Local row int local_row = local_z * local_dimx * local_dimy + local_y * local_dimx + local_x; // Global row int64_t global_row = global_z * global_dimx * global_dimy + global_y * global_dimx + global_x; // Fill l2g and g2l map local2global[local_row] = global_row; global2local[global_row] = local_row; // Check if current z vertex is on the boundary for(int bz = -1; bz <= 1; ++bz) { if(global_z + bz > -1 && global_z + bz < global_dimz) { // Check if current y vertex is on the boundary for(int by = -1; by <= 1; ++by) { if(global_y + by > -1 && global_y + by < global_dimy) { // Check if current x vertex is on the boundary for(int bx = -1; bx <= 1; ++bx) { if(global_x + bx > -1 && global_x + bx < global_dimx) { // Global column int64_t global_col = global_row + bz * global_dimx * global_dimy + by * global_dimx + bx; // Fill global CSR column indices global_csr_col_ind[nnz++] = global_col; } } } } } } global_csr_row_ptr[local_row + 1] = nnz; } } } // Local number of non-zero entries - need to use long long int to make the communication work int64_t local_nnz = global_csr_row_ptr[local_nrow]; // Total number of non-zeros int64_t global_nnz; MPI_Allreduce(&local_nnz, &global_nnz, 1, MPI_INT64_T, MPI_SUM, *comm); // Now, we need to setup the communication pattern std::map> recv_indices; std::map> send_indices; // CSR matrix row pointers PtrType* int_csr_row_ptr = NULL; PtrType* gst_csr_row_ptr = NULL; allocate_host(local_nrow + 1, &int_csr_row_ptr); allocate_host(local_nrow + 1, &gst_csr_row_ptr); int_csr_row_ptr[0] = 0; gst_csr_row_ptr[0] = 0; // Determine, which vertices need to be sent / received for(int i = 0; i < local_nrow; ++i) { int_csr_row_ptr[i + 1] = int_csr_row_ptr[i]; gst_csr_row_ptr[i + 1] = gst_csr_row_ptr[i]; int64_t global_row = local2global[i]; for(PtrType j = global_csr_row_ptr[i]; j < global_csr_row_ptr[i + 1]; ++j) { int64_t global_col = global_csr_col_ind[j]; // Determine which process owns the vertex int64_t idx_z = global_col / (global_dimx * global_dimy); int64_t idx_y = (global_col - idx_z * global_dimy * global_dimx) / global_dimx; int64_t idx_x = global_col % global_dimx; int idx_proc_z = idx_z / local_dimz; int idx_proc_y = idx_y / local_dimy; int idx_proc_x = idx_x / local_dimx; int owner = idx_proc_x + idx_proc_y * nproc_x + idx_proc_z * nproc_y * nproc_x; // If we do not own it, we need to receive it from our neighbor // and also send the current vertex to this neighbor if(owner != rank) { // Store the global column and row id that we have to receive / send from / to a neighbor // We need a set here to eliminate duplicates recv_indices[owner].insert(global_col); send_indices[owner].insert(global_row); ++gst_csr_row_ptr[i + 1]; } else { ++int_csr_row_ptr[i + 1]; } } } // Number of processes we communicate with int nrecv = recv_indices.size(); int nsend = send_indices.size(); // Process ids we communicate with std::vector recvs; std::vector sends; recvs.reserve(nrecv); sends.reserve(nsend); // Index offsets for each neighbor std::vector recv_index_offset; std::vector send_index_offset; recv_index_offset.reserve(nrecv + 1); send_index_offset.reserve(nsend + 1); recv_index_offset.push_back(0); send_index_offset.push_back(0); int cnt = 0; std::map global2ghost; // Go through the recv data for(std::map>::iterator it = recv_indices.begin(); it != recv_indices.end(); ++it) { recvs.push_back(it->first); recv_index_offset.push_back(it->second.size()); for(std::set::iterator iit = it->second.begin(); iit != it->second.end(); ++iit) { global2ghost[*iit] = cnt++; } } // Go through the send data int boundary_nnz = 0; for(std::map>::iterator it = send_indices.begin(); it != send_indices.end(); ++it) { sends.push_back(it->first); send_index_offset.push_back(it->second.size()); boundary_nnz += it->second.size(); } // Exclusive sum for(int i = 0; i < nrecv; ++i) { recv_index_offset[i + 1] += recv_index_offset[i]; } for(int i = 0; i < nsend; ++i) { send_index_offset[i + 1] += send_index_offset[i]; } // Boundary indices std::vector boundary; boundary.reserve(boundary_nnz); for(std::map>::iterator it = send_indices.begin(); it != send_indices.end(); ++it) { for(std::set::iterator iit = it->second.begin(); iit != it->second.end(); ++iit) { boundary.push_back(global2local[*iit]); } } // Initialize manager pm->SetMPICommunicator(comm); pm->SetGlobalNrow(global_nrow); pm->SetGlobalNcol(global_nrow); pm->SetLocalNrow(local_nrow); pm->SetLocalNcol(local_nrow); if(nprocs > 1) { pm->SetBoundaryIndex(boundary_nnz, boundary.data()); pm->SetReceivers(nrecv, recvs.data(), recv_index_offset.data()); pm->SetSenders(nsend, sends.data(), send_index_offset.data()); } mat->SetParallelManager(*pm); // Generate local and ghost matrices local_nnz = int_csr_row_ptr[local_nrow]; int64_t ghost_nnz = gst_csr_row_ptr[local_nrow]; int* int_csr_col_ind = NULL; int* gst_csr_col_ind = NULL; ValueType* int_csr_val = NULL; ValueType* gst_csr_val = NULL; allocate_host(local_nnz, &int_csr_col_ind); allocate_host(local_nnz, &int_csr_val); allocate_host(ghost_nnz, &gst_csr_col_ind); allocate_host(ghost_nnz, &gst_csr_val); // Convert global matrix columns to local columns for(int i = 0; i < local_nrow; ++i) { PtrType local_idx = int_csr_row_ptr[i]; PtrType ghost_idx = gst_csr_row_ptr[i]; int64_t global_row = local2global[i]; for(PtrType j = global_csr_row_ptr[i]; j < global_csr_row_ptr[i + 1]; ++j) { int64_t global_col = global_csr_col_ind[j]; // Determine which process owns the vertex int64_t idx_z = global_col / (global_dimx * global_dimy); int64_t idx_y = (global_col - idx_z * global_dimy * global_dimx) / global_dimx; int64_t idx_x = global_col % global_dimx; int idx_proc_z = idx_z / local_dimz; int idx_proc_y = idx_y / local_dimy; int idx_proc_x = idx_x / local_dimx; int owner = idx_proc_x + idx_proc_y * nproc_x + idx_proc_z * nproc_y * nproc_x; // If we do not own it, we need to receive it from our neighbor // and also send the current vertex to this neighbor if(owner != rank) { // Store the global column and row id that we have to receive / send from / to a neighbor // We need a set here to eliminate duplicates recv_indices[owner].insert(global_col); send_indices[owner].insert(global_row); gst_csr_col_ind[ghost_idx] = global2ghost[global_col]; gst_csr_val[ghost_idx] = -1.0; ++ghost_idx; } else { // This is our part int_csr_col_ind[local_idx] = global2local[global_col]; int_csr_val[local_idx] = (global_col == global_row) ? 26.0 : -1.0; ++local_idx; } } } mat->SetLocalDataPtrCSR(&int_csr_row_ptr, &int_csr_col_ind, &int_csr_val, "mat", local_nnz); mat->SetGhostDataPtrCSR(&gst_csr_row_ptr, &gst_csr_col_ind, &gst_csr_val, "gst", ghost_nnz); mat->Sort(); } rocALUTION-rocm-7.1.0/clients/include/random.cpp000066400000000000000000000036461507377332500213710ustar00rootroot00000000000000/* ************************************************************************ * 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 "random.hpp" // Random number generator // Note: We do not use random_device to initialize the RNG, because we want // repeatability in case of test failure. TODO: Add seed as an optional CLI // argument, and print the seed on output, to ensure repeatability. rocalution_rng_t rocalution_rng(69069); rocalution_rng_t rocalution_seed(rocalution_rng); void rocalution_rng_set(rocalution_rng_t a) { rocalution_rng = a; } void rocalution_seed_set(rocalution_rng_t a) { rocalution_seed = a; } rocalution_rng_t& rocalution_rng_get() { return rocalution_rng; } rocalution_rng_t& rocalution_seed_get() { return rocalution_seed; } rocALUTION-rocm-7.1.0/clients/include/random.hpp000066400000000000000000000077361507377332500214020ustar00rootroot00000000000000/* ************************************************************************ * 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_RANDOM_HPP #define TESTING_RANDOM_HPP #include #include #include #include /* ==================================================================================== */ // Random number generator using rocalution_rng_t = std::mt19937; void rocalution_rng_set(rocalution_rng_t a); void rocalution_seed_set(rocalution_rng_t a); rocalution_rng_t& rocalution_rng_get(); rocalution_rng_t& rocalution_seed_get(); // Reset the seed (mainly to ensure repeatability of failures in a given suite) inline void rocalution_seedrand() { rocalution_rng_set(rocalution_seed_get()); } /* ==================================================================================== */ /* generate random number :*/ /*! \brief generate a random number in range [a,b] */ template inline T random_generator_exact(int a = 1, int b = 10) { return std::uniform_int_distribution(a, b)(rocalution_rng_get()); } template <> inline std::complex random_generator_exact>(int a, int b) { return std::complex(random_generator_exact(a, b), random_generator_exact(a, b)); } template <> inline std::complex random_generator_exact>(int a, int b) { return std::complex(random_generator_exact(a, b), random_generator_exact(a, b)); } template ::value, bool> = true> inline T random_generator(T a = static_cast(1), T b = static_cast(10)) { return random_generator_exact(a, b); } template ::value, bool> = true> inline T random_generator(T a = static_cast(0), T b = static_cast(1)) { return std::uniform_real_distribution(a, b)(rocalution_rng_get()); } template <> inline std::complex random_generator>(std::complex a, std::complex b) { float theta = random_generator(0.0f, 2.0f * acos(-1.0f)); float r = random_generator(std::abs(a), std::abs(b)); return std::complex(r * cos(theta), r * sin(theta)); } template <> inline std::complex random_generator>(std::complex a, std::complex b) { double theta = random_generator(0.0, 2.0 * acos(-1.0)); double r = random_generator(std::abs(a), std::abs(b)); return std::complex(r * cos(theta), r * sin(theta)); } #endif // TESTING_RANDOM_HPP rocALUTION-rocm-7.1.0/clients/include/testing_backend.hpp000066400000000000000000000065011507377332500232330ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2018-2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_BACKEND_HPP #define TESTING_BACKEND_HPP #include "utility.hpp" #include #include using namespace rocalution; void testing_backend_init_order(void) { bool use_acc = false; bool omp_aff = false; int dev = 0; int nthreads = 4; int threshold = 20000; // Try to stop rocalution without initialization stop_rocalution(); // Set OpenMP threads ASSERT_DEATH(set_omp_threads_rocalution(nthreads), ".*Assertion.*"); // Set OpenMP threshold size ASSERT_DEATH(set_omp_threshold_rocalution(threshold), ".*Assertion.*"); // Initialize rocalution platform set_device_rocalution(device); init_rocalution(); // Set OpenMP thread affinity after init_rocalution should terminate ASSERT_DEATH(set_omp_affinity_rocalution(omp_aff), ".*Assertion.*"); // Select a device after init_rocalution should terminate ASSERT_DEATH(set_device_rocalution(dev), ".*Assertion.*"); // Enable/disable accelerator after init_rocalution should terminate ASSERT_DEATH(disable_accelerator_rocalution(use_acc), ".*Assertion.*"); // Stop rocalution platform stop_rocalution(); } void testing_backend(Arguments argus) { int rank = argus.rank; int dev_per_node = argus.dev_per_node; int dev = argus.dev; int nthreads = argus.omp_nthreads; bool affinity = argus.omp_affinity; int threshold = argus.omp_threshold; bool use_acc = argus.use_acc; // Select a device set_device_rocalution(dev); // Enable/disable accelerator disable_accelerator_rocalution(use_acc); // Set OpenMP thread affinity set_omp_affinity_rocalution(affinity); // Initialize rocalution platform init_rocalution(rank, dev_per_node); // Set OpenMP threads set_omp_threads_rocalution(nthreads); // Set OpenMP threshold size set_omp_threshold_rocalution(threshold); // Stop rocalution platform stop_rocalution(); } #endif // TESTING_BACKEND_HPP rocALUTION-rocm-7.1.0/clients/include/testing_bicgstab.hpp000066400000000000000000000126641507377332500234310ustar00rootroot00000000000000/* ************************************************************************ * 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_BICGSTAB_HPP #define TESTING_BICGSTAB_HPP #include "utility.hpp" #include using namespace rocalution; static bool check_residual(float res) { return (res < 1e-2f); } static bool check_residual(double res) { return (res < 1e-5); } template bool testing_bicgstab(Arguments argus) { int ndim = argus.size; std::string precond = argus.precond; unsigned int format = argus.format; bool disable_accelerator = !argus.use_acc; // Initialize rocALUTION platform disable_accelerator_rocalution(disable_accelerator); set_device_rocalution(device); init_rocalution(); // rocALUTION structures LocalMatrix A; LocalVector x; LocalVector b; LocalVector e; // Generate A int* csr_ptr = NULL; int* csr_col = NULL; T* csr_val = NULL; int nrow = gen_2d_laplacian(ndim, &csr_ptr, &csr_col, &csr_val); int nnz = csr_ptr[nrow]; A.SetDataPtrCSR(&csr_ptr, &csr_col, &csr_val, "A", nnz, nrow, nrow); // Move data to accelerator if(!disable_accelerator) { A.MoveToAccelerator(); x.MoveToAccelerator(); b.MoveToAccelerator(); e.MoveToAccelerator(); } // Allocate x, b and e x.Allocate("x", A.GetN()); b.Allocate("b", A.GetM()); e.Allocate("e", A.GetN()); // b = A * 1 e.Ones(); A.Apply(e, &b); // Random initial guess x.SetRandomUniform(12345ULL, -4.0, 6.0); // Solver BiCGStab, LocalVector, T> ls; // Preconditioner Preconditioner, LocalVector, T>* p; if(precond == "None") p = NULL; else if(precond == "Chebyshev") { // Chebyshev preconditioner // Determine min and max eigenvalues T lambda_min; T lambda_max; A.Gershgorin(lambda_min, lambda_max); AIChebyshev, LocalVector, T>* cheb = new AIChebyshev, LocalVector, T>; cheb->Set(3, lambda_max / 7.0, lambda_max); p = cheb; } else if(precond == "FSAI") p = new FSAI, LocalVector, T>; else if(precond == "SPAI") p = new SPAI, LocalVector, T>; else if(precond == "TNS") p = new TNS, LocalVector, T>; else if(precond == "Jacobi") p = new Jacobi, LocalVector, T>; else if(precond == "GS") p = new GS, LocalVector, T>; else if(precond == "SGS") p = new SGS, LocalVector, T>; else if(precond == "ILU") p = new ILU, LocalVector, T>; else if(precond == "ItILU0") p = new ItILU0, LocalVector, T>; else if(precond == "ILUT") p = new ILUT, LocalVector, T>; else if(precond == "IC") p = new IC, LocalVector, T>; else if(precond == "MCGS") p = new MultiColoredGS, LocalVector, T>; else if(precond == "MCSGS") p = new MultiColoredSGS, LocalVector, T>; else if(precond == "MCILU") p = new MultiColoredILU, LocalVector, T>; else return false; ls.Verbose(0); ls.SetOperator(A); // Set preconditioner if(p != NULL) { ls.SetPreconditioner(*p); } ls.Init(1e-8, 0.0, 1e+8, 0, 10000); ls.RecordResidualHistory(); auto n_iter = ls.GetIterationCount(); ls.Build(); // Matrix format A.ConvertTo(format, format == BCSR ? argus.blockdim : 1); ls.Solve(b, &x); const std::string filename = get_temp_dir() + "test_recorded_history.txt"; ls.RecordHistory(filename); std::remove(filename.c_str()); // Verify solution x.ScaleAdd(-1.0, e); T nrm2 = x.Norm(); bool success = check_residual(nrm2); // Clean up ls.Clear(); if(p != NULL) { delete p; } // Stop rocALUTION platform stop_rocalution(); disable_accelerator_rocalution(false); return success; } #endif // TESTING_BICGSTAB_HPP rocALUTION-rocm-7.1.0/clients/include/testing_bicgstabl.hpp000066400000000000000000000124411507377332500235760ustar00rootroot00000000000000/* ************************************************************************ * 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_BICGSTABL_HPP #define TESTING_BICGSTABL_HPP #include "utility.hpp" #include using namespace rocalution; static bool check_residual(float res) { return (res < 1e-1f); } static bool check_residual(double res) { return (res < 1e-5); } template bool testing_bicgstabl(Arguments argus) { int ndim = argus.size; std::string precond = argus.precond; unsigned int format = argus.format; int l = argus.index; bool disable_accelerator = !argus.use_acc; // Initialize rocALUTION platform disable_accelerator_rocalution(disable_accelerator); set_device_rocalution(device); init_rocalution(); // rocALUTION structures LocalMatrix A; LocalVector x; LocalVector b; LocalVector e; // Generate A int* csr_ptr = NULL; int* csr_col = NULL; T* csr_val = NULL; int nrow = gen_2d_laplacian(ndim, &csr_ptr, &csr_col, &csr_val); int nnz = csr_ptr[nrow]; A.SetDataPtrCSR(&csr_ptr, &csr_col, &csr_val, "A", nnz, nrow, nrow); // Move data to accelerator if(!disable_accelerator) { A.MoveToAccelerator(); x.MoveToAccelerator(); b.MoveToAccelerator(); e.MoveToAccelerator(); } // Allocate x, b and e x.Allocate("x", A.GetN()); b.Allocate("b", A.GetM()); e.Allocate("e", A.GetN()); // b = A * 1 e.Ones(); A.Apply(e, &b); // Random initial guess x.SetRandomUniform(12345ULL, -3.0, 4.0); // Solver BiCGStabl, LocalVector, T> ls; // Preconditioner Preconditioner, LocalVector, T>* p; if(precond == "None") p = NULL; else if(precond == "Chebyshev") { // Chebyshev preconditioner // Determine min and max eigenvalues T lambda_min; T lambda_max; A.Gershgorin(lambda_min, lambda_max); AIChebyshev, LocalVector, T>* cheb = new AIChebyshev, LocalVector, T>; cheb->Set(3, lambda_max / 7.0, lambda_max); p = cheb; } else if(precond == "FSAI") p = new FSAI, LocalVector, T>; else if(precond == "SPAI") p = new SPAI, LocalVector, T>; else if(precond == "TNS") p = new TNS, LocalVector, T>; else if(precond == "Jacobi") p = new Jacobi, LocalVector, T>; else if(precond == "GS") p = new GS, LocalVector, T>; else if(precond == "SGS") p = new SGS, LocalVector, T>; else if(precond == "ILU") p = new ILU, LocalVector, T>; else if(precond == "ItILU0") p = new ItILU0, LocalVector, T>; else if(precond == "ILUT") p = new ILUT, LocalVector, T>; else if(precond == "IC") p = new IC, LocalVector, T>; else if(precond == "MCGS") p = new MultiColoredGS, LocalVector, T>; else if(precond == "MCSGS") p = new MultiColoredSGS, LocalVector, T>; else if(precond == "MCILU") p = new MultiColoredILU, LocalVector, T>; else return false; ls.Verbose(0); ls.SetOperator(A); // Set preconditioner if(p != NULL) { ls.SetPreconditioner(*p); } ls.Init(1e-8, 0.0, 1e+8, 10000); ls.SetOrder(l); ls.Build(); // Matrix format A.ConvertTo(format, format == BCSR ? argus.blockdim : 1); ls.Solve(b, &x); // Verify solution x.ScaleAdd(-1.0, e); T nrm2 = x.Norm(); bool success = check_residual(nrm2); // Clean up ls.Clear(); if(p != NULL) { delete p; } // Stop rocALUTION platform stop_rocalution(); disable_accelerator_rocalution(false); return success; } #endif // TESTING_BICGSTABL_HPP rocALUTION-rocm-7.1.0/clients/include/testing_cg.hpp000066400000000000000000000122661507377332500222420ustar00rootroot00000000000000/* ************************************************************************ * 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_CG_HPP #define TESTING_CG_HPP #include "utility.hpp" #include using namespace rocalution; static bool check_residual(float res) { return (res < 1e-3f); } static bool check_residual(double res) { return (res < 1e-6); } template bool testing_cg(Arguments argus) { int ndim = argus.size; std::string precond = argus.precond; unsigned int format = argus.format; bool disable_accelerator = !argus.use_acc; // Initialize rocALUTION platform disable_accelerator_rocalution(disable_accelerator); set_device_rocalution(device); init_rocalution(); // rocALUTION structures LocalMatrix A; LocalVector x; LocalVector b; LocalVector e; // Generate A int* csr_ptr = NULL; int* csr_col = NULL; T* csr_val = NULL; int nrow = gen_2d_laplacian(ndim, &csr_ptr, &csr_col, &csr_val); int nnz = csr_ptr[nrow]; A.SetDataPtrCSR(&csr_ptr, &csr_col, &csr_val, "A", nnz, nrow, nrow); // Move data to accelerator if(!disable_accelerator) { A.MoveToAccelerator(); x.MoveToAccelerator(); b.MoveToAccelerator(); e.MoveToAccelerator(); } // Allocate x, b and e x.Allocate("x", A.GetN()); b.Allocate("b", A.GetM()); e.Allocate("e", A.GetN()); // b = A * 1 e.Ones(); A.Apply(e, &b); // Random initial guess x.SetRandomUniform(12345ULL, -4.0, 6.0); // Solver CG, LocalVector, T> ls; // Preconditioner Preconditioner, LocalVector, T>* p; if(precond == "None") p = NULL; else if(precond == "Chebyshev") { // Chebyshev preconditioner // Determine min and max eigenvalues T lambda_min; T lambda_max; A.Gershgorin(lambda_min, lambda_max); AIChebyshev, LocalVector, T>* cheb = new AIChebyshev, LocalVector, T>; cheb->Set(3, lambda_max / 7.0, lambda_max); p = cheb; } else if(precond == "FSAI") p = new FSAI, LocalVector, T>; else if(precond == "SPAI") p = new SPAI, LocalVector, T>; else if(precond == "TNS") p = new TNS, LocalVector, T>; else if(precond == "Jacobi") p = new Jacobi, LocalVector, T>; else if(precond == "GS") p = new GS, LocalVector, T>; else if(precond == "SGS") p = new SGS, LocalVector, T>; else if(precond == "ILU") p = new ILU, LocalVector, T>; else if(precond == "ItILU0") p = new ItILU0, LocalVector, T>; else if(precond == "ILUT") p = new ILUT, LocalVector, T>; else if(precond == "IC") p = new IC, LocalVector, T>; else if(precond == "MCGS") p = new MultiColoredGS, LocalVector, T>; else if(precond == "MCSGS") p = new MultiColoredSGS, LocalVector, T>; else if(precond == "MCILU") p = new MultiColoredILU, LocalVector, T>; else return false; ls.Verbose(0); ls.SetOperator(A); // Set preconditioner if(p != NULL) { ls.SetPreconditioner(*p); } ls.Init(1e-8, 0.0, 1e+8, 10000); ls.Build(); // Matrix format A.ConvertTo(format, format == BCSR ? argus.blockdim : 1); ls.Solve(b, &x); // Verify solution x.ScaleAdd(-1.0, e); T nrm2 = x.Norm(); bool success = check_residual(nrm2); // Clean up ls.Clear(); if(p != NULL) { delete p; } // Stop rocALUTION platform stop_rocalution(); disable_accelerator_rocalution(false); return success; } #endif // TESTING_CG_HPP rocALUTION-rocm-7.1.0/clients/include/testing_chebyshev.hpp000066400000000000000000000137631507377332500236340ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 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 "utility.hpp" #include template bool testing_chebyshev(Arguments argus) { using namespace rocalution; int ndim = argus.size; std::string precond = argus.precond; unsigned int format = argus.format; std::string matrix_type = argus.matrix_type; bool rebuildnumeric = argus.rebuildnumeric; bool disable_accelerator = !argus.use_acc; // Initialize rocALUTION platform disable_accelerator_rocalution(disable_accelerator); set_device_rocalution(device); init_rocalution(); // rocALUTION structures LocalMatrix A; LocalVector x; LocalVector b; LocalVector b_old; LocalVector* b_k; LocalVector* b_k1; LocalVector* b_tmp; LocalVector e; LocalVector rhs; // Generate A int* csr_ptr = NULL; int* csr_col = NULL; T* csr_val = NULL; int nrow = 0; int ncol = 0; if(matrix_type == "Laplacian2D") { nrow = gen_2d_laplacian(ndim, &csr_ptr, &csr_col, &csr_val); ncol = nrow; } else { stop_rocalution(); disable_accelerator_rocalution(false); return true; } int nnz = csr_ptr[nrow]; T* csr_val2 = NULL; if(rebuildnumeric) { csr_val2 = new T[nnz]; for(int i = 0; i < nnz; i++) { csr_val2[i] = csr_val[i]; } } A.SetDataPtrCSR(&csr_ptr, &csr_col, &csr_val, "A", nnz, nrow, nrow); // Move data to accelerator if(!disable_accelerator) { A.MoveToAccelerator(); x.MoveToAccelerator(); rhs.MoveToAccelerator(); e.MoveToAccelerator(); } // Allocate x, b and e x.Allocate("x", A.GetN()); rhs.Allocate("b", A.GetM()); e.Allocate("e", A.GetN()); T lambda_min; T lambda_max; A.Gershgorin(lambda_min, lambda_max); // Chebyshev iteration Chebyshev, LocalVector, T> ls; // Initialize rhs such that A 1 = rhs e.Ones(); A.Apply(e, &rhs); // Initial zero guess x.Zeros(); // Preconditioner Preconditioner, LocalVector, T>* p; if(precond == "None") p = NULL; else if(precond == "Chebyshev") { // Chebyshev preconditioner // Determine min and max eigenvalues T lambda_min; T lambda_max; A.Gershgorin(lambda_min, lambda_max); AIChebyshev, LocalVector, T>* cheb = new AIChebyshev, LocalVector, T>; cheb->Set(3, lambda_max / 7.0, lambda_max); p = cheb; } else if(precond == "FSAI") p = new FSAI, LocalVector, T>; else if(precond == "SPAI") p = new SPAI, LocalVector, T>; else if(precond == "TNS") p = new TNS, LocalVector, T>; else if(precond == "Jacobi") p = new Jacobi, LocalVector, T>; else if(precond == "GS") p = new GS, LocalVector, T>; else if(precond == "SGS") p = new SGS, LocalVector, T>; else if(precond == "ILU") p = new ILU, LocalVector, T>; else if(precond == "ItILU0") p = new ItILU0, LocalVector, T>; else if(precond == "ILUT") p = new ILUT, LocalVector, T>; else if(precond == "IC") p = new IC, LocalVector, T>; else if(precond == "MCGS") p = new MultiColoredGS, LocalVector, T>; else if(precond == "MCSGS") p = new MultiColoredSGS, LocalVector, T>; else if(precond == "MCILU") p = new MultiColoredILU, LocalVector, T>; else return false; // Set solver operator ls.SetOperator(A); ls.Verbose(0); ls.SetOperator(A); // Set preconditioner if(p != NULL) { ls.SetPreconditioner(*p); } // Set eigenvalues ls.Set(lambda_min, lambda_max); // Build solver ls.Build(); if(rebuildnumeric) { A.UpdateValuesCSR(csr_val2); delete[] csr_val2; A.Apply(e, &rhs); ls.ReBuildNumeric(); ls.Set(lambda_min, lambda_max); } // Solve A x = rhs ls.Solve(rhs, &x); // Clear solver ls.Clear(); if(p != NULL) { delete p; } // Compute error L2 norm e.ScaleAdd(-1.0, x); T error = e.Norm(); std::cout << "Chebyshev iteration ||e - x||_2 = " << error << std::endl; // Stop rocALUTION platform stop_rocalution(); disable_accelerator_rocalution(false); return true; }rocALUTION-rocm-7.1.0/clients/include/testing_cr.hpp000066400000000000000000000122721507377332500222520ustar00rootroot00000000000000/* ************************************************************************ * 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_CR_HPP #define TESTING_CR_HPP #include "utility.hpp" #include using namespace rocalution; /* static bool check_residual(float res) { return (res < 1e-3f); } */ static bool check_residual(double res) { return (res < 1e-6); } template bool testing_cr(Arguments argus) { int ndim = argus.size; std::string precond = argus.precond; unsigned int format = argus.format; bool disable_accelerator = !argus.use_acc; // Initialize rocALUTION platform disable_accelerator_rocalution(disable_accelerator); set_device_rocalution(device); init_rocalution(); // rocALUTION structures LocalMatrix A; LocalVector x; LocalVector b; LocalVector e; // Generate A int* csr_ptr = NULL; int* csr_col = NULL; T* csr_val = NULL; int nrow = gen_2d_laplacian(ndim, &csr_ptr, &csr_col, &csr_val); int nnz = csr_ptr[nrow]; A.SetDataPtrCSR(&csr_ptr, &csr_col, &csr_val, "A", nnz, nrow, nrow); // Move data to accelerator if(!disable_accelerator) { A.MoveToAccelerator(); x.MoveToAccelerator(); b.MoveToAccelerator(); e.MoveToAccelerator(); } // Allocate x, b and e x.Allocate("x", A.GetN()); b.Allocate("b", A.GetM()); e.Allocate("e", A.GetN()); // b = A * 1 e.Ones(); A.Apply(e, &b); // Random initial guess x.SetRandomUniform(12345ULL, -4.0, 6.0); // Solver CR, LocalVector, T> ls; // Preconditioner Preconditioner, LocalVector, T>* p; if(precond == "None") p = NULL; else if(precond == "Chebyshev") { // Chebyshev preconditioner // Determine min and max eigenvalues T lambda_min; T lambda_max; A.Gershgorin(lambda_min, lambda_max); AIChebyshev, LocalVector, T>* cheb = new AIChebyshev, LocalVector, T>; cheb->Set(3, lambda_max / 7.0, lambda_max); p = cheb; } else if(precond == "FSAI") p = new FSAI, LocalVector, T>; else if(precond == "SPAI") p = new SPAI, LocalVector, T>; else if(precond == "TNS") p = new TNS, LocalVector, T>; else if(precond == "Jacobi") p = new Jacobi, LocalVector, T>; else if(precond == "GS") p = new GS, LocalVector, T>; else if(precond == "SGS") p = new SGS, LocalVector, T>; else if(precond == "ILU") p = new ILU, LocalVector, T>; else if(precond == "ItILU0") p = new ItILU0, LocalVector, T>; else if(precond == "ILUT") p = new ILUT, LocalVector, T>; else if(precond == "IC") p = new IC, LocalVector, T>; else if(precond == "MCGS") p = new MultiColoredGS, LocalVector, T>; else if(precond == "MCSGS") p = new MultiColoredSGS, LocalVector, T>; else if(precond == "MCILU") p = new MultiColoredILU, LocalVector, T>; else return false; ls.Verbose(0); ls.SetOperator(A); // Set preconditioner if(p != NULL) { ls.SetPreconditioner(*p); } ls.Init(1e-8, 0.0, 1e+8, 10000); ls.Build(); // Matrix format A.ConvertTo(format, format == BCSR ? argus.blockdim : 1); ls.Solve(b, &x); // Verify solution x.ScaleAdd(-1.0, e); T nrm2 = x.Norm(); bool success = check_residual(nrm2); // Clean up ls.Clear(); if(p != NULL) { delete p; } // Stop rocALUTION platform stop_rocalution(); disable_accelerator_rocalution(false); return success; } #endif // TESTING_CR_HPP rocALUTION-rocm-7.1.0/clients/include/testing_fcg.hpp000066400000000000000000000122731507377332500224060ustar00rootroot00000000000000/* ************************************************************************ * 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_FCG_HPP #define TESTING_FCG_HPP #include "utility.hpp" #include using namespace rocalution; static bool check_residual(float res) { return (res < 1e-3f); } static bool check_residual(double res) { return (res < 1e-6); } template bool testing_fcg(Arguments argus) { int ndim = argus.size; std::string precond = argus.precond; unsigned int format = argus.format; bool disable_accelerator = !argus.use_acc; // Initialize rocALUTION platform disable_accelerator_rocalution(disable_accelerator); set_device_rocalution(device); init_rocalution(); // rocALUTION structures LocalMatrix A; LocalVector x; LocalVector b; LocalVector e; // Generate A int* csr_ptr = NULL; int* csr_col = NULL; T* csr_val = NULL; int nrow = gen_2d_laplacian(ndim, &csr_ptr, &csr_col, &csr_val); int nnz = csr_ptr[nrow]; A.SetDataPtrCSR(&csr_ptr, &csr_col, &csr_val, "A", nnz, nrow, nrow); // Move data to accelerator if(!disable_accelerator) { A.MoveToAccelerator(); x.MoveToAccelerator(); b.MoveToAccelerator(); e.MoveToAccelerator(); } // Allocate x, b and e x.Allocate("x", A.GetN()); b.Allocate("b", A.GetM()); e.Allocate("e", A.GetN()); // b = A * 1 e.Ones(); A.Apply(e, &b); // Random initial guess x.SetRandomUniform(12345ULL, -4.0, 6.0); // Solver FCG, LocalVector, T> ls; // Preconditioner Preconditioner, LocalVector, T>* p; if(precond == "None") p = NULL; else if(precond == "Chebyshev") { // Chebyshev preconditioner // Determine min and max eigenvalues T lambda_min; T lambda_max; A.Gershgorin(lambda_min, lambda_max); AIChebyshev, LocalVector, T>* cheb = new AIChebyshev, LocalVector, T>; cheb->Set(3, lambda_max / 7.0, lambda_max); p = cheb; } else if(precond == "FSAI") p = new FSAI, LocalVector, T>; else if(precond == "SPAI") p = new SPAI, LocalVector, T>; else if(precond == "TNS") p = new TNS, LocalVector, T>; else if(precond == "Jacobi") p = new Jacobi, LocalVector, T>; else if(precond == "GS") p = new GS, LocalVector, T>; else if(precond == "SGS") p = new SGS, LocalVector, T>; else if(precond == "ILU") p = new ILU, LocalVector, T>; else if(precond == "ItILU0") p = new ItILU0, LocalVector, T>; else if(precond == "ILUT") p = new ILUT, LocalVector, T>; else if(precond == "IC") p = new IC, LocalVector, T>; else if(precond == "MCGS") p = new MultiColoredGS, LocalVector, T>; else if(precond == "MCSGS") p = new MultiColoredSGS, LocalVector, T>; else if(precond == "MCILU") p = new MultiColoredILU, LocalVector, T>; else return false; ls.Verbose(0); ls.SetOperator(A); // Set preconditioner if(p != NULL) { ls.SetPreconditioner(*p); } ls.Init(1e-8, 0.0, 1e+8, 10000); ls.Build(); // Matrix format A.ConvertTo(format, format == BCSR ? argus.blockdim : 1); ls.Solve(b, &x); // Verify solution x.ScaleAdd(-1.0, e); T nrm2 = x.Norm(); bool success = check_residual(nrm2); // Clean up ls.Clear(); if(p != NULL) { delete p; } // Stop rocALUTION platform stop_rocalution(); disable_accelerator_rocalution(false); return success; } #endif // TESTING_FCG_HPP rocALUTION-rocm-7.1.0/clients/include/testing_fgmres.hpp000066400000000000000000000122111507377332500231220ustar00rootroot00000000000000/* ************************************************************************ * 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_FGMRES_HPP #define TESTING_FGMRES_HPP #include "utility.hpp" #include using namespace rocalution; template bool testing_fgmres(Arguments argus) { int ndim = argus.size; int basis = argus.index; std::string precond = argus.precond; unsigned int format = argus.format; bool disable_accelerator = !argus.use_acc; // Initialize rocALUTION platform disable_accelerator_rocalution(disable_accelerator); set_device_rocalution(device); init_rocalution(); // rocALUTION structures LocalMatrix A; LocalVector x; LocalVector b; LocalVector e; // Generate A int* csr_ptr = NULL; int* csr_col = NULL; T* csr_val = NULL; int nrow = gen_2d_laplacian(ndim, &csr_ptr, &csr_col, &csr_val); int nnz = csr_ptr[nrow]; A.SetDataPtrCSR(&csr_ptr, &csr_col, &csr_val, "A", nnz, nrow, nrow); // Move data to accelerator if(!disable_accelerator) { A.MoveToAccelerator(); x.MoveToAccelerator(); b.MoveToAccelerator(); e.MoveToAccelerator(); } // Allocate x, b and e x.Allocate("x", A.GetN()); b.Allocate("b", A.GetM()); e.Allocate("e", A.GetN()); // b = A * 1 e.Ones(); A.Apply(e, &b); // Random initial guess x.SetRandomUniform(12345ULL, -4.0, 6.0); // Solver FGMRES, LocalVector, T> ls; // Preconditioner Preconditioner, LocalVector, T>* p; if(precond == "None") p = NULL; else if(precond == "Chebyshev") { // Chebyshev preconditioner // Determine min and max eigenvalues T lambda_min; T lambda_max; A.Gershgorin(lambda_min, lambda_max); AIChebyshev, LocalVector, T>* cheb = new AIChebyshev, LocalVector, T>; cheb->Set(3, lambda_max / 7.0, lambda_max); p = cheb; } else if(precond == "FSAI") p = new FSAI, LocalVector, T>; else if(precond == "SPAI") p = new SPAI, LocalVector, T>; else if(precond == "TNS") p = new TNS, LocalVector, T>; else if(precond == "Jacobi") p = new Jacobi, LocalVector, T>; else if(precond == "GS") p = new GS, LocalVector, T>; else if(precond == "SGS") p = new SGS, LocalVector, T>; else if(precond == "ILU") p = new ILU, LocalVector, T>; else if(precond == "ItILU0") p = new ItILU0, LocalVector, T>; else if(precond == "ILUT") p = new ILUT, LocalVector, T>; else if(precond == "IC") p = new IC, LocalVector, T>; else if(precond == "MCGS") p = new MultiColoredGS, LocalVector, T>; else if(precond == "MCSGS") p = new MultiColoredSGS, LocalVector, T>; else if(precond == "MCILU") p = new MultiColoredILU, LocalVector, T>; else return false; ls.Verbose(0); ls.SetOperator(A); // Set preconditioner if(p != NULL) { ls.SetPreconditioner(*p); } ls.Init(1e-6, 0.0, 1e+8, 10000); ls.SetBasisSize(basis); ls.Build(); // Matrix format A.ConvertTo(format, format == BCSR ? argus.blockdim : 1); ls.Solve(b, &x); // Verify solution x.ScaleAdd(-1.0, e); T nrm2 = x.Norm(); bool success = (nrm2 < 1e3); // Clean up ls.Clear(); if(p != NULL) { delete p; } // Stop rocALUTION platform stop_rocalution(); disable_accelerator_rocalution(false); return success; } #endif // TESTING_FGMRES_HPP rocALUTION-rocm-7.1.0/clients/include/testing_global_matrix.hpp000066400000000000000000000424071507377332500244750ustar00rootroot00000000000000/* ************************************************************************ * 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. * * ************************************************************************ */ #pragma once #ifndef TESTING_GLOBAL_MATRIX_HPP #define TESTING_GLOBAL_MATRIX_HPP #include "utility.hpp" #include #include using namespace rocalution; template void testing_global_matrix_bad_args(void) { int safe_size = 100; // Initialize rocALUTION set_device_rocalution(device); init_rocalution(); GlobalMatrix mat; GlobalVector vec; int* idata = nullptr; T* data = nullptr; allocate_host(safe_size, &idata); allocate_host(safe_size, &data); // SetDataPtrCSR { int* null_int = nullptr; T* null_data = nullptr; ASSERT_DEATH(mat.SetDataPtrCSR( nullptr, &idata, &data, &idata, &idata, &data, "", safe_size, safe_size), ".*Assertion.*local_row_offset != (NULL|__null)*"); ASSERT_DEATH(mat.SetDataPtrCSR( &idata, nullptr, &data, &idata, &idata, &data, "", safe_size, safe_size), ".*Assertion.*local_col != (NULL|__null)*"); ASSERT_DEATH(mat.SetDataPtrCSR( &idata, &idata, nullptr, &idata, &idata, &data, "", safe_size, safe_size), ".*Assertion.*local_val != (NULL|__null)*"); ASSERT_DEATH(mat.SetDataPtrCSR( &idata, &idata, &data, nullptr, &idata, &data, "", safe_size, safe_size), ".*Assertion.*ghost_row_offset != (NULL|__null)*"); ASSERT_DEATH(mat.SetDataPtrCSR( &idata, &idata, &data, &idata, nullptr, &data, "", safe_size, safe_size), ".*Assertion.*ghost_col != (NULL|__null)*"); ASSERT_DEATH(mat.SetDataPtrCSR( &idata, &idata, &data, &idata, &idata, nullptr, "", safe_size, safe_size), ".*Assertion.*ghost_val != (NULL|__null)*"); ASSERT_DEATH(mat.SetDataPtrCSR( &null_int, &idata, &data, &idata, &idata, &data, "", safe_size, safe_size), ".*Assertion.*local_row_offset != (NULL|__null)*"); ASSERT_DEATH(mat.SetDataPtrCSR( &idata, &null_int, &data, &idata, &idata, &data, "", safe_size, safe_size), ".*Assertion.*local_col != (NULL|__null)*"); ASSERT_DEATH( mat.SetDataPtrCSR( &idata, &idata, &null_data, &idata, &idata, &data, "", safe_size, safe_size), ".*Assertion.*local_val != (NULL|__null)*"); ASSERT_DEATH(mat.SetDataPtrCSR( &idata, &idata, &data, &null_int, &idata, &data, "", safe_size, safe_size), ".*Assertion.*ghost_row_offset != (NULL|__null)*"); ASSERT_DEATH(mat.SetDataPtrCSR( &idata, &idata, &data, &idata, &null_int, &data, "", safe_size, safe_size), ".*Assertion.*ghost_col != (NULL|__null)*"); ASSERT_DEATH( mat.SetDataPtrCSR( &idata, &idata, &data, &idata, &idata, &null_data, "", safe_size, safe_size), ".*Assertion.*ghost_val != (NULL|__null)*"); } // SetDataPtrCOO { int* null_int = nullptr; T* null_data = nullptr; ASSERT_DEATH(mat.SetDataPtrCOO( nullptr, &idata, &data, &idata, &idata, &data, "", safe_size, safe_size), ".*Assertion.*local_row != (NULL|__null)*"); ASSERT_DEATH(mat.SetDataPtrCOO( &idata, nullptr, &data, &idata, &idata, &data, "", safe_size, safe_size), ".*Assertion.*local_col != (NULL|__null)*"); ASSERT_DEATH(mat.SetDataPtrCOO( &idata, &idata, nullptr, &idata, &idata, &data, "", safe_size, safe_size), ".*Assertion.*local_val != (NULL|__null)*"); ASSERT_DEATH(mat.SetDataPtrCOO( &idata, &idata, &data, nullptr, &idata, &data, "", safe_size, safe_size), ".*Assertion.*ghost_row != (NULL|__null)*"); ASSERT_DEATH(mat.SetDataPtrCOO( &idata, &idata, &data, &idata, nullptr, &data, "", safe_size, safe_size), ".*Assertion.*ghost_col != (NULL|__null)*"); ASSERT_DEATH(mat.SetDataPtrCOO( &idata, &idata, &data, &idata, &idata, nullptr, "", safe_size, safe_size), ".*Assertion.*ghost_val != (NULL|__null)*"); ASSERT_DEATH(mat.SetDataPtrCOO( &null_int, &idata, &data, &idata, &idata, &data, "", safe_size, safe_size), ".*Assertion.*local_row != (NULL|__null)*"); ASSERT_DEATH(mat.SetDataPtrCOO( &idata, &null_int, &data, &idata, &idata, &data, "", safe_size, safe_size), ".*Assertion.*local_col != (NULL|__null)*"); ASSERT_DEATH( mat.SetDataPtrCOO( &idata, &idata, &null_data, &idata, &idata, &data, "", safe_size, safe_size), ".*Assertion.*local_val != (NULL|__null)*"); ASSERT_DEATH(mat.SetDataPtrCOO( &idata, &idata, &data, &null_int, &idata, &data, "", safe_size, safe_size), ".*Assertion.*ghost_row != (NULL|__null)*"); ASSERT_DEATH(mat.SetDataPtrCOO( &idata, &idata, &data, &idata, &null_int, &data, "", safe_size, safe_size), ".*Assertion.*ghost_col != (NULL|__null)*"); ASSERT_DEATH( mat.SetDataPtrCOO( &idata, &idata, &data, &idata, &idata, &null_data, "", safe_size, safe_size), ".*Assertion.*ghost_val != (NULL|__null)*"); } // SetLocalDataPtrCSR { int* null_int = nullptr; T* null_data = nullptr; ASSERT_DEATH(mat.SetLocalDataPtrCSR(nullptr, &idata, &data, "", safe_size), ".*Assertion.*row_offset != (NULL|__null)*"); ASSERT_DEATH(mat.SetLocalDataPtrCSR(&idata, nullptr, &data, "", safe_size), ".*Assertion.*col != (NULL|__null)*"); ASSERT_DEATH(mat.SetLocalDataPtrCSR(&idata, &idata, nullptr, "", safe_size), ".*Assertion.*val != (NULL|__null)*"); ASSERT_DEATH(mat.SetLocalDataPtrCSR(&null_int, &idata, &data, "", safe_size), ".*Assertion.*row_offset != (NULL|__null)*"); ASSERT_DEATH(mat.SetLocalDataPtrCSR(&idata, &null_int, &data, "", safe_size), ".*Assertion.*col != (NULL|__null)*"); ASSERT_DEATH(mat.SetLocalDataPtrCSR(&idata, &idata, &null_data, "", safe_size), ".*Assertion.*val != (NULL|__null)*"); } // SetGhostDataPtrCSR { int* null_int = nullptr; T* null_data = nullptr; ASSERT_DEATH(mat.SetGhostDataPtrCSR(nullptr, &idata, &data, "", safe_size), ".*Assertion.*row_offset != (NULL|__null)*"); ASSERT_DEATH(mat.SetGhostDataPtrCSR(&idata, nullptr, &data, "", safe_size), ".*Assertion.*col != (NULL|__null)*"); ASSERT_DEATH(mat.SetGhostDataPtrCSR(&idata, &idata, nullptr, "", safe_size), ".*Assertion.*val != (NULL|__null)*"); ASSERT_DEATH(mat.SetGhostDataPtrCSR(&null_int, &idata, &data, "", safe_size), ".*Assertion.*row_offset != (NULL|__null)*"); ASSERT_DEATH(mat.SetGhostDataPtrCSR(&idata, &null_int, &data, "", safe_size), ".*Assertion.*col != (NULL|__null)*"); ASSERT_DEATH(mat.SetGhostDataPtrCSR(&idata, &idata, &null_data, "", safe_size), ".*Assertion.*val != (NULL|__null)*"); } // SetLocalDataPtrCOO { int* null_int = nullptr; T* null_data = nullptr; ASSERT_DEATH(mat.SetLocalDataPtrCOO(nullptr, &idata, &data, "", safe_size), ".*Assertion.*row != (NULL|__null)*"); ASSERT_DEATH(mat.SetLocalDataPtrCOO(&idata, nullptr, &data, "", safe_size), ".*Assertion.*col != (NULL|__null)*"); ASSERT_DEATH(mat.SetLocalDataPtrCOO(&idata, &idata, nullptr, "", safe_size), ".*Assertion.*val != (NULL|__null)*"); ASSERT_DEATH(mat.SetLocalDataPtrCOO(&null_int, &idata, &data, "", safe_size), ".*Assertion.*row != (NULL|__null)*"); ASSERT_DEATH(mat.SetLocalDataPtrCOO(&idata, &null_int, &data, "", safe_size), ".*Assertion.*col != (NULL|__null)*"); ASSERT_DEATH(mat.SetLocalDataPtrCOO(&idata, &idata, &null_data, "", safe_size), ".*Assertion.*val != (NULL|__null)*"); } // SetGhostDataPtrCOO { int* null_int = nullptr; T* null_data = nullptr; ASSERT_DEATH(mat.SetGhostDataPtrCOO(nullptr, &idata, &data, "", safe_size), ".*Assertion.*row != (NULL|__null)*"); ASSERT_DEATH(mat.SetGhostDataPtrCOO(&idata, nullptr, &data, "", safe_size), ".*Assertion.*col != (NULL|__null)*"); ASSERT_DEATH(mat.SetGhostDataPtrCOO(&idata, &idata, nullptr, "", safe_size), ".*Assertion.*val != (NULL|__null)*"); ASSERT_DEATH(mat.SetGhostDataPtrCOO(&null_int, &idata, &data, "", safe_size), ".*Assertion.*row != (NULL|__null)*"); ASSERT_DEATH(mat.SetGhostDataPtrCOO(&idata, &null_int, &data, "", safe_size), ".*Assertion.*col != (NULL|__null)*"); ASSERT_DEATH(mat.SetGhostDataPtrCOO(&idata, &idata, &null_data, "", safe_size), ".*Assertion.*val != (NULL|__null)*"); } // LeaveDataPtrCSR { int* null_int = nullptr; T* null_data = nullptr; ASSERT_DEATH( mat.LeaveDataPtrCSR(&idata, &null_int, &null_data, &null_int, &null_int, &null_data), ".*Assertion.*local_row_offset == (NULL|__null)*"); ASSERT_DEATH( mat.LeaveDataPtrCSR(&null_int, &idata, &null_data, &null_int, &null_int, &null_data), ".*Assertion.*local_col == (NULL|__null)*"); ASSERT_DEATH( mat.LeaveDataPtrCSR(&null_int, &null_int, &data, &null_int, &null_int, &null_data), ".*Assertion.*local_val == (NULL|__null)*"); ASSERT_DEATH( mat.LeaveDataPtrCSR(&null_int, &null_int, &null_data, &idata, &null_int, &null_data), ".*Assertion.*ghost_row_offset == (NULL|__null)*"); ASSERT_DEATH( mat.LeaveDataPtrCSR(&null_int, &null_int, &null_data, &null_int, &idata, &null_data), ".*Assertion.*ghost_col == (NULL|__null)*"); ASSERT_DEATH( mat.LeaveDataPtrCSR(&null_int, &null_int, &null_data, &null_int, &null_int, &data), ".*Assertion.*ghost_val == (NULL|__null)*"); } // LeaveDataPtrCOO { int* null_int = nullptr; T* null_data = nullptr; ASSERT_DEATH( mat.LeaveDataPtrCOO(&idata, &null_int, &null_data, &null_int, &null_int, &null_data), ".*Assertion.*local_row == (NULL|__null)*"); ASSERT_DEATH( mat.LeaveDataPtrCOO(&null_int, &idata, &null_data, &null_int, &null_int, &null_data), ".*Assertion.*local_col == (NULL|__null)*"); ASSERT_DEATH( mat.LeaveDataPtrCOO(&null_int, &null_int, &data, &null_int, &null_int, &null_data), ".*Assertion.*local_val == (NULL|__null)*"); ASSERT_DEATH( mat.LeaveDataPtrCOO(&null_int, &null_int, &null_data, &idata, &null_int, &null_data), ".*Assertion.*ghost_row == (NULL|__null)*"); ASSERT_DEATH( mat.LeaveDataPtrCOO(&null_int, &null_int, &null_data, &null_int, &idata, &null_data), ".*Assertion.*ghost_col == (NULL|__null)*"); ASSERT_DEATH( mat.LeaveDataPtrCOO(&null_int, &null_int, &null_data, &null_int, &null_int, &data), ".*Assertion.*ghost_val == (NULL|__null)*"); } // LeaveLocalDataPtrCSR { int* null_int = nullptr; T* null_data = nullptr; ASSERT_DEATH(mat.LeaveLocalDataPtrCSR(&idata, &null_int, &null_data), ".*Assertion.*row_offset == (NULL|__null)*"); ASSERT_DEATH(mat.LeaveLocalDataPtrCSR(&null_int, &idata, &null_data), ".*Assertion.*col == (NULL|__null)*"); ASSERT_DEATH(mat.LeaveLocalDataPtrCSR(&null_int, &null_int, &data), ".*Assertion.*val == (NULL|__null)*"); } // LeaveGhostDataPtrCSR { int* null_int = nullptr; T* null_data = nullptr; ASSERT_DEATH(mat.LeaveGhostDataPtrCSR(&idata, &null_int, &null_data), ".*Assertion.*row_offset == (NULL|__null)*"); ASSERT_DEATH(mat.LeaveGhostDataPtrCSR(&null_int, &idata, &null_data), ".*Assertion.*col == (NULL|__null)*"); ASSERT_DEATH(mat.LeaveGhostDataPtrCSR(&null_int, &null_int, &data), ".*Assertion.*val == (NULL|__null)*"); } // LeaveLocalDataPtrCOO { int* null_int = nullptr; T* null_data = nullptr; ASSERT_DEATH(mat.LeaveLocalDataPtrCOO(&idata, &null_int, &null_data), ".*Assertion.*row == (NULL|__null)*"); ASSERT_DEATH(mat.LeaveLocalDataPtrCOO(&null_int, &idata, &null_data), ".*Assertion.*col == (NULL|__null)*"); ASSERT_DEATH(mat.LeaveLocalDataPtrCOO(&null_int, &null_int, &data), ".*Assertion.*val == (NULL|__null)*"); } // LeaveGhostDataPtrCOO { int* null_int = nullptr; T* null_data = nullptr; ASSERT_DEATH(mat.LeaveGhostDataPtrCOO(&idata, &null_int, &null_data), ".*Assertion.*row == (NULL|__null)*"); ASSERT_DEATH(mat.LeaveGhostDataPtrCOO(&null_int, &idata, &null_data), ".*Assertion.*col == (NULL|__null)*"); ASSERT_DEATH(mat.LeaveGhostDataPtrCOO(&null_int, &null_int, &data), ".*Assertion.*val == (NULL|__null)*"); } // Apply { GlobalVector* null_vec = nullptr; ASSERT_DEATH(mat.Apply(vec, null_vec), ".*Assertion.*out != (NULL|__null)*"); } // ApplyAdd { GlobalVector* null_vec = nullptr; ASSERT_DEATH(mat.ApplyAdd(vec, 1.0, null_vec), ".*Assertion.*out != (NULL|__null)*"); } // ExtractInverseDiagonal { GlobalVector* null_vec = nullptr; ASSERT_DEATH(mat.ExtractInverseDiagonal(null_vec), ".*Assertion.*vec_inv_diag != (NULL|__null)*"); } // InitialPairwiseAggregation { int val; int* null_int = nullptr; LocalVector lvint; LocalVector* null_vec = nullptr; ASSERT_DEATH(mat.InitialPairwiseAggregation(0.1, val, null_vec, val, &null_int, val, 0), ".*Assertion.*G != (NULL|__null)*"); ASSERT_DEATH(mat.InitialPairwiseAggregation(0.1, val, &lvint, val, &idata, val, 0), ".*Assertion.*rG == (NULL|__null)*"); } // FurtherPairwiseAggregation { int val; int* null_int = nullptr; LocalVector lvint; LocalVector* null_vec = nullptr; ASSERT_DEATH(mat.FurtherPairwiseAggregation(0.1, val, null_vec, val, &idata, val, 0), ".*Assertion.*G != (NULL|__null)*"); ASSERT_DEATH(mat.FurtherPairwiseAggregation(0.1, val, &lvint, val, &null_int, val, 0), ".*Assertion.*rG != (NULL|__null)*"); } // CoarsenOperator { GlobalMatrix Ac; ParallelManager pm; LocalVector lvint; GlobalMatrix* null_mat = nullptr; int* null_int = nullptr; ASSERT_DEATH( mat.CoarsenOperator(null_mat, safe_size, safe_size, lvint, safe_size, idata, safe_size), ".*Assertion.*Ac != (NULL|__null)*"); ASSERT_DEATH( mat.CoarsenOperator(&Ac, safe_size, safe_size, lvint, safe_size, null_int, safe_size), ".*Assertion.*rG != (NULL|__null)*"); } free_host(&idata); free_host(&data); // Stop rocALUTION stop_rocalution(); } #endif // TESTING_GLOBAL_MATRIX_HPP rocALUTION-rocm-7.1.0/clients/include/testing_global_vector.hpp000066400000000000000000000043731507377332500244730ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2018-2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_GLOBAL_VECTOR_HPP #define TESTING_GLOBAL_VECTOR_HPP #include "utility.hpp" #include #include using namespace rocalution; template void testing_global_vector_bad_args(void) { int safe_size = 100; // Initialize rocALUTION set_device_rocalution(device); init_rocalution(); GlobalVector vec; // SetDataPtr { T* null_data = nullptr; ASSERT_DEATH(vec.SetDataPtr(nullptr, "", safe_size), ".*Assertion.*ptr != (NULL|__null)*"); ASSERT_DEATH(vec.SetDataPtr(&null_data, "", safe_size), ".*Assertion.*ptr != (NULL|__null)*"); } // LeaveDataPtr { T* data = nullptr; allocate_host(safe_size, &data); ASSERT_DEATH(vec.LeaveDataPtr(&data), ".*Assertion.*ptr == (NULL|__null)*"); free_host(&data); } // Stop rocALUTION stop_rocalution(); } #endif // TESTING_GLOBAL_VECTOR_HPP rocALUTION-rocm-7.1.0/clients/include/testing_gmres.hpp000066400000000000000000000126671507377332500227730ustar00rootroot00000000000000/* ************************************************************************ * 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_GMRES_HPP #define TESTING_GMRES_HPP #include "utility.hpp" #include using namespace rocalution; template bool testing_gmres(Arguments argus, bool expectConvergence = true) { int ndim = argus.size; int basis = argus.index; std::string matrix = argus.matrix; std::string precond = argus.precond; unsigned int format = argus.format; bool disable_accelerator = !argus.use_acc; // Initialize rocALUTION platform disable_accelerator_rocalution(disable_accelerator); set_device_rocalution(device); init_rocalution(); // rocALUTION structures LocalMatrix A; LocalVector x; LocalVector b; LocalVector e; // Generate A int* csr_ptr = NULL; int* csr_col = NULL; T* csr_val = NULL; int nrow = 0; if(matrix == "laplacian") nrow = gen_2d_laplacian(ndim, &csr_ptr, &csr_col, &csr_val); else if(matrix == "permuted_identity") nrow = gen_permuted_identity(ndim, &csr_ptr, &csr_col, &csr_val); else return false; int nnz = csr_ptr[nrow]; A.SetDataPtrCSR(&csr_ptr, &csr_col, &csr_val, "A", nnz, nrow, nrow); // Move data to accelerator if(!disable_accelerator) { A.MoveToAccelerator(); x.MoveToAccelerator(); b.MoveToAccelerator(); e.MoveToAccelerator(); } // Allocate x, b and e x.Allocate("x", A.GetN()); b.Allocate("b", A.GetM()); e.Allocate("e", A.GetN()); // b = A * 1 e.Ones(); A.Apply(e, &b); // Random initial guess x.SetRandomUniform(12345ULL, -4.0, 6.0); // Solver GMRES, LocalVector, T> ls; // Preconditioner Preconditioner, LocalVector, T>* p; if(precond == "None") p = NULL; else if(precond == "Chebyshev") { // Chebyshev preconditioner // Determine min and max eigenvalues T lambda_min; T lambda_max; A.Gershgorin(lambda_min, lambda_max); AIChebyshev, LocalVector, T>* cheb = new AIChebyshev, LocalVector, T>; cheb->Set(3, lambda_max / 7.0, lambda_max); p = cheb; } else if(precond == "FSAI") p = new FSAI, LocalVector, T>; else if(precond == "SPAI") p = new SPAI, LocalVector, T>; else if(precond == "TNS") p = new TNS, LocalVector, T>; else if(precond == "Jacobi") p = new Jacobi, LocalVector, T>; else if(precond == "GS") p = new GS, LocalVector, T>; else if(precond == "SGS") p = new SGS, LocalVector, T>; else if(precond == "ILU") p = new ILU, LocalVector, T>; else if(precond == "ItILU0") p = new ItILU0, LocalVector, T>; else if(precond == "ILUT") p = new ILUT, LocalVector, T>; else if(precond == "IC") p = new IC, LocalVector, T>; else if(precond == "MCGS") p = new MultiColoredGS, LocalVector, T>; else if(precond == "MCSGS") p = new MultiColoredSGS, LocalVector, T>; else if(precond == "MCILU") p = new MultiColoredILU, LocalVector, T>; else return false; ls.Verbose(0); ls.SetOperator(A); // Set preconditioner if(p != NULL) { ls.SetPreconditioner(*p); } ls.Init(1e-6, 0.0, 1e+8, 10000); ls.SetBasisSize(basis); ls.Build(); // Matrix format A.ConvertTo(format, format == BCSR ? argus.blockdim : 1); ls.Solve(b, &x); // Verify solution x.ScaleAdd(-1.0, e); T nrm2 = x.Norm(); bool success = expectConvergence ? (nrm2 < 1e3) : true; // Clean up ls.Clear(); if(p != NULL) { delete p; } // Stop rocALUTION platform stop_rocalution(); disable_accelerator_rocalution(false); return success; } #endif // TESTING_GMRES_HPP rocALUTION-rocm-7.1.0/clients/include/testing_idr.hpp000066400000000000000000000124521507377332500224240ustar00rootroot00000000000000/* ************************************************************************ * 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_IDR_HPP #define TESTING_IDR_HPP #include "utility.hpp" #include using namespace rocalution; static bool check_residual(float res) { return (res < 1e-1f); } static bool check_residual(double res) { return (res < 1e-5); } template bool testing_idr(Arguments argus) { int ndim = argus.size; std::string precond = argus.precond; unsigned int format = argus.format; int l = argus.index; bool disable_accelerator = !argus.use_acc; // Initialize rocALUTION platform disable_accelerator_rocalution(disable_accelerator); set_device_rocalution(device); init_rocalution(); // rocALUTION structures LocalMatrix A; LocalVector x; LocalVector b; LocalVector e; // Generate A int* csr_ptr = NULL; int* csr_col = NULL; T* csr_val = NULL; int nrow = gen_2d_laplacian(ndim, &csr_ptr, &csr_col, &csr_val); int nnz = csr_ptr[nrow]; A.SetDataPtrCSR(&csr_ptr, &csr_col, &csr_val, "A", nnz, nrow, nrow); // Move data to accelerator if(!disable_accelerator) { A.MoveToAccelerator(); x.MoveToAccelerator(); b.MoveToAccelerator(); e.MoveToAccelerator(); } // Allocate x, b and e x.Allocate("x", A.GetN()); b.Allocate("b", A.GetM()); e.Allocate("e", A.GetN()); // b = A * 1 e.Ones(); A.Apply(e, &b); // Random initial guess x.SetRandomUniform(123456ULL, -4.0, 6.0); // Solver IDR, LocalVector, T> ls; // Preconditioner Preconditioner, LocalVector, T>* p; if(precond == "None") p = NULL; else if(precond == "Chebyshev") { // Chebyshev preconditioner // Determine min and max eigenvalues T lambda_min; T lambda_max; A.Gershgorin(lambda_min, lambda_max); AIChebyshev, LocalVector, T>* cheb = new AIChebyshev, LocalVector, T>; cheb->Set(3, lambda_max / 7.0, lambda_max); p = cheb; } else if(precond == "FSAI") p = new FSAI, LocalVector, T>; else if(precond == "SPAI") p = new SPAI, LocalVector, T>; else if(precond == "TNS") p = new TNS, LocalVector, T>; else if(precond == "Jacobi") p = new Jacobi, LocalVector, T>; else if(precond == "GS") p = new GS, LocalVector, T>; else if(precond == "SGS") p = new SGS, LocalVector, T>; else if(precond == "ILU") p = new ILU, LocalVector, T>; else if(precond == "ItILU0") p = new ItILU0, LocalVector, T>; else if(precond == "ILUT") p = new ILUT, LocalVector, T>; else if(precond == "IC") p = new IC, LocalVector, T>; else if(precond == "MCGS") p = new MultiColoredGS, LocalVector, T>; else if(precond == "MCSGS") p = new MultiColoredSGS, LocalVector, T>; else if(precond == "MCILU") p = new MultiColoredILU, LocalVector, T>; else return false; ls.Verbose(0); ls.SetOperator(A); // Set preconditioner if(p != NULL) { ls.SetPreconditioner(*p); } ls.Init(1e-8, 0.0, 1e+8, 10000); ls.SetShadowSpace(l); ls.SetRandomSeed(12345ULL); ls.Build(); // Matrix format A.ConvertTo(format, format == BCSR ? argus.blockdim : 1); ls.Solve(b, &x); // Verify solution x.ScaleAdd(-1.0, e); T nrm2 = x.Norm(); bool success = check_residual(nrm2); // Clean up ls.Clear(); if(p != NULL) { delete p; } // Stop rocALUTION platform stop_rocalution(); disable_accelerator_rocalution(false); return success; } #endif // TESTING_IDR_HPP rocALUTION-rocm-7.1.0/clients/include/testing_inversion.hpp000066400000000000000000000075241507377332500236660ustar00rootroot00000000000000/* ************************************************************************ * 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_INVERSION_HPP #define TESTING_INVERSION_HPP #include "utility.hpp" #include using namespace rocalution; static bool check_residual(float res) { return (res < 1e-3f); } static bool check_residual(double res) { return (res < 1e-6); } template bool testing_inversion(Arguments argus) { int ndim = argus.size; unsigned int format = argus.format; std::string matrix_type = argus.matrix_type; const bool use_host_and_acc = argus.use_acc; // Initialize rocALUTION platform set_device_rocalution(device); init_rocalution(); // rocALUTION structures LocalMatrix A; LocalVector x; LocalVector b; LocalVector e; // Generate A int* csr_ptr = NULL; int* csr_col = NULL; T* csr_val = NULL; int nrow = 0; int ncol = 0; if(matrix_type == "Laplacian2D") { nrow = gen_2d_laplacian(ndim, &csr_ptr, &csr_col, &csr_val); ncol = nrow; } else if(matrix_type == "PermutedIdentity") { nrow = gen_permuted_identity(ndim, &csr_ptr, &csr_col, &csr_val); ncol = nrow; } else { return false; } int nnz = csr_ptr[nrow]; A.SetDataPtrCSR(&csr_ptr, &csr_col, &csr_val, "A", nnz, nrow, nrow); // Allocate x, b and e x.Allocate("x", A.GetN()); b.Allocate("b", A.GetM()); e.Allocate("e", A.GetN()); // b = A * 1 e.Ones(); A.Apply(e, &b); // Random initial guess x.SetRandomUniform(12345ULL, -4.0, 6.0); // Solver Inversion, LocalVector, T> dls; dls.Verbose(0); dls.SetOperator(A); dls.Build(); // Matrix format A.ConvertTo(format, format == BCSR ? argus.blockdim : 1); // Move data to accelerator dls.MoveToAccelerator(); A.MoveToAccelerator(); x.MoveToAccelerator(); b.MoveToAccelerator(); e.MoveToAccelerator(); dls.Solve(b, &x); // Verify solution x.ScaleAdd(-1.0, e); T nrm2_acc = x.Norm(); bool success = check_residual(nrm2_acc); if(use_host_and_acc) { dls.MoveToHost(); A.MoveToHost(); x.MoveToHost(); e.MoveToHost(); b.MoveToHost(); dls.Solve(b, &x); // Verify solution x.ScaleAdd(-1.0, e); T nrm2_host = x.Norm(); success = success && check_residual(nrm2_host); } // Clean up dls.Clear(); // Stop rocALUTION platform stop_rocalution(); return success; } #endif // TESTING_INVERSION_HPP rocALUTION-rocm-7.1.0/clients/include/testing_itsolver.hpp000066400000000000000000000112061507377332500235110ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 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 "utility.hpp" #include template bool testing_itsolver(Arguments argus) { using namespace rocalution; int ndim = argus.size; unsigned int format = argus.format; std::string matrix_type = argus.matrix_type; bool disable_accelerator = !argus.use_acc; // Initialize rocALUTION platform disable_accelerator_rocalution(disable_accelerator); set_device_rocalution(device); init_rocalution(); // rocALUTION structures LocalMatrix A; LocalVector x; LocalVector b; LocalVector e; // Generate A int* csr_ptr = NULL; int* csr_col = NULL; T* csr_val = NULL; int nrow = 0; int ncol = 0; if(matrix_type == "Laplacian2D") { nrow = gen_2d_laplacian(ndim, &csr_ptr, &csr_col, &csr_val); ncol = nrow; } else if(matrix_type == "PermutedIdentity") { nrow = gen_permuted_identity(ndim, &csr_ptr, &csr_col, &csr_val); ncol = nrow; } else { stop_rocalution(); disable_accelerator_rocalution(false); return true; } int nnz = csr_ptr[nrow]; A.SetDataPtrCSR(&csr_ptr, &csr_col, &csr_val, "A", nnz, nrow, nrow); // Move data to accelerator if(!disable_accelerator) { A.MoveToAccelerator(); x.MoveToAccelerator(); b.MoveToAccelerator(); e.MoveToAccelerator(); } // Allocate x, b and e x.Allocate("x", A.GetN()); b.Allocate("b", A.GetM()); e.Allocate("e", A.GetN()); // Linear Solver FixedPoint, LocalVector, T> fp; // Preconditioner ItILU0, LocalVector, T> p; // Set iterative ILU stopping criteria p.SetTolerance(1e-8); p.SetMaxIter(50); p.SetAlgorithm(ItILU0Algorithm::SyncSplit); // Set up iterative triangular solve SolverDescr descr; descr.SetTriSolverAlg(TriSolverAlg_Iterative); descr.SetIterativeSolverMaxIteration(30); descr.SetIterativeSolverTolerance(1e-8); descr.DisableIterativeSolverTolerance(); descr.EnableIterativeSolverTolerance(); SolverDescr descr_new(descr); // Copy the descriptor p.SetSolverDescriptor(descr_new); // Initialize b such that A 1 = b e.Ones(); A.Apply(e, &b); // Initial zero guess x.Zeros(); // Set solver operator fp.SetOperator(A); // Set solver preconditioner fp.SetPreconditioner(p); // Build solver fp.Build(); // Verbosity output fp.Verbose(1); fp.InitMinIter(1); fp.InitMaxIter(1000); fp.InitTol(1e-8, 1e-8, 1e-8); // Print matrix info A.Info(); // Solve A x = b fp.Solve(b, &x); int niter_preconditioner; const double* history = p.GetConvergenceHistory(&niter_preconditioner); auto res_final = fp.GetCurrentResidual(); //auto res_init = fp.GetInitialResidual(); //auto niter = fp.GetNumIterations(); auto status_solver = fp.GetSolverStatus(); auto ind = fp.GetAmaxResidualIndex(); // Clear solver fp.Clear(); // Compute error L2 norm e.ScaleAdd(-1.0, x); T error = e.Norm(); std::cout << "||e - x||_2 = " << error << std::endl; // Stop rocALUTION platform stop_rocalution(); disable_accelerator_rocalution(false); return true; }rocALUTION-rocm-7.1.0/clients/include/testing_local_matrix.hpp000066400000000000000000002530541507377332500243310ustar00rootroot00000000000000/* ************************************************************************ * 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_LOCAL_MATRIX_HPP #define TESTING_LOCAL_MATRIX_HPP #include "utility.hpp" #include #include using namespace rocalution; template void testing_local_matrix_bad_args(void) { int safe_size = 100; // Initialize rocALUTION set_device_rocalution(device); init_rocalution(); LocalMatrix mat1; LocalMatrix mat2; LocalVector vec1; LocalVector bool1; LocalVector int1; LocalVector int641; // null pointers int* null_int = nullptr; T* null_data = nullptr; // Valid pointers int* vint = nullptr; T* vdata = nullptr; allocate_host(safe_size, &vint); allocate_host(safe_size, &vdata); // Valid matrices LocalMatrix mat3; mat3.AllocateCSR("valid", safe_size, safe_size, safe_size); // ExtractSubMatrix, ExtractSubMatrices, Extract(Inverse)Diagonal, ExtractL/U { LocalMatrix* mat_null = nullptr; LocalMatrix** mat_null2 = nullptr; LocalMatrix*** pmat = new LocalMatrix**[1]; pmat[0] = new LocalMatrix*[1]; pmat[0][0] = new LocalMatrix; LocalVector* null_vec = nullptr; ASSERT_DEATH(mat1.ExtractSubMatrix(0, 0, safe_size, safe_size, mat_null), ".*Assertion.*mat != (NULL|__null)*"); ASSERT_DEATH(mat1.ExtractSubMatrices(safe_size, safe_size, null_int, vint, pmat), ".*Assertion.*row_offset != (NULL|__null)*"); ASSERT_DEATH(mat1.ExtractSubMatrices(safe_size, safe_size, vint, null_int, pmat), ".*Assertion.*col_offset != (NULL|__null)*"); ASSERT_DEATH(mat1.ExtractSubMatrices(safe_size, safe_size, vint, vint, nullptr), ".*Assertion.*mat != (NULL|__null)*"); ASSERT_DEATH(mat1.ExtractSubMatrices(safe_size, safe_size, vint, vint, &mat_null2), ".*Assertion.*mat != (NULL|__null)*"); ASSERT_DEATH(mat1.ExtractDiagonal(null_vec), ".*Assertion.*vec_diag != (NULL|__null)*"); ASSERT_DEATH(mat1.ExtractInverseDiagonal(null_vec), ".*Assertion.*vec_inv_diag != (NULL|__null)*"); ASSERT_DEATH(mat1.ExtractL(mat_null, true), ".*Assertion.*L != (NULL|__null)*"); ASSERT_DEATH(mat1.ExtractU(mat_null, true), ".*Assertion.*U != (NULL|__null)*"); delete pmat[0][0]; delete[] pmat[0]; delete[] pmat; } // CMK, RCMK, ConnectivityOrder, MultiColoring, MaximalIndependentSet, ZeroBlockPermutation { int val; LocalVector* null_vec = nullptr; ASSERT_DEATH(mat1.CMK(null_vec), ".*Assertion.*permutation != (NULL|__null)*"); ASSERT_DEATH(mat1.RCMK(null_vec), ".*Assertion.*permutation != (NULL|__null)*"); ASSERT_DEATH(mat1.ConnectivityOrder(null_vec), ".*Assertion.*permutation != (NULL|__null)*"); ASSERT_DEATH(mat1.MultiColoring(val, &vint, &int1), ".*Assertion.*size_colors == (NULL|__null)*"); ASSERT_DEATH(mat1.MultiColoring(val, &null_int, null_vec), ".*Assertion.*permutation != (NULL|__null)*"); ASSERT_DEATH(mat1.MaximalIndependentSet(val, null_vec), ".*Assertion.*permutation != (NULL|__null)*"); ASSERT_DEATH(mat1.ZeroBlockPermutation(val, null_vec), ".*Assertion.*permutation != (NULL|__null)*"); } // LSolve, USolve, LLSolve, LUSolve, QRSolve { LocalVector* null_vec = nullptr; ASSERT_DEATH(mat1.LSolve(vec1, null_vec), ".*Assertion.*out != (NULL|__null)*"); ASSERT_DEATH(mat1.USolve(vec1, null_vec), ".*Assertion.*out != (NULL|__null)*"); ASSERT_DEATH(mat1.LLSolve(vec1, null_vec), ".*Assertion.*out != (NULL|__null)*"); ASSERT_DEATH(mat1.LLSolve(vec1, vec1, null_vec), ".*Assertion.*out != (NULL|__null)*"); ASSERT_DEATH(mat1.LUSolve(vec1, null_vec), ".*Assertion.*out != (NULL|__null)*"); ASSERT_DEATH(mat1.QRSolve(vec1, null_vec), ".*Assertion.*out != (NULL|__null)*"); } // ItLSolve, ItUSolve, ItLLSolve, ItLUSolve { LocalVector* null_vec = nullptr; int max_iter = 1; double tol = 0; ASSERT_DEATH(mat1.ItLSolve(max_iter, tol, true, vec1, null_vec), ".*Assertion.*out != (NULL|__null)*"); ASSERT_DEATH(mat1.ItUSolve(max_iter, tol, true, vec1, null_vec), ".*Assertion.*out != (NULL|__null)*"); ASSERT_DEATH(mat1.ItLLSolve(max_iter, tol, true, vec1, null_vec), ".*Assertion.*out != (NULL|__null)*"); ASSERT_DEATH(mat1.ItLLSolve(max_iter, tol, true, vec1, vec1, null_vec), ".*Assertion.*out != (NULL|__null)*"); ASSERT_DEATH(mat1.ItLUSolve(max_iter, tol, true, vec1, null_vec), ".*Assertion.*out != (NULL|__null)*"); } // ICFactorize, Householder { T val; LocalVector* null_vec = nullptr; ASSERT_DEATH(mat1.ICFactorize(null_vec), ".*Assertion.*inv_diag != (NULL|__null)*"); ASSERT_DEATH(mat1.Householder(0, val, null_vec), ".*Assertion.*vec != (NULL|__null)*"); } // CopyFrom functions { ASSERT_DEATH(mat1.UpdateValuesCSR(null_data), ".*Assertion.*val != (NULL|__null)*"); ASSERT_DEATH(mat1.CopyFromCSR(null_int, vint, vdata), ".*Assertion.*row_offsets != (NULL|__null)*"); ASSERT_DEATH(mat3.CopyFromCSR(vint, null_int, vdata), ".*Assertion.*col != (NULL|__null)*"); ASSERT_DEATH(mat3.CopyFromCSR(vint, vint, null_data), ".*Assertion.*val != (NULL|__null)*"); ASSERT_DEATH(mat1.CopyToCSR(null_int, vint, vdata), ".*Assertion.*row_offsets != (NULL|__null)*"); ASSERT_DEATH(mat3.CopyToCSR(vint, null_int, vdata), ".*Assertion.*col != (NULL|__null)*"); ASSERT_DEATH(mat3.CopyToCSR(vint, vint, null_data), ".*Assertion.*val != (NULL|__null)*"); ASSERT_DEATH(mat1.CopyFromCOO(null_int, vint, vdata), ".*Assertion.*row != (NULL|__null)*"); ASSERT_DEATH(mat1.CopyFromCOO(vint, null_int, vdata), ".*Assertion.*col != (NULL|__null)*"); ASSERT_DEATH(mat1.CopyFromCOO(vint, vint, null_data), ".*Assertion.*val != (NULL|__null)*"); ASSERT_DEATH(mat1.CopyToCOO(null_int, vint, vdata), ".*Assertion.*row != (NULL|__null)*"); ASSERT_DEATH(mat1.CopyToCOO(vint, null_int, vdata), ".*Assertion.*col != (NULL|__null)*"); ASSERT_DEATH(mat1.CopyToCOO(vint, vint, null_data), ".*Assertion.*val != (NULL|__null)*"); ASSERT_DEATH( mat1.CopyFromHostCSR(null_int, vint, vdata, "", safe_size, safe_size, safe_size), ".*Assertion.*row_offset != (NULL|__null)*"); ASSERT_DEATH( mat1.CopyFromHostCSR(vint, null_int, vdata, "", safe_size, safe_size, safe_size), ".*Assertion.*col != (NULL|__null)*"); ASSERT_DEATH( mat1.CopyFromHostCSR(vint, vint, null_data, "", safe_size, safe_size, safe_size), ".*Assertion.*val != (NULL|__null)*"); } // CreateFromMat { LocalMatrix* null_mat = nullptr; ASSERT_DEATH(mat1.CreateFromMap(int1, safe_size, safe_size, null_mat), ".*Assertion.*pro != (NULL|__null)*"); } // Apply(Add) { LocalVector* null_vec = nullptr; ASSERT_DEATH(mat1.Apply(vec1, null_vec), ".*Assertion.*out != (NULL|__null)*"); ASSERT_DEATH(mat1.ApplyAdd(vec1, 1.0, null_vec), ".*Assertion.*out != (NULL|__null)*"); } // Row/Column manipulation { LocalVector* null_vec = nullptr; ASSERT_DEATH(mat1.ExtractColumnVector(0, null_vec), ".*Assertion.*vec != (NULL|__null)*"); ASSERT_DEATH(mat1.ExtractRowVector(0, null_vec), ".*Assertion.*vec != (NULL|__null)*"); } // AMG { int val; LocalVector* bool_null_vec = nullptr; LocalVector* int64_null_vec = nullptr; ASSERT_DEATH(mat1.AMGGreedyAggregate(0.1, bool_null_vec, &int641, &int641), ".*Assertion.*connections != (NULL|__null)*"); ASSERT_DEATH(mat1.AMGGreedyAggregate(0.1, &bool1, int64_null_vec, &int641), ".*Assertion.*aggregates != (NULL|__null)*"); ASSERT_DEATH(mat1.AMGGreedyAggregate(0.1, &bool1, &int641, int64_null_vec), ".*Assertion.*aggregate_root_nodes != (NULL|__null)*"); LocalMatrix* null_mat = nullptr; ASSERT_DEATH(mat1.AMGSmoothedAggregation(0.1, bool1, int641, int641, null_mat), ".*Assertion.*prolong != (NULL|__null)*"); } { int val; LocalVector* null_vec = nullptr; LocalMatrix* null_mat = nullptr; ASSERT_DEATH(mat1.AMGUnsmoothedAggregation(int641, int641, null_mat), ".*Assertion.*prolong != (NULL|__null)*"); ASSERT_DEATH(mat1.InitialPairwiseAggregation(0.1, val, null_vec, val, &null_int, val, 0), ".*Assertion.*G != (NULL|__null)*"); ASSERT_DEATH(mat1.InitialPairwiseAggregation(0.1, val, &int1, val, &vint, val, 0), ".*Assertion.*rG == (NULL|__null)*"); ASSERT_DEATH( mat1.InitialPairwiseAggregation(mat2, 0.1, val, null_vec, val, &null_int, val, 0), ".*Assertion.*G != (NULL|__null)*"); ASSERT_DEATH(mat1.InitialPairwiseAggregation(mat2, 0.1, val, &int1, val, &vint, val, 0), ".*Assertion.*rG == (NULL|__null)*"); ASSERT_DEATH(mat1.FurtherPairwiseAggregation(0.1, val, null_vec, val, &vint, val, 0), ".*Assertion.*G != (NULL|__null)*"); ASSERT_DEATH(mat1.FurtherPairwiseAggregation(0.1, val, &int1, val, &null_int, val, 0), ".*Assertion.*rG != (NULL|__null)*"); ASSERT_DEATH(mat1.FurtherPairwiseAggregation(mat2, 0.1, val, null_vec, val, &vint, val, 0), ".*Assertion.*G != (NULL|__null)*"); ASSERT_DEATH(mat1.FurtherPairwiseAggregation(mat2, 0.1, val, &int1, val, &null_int, val, 0), ".*Assertion.*rG != (NULL|__null)*"); ASSERT_DEATH( mat1.CoarsenOperator(null_mat, safe_size, safe_size, int1, safe_size, vint, safe_size), ".*Assertion.*Ac != (NULL|__null)*"); ASSERT_DEATH( mat1.CoarsenOperator(&mat2, safe_size, safe_size, int1, safe_size, null_int, safe_size), ".*Assertion.*rG != (NULL|__null)*"); } // SetDataPtr { ASSERT_DEATH( mat1.SetDataPtrCOO(&null_int, &vint, &vdata, "", safe_size, safe_size, safe_size), ".*Assertion.*row != (NULL|__null)*"); ASSERT_DEATH( mat1.SetDataPtrCOO(&vint, &null_int, &vdata, "", safe_size, safe_size, safe_size), ".*Assertion.*col != (NULL|__null)*"); ASSERT_DEATH( mat1.SetDataPtrCOO(&vint, &vint, &null_data, "", safe_size, safe_size, safe_size), ".*Assertion.*val != (NULL|__null)*"); ASSERT_DEATH( mat1.SetDataPtrCOO(nullptr, &vint, &vdata, "", safe_size, safe_size, safe_size), ".*Assertion.*row != (NULL|__null)*"); ASSERT_DEATH( mat1.SetDataPtrCOO(&vint, nullptr, &vdata, "", safe_size, safe_size, safe_size), ".*Assertion.*col != (NULL|__null)*"); ASSERT_DEATH(mat1.SetDataPtrCOO(&vint, &vint, nullptr, "", safe_size, safe_size, safe_size), ".*Assertion.*val != (NULL|__null)*"); ASSERT_DEATH( mat1.SetDataPtrCSR(&null_int, &vint, &vdata, "", safe_size, safe_size, safe_size), ".*Assertion.*row_offset != (NULL|__null)*"); ASSERT_DEATH( mat1.SetDataPtrCSR(&vint, &null_int, &vdata, "", safe_size, safe_size, safe_size), ".*Assertion.*col != (NULL|__null)*"); ASSERT_DEATH( mat1.SetDataPtrCSR(&vint, &vint, &null_data, "", safe_size, safe_size, safe_size), ".*Assertion.*val != (NULL|__null)*"); ASSERT_DEATH( mat1.SetDataPtrCSR(nullptr, &vint, &vdata, "", safe_size, safe_size, safe_size), ".*Assertion.*row_offset != (NULL|__null)*"); ASSERT_DEATH( mat1.SetDataPtrCSR(&vint, nullptr, &vdata, "", safe_size, safe_size, safe_size), ".*Assertion.*col != (NULL|__null)*"); ASSERT_DEATH(mat1.SetDataPtrCSR(&vint, &vint, nullptr, "", safe_size, safe_size, safe_size), ".*Assertion.*val != (NULL|__null)*"); ASSERT_DEATH( mat1.SetDataPtrMCSR(&null_int, &vint, &vdata, "", safe_size, safe_size, safe_size), ".*Assertion.*row_offset != (NULL|__null)*"); ASSERT_DEATH( mat1.SetDataPtrMCSR(&vint, &null_int, &vdata, "", safe_size, safe_size, safe_size), ".*Assertion.*col != (NULL|__null)*"); ASSERT_DEATH( mat1.SetDataPtrMCSR(&vint, &vint, &null_data, "", safe_size, safe_size, safe_size), ".*Assertion.*val != (NULL|__null)*"); ASSERT_DEATH( mat1.SetDataPtrMCSR(nullptr, &vint, &vdata, "", safe_size, safe_size, safe_size), ".*Assertion.*row_offset != (NULL|__null)*"); ASSERT_DEATH( mat1.SetDataPtrMCSR(&vint, nullptr, &vdata, "", safe_size, safe_size, safe_size), ".*Assertion.*col != (NULL|__null)*"); ASSERT_DEATH( mat1.SetDataPtrMCSR(&vint, &vint, nullptr, "", safe_size, safe_size, safe_size), ".*Assertion.*val != (NULL|__null)*"); ASSERT_DEATH( mat1.SetDataPtrELL(&null_int, &vdata, "", safe_size, safe_size, safe_size, safe_size), ".*Assertion.*col != (NULL|__null)*"); ASSERT_DEATH( mat1.SetDataPtrELL(&vint, &null_data, "", safe_size, safe_size, safe_size, safe_size), ".*Assertion.*val != (NULL|__null)*"); ASSERT_DEATH( mat1.SetDataPtrELL(nullptr, &vdata, "", safe_size, safe_size, safe_size, safe_size), ".*Assertion.*col != (NULL|__null)*"); ASSERT_DEATH( mat1.SetDataPtrELL(&vint, nullptr, "", safe_size, safe_size, safe_size, safe_size), ".*Assertion.*val != (NULL|__null)*"); ASSERT_DEATH( mat1.SetDataPtrDIA(&null_int, &vdata, "", safe_size, safe_size, safe_size, safe_size), ".*Assertion.*offset != (NULL|__null)*"); ASSERT_DEATH( mat1.SetDataPtrDIA(&vint, &null_data, "", safe_size, safe_size, safe_size, safe_size), ".*Assertion.*val != (NULL|__null)*"); ASSERT_DEATH( mat1.SetDataPtrDIA(nullptr, &vdata, "", safe_size, safe_size, safe_size, safe_size), ".*Assertion.*offset != (NULL|__null)*"); ASSERT_DEATH( mat1.SetDataPtrDIA(&vint, nullptr, "", safe_size, safe_size, safe_size, safe_size), ".*Assertion.*val != (NULL|__null)*"); ASSERT_DEATH(mat1.SetDataPtrDENSE(&null_data, "", safe_size, safe_size), ".*Assertion.*val != (NULL|__null)*"); ASSERT_DEATH(mat1.SetDataPtrDENSE(nullptr, "", safe_size, safe_size), ".*Assertion.*val != (NULL|__null)*"); } // LeaveDataPtr { int val; ASSERT_DEATH(mat1.LeaveDataPtrCOO(&vint, &null_int, &null_data), ".*Assertion.*row == (NULL|__null)*"); ASSERT_DEATH(mat1.LeaveDataPtrCOO(&null_int, &vint, &null_data), ".*Assertion.*col == (NULL|__null)*"); ASSERT_DEATH(mat1.LeaveDataPtrCOO(&null_int, &null_int, &vdata), ".*Assertion.*val == (NULL|__null)*"); ASSERT_DEATH(mat1.LeaveDataPtrCSR(&vint, &null_int, &null_data), ".*Assertion.*row_offset == (NULL|__null)*"); ASSERT_DEATH(mat1.LeaveDataPtrCSR(&null_int, &vint, &null_data), ".*Assertion.*col == (NULL|__null)*"); ASSERT_DEATH(mat1.LeaveDataPtrCSR(&null_int, &null_int, &vdata), ".*Assertion.*val == (NULL|__null)*"); ASSERT_DEATH(mat1.LeaveDataPtrMCSR(&vint, &null_int, &null_data), ".*Assertion.*row_offset == (NULL|__null)*"); ASSERT_DEATH(mat1.LeaveDataPtrMCSR(&null_int, &vint, &null_data), ".*Assertion.*col == (NULL|__null)*"); ASSERT_DEATH(mat1.LeaveDataPtrMCSR(&null_int, &null_int, &vdata), ".*Assertion.*val == (NULL|__null)*"); ASSERT_DEATH(mat1.LeaveDataPtrELL(&null_int, &vdata, val), ".*Assertion.*val == (NULL|__null)*"); ASSERT_DEATH(mat1.LeaveDataPtrELL(&vint, &null_data, val), ".*Assertion.*col == (NULL|__null)*"); ASSERT_DEATH(mat1.LeaveDataPtrDIA(&null_int, &vdata, val), ".*Assertion.*val == (NULL|__null)*"); ASSERT_DEATH(mat1.LeaveDataPtrDIA(&vint, &null_data, val), ".*Assertion.*offset == (NULL|__null)*"); ASSERT_DEATH(mat1.LeaveDataPtrDENSE(&vdata), ".*Assertion.*val == (NULL|__null)*"); } free_host(&vint); free_host(&vdata); // Stop rocALUTION stop_rocalution(); } template bool testing_local_matrix_conversions(Arguments argus) { int size = argus.size; int blockdim = argus.blockdim; std::string matrix_type = argus.matrix_type; // Initialize rocALUTION set_device_rocalution(device); init_rocalution(); // Generate A int* csr_ptr = NULL; int* csr_col = NULL; T* csr_val = NULL; int nrow = 0; int ncol = 0; if(matrix_type == "Laplacian2D") { nrow = gen_2d_laplacian(size, &csr_ptr, &csr_col, &csr_val); ncol = nrow; } else if(matrix_type == "PermutedIdentity") { nrow = gen_permuted_identity(size, &csr_ptr, &csr_col, &csr_val); ncol = nrow; } else if(matrix_type == "Random") { nrow = gen_random(100 * size, 50 * size, 6, &csr_ptr, &csr_col, &csr_val); ncol = 50 * size; } else { return false; } int nnz = csr_ptr[nrow]; LocalMatrix A; A.SetDataPtrCSR(&csr_ptr, &csr_col, &csr_val, "A", nnz, nrow, ncol); assert(csr_ptr == NULL); assert(csr_col == NULL); assert(csr_val == NULL); bool success = true; // Check host conversions A.ConvertToCOO(); success &= A.Check(); A.ConvertToDIA(); success &= A.Check(); A.ConvertToELL(); success &= A.Check(); A.ConvertToHYB(); success &= A.Check(); A.ConvertToDENSE(); success &= A.Check(); A.ConvertToMCSR(); success &= A.Check(); A.ConvertToBCSR(blockdim); success &= A.Check(); A.ConvertToCSR(); success &= A.Check(); // Check accelerator conversions A.MoveToAccelerator(); A.ConvertToCOO(); success &= A.Check(); A.ConvertToDIA(); success &= A.Check(); A.ConvertToELL(); success &= A.Check(); A.ConvertToHYB(); success &= A.Check(); A.ConvertToDENSE(); success &= A.Check(); A.ConvertToMCSR(); success &= A.Check(); A.ConvertToBCSR(blockdim); success &= A.Check(); A.ConvertToCSR(); success &= A.Check(); // Stop rocALUTION platform stop_rocalution(); return success; } template bool testing_local_matrix_allocations(Arguments argus) { int size = argus.size; int blockdim = argus.blockdim; int m = size; int n = size; int mb = (m + blockdim - 1) / blockdim; int nb = (n + blockdim - 1) / blockdim; int nnz = 0.05 * m * n; if(nnz == 0) { nnz = m * n; } int nnzb = 0.01 * mb * nb; if(nnzb == 0) { nnzb = mb * nb; } // Initialize rocALUTION set_device_rocalution(device); init_rocalution(); int ndiag = 5; int ell_max_row = 6; int ell_nnz = ell_max_row * m; int coo_nnz = (nnz - ell_nnz) < 0 ? 0 : nnz - ell_nnz; // Testing allocating matrix types LocalMatrix A; A.AllocateCSR("A", nnz, m, n); LocalMatrix B; B.AllocateBCSR("B", nnzb, mb, nb, blockdim); LocalMatrix C; C.AllocateCOO("C", nnz, m, n); LocalMatrix D; D.AllocateDIA("D", nnz, m, n, ndiag); LocalMatrix E; E.AllocateMCSR("E", nnz, m, n); LocalMatrix F; F.AllocateELL("F", ell_nnz, m, n, ell_max_row); LocalMatrix G; G.AllocateHYB("G", ell_nnz, coo_nnz, ell_max_row, m, n); LocalMatrix H; H.AllocateDENSE("H", m, n); // Stop rocALUTION platform stop_rocalution(); return true; } template bool testing_local_matrix_zero(Arguments argus) { int size = argus.size; int blockdim = argus.blockdim; int m = size; int n = size; int mb = (m + blockdim - 1) / blockdim; int nb = (n + blockdim - 1) / blockdim; int nnz = 0.05 * m * n; if(nnz == 0) { nnz = m * n; } // Initialize rocALUTION set_device_rocalution(device); init_rocalution(); // Testing Zeros LocalMatrix A; A.AllocateCSR("A", nnz, m, n); A.Zeros(); A.Info(); // Stop rocALUTION platform stop_rocalution(); return true; } template bool testing_local_matrix_set_data_ptr(Arguments argus) { int size = argus.size; int blockdim = argus.blockdim; int m = size; int n = size; int mb = (m + blockdim - 1) / blockdim; int nb = (n + blockdim - 1) / blockdim; int nnz = 0.05 * m * n; if(nnz == 0) { nnz = m * n; } int nnzb = 0.01 * mb * nb; if(nnzb == 0) { nnzb = mb * nb; } // Initialize rocALUTION set_device_rocalution(device); init_rocalution(); int ndiag = 5; int ell_max_row = 6; int ell_nnz = ell_max_row * m; int coo_nnz = (nnz - ell_nnz) < 0 ? 0 : nnz - ell_nnz; // Testing allocating matrix types { LocalMatrix A; int* row_offset = NULL; int* col = NULL; T* val = NULL; allocate_host(m + 1, &row_offset); allocate_host(nnz, &col); allocate_host(nnz, &val); set_to_zero_host(m + 1, row_offset); set_to_zero_host(nnz, col); set_to_zero_host(nnz, val); A.SetDataPtrCSR(&row_offset, &col, &val, "A", nnz, m, n); A.LeaveDataPtrCSR(&row_offset, &col, &val); free_host(&row_offset); free_host(&col); free_host(&val); } { LocalMatrix B; int* row_offset = NULL; int* col = NULL; T* val = NULL; allocate_host(mb + 1, &row_offset); allocate_host(nnzb, &col); allocate_host(nnzb, &val); set_to_zero_host(mb + 1, row_offset); set_to_zero_host(nnzb, col); set_to_zero_host(nnzb, val); B.SetDataPtrBCSR(&row_offset, &col, &val, "C", nnzb, mb, nb, blockdim); B.LeaveDataPtrBCSR(&row_offset, &col, &val, blockdim); free_host(&row_offset); free_host(&col); free_host(&val); } { LocalMatrix C; int* row = NULL; int* col = NULL; T* val = NULL; allocate_host(nnz, &row); allocate_host(nnz, &col); allocate_host(nnz, &val); set_to_zero_host(nnz, row); set_to_zero_host(nnz, col); set_to_zero_host(nnz, val); C.SetDataPtrCOO(&row, &col, &val, "C", nnz, m, n); C.LeaveDataPtrCOO(&row, &col, &val); free_host(&row); free_host(&col); free_host(&val); } { LocalMatrix E; int* row_offset = NULL; int* col = NULL; T* val = NULL; allocate_host(m + 1, &row_offset); allocate_host(nnz, &col); allocate_host(nnz, &val); set_to_zero_host(m + 1, row_offset); set_to_zero_host(nnz, col); set_to_zero_host(nnz, val); E.SetDataPtrMCSR(&row_offset, &col, &val, "C", nnz, m, n); E.LeaveDataPtrMCSR(&row_offset, &col, &val); free_host(&row_offset); free_host(&col); free_host(&val); } { LocalMatrix F; int* col = NULL; T* val = NULL; allocate_host(ell_nnz, &col); allocate_host(ell_nnz, &val); set_to_zero_host(ell_nnz, col); set_to_zero_host(ell_nnz, val); F.SetDataPtrELL(&col, &val, "C", ell_nnz, m, n, ell_max_row); F.LeaveDataPtrELL(&col, &val, ell_max_row); free_host(&col); free_host(&val); } { LocalMatrix H; T* val = NULL; allocate_host(m * n, &val); set_to_zero_host(m * n, val); H.SetDataPtrDENSE(&val, "C", m, n); H.LeaveDataPtrDENSE(&val); free_host(&val); } // Stop rocALUTION platform stop_rocalution(); return true; } template LocalMatrix getTestMatrix() { // Create a simple 2x2 CSR matrix LocalMatrix matrix; matrix.AllocateCSR("TestMatrix", 4, 2, 2); int row_offsets[3] = {0, 2, 4}; int col_indices[4] = {0, 1, 0, 1}; T values[4] = {1.0, 2.0, 3.0, 4.0}; matrix.CopyFromCSR(row_offsets, col_indices, values); return matrix; } template void getTestMatrix(Arguments argus, LocalMatrix& matrix, bool& is_invertible) { int size = argus.size; int blockdim = argus.blockdim; std::string matrix_type = argus.matrix_type; // Generate A int* csr_ptr = NULL; int* csr_col = NULL; T* csr_val = NULL; int nrow = 0; int ncol = 0; if(matrix_type == "Laplacian2D") { nrow = gen_2d_laplacian(size, &csr_ptr, &csr_col, &csr_val); ncol = nrow; is_invertible = true; } else if(matrix_type == "PermutedIdentity") { nrow = gen_permuted_identity(size, &csr_ptr, &csr_col, &csr_val); ncol = nrow; is_invertible = true; } else if(matrix_type == "Random") { nrow = gen_random(100 * size, 50 * size, 6, &csr_ptr, &csr_col, &csr_val); ncol = 50 * size; is_invertible = false; } else { is_invertible = true; matrix = getTestMatrix(); return; } int nnz = csr_ptr[nrow]; matrix.SetDataPtrCSR(&csr_ptr, &csr_col, &csr_val, "TestMatrix", nnz, nrow, ncol); } template void getTestMatrix(Arguments argus, LocalMatrix& matrix) { bool is_invertible; getTestMatrix(argus, matrix, is_invertible); } template void getMatrixVal(const LocalMatrix& matrix, T* values) { // Copy the values from the matrix to the provided array int64_t m = matrix.GetM(); int64_t nnz = matrix.GetNnz(); int* row_offsets = new int[m + 1]; int* col_indices = new int[nnz]; T* matrix_values = new T[nnz]; matrix.CopyToCSR(row_offsets, col_indices, matrix_values); for(int i = 0; i < nnz; ++i) { values[i] = matrix_values[i]; } delete[] row_offsets; delete[] col_indices; delete[] matrix_values; } template void getMatrixDiagVal(const LocalMatrix& matrix, T* values) { // Copy the values from the matrix to the provided array int64_t m = matrix.GetM(); int64_t nnz = matrix.GetNnz(); int* row_offsets = new int[m + 1]; int* col_indices = new int[nnz]; T* matrix_values = new T[nnz]; matrix.CopyToCSR(row_offsets, col_indices, matrix_values); for(int row = 0; row < m; ++row) { int start = row_offsets[row]; int end = row_offsets[row + 1]; for(int i = start; i < end; ++i) { if(col_indices[i] == row) // Diagonal element { values[row] = matrix_values[i]; break; // Only one diagonal element per row } } } delete[] row_offsets; delete[] col_indices; delete[] matrix_values; } void checkPermutation(const LocalVector& permutation) { // Check that permutation is a valid permutation of 0..N-1 std::vector seen(permutation.GetSize(), 0); for(int i = 0; i < permutation.GetSize(); ++i) { int idx = permutation[i]; EXPECT_GE(idx, 0); EXPECT_LT(idx, permutation.GetSize()); seen[idx]++; } for(int i = 0; i < seen.size(); ++i) { EXPECT_EQ(seen[i], 1); // Each index appears exactly once } } template T getTolerance() { // Set tolerance based on the type if(std::is_same::value) { return 1e-5f; // Tolerance for float } else { return 1e-10; // Default tolerance for other types } } // Helper to extract dense matrix from LocalMatrix template std::vector> extract_dense_matrix(const LocalMatrix& matrix) { int m = matrix.GetM(); int n = matrix.GetN(); int nnz = matrix.GetNnz(); std::vector> dense(m, std::vector(n, static_cast(0))); std::vector row_offsets(m + 1); std::vector col_indices(nnz); std::vector values(nnz); matrix.CopyToCSR(row_offsets.data(), col_indices.data(), values.data()); for(int row = 0; row < m; ++row) { for(int idx = row_offsets[row]; idx < row_offsets[row + 1]; ++idx) { int col = col_indices[idx]; dense[row][col] = values[idx]; } } return dense; } template void testing_local_allocate() { // Test AllocateCSR { LocalMatrix mat; EXPECT_NO_THROW(mat.AllocateCSR("AllocatedMatrix", 4, 2, 2)); EXPECT_EQ(mat.GetNnz(), 4); EXPECT_EQ(mat.GetM(), 2); EXPECT_EQ(mat.GetN(), 2); } // Test AllocateCOO { LocalMatrix mat; mat.AllocateCOO("AllocatedMatrix", 4, 2, 2); EXPECT_EQ(mat.GetNnz(), 4); EXPECT_EQ(mat.GetM(), 2); EXPECT_EQ(mat.GetN(), 2); } // Test AllocateBCSR { LocalMatrix mat; int nnzb = 4, mb = 2, nb = 2, blockdim = 2; EXPECT_NO_THROW(mat.AllocateBCSR("BCSR", nnzb, mb, nb, blockdim)); EXPECT_EQ(mat.GetNnz(), nnzb * blockdim * blockdim); EXPECT_EQ(mat.GetM(), mb * blockdim); EXPECT_EQ(mat.GetN(), nb * blockdim); } // Test AllocateDIA { LocalMatrix mat; int nnz = 6, m = 3, n = 3, ndiag = 2; EXPECT_NO_THROW(mat.AllocateDIA("DIA", nnz, m, n, ndiag)); EXPECT_EQ(mat.GetNnz(), nnz); EXPECT_EQ(mat.GetM(), m); EXPECT_EQ(mat.GetN(), n); } // Test AllocateMCSR { LocalMatrix mat; int nnz = 5, m = 3, n = 3; EXPECT_NO_THROW(mat.AllocateMCSR("MCSR", nnz, m, n)); EXPECT_EQ(mat.GetNnz(), nnz); EXPECT_EQ(mat.GetM(), m); EXPECT_EQ(mat.GetN(), n); } // Test AllocateELL { LocalMatrix mat; int ell_nnz = 6, m = 3, n = 3, ell_max_row = 2; EXPECT_NO_THROW(mat.AllocateELL("ELL", ell_nnz, m, n, ell_max_row)); EXPECT_EQ(mat.GetNnz(), ell_nnz); EXPECT_EQ(mat.GetM(), m); EXPECT_EQ(mat.GetN(), n); } // Test AllocateHYB { LocalMatrix mat; int m = 3, n = 3; int ell_max_row = 2; int ell_nnz = ell_max_row * m; // 2 * 3 = 6 int coo_nnz = 2; EXPECT_NO_THROW(mat.AllocateHYB("HYB", ell_nnz, coo_nnz, ell_max_row, m, n)); EXPECT_EQ(mat.GetNnz(), ell_nnz + coo_nnz); // 8 EXPECT_EQ(mat.GetM(), m); EXPECT_EQ(mat.GetN(), n); } // Test AllocateDENSE { LocalMatrix mat; int m = 3, n = 3; EXPECT_NO_THROW(mat.AllocateDENSE("DENSE", m, n)); EXPECT_EQ(mat.GetNnz(), m * n); EXPECT_EQ(mat.GetM(), m); EXPECT_EQ(mat.GetN(), n); } } template void testing_check_with_empty_matrix() { LocalMatrix empty_matrix; // Check should pass without any issues EXPECT_NO_THROW(empty_matrix.Check()); // Info should not throw an error EXPECT_NO_THROW(empty_matrix.Info()); } template void testing_local_copy_from_async() { auto matrix = getTestMatrix(); LocalMatrix copy_matrix; // CopyFromAsync should copy the matrix asynchronously (if supported) EXPECT_NO_THROW(copy_matrix.CopyFromAsync(matrix)); EXPECT_NO_THROW(matrix.Sync()); EXPECT_EQ(copy_matrix.GetM(), matrix.GetM()); EXPECT_EQ(copy_matrix.GetN(), matrix.GetN()); EXPECT_EQ(copy_matrix.GetNnz(), matrix.GetNnz()); // Compare dense representations auto dense_orig = extract_dense_matrix(matrix); auto dense_copy = extract_dense_matrix(copy_matrix); EXPECT_EQ(dense_orig.size(), dense_copy.size()); for(size_t i = 0; i < dense_orig.size(); ++i) { EXPECT_EQ(dense_orig[i].size(), dense_copy[i].size()); for(size_t j = 0; j < dense_orig[i].size(); ++j) { EXPECT_EQ(dense_orig[i][j], dense_copy[i][j]); } } } template void testing_local_update_values_csr() { auto matrix = getTestMatrix(); int64_t nnz = matrix.GetNnz(); // Use std::vector instead of raw arrays std::vector new_values(nnz); for(int64_t i = 0; i < nnz; ++i) { new_values[i] = static_cast(i + 10); // Fill with some values } // UpdateValuesCSR should update the values in the matrix EXPECT_NO_THROW(matrix.UpdateValuesCSR(new_values.data())); std::vector check_values(nnz); getMatrixVal(matrix, check_values.data()); for(int64_t i = 0; i < nnz; ++i) { EXPECT_EQ(check_values[i], new_values[i]); } } template void testing_local_move_to_accelerator() { auto matrix = getTestMatrix(); for(int i = 0; i < 10; i++) { EXPECT_NO_THROW(matrix.MoveToAccelerator()); } for(int i = 0; i < 10; i++) { EXPECT_NO_THROW(matrix.MoveToHost()); } for(int i = 0; i < 10; i++) { EXPECT_NO_THROW(matrix.MoveToHost()); EXPECT_NO_THROW(matrix.MoveToAccelerator()); } EXPECT_EQ(matrix.Check(), true); } template void testing_local_move_to_accelerator_async() { auto matrix = getTestMatrix(); // MoveToAcceleratorAsync should move the matrix asynchronously for(int i = 0; i < 10; i++) { EXPECT_NO_THROW(matrix.MoveToAcceleratorAsync()); } for(int i = 0; i < 10; i++) { EXPECT_NO_THROW(matrix.MoveToHostAsync()); } for(int i = 0; i < 10; i++) { EXPECT_NO_THROW(matrix.MoveToHostAsync()); EXPECT_NO_THROW(matrix.MoveToAcceleratorAsync()); } EXPECT_NO_THROW(matrix.Sync()); EXPECT_EQ(matrix.Check(), true); } template void testing_local_move_to_host_async() { auto matrix = getTestMatrix(); // MoveToHostAsync should move the matrix asynchronously to host EXPECT_NO_THROW(matrix.MoveToHostAsync()); EXPECT_NO_THROW(matrix.Sync()); EXPECT_EQ(matrix.GetM(), 2); EXPECT_EQ(matrix.GetN(), 2); } template void testing_local_clear(Arguments argus) { LocalMatrix matrix; getTestMatrix(argus, matrix); // Clear should remove all data from the matrix // This test checks if the Clear operation is valid // by checking if the number of non-zero entries (nnz) is zero // and the dimensions (m, n) are also zero. matrix.Clear(); EXPECT_EQ(matrix.GetNnz(), 0); EXPECT_EQ(matrix.GetM(), 0); EXPECT_EQ(matrix.GetN(), 0); } template void testing_local_zeros(Arguments argus) { LocalMatrix matrix; getTestMatrix(argus, matrix); // Zeros should set all values in the matrix to zero // This test checks if the Zeros operation is valid // by checking if all values in the matrix are zero after the operation. matrix.Zeros(); matrix.Check(); matrix.Info(); int64_t nnz = matrix.GetNnz(); T* check_values = new T[nnz]; getMatrixVal(matrix, check_values); for(int64_t i = 0; i < nnz; ++i) { EXPECT_EQ(check_values[i], static_cast(0)); } delete[] check_values; } template void testing_local_copy(Arguments argus) { LocalMatrix matrix; getTestMatrix(argus, matrix); // CopyFrom should create a copy of the matrix // This test checks if the copy operation is valid // by comparing the original matrix with the copied matrix. LocalMatrix copy_matrix; copy_matrix.CopyFrom(matrix); EXPECT_EQ(copy_matrix.GetNnz(), matrix.GetNnz()); EXPECT_EQ(copy_matrix.GetM(), matrix.GetM()); EXPECT_EQ(copy_matrix.GetN(), matrix.GetN()); // Compare dense representations auto dense_orig = extract_dense_matrix(matrix); auto dense_copy = extract_dense_matrix(copy_matrix); EXPECT_EQ(dense_orig.size(), dense_copy.size()); for(size_t i = 0; i < dense_orig.size(); ++i) { EXPECT_EQ(dense_orig[i].size(), dense_copy[i].size()); for(size_t j = 0; j < dense_orig[i].size(); ++j) { EXPECT_EQ(dense_orig[i][j], dense_copy[i][j]); } } } template void testing_local_scale(Arguments argus) { LocalMatrix matrix; getTestMatrix(argus, matrix); // Scale should multiply all values in the matrix by a scalar // This test checks if the scaling operation is valid // by comparing the scaled values with the expected values. // The expected values are obtained by multiplying the original values // by the scaling factor. // Save original dense matrix auto orig_dense = extract_dense_matrix(matrix); // Scale the matrix by 2.0 matrix.Scale(2.0); // Extract new dense matrix auto new_dense = extract_dense_matrix(matrix); // Compare each value int m = matrix.GetM(); int n = matrix.GetN(); for(int i = 0; i < m; ++i) for(int j = 0; j < n; ++j) EXPECT_EQ(new_dense[i][j], orig_dense[i][j] * 2.0); } template void testing_local_extract_diagonal(Arguments argus) { if(argus.matrix_type != "Laplacian2D") { return; } LocalMatrix matrix; getTestMatrix(argus, matrix); // ExtractDiagonal should extract the diagonal of the matrix // and store it in a LocalVector // This test checks if the diagonal extraction is correct // by comparing the extracted diagonal with the expected values. // The expected values are obtained by iterating through the matrix // and checking the diagonal elements. LocalVector diag; matrix.ExtractDiagonal(&diag); int64_t m = matrix.GetM(); T* check_values = new T[m]; getMatrixDiagVal(matrix, check_values); EXPECT_EQ(diag.GetSize(), m); for(int i = 0; i < m; ++i) { EXPECT_EQ(diag[i], check_values[i]); } delete[] check_values; } template void testing_local_extract_inverse_diagonal(Arguments argus) { if(argus.matrix_type != "Laplacian2D") { return; } LocalMatrix matrix; getTestMatrix(argus, matrix); // ExtractInverseDiagonal should extract the inverse diagonal of the matrix // and store it in a LocalVector // This test checks if the inverse diagonal extraction is correct // by comparing the extracted inverse diagonal with the expected values. // The expected values are obtained by taking the reciprocal of the diagonal elements. LocalVector diag; matrix.ExtractDiagonal(&diag); LocalVector inv_diag; matrix.ExtractInverseDiagonal(&inv_diag); EXPECT_EQ(inv_diag.GetSize(), diag.GetSize()); for(int i = 0; i < diag.GetSize(); ++i) { EXPECT_NEAR(diag[i], 1.0 / inv_diag[i], getTolerance() * std::abs(diag[i])); // Allow some tolerance } } template void testing_local_transpose(Arguments argus) { LocalMatrix matrix; getTestMatrix(argus, matrix); // This test checks if the transpose operation is valid // by applying the matrix to two vectors and checking if the results // are consistent with the transpose operation. LocalVector vec1, vec2, tmp1, tmp2; vec1.Allocate("TestVector1", matrix.GetM()); vec2.Allocate("TestVector2", matrix.GetN()); tmp1.Allocate("TemporaryVector1", matrix.GetM()); tmp2.Allocate("TemporaryVector2", matrix.GetN()); vec1.SetRandomUniform(static_cast(0), static_cast(1)); vec2.SetRandomUniform(static_cast(0), static_cast(1)); matrix.Apply(vec2, &tmp1); T val1 = vec1.Dot(tmp1); matrix.Transpose(); matrix.Apply(vec1, &tmp2); T val2 = vec2.Dot(tmp2); EXPECT_NEAR(val1, val2, getTolerance() * std::abs(val1)); // Allow some tolerance } template void testing_clone_matrix(Arguments argus) { LocalMatrix matrix; getTestMatrix(argus, matrix); // Clone the matrix // This should create a new matrix with the same data // and structure as the original matrix LocalMatrix clone; clone.CloneFrom(matrix); EXPECT_EQ(clone.GetNnz(), matrix.GetNnz()); EXPECT_EQ(clone.GetM(), matrix.GetM()); EXPECT_EQ(clone.GetN(), matrix.GetN()); // Compare dense representations auto dense_orig = extract_dense_matrix(matrix); auto dense_clone = extract_dense_matrix(clone); EXPECT_EQ(dense_orig.size(), dense_clone.size()); for(size_t i = 0; i < dense_orig.size(); ++i) { EXPECT_EQ(dense_orig[i].size(), dense_clone[i].size()); for(size_t j = 0; j < dense_orig[i].size(); ++j) { EXPECT_EQ(dense_orig[i][j], dense_clone[i][j]); } } } template void testing_invert_matrix(Arguments argus) { LocalMatrix matrix; bool is_invertible; getTestMatrix(argus, matrix, is_invertible); if(!is_invertible) { return; } LocalVector vec1, vec2, tmp1; vec1.Allocate("TestVector1", matrix.GetM()); vec2.Allocate("TestVector2", matrix.GetM()); tmp1.Allocate("TemporaryVector1", matrix.GetM()); vec1.SetRandomUniform(static_cast(0), static_cast(1)); vec2.CopyFrom(vec1); matrix.Apply(vec1, &tmp1); matrix.Invert(); matrix.Apply(tmp1, &vec1); for(int i = 0; i < vec1.GetSize(); ++i) { // Check if the result is close to the initial vector EXPECT_NEAR(vec1[i], vec2[i], getTolerance() * std::abs(vec2[i])); } } template void testing_set_data_pointer() { // CSR { LocalMatrix mat = getTestMatrix(); int* row_offsets = new int[3]{0, 2, 4}; int* col_indices = new int[4]{0, 1, 0, 1}; T* values = new T[4]{1.0, 2.0, 3.0, 4.0}; mat.SetDataPtrCSR(&row_offsets, &col_indices, &values, "TestMatrix", 4, 2, 2); EXPECT_EQ(mat.GetNnz(), 4); EXPECT_EQ(mat.GetM(), 2); EXPECT_EQ(mat.GetN(), 2); delete[] row_offsets; delete[] col_indices; delete[] values; } } template void testing_leave_data_pointer() { auto matrix = getTestMatrix(); int* row_offsets = nullptr; int* col_indices = nullptr; T* values = nullptr; matrix.LeaveDataPtrCSR(&row_offsets, &col_indices, &values); EXPECT_NE(row_offsets, nullptr); EXPECT_NE(col_indices, nullptr); EXPECT_NE(values, nullptr); EXPECT_EQ(matrix.GetNnz(), 0); EXPECT_EQ(matrix.GetM(), 0); EXPECT_EQ(matrix.GetN(), 0); delete[] row_offsets; delete[] col_indices; delete[] values; } template void testing_maximal_independent_set(Arguments argus) { if(argus.matrix_type != "Laplacian2D") { return; } LocalMatrix matrix; bool is_invertible; getTestMatrix(argus, matrix, is_invertible); LocalVector permutation; int size = 0; // Compute the Maximal Independent Set matrix.MaximalIndependentSet(size, &permutation); // Validate the size of the independent set EXPECT_GT(size, 0); EXPECT_EQ(permutation.GetSize(), matrix.GetM()); checkPermutation(permutation); } template void testing_zero_block_permutation(Arguments argus) { if(argus.matrix_type != "Laplacian2D") { return; } LocalMatrix matrix; bool is_invertible; getTestMatrix(argus, matrix, is_invertible); LocalVector permutation; int size = 0; // Compute the Zero Block Permutation matrix.ZeroBlockPermutation(size, &permutation); // Validate the size of the permutation EXPECT_GT(size, 0); EXPECT_EQ(permutation.GetSize(), matrix.GetM()); checkPermutation(permutation); } template void testing_Householder(Arguments argus) { if(argus.matrix_type != "Laplacian2D") { return; } LocalMatrix matrix; getTestMatrix(argus, matrix); LocalVector vec; int idx = 0; vec.Allocate("HouseholderVector", matrix.GetM() - idx); T beta = 0.0; // Perform Householder transformation matrix.Householder(idx, beta, &vec); // Validate the result EXPECT_GT(beta, 0.0); //// Get the first column as a vector //LocalVector x; //x.Allocate("ExtractedColumn", matrix.GetM()); //matrix.ExtractColumnVector(0, &x); // //// Compute v^T x //T vTx = 0; //for(int i = 0; i < x.GetSize(); ++i) // vTx += x[i] * vec[i]; // //// Compute Hx = x - beta * v * v^T x //LocalVector Hx; //Hx.Allocate("Hx", x.GetSize()); //for(int i = 0; i < x.GetSize(); ++i) // Hx[i] = x[i] - beta * vec[i] * vTx; // //// Check that Hx[1:] are (close to) zero //for(int i = 1; i < Hx.GetSize(); ++i) // EXPECT_NEAR(Hx[i], 0.0, 1e-6); } template void testing_CMK(Arguments argus) { LocalMatrix matrix; getTestMatrix(argus, matrix); LocalVector permutation; // Perform CMK ordering matrix.CMK(&permutation); // Validate the permutation vector EXPECT_EQ(permutation.GetSize(), matrix.GetM()); checkPermutation(permutation); } template void testing_RCMK(Arguments argus) { LocalMatrix matrix; getTestMatrix(argus, matrix); LocalVector permutation; // Perform RCMK ordering matrix.RCMK(&permutation); // Validate the permutation vector EXPECT_EQ(permutation.GetSize(), matrix.GetM()); checkPermutation(permutation); } template void testing_connectivity_order(Arguments argus) { LocalMatrix matrix; getTestMatrix(argus, matrix); LocalVector permutation; // Perform ConnectivityOrder matrix.ConnectivityOrder(&permutation); // Validate the permutation vector EXPECT_EQ(permutation.GetSize(), matrix.GetM()); checkPermutation(permutation); } template void testing_symbolic_power(Arguments argus) { LocalMatrix matrix; getTestMatrix(argus, matrix); if(matrix.GetM() != matrix.GetN()) { // SymbolicPower is only defined for square matrices return; } // Compute expected symbolic square pattern std::set> expected_pattern; { int* row_offsets = new int[matrix.GetM() + 1]; int* col_indices = new int[matrix.GetNnz()]; T* matrix_values = new T[matrix.GetNnz()]; matrix.CopyToCSR(row_offsets, col_indices, matrix_values); // Save original pattern std::set> original_pattern; for(int row = 0; row < matrix.GetM(); ++row) { for(int idx = row_offsets[row]; idx < row_offsets[row + 1]; ++idx) original_pattern.insert({row, col_indices[idx]}); } for(int i = 0; i < matrix.GetM(); ++i) { for(int k = 0; k < matrix.GetN(); ++k) { if(original_pattern.count({i, k})) { for(int j = 0; j < matrix.GetN(); ++j) { if(original_pattern.count({k, j})) expected_pattern.insert({i, j}); } } } } delete[] row_offsets; delete[] col_indices; delete[] matrix_values; } // Perform SymbolicPower matrix.SymbolicPower(2); // Extract new pattern std::set> new_pattern; { int* row_offsets = new int[matrix.GetM() + 1]; int* col_indices = new int[matrix.GetNnz()]; T* matrix_values = new T[matrix.GetNnz()]; matrix.CopyToCSR(row_offsets, col_indices, matrix_values); for(int row = 0; row < matrix.GetM(); ++row) { for(int idx = row_offsets[row]; idx < row_offsets[row + 1]; ++idx) new_pattern.insert({row, col_indices[idx]}); } delete[] row_offsets; delete[] col_indices; delete[] matrix_values; } // Compare EXPECT_EQ(new_pattern, expected_pattern); } template void testing_scale_off_diagonal(Arguments argus) { LocalMatrix matrix; getTestMatrix(argus, matrix); // Save the original matrix auto orig_dense = extract_dense_matrix(matrix); // Scale off-diagonal elements by 2.0 EXPECT_NO_THROW(matrix.ScaleOffDiagonal(2.0)); // Extract new dense matrix auto new_dense = extract_dense_matrix(matrix); int m = matrix.GetM(); int n = matrix.GetN(); // Check: diagonal elements unchanged, off-diagonal elements scaled by 2 for(int i = 0; i < m; ++i) for(int j = 0; j < n; ++j) if(i == j) EXPECT_EQ(new_dense[i][j], orig_dense[i][j]); else EXPECT_EQ(new_dense[i][j], orig_dense[i][j] * 2.0); } template void testing_add_scalar(Arguments argus) { LocalMatrix matrix; getTestMatrix(argus, matrix); int64_t nnz = matrix.GetNnz(); T* values = new T[nnz]; getMatrixVal(matrix, values); // Perform AddScalar matrix.AddScalar(1.0); // Validate the result T* values_new = new T[nnz]; getMatrixVal(matrix, values_new); for(int64_t i = 0; i < nnz; ++i) { EXPECT_NEAR(values_new[i], values[i] + 1.0, getTolerance() * std::abs(values_new[i])); } delete[] values; delete[] values_new; } template void testing_replace_column_vector(Arguments argus) { LocalMatrix matrix; getTestMatrix(argus, matrix); int n = matrix.GetN(); int m = matrix.GetM(); // Test replacing each column with a known vector and verify for(int col = 0; col < n; ++col) { LocalVector vec; vec.Allocate("ColumnVector", m); for(int i = 0; i < m; ++i) vec[i] = static_cast(i + 100 * col); // Unique values per column // Replace column col EXPECT_NO_THROW(matrix.ReplaceColumnVector(col, vec)); // Extract column col LocalVector extracted_vec; extracted_vec.Allocate("ExtractedColumn", m); EXPECT_NO_THROW(matrix.ExtractColumnVector(col, &extracted_vec)); // Verify the replacement for(int i = 0; i < m; ++i) EXPECT_EQ(extracted_vec[i], vec[i]); } } template void testing_extract_column_vector(Arguments argus) { LocalMatrix matrix; getTestMatrix(argus, matrix); int n = matrix.GetN(); int m = matrix.GetM(); // Extract each column and compare with dense representation auto dense = extract_dense_matrix(matrix); for(int col = 0; col < n; ++col) { LocalVector vec; vec.Allocate("ExtractedColumn", m); // Extract column vector EXPECT_NO_THROW(matrix.ExtractColumnVector(col, &vec)); // Validate the result for(int row = 0; row < m; ++row) { EXPECT_EQ(vec[row], dense[row][col]); } } } template void testing_set_data_ptr_DIA() { // Create a LocalMatrix LocalMatrix mat; // Define DIA matrix parameters int64_t nnz = 12; // Number of non-zero elements int64_t nrow = 6; // Number of rows int64_t ncol = 6; // Number of columns int num_diag = 2; // Number of diagonals // Allocate memory for DIA data int* offset = new int[num_diag]{0, 1}; // Diagonal offsets T* val = new T[nnz]{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0}; // Ensure assertions are valid ASSERT_NE(offset, nullptr); ASSERT_NE(val, nullptr); ASSERT_GT(nnz, 0); ASSERT_GT(nrow, 0); ASSERT_GT(num_diag, 0); // Check nnz consistency if(nrow < ncol) { ASSERT_EQ(nnz, ncol * num_diag); } else { ASSERT_EQ(nnz, nrow * num_diag); } // Set the DIA data pointer EXPECT_NO_THROW(mat.SetDataPtrDIA(&offset, &val, "TestMatrix", nnz, nrow, ncol, num_diag)); // Validate that the matrix has been set correctly EXPECT_EQ(mat.GetNnz(), nnz); EXPECT_EQ(mat.GetN(), nrow); EXPECT_EQ(mat.GetM(), ncol); // Validate that the data pointers are now owned by the matrix EXPECT_EQ(offset, nullptr); EXPECT_EQ(val, nullptr); } template void testing_leave_data_ptr_DIA() { // Create a LocalMatrix LocalMatrix mat; // Define DIA matrix parameters int64_t nnz = 12; // Number of non-zero elements int64_t nrow = 6; // Number of rows int64_t ncol = 6; // Number of columns int num_diag = 2; // Number of diagonals // Allocate memory for DIA data int* offset = new int[num_diag]{0, 1}; // Diagonal offsets T* val = new T[nnz]{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0}; // Set the DIA data pointer mat.SetDataPtrDIA(&offset, &val, "TestMatrix", nnz, nrow, ncol, num_diag); // Ensure the matrix is in DIA format ASSERT_TRUE(mat.GetFormat() == DIA); // Prepare pointers to retrieve the data int* retrieved_offset = nullptr; T* retrieved_val = nullptr; int retrieved_num_diag = 0; // Leave the DIA data pointer EXPECT_NO_THROW(mat.LeaveDataPtrDIA(&retrieved_offset, &retrieved_val, retrieved_num_diag)); // Validate that the data pointers are correctly retrieved ASSERT_NE(retrieved_offset, nullptr); ASSERT_NE(retrieved_val, nullptr); EXPECT_EQ(retrieved_num_diag, num_diag); // Validate the retrieved data for(int i = 0; i < num_diag; ++i) { EXPECT_EQ(retrieved_offset[i], i); // Offsets: 0, 1 } for(int i = 0; i < nnz; ++i) { EXPECT_EQ(retrieved_val[i], static_cast(i + 1)); // Values: 1.0, 2.0, ..., 12.0 } EXPECT_EQ(mat.GetNnz(), 0); EXPECT_EQ(mat.GetM(), 0); EXPECT_EQ(mat.GetN(), 0); // Clean up the retrieved pointers delete[] retrieved_offset; delete[] retrieved_val; } template void testing_copy_from_COO() { // Create a LocalMatrix LocalMatrix mat; // Define COO matrix parameters int64_t nnz = 4; // Number of non-zero elements int64_t nrow = 3; // Number of rows int64_t ncol = 3; // Number of columns // Allocate memory for COO data int row[] = {0, 1, 2, 2}; // Row indices int col[] = {0, 1, 2, 0}; // Column indices T val[] = {1.0, 2.0, 3.0, 4.0}; // Non-zero values // Allocate the matrix in COO format mat.AllocateCOO("TestMatrix", nnz, nrow, ncol); // Ensure assertions are valid ASSERT_NE(row, nullptr); ASSERT_NE(col, nullptr); ASSERT_NE(val, nullptr); ASSERT_EQ(mat.GetFormat(), COO); // Copy data from COO EXPECT_NO_THROW(mat.CopyFromCOO(row, col, val)); // Validate the matrix properties EXPECT_EQ(mat.GetNnz(), nnz); EXPECT_EQ(mat.GetM(), nrow); EXPECT_EQ(mat.GetN(), ncol); // Validate that the matrix is still in COO format EXPECT_EQ(mat.GetFormat(), COO); } template void testing_copy_to_COO() { // Create a LocalMatrix LocalMatrix mat; // Define COO matrix parameters int64_t nnz = 4; // Number of non-zero elements int64_t nrow = 3; // Number of rows int64_t ncol = 3; // Number of columns // Allocate memory for COO data int row[] = {0, 1, 2, 2}; // Row indices int col[] = {0, 1, 2, 0}; // Column indices T val[] = {1.0, 2.0, 3.0, 4.0}; // Non-zero values // Allocate the matrix in COO format and copy data mat.AllocateCOO("TestMatrix", nnz, nrow, ncol); mat.CopyFromCOO(row, col, val); // Ensure assertions are valid ASSERT_EQ(mat.GetFormat(), COO); ASSERT_EQ(mat.GetNnz(), nnz); ASSERT_EQ(mat.GetM(), nrow); ASSERT_EQ(mat.GetN(), ncol); // Prepare arrays to retrieve the data int* retrieved_row = new int[nnz]; int* retrieved_col = new int[nnz]; T* retrieved_val = new T[nnz]; // Copy data to COO EXPECT_NO_THROW(mat.CopyToCOO(retrieved_row, retrieved_col, retrieved_val)); // Validate the retrieved data for(int i = 0; i < nnz; ++i) { EXPECT_EQ(retrieved_row[i], row[i]); EXPECT_EQ(retrieved_col[i], col[i]); EXPECT_DOUBLE_EQ(retrieved_val[i], val[i]); } // Clean up delete[] retrieved_row; delete[] retrieved_col; delete[] retrieved_val; } template void testing_copy_from_host_CSR() { // Create a LocalMatrix LocalMatrix mat; // Define CSR matrix parameters int64_t nnz = 4; // Number of non-zero elements int64_t nrow = 3; // Number of rows int64_t ncol = 3; // Number of columns // Allocate memory for CSR data PtrType row_offset[] = {0, 1, 3, 4}; // Row offsets int col[] = {0, 1, 2, 2}; // Column indices double val[] = {1.0, 2.0, 3.0, 4.0}; // Non-zero values // Ensure assertions are valid ASSERT_NE(row_offset, nullptr); ASSERT_NE(col, nullptr); ASSERT_NE(val, nullptr); ASSERT_GE(nnz, 0); ASSERT_GE(nrow, 0); ASSERT_GE(ncol, 0); // Copy data from host CSR EXPECT_NO_THROW(mat.CopyFromHostCSR(row_offset, col, val, "TestMatrix", nnz, nrow, ncol)); // Validate the matrix properties EXPECT_EQ(mat.GetNnz(), nnz); EXPECT_EQ(mat.GetM(), nrow); EXPECT_EQ(mat.GetN(), ncol); // Validate that the matrix is in CSR format EXPECT_EQ(mat.GetFormat(), CSR); } // Helper function to create a sample MTX file void CreateSampleMTXFile(const std::string& filename) { std::ofstream file(filename); ASSERT_TRUE(file.is_open()); // Write a simple 3x3 matrix in MTX format file << "%%MatrixMarket matrix coordinate real general\n"; file << "% Sample MTX file\n"; file << "3 3 4\n"; // 3 rows, 3 columns, 4 non-zero elements file << "1 1 1.0\n"; file << "1 2 2.0\n"; file << "2 3 3.0\n"; file << "3 1 4.0\n"; file.close(); } template void testing_read_file_MTX() { // Create a sample MTX file const std::string filename = get_temp_dir() + "test_matrix.mtx"; CreateSampleMTXFile(filename); // Create a LocalMatrix LocalMatrix mat; // Read the matrix from the MTX file EXPECT_NO_THROW(mat.ReadFileMTX(filename)); // Validate the matrix properties EXPECT_EQ(mat.GetM(), 3); // Number of rows EXPECT_EQ(mat.GetN(), 3); // Number of columns EXPECT_EQ(mat.GetNnz(), 4); // Number of non-zero elements // Convert the matrix to CSR format EXPECT_NO_THROW(mat.ConvertToCSR()); // Validate the matrix format EXPECT_EQ(mat.GetFormat(), CSR); // Prepare arrays to retrieve the data PtrType* row_offset = new PtrType[4]; int* col = new int[4]; T* val = new T[4]; // Copy data to CSR EXPECT_NO_THROW(mat.CopyToCSR(row_offset, col, val)); // Validate the retrieved data EXPECT_EQ(row_offset[0], 0); EXPECT_EQ(row_offset[1], 2); EXPECT_EQ(row_offset[2], 3); EXPECT_EQ(row_offset[3], 4); EXPECT_EQ(col[0], 0); EXPECT_DOUBLE_EQ(val[0], 1.0); EXPECT_EQ(col[1], 1); EXPECT_DOUBLE_EQ(val[1], 2.0); EXPECT_EQ(col[2], 2); EXPECT_DOUBLE_EQ(val[2], 3.0); EXPECT_EQ(col[3], 0); EXPECT_DOUBLE_EQ(val[3], 4.0); // Clean up delete[] row_offset; delete[] col; delete[] val; // Remove the sample MTX file std::remove(filename.c_str()); } // Helper function to create a test CSR file void CreateTestCSRFile(const std::string& filename) { std::ofstream file(filename); ASSERT_TRUE(file.is_open()); // Example CSR format for a 3x3 matrix: // Matrix: // 1 0 2 // 0 3 0 // 4 0 5 // // CSR representation: // Row pointers: [0, 2, 3, 5] // Column indices: [0, 2, 1, 0, 2] // Values: [1, 2, 3, 4, 5] file << "3 3 5\n"; // 3 rows, 3 columns, 5 non-zero elements file << "0 2 3 5\n"; // Row pointers file << "0 2 1 0 2\n"; // Column indices file << "1 2 3 4 5\n"; // Values file.close(); } // Helper function to read the contents of a file into a string std::string testing_ReadFileContents(const std::string& filename) { std::ifstream file(filename); std::stringstream buffer; buffer << file.rdbuf(); return buffer.str(); } template void testing_write_file_MTX() { // Step 1: Create a LocalMatrix in CSR format LocalMatrix matrix; matrix.AllocateCSR("test", 5, 3, 3); // 3x3 matrix with 5 non-zero elements // Fill the matrix with some values // Matrix representation: // [ 1.0 0.0 2.0 ] // [ 0.0 3.0 0.0 ] // [ 4.0 0.0 5.0 ] int row_offsets[4] = {0, 2, 3, 5}; int col_indices[5] = {0, 2, 1, 0, 2}; T values[5] = {1.0, 2.0, 3.0, 4.0, 5.0}; matrix.CopyFromCSR(row_offsets, col_indices, values); // Step 2: Write the matrix to a file in MTX format const std::string filename = get_temp_dir() + "test_matrix.mtx"; ASSERT_NO_THROW(matrix.WriteFileMTX(filename)); // Step 3: Verify the contents of the file std::string file_contents = testing_ReadFileContents(filename); // Expected MTX file contents std::string expected_contents = "%%MatrixMarket matrix coordinate real general\n" "3 3 5\n" // 3x3 matrix with 5 non-zero elements "1 1 1\n" "1 3 2\n" "2 2 3\n" "3 1 4\n" "3 3 5\n"; // Compare the actual file contents with the expected contents EXPECT_EQ(file_contents, expected_contents); // Clean up the test file std::remove(filename.c_str()); } template void testing_write_file_RSIO() { // Step 1: Create a LocalMatrix in CSR format LocalMatrix matrix; matrix.AllocateCSR("test", 5, 3, 3); // 3x3 matrix with 5 non-zero elements // Fill the matrix with some values // Matrix representation: // [ 1.0 0.0 2.0 ] // [ 0.0 3.0 0.0 ] // [ 4.0 0.0 5.0 ] int row_offsets[4] = {0, 2, 3, 5}; int col_indices[5] = {0, 2, 1, 0, 2}; T values[5] = {1.0, 2.0, 3.0, 4.0, 5.0}; matrix.CopyFromCSR(row_offsets, col_indices, values); // Step 2: Write the matrix to a file in RSIO format const std::string filename = get_temp_dir() + "test_matrix.rsio"; ASSERT_NO_THROW(matrix.WriteFileRSIO(filename)); // Create a LocalMatrix LocalMatrix mat; // Read the matrix from the RSIO file EXPECT_NO_THROW(mat.ReadFileRSIO(filename)); // Clean up the test file std::remove(filename.c_str()); } template void testing_local_apply(Arguments argus) { LocalMatrix matrix; getTestMatrix(argus, matrix); LocalVector x, y; x.Allocate("x", matrix.GetN()); y.Allocate("y", matrix.GetM()); // Fill x with test values for(int i = 0; i < x.GetSize(); ++i) x[i] = static_cast(i + 1); // Compute expected result std::vector expected(y.GetSize(), 0); int* row_offsets = new int[matrix.GetM() + 1]; int* col_indices = new int[matrix.GetNnz()]; T* values = new T[matrix.GetNnz()]; matrix.CopyToCSR(row_offsets, col_indices, values); for(int row = 0; row < matrix.GetM(); ++row) { for(int idx = row_offsets[row]; idx < row_offsets[row + 1]; ++idx) expected[row] += values[idx] * x[col_indices[idx]]; } // Call Apply matrix.Apply(x, &y); // Compare for(int i = 0; i < y.GetSize(); ++i) EXPECT_NEAR(y[i], expected[i], getTolerance() * std::abs(y[i])); delete[] row_offsets; delete[] col_indices; delete[] values; } template void testing_local_apply_add(Arguments argus) { LocalMatrix matrix; getTestMatrix(argus, matrix); LocalVector x, y, y_orig, tmp; x.Allocate("x", matrix.GetN()); y.Allocate("y", matrix.GetM()); y_orig.Allocate("y_orig", matrix.GetM()); tmp.Allocate("tmp", matrix.GetM()); // Fill x and y with test values for(int i = 0; i < x.GetSize(); ++i) x[i] = static_cast(i + 1); for(int i = 0; i < y.GetSize(); ++i) y[i] = static_cast(2 * i); y_orig.CopyFrom(y); // Compute matrix * x matrix.Apply(x, &tmp); // Compute expected result std::vector expected(y.GetSize()); T scalar = static_cast(3); for(int i = 0; i < y.GetSize(); ++i) expected[i] = y_orig[i] + scalar * tmp[i]; // Call ApplyAdd matrix.ApplyAdd(x, scalar, &y); // Compare for(int i = 0; i < y.GetSize(); ++i) EXPECT_NEAR(y[i], expected[i], getTolerance() * std::abs(y[i])); } template void testing_local_extract_submatrix(Arguments argus) { if(argus.matrix_type != "Laplacian2D") { return; } LocalMatrix matrix; getTestMatrix(argus, matrix); LocalMatrix submatrix; int row_offset = 0, col_offset = 0, row_size = 2, col_size = 2; EXPECT_NO_THROW( matrix.ExtractSubMatrix(row_offset, row_size, col_offset, col_size, &submatrix)); auto orig_dense = extract_dense_matrix(matrix); auto sub_dense = extract_dense_matrix(submatrix); for(int i = 0; i < submatrix.GetM(); ++i) for(int j = 0; j < submatrix.GetN(); ++j) EXPECT_EQ(sub_dense[i][j], orig_dense[row_offset + i][col_offset + j]); } template void testing_local_extract_u(Arguments argus) { LocalMatrix matrix; getTestMatrix(argus, matrix); // Extract U with both strictly and non-strictly upper LocalMatrix U_strict, U_non_strict; EXPECT_NO_THROW(matrix.ExtractU(&U_strict, false)); EXPECT_NO_THROW(matrix.ExtractU(&U_non_strict, true)); // Both should have the same dimensions as the original EXPECT_EQ(U_strict.GetM(), matrix.GetM()); EXPECT_EQ(U_strict.GetN(), matrix.GetN()); EXPECT_EQ(U_non_strict.GetM(), matrix.GetM()); EXPECT_EQ(U_non_strict.GetN(), matrix.GetN()); // Compare dense representations auto orig_dense = extract_dense_matrix(matrix); auto strict_dense = extract_dense_matrix(U_strict); auto non_strict_dense = extract_dense_matrix(U_non_strict); int m = matrix.GetM(); int n = matrix.GetN(); // Strictly upper: only elements above diagonal for(int i = 0; i < m; ++i) for(int j = 0; j < n; ++j) if(j > i) EXPECT_EQ(strict_dense[i][j], orig_dense[i][j]); else EXPECT_EQ(strict_dense[i][j], static_cast(0)); // Non-strictly upper: diagonal and above for(int i = 0; i < m; ++i) for(int j = 0; j < n; ++j) if(j >= i) EXPECT_EQ(non_strict_dense[i][j], orig_dense[i][j]); else EXPECT_EQ(non_strict_dense[i][j], static_cast(0)); } template void testing_local_extract_l(Arguments argus) { LocalMatrix matrix; getTestMatrix(argus, matrix); // Extract L with both strictly and non-strictly lower LocalMatrix L_strict, L_non_strict; EXPECT_NO_THROW(matrix.ExtractL(&L_strict, false)); EXPECT_NO_THROW(matrix.ExtractL(&L_non_strict, true)); // Both should have the same dimensions as the original EXPECT_EQ(L_strict.GetM(), matrix.GetM()); EXPECT_EQ(L_strict.GetN(), matrix.GetN()); EXPECT_EQ(L_non_strict.GetM(), matrix.GetM()); EXPECT_EQ(L_non_strict.GetN(), matrix.GetN()); // Compare dense representations auto orig_dense = extract_dense_matrix(matrix); auto strict_dense = extract_dense_matrix(L_strict); auto non_strict_dense = extract_dense_matrix(L_non_strict); int m = matrix.GetM(); int n = matrix.GetN(); // Strictly lower: only elements below diagonal for(int i = 0; i < m; ++i) for(int j = 0; j < n; ++j) if(j < i) EXPECT_EQ(strict_dense[i][j], orig_dense[i][j]); else EXPECT_EQ(strict_dense[i][j], static_cast(0)); // Non-strictly lower: diagonal and below for(int i = 0; i < m; ++i) for(int j = 0; j < n; ++j) if(j <= i) EXPECT_EQ(non_strict_dense[i][j], orig_dense[i][j]); else EXPECT_EQ(non_strict_dense[i][j], static_cast(0)); } template void testing_local_matrix_add(Arguments argus) { LocalMatrix matrix1; getTestMatrix(argus, matrix1); LocalMatrix matrix2; getTestMatrix(argus, matrix2); // Save dense representations before addition auto dense1 = extract_dense_matrix(matrix1); auto dense2 = extract_dense_matrix(matrix2); // Perform matrix addition EXPECT_NO_THROW(matrix1.MatrixAdd(matrix2)); // Extract the result as dense auto dense_sum = extract_dense_matrix(matrix1); // Check that the result is the element-wise sum int m = dense1.size(); int n = m > 0 ? dense1[0].size() : 0; for(int i = 0; i < m; ++i) for(int j = 0; j < n; ++j) EXPECT_EQ(dense_sum[i][j], dense1[i][j] + dense2[i][j]); } template void testing_local_gershgorin(Arguments argus) { if(argus.matrix_type != "Laplacian2D" || argus.matrix_type != "PermutedIdentity") { return; } LocalMatrix matrix; getTestMatrix(argus, matrix); T lower = 0, upper = 0; EXPECT_NO_THROW(matrix.Gershgorin(lower, upper)); if(argus.matrix_type == "Laplacian2D") { // For Laplacian2D, the Gershgorin bounds should be [0, 4] EXPECT_NEAR(lower, static_cast(0), getTolerance()); EXPECT_NEAR(upper, static_cast(4), getTolerance()); } else if(argus.matrix_type == "PermutedIdentity") { // For PermutedIdentity, the Gershgorin bounds should be [1, 1] EXPECT_NEAR(lower, static_cast(1), getTolerance()); EXPECT_NEAR(upper, static_cast(1), getTolerance()); } } template void testing_local_scale_diagonal(Arguments argus) { if(argus.matrix_type != "Laplacian2D") { return; } LocalMatrix matrix; getTestMatrix(argus, matrix); // Scale the diagonal by a factor of 2.0 // This should not throw an exception // and should correctly scale the diagonal elements LocalVector diag_vec; matrix.ExtractDiagonal(&diag_vec); EXPECT_NO_THROW(matrix.ScaleDiagonal(2.0)); LocalVector diag_vec_2; matrix.ExtractDiagonal(&diag_vec_2); // Validate that the diagonal elements are scaled correctly for(int i = 0; i < diag_vec.GetSize(); ++i) { EXPECT_NEAR(diag_vec_2[i], diag_vec[i] * 2.0, getTolerance() * std::abs(diag_vec[i])); } } template void testing_local_add_scalar_diagonal(Arguments argus) { if(argus.matrix_type != "Laplacian2D") { return; } LocalMatrix matrix; getTestMatrix(argus, matrix); // Add a scalar value of 1.0 to the diagonal elements // This should not throw an exception // and should correctly add the scalar to the diagonal elements LocalVector diag_vec; matrix.ExtractDiagonal(&diag_vec); EXPECT_NO_THROW(matrix.AddScalarDiagonal(1.0)); LocalVector diag_vec_2; matrix.ExtractDiagonal(&diag_vec_2); // Validate that the diagonal elements are incremented correctly for(int i = 0; i < diag_vec.GetSize(); ++i) { EXPECT_NEAR(diag_vec_2[i], diag_vec[i] + 1.0, getTolerance() * std::abs(diag_vec[i])); } } template void testing_local_add_scalar_off_diagonal(Arguments argus) { LocalMatrix matrix; getTestMatrix(argus, matrix); // Extract strictly lower and strictly upper matrices LocalMatrix L, U; matrix.ExtractL(&L, false); // strictly lower matrix.ExtractU(&U, false); // strictly upper // Add 1.0 to strictly lower and strictly upper matrices L.AddScalar(1.0); U.AddScalar(1.0); // Extract diagonal matrix LocalMatrix D; D.AllocateCSR("diag", matrix.GetM(), matrix.GetM(), matrix.GetN()); LocalVector diag_vec; matrix.ExtractDiagonal(&diag_vec); int m = matrix.GetM(); std::vector row_offsets(m + 1), col_indices(m); std::vector values(m); for(int i = 0; i < m; ++i) { row_offsets[i] = i; col_indices[i] = i; values[i] = diag_vec[i]; } row_offsets[m] = m; D.CopyFromCSR(row_offsets.data(), col_indices.data(), values.data()); // Now perform AddScalarOffDiagonal on the matrix under test EXPECT_NO_THROW(matrix.AddScalarOffDiagonal(1.0)); // Validate by applying all matrices to a random vector and comparing results LocalVector x, y_expected, y_actual, y_L, y_U, y_D; int n = matrix.GetN(); x.Allocate("x", n); y_expected.Allocate("y_expected", matrix.GetM()); y_actual.Allocate("y_actual", matrix.GetM()); y_L.Allocate("y_L", matrix.GetM()); y_U.Allocate("y_U", matrix.GetM()); y_D.Allocate("y_D", matrix.GetM()); x.SetRandomUniform(static_cast(0), static_cast(1)); L.Apply(x, &y_L); U.Apply(x, &y_U); D.Apply(x, &y_D); // y_expected = y_L + y_U + y_D for(int i = 0; i < y_expected.GetSize(); ++i) y_expected[i] = y_L[i] + y_U[i] + y_D[i]; matrix.Apply(x, &y_actual); for(int i = 0; i < y_actual.GetSize(); ++i) EXPECT_NEAR(y_actual[i], y_expected[i], getTolerance() * std::abs(y_expected[i])); } template void testing_local_matrix_mult(Arguments argus) { LocalMatrix matrix1; getTestMatrix(argus, matrix1); if(matrix1.GetN() != matrix1.GetM()) { // If the matrix is not square, we skip the test GTEST_SKIP() << "Matrix is not square, skipping matrix multiplication test."; } LocalMatrix matrix2; getTestMatrix(argus, matrix2); LocalMatrix matrix3; getTestMatrix(argus, matrix3); // Perform matrix multiplication EXPECT_NO_THROW(matrix1.MatrixMult(matrix2, matrix3)); // Extract dense representations auto dense1 = extract_dense_matrix(matrix1); auto dense2 = extract_dense_matrix(matrix2); auto dense3 = extract_dense_matrix(matrix3); int m = matrix1.GetM(); int n = matrix1.GetN(); int k = matrix2.GetN(); // Check the result: dense1 = dense2 * dense3 for(int i = 0; i < m; ++i) for(int j = 0; j < n; ++j) { T expected = static_cast(0); for(int l = 0; l < k; ++l) expected += dense2[i][l] * dense3[l][j]; EXPECT_NEAR(dense1[i][j], expected, getTolerance() * std::abs(expected)); } } template void testing_local_triple_matrix_product(Arguments argus) { LocalMatrix matrixA, matrixB, matrixC, matrixD; getTestMatrix(argus, matrixA); getTestMatrix(argus, matrixB); getTestMatrix(argus, matrixC); getTestMatrix(argus, matrixD); // Perform triple matrix product // d = A * B * C EXPECT_NO_THROW(matrixD.TripleMatrixProduct(matrixA, matrixB, matrixC)); // Prepare a random input vector of appropriate size (matching matrixD's column count) int n = matrixD.GetN(); LocalVector x, y1, y2, y3, y_ref; x.Allocate("x", n); y1.Allocate("y1", matrixC.GetN()); y2.Allocate("y2", matrixB.GetN()); y3.Allocate("y3", matrixA.GetN()); y_ref.Allocate("y_ref", matrixD.GetM()); // Fill x with random values x.SetRandomUniform(static_cast(0), static_cast(1)); // Reference: y_ref = matrixD * x matrixD.Apply(x, &y_ref); // Stepwise: y1 = matrixC * x matrixC.Apply(x, &y1); // y2 = matrixB * y1 matrixB.Apply(y1, &y2); // y3 = matrixA * y2 matrixA.Apply(y2, &y3); // Compare y3 (stepwise) with y_ref (direct) ASSERT_EQ(y3.GetSize(), y_ref.GetSize()); for(int i = 0; i < y_ref.GetSize(); ++i) EXPECT_NEAR(y_ref[i], y3[i], getTolerance() * std::abs(y_ref[i])); } template void testing_local_diagonal_matrix_mult_r(Arguments argus) { LocalMatrix matrix; getTestMatrix(argus, matrix); int n = matrix.GetN(); LocalVector diag; diag.Allocate("diag", matrix.GetN()); for(int i = 0; i < diag.GetSize(); ++i) diag[i] = static_cast(2); // Save original dense matrix auto orig_dense = extract_dense_matrix(matrix); // Perform right diagonal multiplication EXPECT_NO_THROW(matrix.DiagonalMatrixMultR(diag)); // Extract new dense matrix auto new_dense = extract_dense_matrix(matrix); // Each column j should be scaled by diag[j] int m = matrix.GetM(); for(int i = 0; i < m; ++i) for(int j = 0; j < n; ++j) EXPECT_NEAR(new_dense[i][j], orig_dense[i][j] * diag[j], getTolerance() * std::abs(orig_dense[i][j] * diag[j])); } template void testing_local_diagonal_matrix_mult(Arguments argus) { LocalMatrix matrix; getTestMatrix(argus, matrix); int m = matrix.GetM(); // Create a diagonal vector with known values LocalVector diag; diag.Allocate("diag", m); for(int i = 0; i < diag.GetSize(); ++i) diag[i] = static_cast(2); // Save original dense matrix auto orig_dense = extract_dense_matrix(matrix); // Perform left diagonal multiplication EXPECT_NO_THROW(matrix.DiagonalMatrixMult(diag)); // Extract new dense matrix auto new_dense = extract_dense_matrix(matrix); // Each row i should be scaled by diag[i] int n = matrix.GetN(); for(int i = 0; i < m; ++i) for(int j = 0; j < n; ++j) EXPECT_NEAR(new_dense[i][j], orig_dense[i][j] * diag[i], getTolerance() * std::abs(orig_dense[i][j] * diag[i])); } template void testing_local_diagonal_matrix_mult_l(Arguments argus) { LocalMatrix matrix; getTestMatrix(argus, matrix); int m = matrix.GetM(); // Create a diagonal vector with known values LocalVector diag; diag.Allocate("diag", m); for(int i = 0; i < diag.GetSize(); ++i) diag[i] = static_cast(2); // Save original dense matrix auto orig_dense = extract_dense_matrix(matrix); // Perform left diagonal multiplication EXPECT_NO_THROW(matrix.DiagonalMatrixMultL(diag)); // Extract new dense matrix auto new_dense = extract_dense_matrix(matrix); // Each row i should be scaled by diag[i] int n = matrix.GetN(); for(int i = 0; i < m; ++i) for(int j = 0; j < n; ++j) EXPECT_NEAR(new_dense[i][j], orig_dense[i][j] * diag[i], getTolerance() * std::abs(orig_dense[i][j] * diag[i])); } template void testing_local_compress(Arguments argus) { LocalMatrix matrix; getTestMatrix(argus, matrix); // Optionally, set some small values to test removal int64_t nnz = matrix.GetNnz(); T* values = new T[nnz]; getMatrixVal(matrix, values); if(nnz > 1) values[1] = static_cast(1e-10); // Set one value below threshold matrix.UpdateValuesCSR(values); // Compress with threshold 1e-8 EXPECT_NO_THROW(matrix.Compress(1e-8)); // Extract values after compression int64_t new_nnz = matrix.GetNnz(); int m = matrix.GetM(); int n = matrix.GetN(); int* row_offsets = new int[m + 1]; int* col_indices = new int[new_nnz]; T* new_values = new T[new_nnz]; matrix.CopyToCSR(row_offsets, col_indices, new_values); // All remaining off-diagonal values should have abs(value) > 1e-8 for(int row = 0; row < m; ++row) { for(int idx = row_offsets[row]; idx < row_offsets[row + 1]; ++idx) { int col = col_indices[idx]; if(row != col) EXPECT_GT(std::abs(new_values[idx]), 1e-8); } } delete[] values; delete[] row_offsets; delete[] col_indices; delete[] new_values; } template void testing_local_replace_row_vector(Arguments argus) { LocalMatrix matrix; getTestMatrix(argus, matrix); const int n = matrix.GetN(); const int max_row_to_replace = 5 < matrix.GetM() ? 5 : matrix.GetM(); for(int row_to_replace = 0; row_to_replace < max_row_to_replace; ++row_to_replace) { // Create a vector with known values LocalVector vec; vec.Allocate("RowVector", n); for(int j = 0; j < n; ++j) vec[j] = static_cast(j + 10); // Save original dense matrix auto orig_dense = extract_dense_matrix(matrix); // Replace the row EXPECT_NO_THROW(matrix.ReplaceRowVector(row_to_replace, vec)); // Extract new dense matrix auto new_dense = extract_dense_matrix(matrix); // Validate the replaced row for(int j = 0; j < n; ++j) EXPECT_EQ(new_dense[row_to_replace][j], vec[j]); // Validate that other rows are unchanged for(int i = 0; i < matrix.GetM(); ++i) if(i != row_to_replace) for(int j = 0; j < n; ++j) EXPECT_EQ(new_dense[i][j], orig_dense[i][j]); } } template void testing_local_extract_row_vector(Arguments argus) { LocalMatrix matrix; getTestMatrix(argus, matrix); LocalVector vec; vec.Allocate("ExtractedRow", matrix.GetN()); // Extract row vector matrix.ExtractRowVector(1, &vec); // Validate the result using the dense matrix auto dense = extract_dense_matrix(matrix); for(int j = 0; j < matrix.GetN(); ++j) EXPECT_EQ(vec[j], dense[1][j]); } template void testing_local_key(Arguments argus) { LocalMatrix matrix; getTestMatrix(argus, matrix); long int row_key = 0, col_key = 0, val_key = 0; // Call Key and check it does not throw EXPECT_NO_THROW(matrix.Key(row_key, col_key, val_key)); // Check that the keys are set (for a non-empty matrix, at least one should be nonzero) EXPECT_TRUE(row_key != 0 || col_key != 0 || val_key != 0); } template void testing_initial_pairwise_aggregation() { auto matrix = getTestMatrix(); // Prepare required arguments double strength = 0.25; int nrow = matrix.GetM(); LocalVector G; int* rG = NULL; int nc = 0, nc2 = 0, nc3 = 0; // Allocate G with the correct size G.Allocate("G", nrow); // Call InitialPairwiseAggregation with all required arguments EXPECT_NO_THROW(matrix.InitialPairwiseAggregation(strength, nc, &G, nc2, &rG, nc3, 0)); // Check that the output vectors have the expected size EXPECT_EQ(G.GetSize(), nrow); // Optionally, check that the output vectors contain valid indices for(int i = 0; i < nrow; ++i) { EXPECT_GE(G[i], 0); EXPECT_GE(rG[i], 0); } } template void testing_initial_pairwise_aggregation_2() { // Create a test matrix and a coarse matrix auto mat = getTestMatrix(); auto coarse_mat = getTestMatrix(); // Prepare required arguments double strength = 0.25; int nrow = mat.GetM(); LocalVector G; int* rG = nullptr; int nc = 0, nc2 = 0, nc3 = 0; // Allocate G with the correct size G.Allocate("G", nrow); // Call InitialPairwiseAggregation with all required arguments EXPECT_NO_THROW(mat.InitialPairwiseAggregation(coarse_mat, strength, nc, &G, nc2, &rG, nc3, 0)); // Check that the output vectors have the expected size EXPECT_EQ(G.GetSize(), nrow); // Optionally, check that the output vectors contain valid indices for(int i = 0; i < nrow; ++i) { EXPECT_GE(G[i], 0); EXPECT_GE(rG[i], 0); } } #endif // TESTING_LOCAL_MATRIX_HPP rocALUTION-rocm-7.1.0/clients/include/testing_local_matrix_itsolve.hpp000066400000000000000000000252131507377332500260700ustar00rootroot00000000000000/* ************************************************************************ * 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 #include "utility.hpp" #include #include using namespace rocalution; static bool check_residual(float res) { return (res < 1e-3f); } static bool check_residual(double res) { return (res < 1e-6); } template bool testing_local_matrix_itlusolve(Arguments argus) { const int size = argus.size; const unsigned int format = argus.format; const int max_iter = 200; const T tol = static_cast(1e-7); // Initialize rocALUTION set_device_rocalution(device); init_rocalution(); // rocALUTION structures LocalMatrix A; LocalVector base_x; LocalVector test_x; LocalVector b; LocalVector e; // Generate A int* csr_ptr = NULL; int* csr_col = NULL; T* csr_val = NULL; int nrow = 0; int ncol = 0; nrow = gen_2d_laplacian(size, &csr_ptr, &csr_col, &csr_val); ncol = nrow; int nnz = csr_ptr[nrow]; assert(csr_ptr != NULL); assert(csr_col != NULL); assert(csr_val != NULL); A.SetDataPtrCSR(&csr_ptr, &csr_col, &csr_val, "A", nnz, nrow, nrow); // Move data to accelerator A.MoveToAccelerator(); base_x.MoveToAccelerator(); b.MoveToAccelerator(); e.MoveToAccelerator(); // Allocate x, b and e base_x.Allocate("x", A.GetN()); b.Allocate("b", A.GetM()); e.Allocate("e", A.GetN()); // b = A * 1 e.Ones(); A.Apply(e, &b); // Random initial guess base_x.SetRandomUniform(12345ULL, -4.0, 6.0); test_x.CloneFrom(base_x); // Matrix format A.ConvertTo(format, format == BCSR ? argus.blockdim : 1); // Factor A.LUFactorize(); // Compare Solves bool success = true; T nrm2 = 1; // LUSolve on device A.ItLUAnalyse(); A.ItLUSolve(max_iter, tol, true, b, &test_x); A.ItLUAnalyseClear(); test_x.ScaleAdd(-1.0, e); nrm2 = test_x.Norm(); success &= check_residual(nrm2); // LUSolve on host A.MoveToHost(); b.MoveToHost(); test_x.CopyFrom(base_x); test_x.MoveToHost(); A.ItLUAnalyse(); A.ItLUSolve(max_iter, tol, true, b, &test_x); A.ItLUAnalyseClear(); test_x.MoveToAccelerator(); test_x.ScaleAdd(-1.0, e); nrm2 = test_x.Norm(); success &= check_residual(nrm2); // Stop rocALUTION platform stop_rocalution(); return success; } template bool testing_local_matrix_itllsolve(Arguments argus) { const int size = argus.size; const unsigned int format = argus.format; const int max_iter = 200; const T tol = static_cast(1e-7); // Initialize rocALUTION set_device_rocalution(device); init_rocalution(); // rocALUTION structures LocalMatrix A; LocalMatrix L; LocalVector base_x; LocalVector test_x; LocalVector b; LocalVector e; // Generate A int* csr_ptr = NULL; int* csr_col = NULL; T* csr_val = NULL; int nrow = 0; int ncol = 0; nrow = gen_2d_laplacian(size, &csr_ptr, &csr_col, &csr_val); ncol = nrow; int nnz = csr_ptr[nrow]; assert(csr_ptr != NULL); assert(csr_col != NULL); assert(csr_val != NULL); A.SetDataPtrCSR(&csr_ptr, &csr_col, &csr_val, "A", nnz, nrow, nrow); // Move data to accelerator A.MoveToAccelerator(); L.MoveToAccelerator(); base_x.MoveToAccelerator(); b.MoveToAccelerator(); e.MoveToAccelerator(); // Allocate x, b and e base_x.Allocate("x", A.GetM()); b.Allocate("b", A.GetM()); e.Allocate("e", A.GetM()); // Set up L A.ExtractL(&L, true); // b = LL^T * 1 e.Ones(); { LocalMatrix Lt; LocalVector tmp; Lt.MoveToAccelerator(); tmp.MoveToAccelerator(); tmp.Allocate("tmp", A.GetN()); L.Transpose(&Lt); Lt.Apply(e, &tmp); L.Apply(tmp, &b); } // Random initial guess base_x.SetRandomUniform(12345ULL, -4.0, 6.0); test_x.CloneFrom(base_x); // Matrix format L.ConvertTo(format, format == BCSR ? argus.blockdim : 1); // Compare Solves bool success = true; T nrm2 = 1; // LLSolve on device L.ItLLAnalyse(); L.ItLLSolve(max_iter, tol, true, b, &test_x); L.ItLLAnalyseClear(); test_x.ScaleAdd(-1.0, e); nrm2 = test_x.Norm(); success &= check_residual(nrm2); // LLSolve on host L.MoveToHost(); b.MoveToHost(); test_x.CopyFrom(base_x); test_x.MoveToHost(); L.ItLLAnalyse(); L.ItLLSolve(max_iter, tol, true, b, &test_x); L.ItLLAnalyseClear(); test_x.MoveToAccelerator(); test_x.ScaleAdd(-1.0, e); nrm2 = test_x.Norm(); success &= check_residual(nrm2); // Stop rocALUTION platform stop_rocalution(); return success; } template bool testing_local_matrix_itlsolve(Arguments argus) { const int size = argus.size; const unsigned int format = argus.format; const bool unit_diag = argus.unit_diag; const int max_iter = 200; const T tol = static_cast(1e-7); // Initialize rocALUTION set_device_rocalution(device); init_rocalution(); // rocALUTION structures LocalMatrix A; LocalMatrix L; LocalVector base_x; LocalVector test_x; LocalVector b; LocalVector e; // Generate A int* csr_ptr = NULL; int* csr_col = NULL; T* csr_val = NULL; int nrow = 0; int ncol = 0; nrow = gen_2d_laplacian(size, &csr_ptr, &csr_col, &csr_val); ncol = nrow; int nnz = csr_ptr[nrow]; assert(csr_ptr != NULL); assert(csr_col != NULL); assert(csr_val != NULL); A.SetDataPtrCSR(&csr_ptr, &csr_col, &csr_val, "A", nnz, nrow, nrow); // Move data to accelerator A.MoveToAccelerator(); L.MoveToAccelerator(); base_x.MoveToAccelerator(); b.MoveToAccelerator(); e.MoveToAccelerator(); // Allocate x, b and e base_x.Allocate("x", A.GetN()); b.Allocate("b", A.GetM()); e.Allocate("e", A.GetN()); // Set up L A.ExtractL(&L, !unit_diag); // b = L * 1 e.Ones(); L.Apply(e, &b); if(unit_diag) { // b + 1 * e b.ScaleAdd(1, e); } // Random initial guess base_x.SetRandomUniform(12345ULL, -4.0, 6.0); test_x.CloneFrom(base_x); // Matrix format L.ConvertTo(format, format == BCSR ? argus.blockdim : 1); // Compare Solves bool success = true; T nrm2 = 1; // LSolve on device L.ItLAnalyse(unit_diag); L.ItLSolve(max_iter, tol, true, b, &test_x); L.ItLAnalyseClear(); test_x.ScaleAdd(-1.0, e); nrm2 = test_x.Norm(); success &= check_residual(nrm2); // LSolve on host L.MoveToHost(); b.MoveToHost(); test_x.CopyFrom(base_x); test_x.MoveToHost(); L.ItLAnalyse(unit_diag); L.ItLSolve(max_iter, tol, true, b, &test_x); L.ItLAnalyseClear(); test_x.MoveToAccelerator(); test_x.ScaleAdd(-1.0, e); nrm2 = test_x.Norm(); success &= check_residual(nrm2); // Stop rocALUTION platform stop_rocalution(); return success; } template bool testing_local_matrix_itusolve(Arguments argus) { const int size = argus.size; const unsigned int format = argus.format; const bool unit_diag = argus.unit_diag; const int max_iter = 200; const T tol = static_cast(1e-7); // Initialize rocALUTION set_device_rocalution(device); init_rocalution(); // rocALUTION structures LocalMatrix A; LocalMatrix U; LocalVector base_x; LocalVector test_x; LocalVector b; LocalVector e; // Generate A int* csr_ptr = NULL; int* csr_col = NULL; T* csr_val = NULL; int nrow = 0; int ncol = 0; nrow = gen_2d_laplacian(size, &csr_ptr, &csr_col, &csr_val); ncol = nrow; int nnz = csr_ptr[nrow]; assert(csr_ptr != NULL); assert(csr_col != NULL); assert(csr_val != NULL); A.SetDataPtrCSR(&csr_ptr, &csr_col, &csr_val, "A", nnz, nrow, nrow); // Move data to accelerator A.MoveToAccelerator(); U.MoveToAccelerator(); base_x.MoveToAccelerator(); b.MoveToAccelerator(); e.MoveToAccelerator(); // Allocate x, b and e base_x.Allocate("x", A.GetN()); b.Allocate("b", A.GetM()); e.Allocate("e", A.GetN()); // Set up U A.ExtractU(&U, !unit_diag); // b = U * 1 e.Ones(); U.Apply(e, &b); if(unit_diag) { // b + 1 * e b.ScaleAdd(1, e); } // Random initial guess base_x.SetRandomUniform(12345ULL, -4.0, 6.0); test_x.CloneFrom(base_x); // Matrix format U.ConvertTo(format, format == BCSR ? argus.blockdim : 1); // Compare Solves bool success = true; T nrm2 = 1; // USolve on device U.ItUAnalyse(unit_diag); U.ItUSolve(max_iter, tol, true, b, &test_x); U.ItUAnalyseClear(); test_x.ScaleAdd(-1.0, e); nrm2 = test_x.Norm(); success &= check_residual(nrm2); // USolve on host U.MoveToHost(); b.MoveToHost(); test_x.CopyFrom(base_x); test_x.MoveToHost(); U.ItUAnalyse(unit_diag); U.ItUSolve(max_iter, tol, true, b, &test_x); U.ItUAnalyseClear(); test_x.MoveToAccelerator(); test_x.ScaleAdd(-1.0, e); nrm2 = test_x.Norm(); success &= check_residual(nrm2); // Stop rocALUTION platform stop_rocalution(); return success; } rocALUTION-rocm-7.1.0/clients/include/testing_local_matrix_multicoloring.hpp000066400000000000000000000073201507377332500272710ustar00rootroot00000000000000/* ************************************************************************ * 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 #include "utility.hpp" #include "validate.hpp" #include #include using namespace rocalution; template bool testing_local_matrix_multicoloring(Arguments argus) { const int size = argus.size; const std::string matrix_type = argus.matrix_type; const unsigned int format = argus.format; // Initialize rocALUTION set_device_rocalution(device); init_rocalution(); // Generate A int* csr_ptr = NULL; int* csr_col = NULL; T* csr_val = NULL; int nrow = 0; int ncol = 0; if(matrix_type == "Laplacian2D") { nrow = gen_2d_laplacian(size, &csr_ptr, &csr_col, &csr_val); ncol = nrow; } else if(matrix_type == "PermutedIdentity") { nrow = gen_permuted_identity(size, &csr_ptr, &csr_col, &csr_val); ncol = nrow; } else if(matrix_type == "Random") { nrow = gen_random(100 * size, 100 * size, 6, &csr_ptr, &csr_col, &csr_val); ncol = 100 * size; } else { return false; } int nnz = csr_ptr[nrow]; assert(csr_ptr != NULL); assert(csr_col != NULL); assert(csr_val != NULL); LocalMatrix A; A.MoveToHost(); A.AllocateCSR("A", nnz, nrow, ncol); A.CopyFromCSR(csr_ptr, csr_col, csr_val); // Matrix format A.ConvertTo(format, format == BCSR ? argus.blockdim : 1); // coloring data LocalVector coloring; int num_colors; int* size_colors = NULL; int* perm = new int[nrow]; bool success = true; // Check host multicoloring A.MultiColoring(num_colors, &size_colors, &coloring); coloring.CopyToHostData(perm); success &= valid_permutation(nrow, perm); success &= valid_coloring(nrow, csr_ptr, csr_col, num_colors, size_colors, perm); // Reset coloring.Clear(); delete[] size_colors; size_colors = NULL; // Check accelerator multicoloring A.MoveToAccelerator(); coloring.MoveToAccelerator(); A.MultiColoring(num_colors, &size_colors, &coloring); coloring.CopyToHostData(perm); success &= valid_permutation(nrow, perm); success &= valid_coloring(nrow, csr_ptr, csr_col, num_colors, size_colors, perm); // Clean up delete[] csr_ptr; delete[] csr_col; delete[] csr_val; delete[] size_colors; delete[] perm; // Stop rocALUTION platform stop_rocalution(); return success; } rocALUTION-rocm-7.1.0/clients/include/testing_local_matrix_solve.hpp000066400000000000000000000241621507377332500255350ustar00rootroot00000000000000/* ************************************************************************ * 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 #include "utility.hpp" #include #include using namespace rocalution; static bool check_residual(float res) { return (res < 1e-3f); } static bool check_residual(double res) { return (res < 1e-6); } template bool testing_local_matrix_lusolve(Arguments argus) { const int size = argus.size; const unsigned int format = argus.format; // Initialize rocALUTION set_device_rocalution(device); init_rocalution(); // rocALUTION structures LocalMatrix A; LocalVector base_x; LocalVector test_x; LocalVector b; LocalVector e; // Generate A int* csr_ptr = NULL; int* csr_col = NULL; T* csr_val = NULL; int nrow = 0; int ncol = 0; nrow = gen_2d_laplacian(size, &csr_ptr, &csr_col, &csr_val); ncol = nrow; int nnz = csr_ptr[nrow]; assert(csr_ptr != NULL); assert(csr_col != NULL); assert(csr_val != NULL); A.SetDataPtrCSR(&csr_ptr, &csr_col, &csr_val, "A", nnz, nrow, nrow); // Move data to accelerator A.MoveToAccelerator(); base_x.MoveToAccelerator(); b.MoveToAccelerator(); e.MoveToAccelerator(); // Allocate x, b and e base_x.Allocate("x", A.GetN()); b.Allocate("b", A.GetM()); e.Allocate("e", A.GetN()); // b = A * 1 e.Ones(); A.Apply(e, &b); // Random initial guess base_x.SetRandomUniform(12345ULL, -4.0, 6.0); test_x.CloneFrom(base_x); // Matrix format A.ConvertTo(format, format == BCSR ? argus.blockdim : 1); // Factor A.LUFactorize(); // Compare Solves bool success = true; T nrm2 = 1; // LUSolve on device A.LUAnalyse(); A.LUSolve(b, &test_x); A.LUAnalyseClear(); test_x.ScaleAdd(-1.0, e); nrm2 = test_x.Norm(); success &= check_residual(nrm2); // LUSolve on host A.MoveToHost(); b.MoveToHost(); test_x.CopyFrom(base_x); test_x.MoveToHost(); A.LUAnalyse(); A.LUSolve(b, &test_x); A.LUAnalyseClear(); test_x.MoveToAccelerator(); test_x.ScaleAdd(-1.0, e); nrm2 = test_x.Norm(); success &= check_residual(nrm2); // Stop rocALUTION platform stop_rocalution(); return success; } template bool testing_local_matrix_llsolve(Arguments argus) { const int size = argus.size; const unsigned int format = argus.format; // Initialize rocALUTION set_device_rocalution(device); init_rocalution(); // rocALUTION structures LocalMatrix A; LocalMatrix L; LocalVector base_x; LocalVector test_x; LocalVector b; LocalVector e; // Generate A int* csr_ptr = NULL; int* csr_col = NULL; T* csr_val = NULL; int nrow = 0; int ncol = 0; nrow = gen_2d_laplacian(size, &csr_ptr, &csr_col, &csr_val); ncol = nrow; int nnz = csr_ptr[nrow]; assert(csr_ptr != NULL); assert(csr_col != NULL); assert(csr_val != NULL); A.SetDataPtrCSR(&csr_ptr, &csr_col, &csr_val, "A", nnz, nrow, nrow); // Move data to accelerator A.MoveToAccelerator(); L.MoveToAccelerator(); base_x.MoveToAccelerator(); b.MoveToAccelerator(); e.MoveToAccelerator(); // Allocate x, b and e base_x.Allocate("x", A.GetM()); b.Allocate("b", A.GetM()); e.Allocate("e", A.GetM()); // Set up L A.ExtractL(&L, true); // b = LL^T * 1 e.Ones(); { LocalMatrix Lt; LocalVector tmp; Lt.MoveToAccelerator(); tmp.MoveToAccelerator(); tmp.Allocate("tmp", A.GetN()); L.Transpose(&Lt); Lt.Apply(e, &tmp); L.Apply(tmp, &b); } // Random initial guess base_x.SetRandomUniform(12345ULL, -4.0, 6.0); test_x.CloneFrom(base_x); // Matrix format L.ConvertTo(format, format == BCSR ? argus.blockdim : 1); // Compare Solves bool success = true; T nrm2 = 1; // LLSolve on device L.LLAnalyse(); L.LLSolve(b, &test_x); L.LAnalyseClear(); test_x.ScaleAdd(-1.0, e); nrm2 = test_x.Norm(); success &= check_residual(nrm2); // LLSolve on host L.MoveToHost(); b.MoveToHost(); test_x.CopyFrom(base_x); test_x.MoveToHost(); L.LLAnalyse(); L.LLSolve(b, &test_x); L.LLAnalyseClear(); test_x.MoveToAccelerator(); test_x.ScaleAdd(-1.0, e); nrm2 = test_x.Norm(); success &= check_residual(nrm2); // Stop rocALUTION platform stop_rocalution(); return success; } template bool testing_local_matrix_lsolve(Arguments argus) { const int size = argus.size; const unsigned int format = argus.format; const bool unit_diag = argus.unit_diag; // Initialize rocALUTION set_device_rocalution(device); init_rocalution(); // rocALUTION structures LocalMatrix A; LocalMatrix L; LocalVector base_x; LocalVector test_x; LocalVector b; LocalVector e; // Generate A int* csr_ptr = NULL; int* csr_col = NULL; T* csr_val = NULL; int nrow = 0; int ncol = 0; nrow = gen_2d_laplacian(size, &csr_ptr, &csr_col, &csr_val); ncol = nrow; int nnz = csr_ptr[nrow]; assert(csr_ptr != NULL); assert(csr_col != NULL); assert(csr_val != NULL); A.SetDataPtrCSR(&csr_ptr, &csr_col, &csr_val, "A", nnz, nrow, nrow); // Move data to accelerator A.MoveToAccelerator(); L.MoveToAccelerator(); base_x.MoveToAccelerator(); b.MoveToAccelerator(); e.MoveToAccelerator(); // Allocate x, b and e base_x.Allocate("x", A.GetN()); b.Allocate("b", A.GetM()); e.Allocate("e", A.GetN()); // Set up L A.ExtractL(&L, !unit_diag); // b = L * 1 e.Ones(); L.Apply(e, &b); if(unit_diag) { // b + 1 * e b.ScaleAdd(1, e); } // Random initial guess base_x.SetRandomUniform(12345ULL, -4.0, 6.0); test_x.CloneFrom(base_x); // Matrix format L.ConvertTo(format, format == BCSR ? argus.blockdim : 1); // Compare Solves bool success = true; T nrm2 = 1; // LSolve on device L.LAnalyse(unit_diag); L.LSolve(b, &test_x); L.LAnalyseClear(); test_x.ScaleAdd(-1.0, e); nrm2 = test_x.Norm(); success &= check_residual(nrm2); // LSolve on host L.MoveToHost(); b.MoveToHost(); test_x.CopyFrom(base_x); test_x.MoveToHost(); L.LAnalyse(unit_diag); L.LSolve(b, &test_x); L.LAnalyseClear(); test_x.MoveToAccelerator(); test_x.ScaleAdd(-1.0, e); nrm2 = test_x.Norm(); success &= check_residual(nrm2); // Stop rocALUTION platform stop_rocalution(); return success; } template bool testing_local_matrix_usolve(Arguments argus) { const int size = argus.size; const unsigned int format = argus.format; const bool unit_diag = argus.unit_diag; // Initialize rocALUTION set_device_rocalution(device); init_rocalution(); // rocALUTION structures LocalMatrix A; LocalMatrix U; LocalVector base_x; LocalVector test_x; LocalVector b; LocalVector e; // Generate A int* csr_ptr = NULL; int* csr_col = NULL; T* csr_val = NULL; int nrow = 0; int ncol = 0; nrow = gen_2d_laplacian(size, &csr_ptr, &csr_col, &csr_val); ncol = nrow; int nnz = csr_ptr[nrow]; assert(csr_ptr != NULL); assert(csr_col != NULL); assert(csr_val != NULL); A.SetDataPtrCSR(&csr_ptr, &csr_col, &csr_val, "A", nnz, nrow, nrow); // Move data to accelerator A.MoveToAccelerator(); U.MoveToAccelerator(); base_x.MoveToAccelerator(); b.MoveToAccelerator(); e.MoveToAccelerator(); // Allocate x, b and e base_x.Allocate("x", A.GetN()); b.Allocate("b", A.GetM()); e.Allocate("e", A.GetN()); // Set up U A.ExtractU(&U, !unit_diag); // b = U * 1 e.Ones(); U.Apply(e, &b); if(unit_diag) { // b + 1 * e b.ScaleAdd(1, e); } // Random initial guess base_x.SetRandomUniform(12345ULL, -4.0, 6.0); test_x.CloneFrom(base_x); // Matrix format U.ConvertTo(format, format == BCSR ? argus.blockdim : 1); // Compare Solves bool success = true; T nrm2 = 1; // USolve on device U.UAnalyse(unit_diag); U.USolve(b, &test_x); U.UAnalyseClear(); test_x.ScaleAdd(-1.0, e); nrm2 = test_x.Norm(); success &= check_residual(nrm2); // USolve on host U.MoveToHost(); b.MoveToHost(); test_x.CopyFrom(base_x); test_x.MoveToHost(); U.UAnalyse(unit_diag); U.USolve(b, &test_x); U.UAnalyseClear(); test_x.MoveToAccelerator(); test_x.ScaleAdd(-1.0, e); nrm2 = test_x.Norm(); success &= check_residual(nrm2); // Stop rocALUTION platform stop_rocalution(); return success; } rocALUTION-rocm-7.1.0/clients/include/testing_local_stencil.hpp000066400000000000000000000041251507377332500244570ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2018-2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_LOCAL_STENCIL_HPP #define TESTING_LOCAL_STENCIL_HPP #include "utility.hpp" #include #include using namespace rocalution; template void testing_local_stencil_bad_args(void) { // Initialize rocALUTION set_device_rocalution(device); init_rocalution(); LocalStencil stn(Laplace2D); LocalVector vec; // Apply { LocalVector* null_vec = nullptr; ASSERT_DEATH(stn.Apply(vec, null_vec), ".*Assertion.*out != (NULL|__null)*"); } // ApplyAdd { LocalVector* null_vec = nullptr; ASSERT_DEATH(stn.ApplyAdd(vec, 1.0, null_vec), ".*Assertion.*out != (NULL|__null)*"); } // Stop rocALUTION stop_rocalution(); } #endif // TESTING_LOCAL_STENCIL_HPP rocALUTION-rocm-7.1.0/clients/include/testing_local_vector.hpp000066400000000000000000001200661507377332500243230ustar00rootroot00000000000000/* ************************************************************************ * 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_LOCAL_VECTOR_HPP #define TESTING_LOCAL_VECTOR_HPP #include "utility.hpp" #include #include using namespace rocalution; template void testing_local_vector_bad_args(void) { int safe_size = 100; // Initialize rocALUTION set_device_rocalution(device); init_rocalution(); // LocalVector object LocalVector vec; // SetDataPtr { T* null_ptr = nullptr; ASSERT_DEATH(vec.SetDataPtr(nullptr, "", safe_size), ".*Assertion.*ptr != (NULL|__null)*"); ASSERT_DEATH(vec.SetDataPtr(&null_ptr, "", safe_size), ".*Assertion.*ptr != (NULL|__null)*"); } // LeaveDataPtr { T* vdata = nullptr; allocate_host(safe_size, &vdata); ASSERT_DEATH(vec.LeaveDataPtr(&vdata), ".*Assertion.*ptr == (NULL|__null)*"); free_host(&vdata); } // CopyFromData { T* null_ptr = nullptr; ASSERT_DEATH(vec.CopyFromData(null_ptr), ".*Assertion.*data != (NULL|__null)*"); } // CopyToData { T* null_ptr = nullptr; ASSERT_DEATH(vec.CopyToData(null_ptr), ".*Assertion.*data != (NULL|__null)*"); } // GetContinuousValues { vec.Allocate("", safe_size); T* null_T = nullptr; ASSERT_DEATH(vec.GetContinuousValues(0, safe_size, null_T), ".*Assertion.*values != (NULL|__null)*"); } // ExtractCoarseMapping { int* null_int = nullptr; int* vint = nullptr; allocate_host(safe_size, &vint); ASSERT_DEATH(vec.ExtractCoarseMapping(0, 0, null_int, 0, vint, vint), ".*Assertion.*index != (NULL|__null)*"); ASSERT_DEATH(vec.ExtractCoarseMapping(0, 0, vint, 0, null_int, vint), ".*Assertion.*size != (NULL|__null)*"); ASSERT_DEATH(vec.ExtractCoarseMapping(0, 0, vint, 0, vint, null_int), ".*Assertion.*map != (NULL|__null)*"); free_host(&vint); } // ExtractCoarseBoundary { int* null_int = nullptr; int* vint = nullptr; allocate_host(safe_size, &vint); ASSERT_DEATH(vec.ExtractCoarseBoundary(0, 0, null_int, 0, vint, vint), ".*Assertion.*index != (NULL|__null)*"); ASSERT_DEATH(vec.ExtractCoarseBoundary(0, 0, vint, 0, null_int, vint), ".*Assertion.*size != (NULL|__null)*"); ASSERT_DEATH(vec.ExtractCoarseBoundary(0, 0, vint, 0, vint, null_int), ".*Assertion.*boundary != (NULL|__null)*"); free_host(&vint); } // Stop rocALUTION stop_rocalution(); } template LocalVector getTestVector(int size = 10) { // Create a LocalVector LocalVector vec; vec.Allocate("TestVector", size); // Fill the source vector with some values for(int i = 0; i < size; ++i) { vec[i] = static_cast(i + 1); } return vec; } template void testing_get_interior(const Arguments& argus) { // Get a LocalVector with size from argus LocalVector vec = getTestVector(argus.size); // Call GetInterior LocalVector& interior = vec.GetInterior(); // Validate that the returned reference is the same as the original object EXPECT_EQ(&interior, &vec); // Validate that the size and properties of the vector remain unchanged EXPECT_EQ(interior.GetSize(), vec.GetSize()); for(int i = 0; i < vec.GetSize(); ++i) { EXPECT_EQ(vec[i], interior[i]); } } template void testing_const_get_interior(const Arguments& argus) { // Get a LocalVector with size from argus const LocalVector vec = getTestVector(argus.size); // Call GetInterior const LocalVector& interior = vec.GetInterior(); // Validate that the returned reference is the same as the original object EXPECT_EQ(&interior, &vec); // Validate that the size and properties of the vector remain unchanged EXPECT_EQ(interior.GetSize(), vec.GetSize()); for(int i = 0; i < vec.GetSize(); ++i) { EXPECT_EQ(vec[i], interior[i]); } } template void testing_check(const Arguments& argus) { // Create a LocalVector and allocate some size LocalVector vec = getTestVector(argus.size); // Check the vector EXPECT_NO_THROW(vec.Check()); } template void testing_zeros(const Arguments& argus) { // Create a LocalVector and allocate some size LocalVector vec = getTestVector(argus.size); vec.Zeros(); // Validate that all elements are set to zero for(int i = 0; i < vec.GetSize(); ++i) { EXPECT_EQ(vec[i], static_cast(0.0)); } } template void testing_ones(const Arguments& argus) { // Create a LocalVector and allocate some size LocalVector vec = getTestVector(argus.size); vec.Ones(); // Validate that all elements are set to one for(int i = 0; i < vec.GetSize(); ++i) { EXPECT_EQ(vec[i], static_cast(1.0)); } } template void testing_set_values(const Arguments& argus) { // Create a LocalVector and allocate some size LocalVector vec = getTestVector(argus.size); // Set values in the vector T value = static_cast(5.0); vec.SetValues(value); // Validate that all elements are set to the specified value for(int i = 0; i < vec.GetSize(); ++i) { EXPECT_EQ(vec[i], value); } } template void testing_set_random_uniform(const Arguments& argus) { // Create a LocalVector and allocate some size LocalVector vec = getTestVector(argus.size); // Set random values in the vector T min = static_cast(0.0); T max = static_cast(1.0); vec.SetRandomUniform(min, max); // Validate that all elements are within the specified range for(int i = 0; i < vec.GetSize(); ++i) { EXPECT_GE(vec[i], min); EXPECT_LE(vec[i], max); } } template void testing_set_random_normal(const Arguments& argus) { // Create a LocalVector and allocate some size LocalVector vec = getTestVector(argus.size > 0 ? argus.size : 1000); // Set random values in the vector T mean = static_cast(0.0); T std = static_cast(1.0); vec.SetRandomNormal(mean, std); // Validate that the mean of all elements is close to the specified mean T sum = 0.0; for(int i = 0; i < vec.GetSize(); ++i) { sum += vec[i]; } T calculated_mean = sum / vec.GetSize(); EXPECT_NEAR(calculated_mean, mean, 3 * std); // Validate that the standard deviation of all elements is close to the specified std T sum_sq = 0.0; for(int i = 0; i < vec.GetSize(); ++i) { sum_sq += (vec[i] - calculated_mean) * (vec[i] - calculated_mean); } T calculated_std = std::sqrt(sum_sq / vec.GetSize()); EXPECT_NEAR(calculated_std, std, 3 * std); } template void testing_copy_from(const Arguments& argus) { // Create a LocalVector and allocate some size LocalVector vec = getTestVector(argus.size); // Create another LocalVector to copy from LocalVector src_vec = getTestVector(argus.size); // Copy values from the source vector EXPECT_NO_THROW(vec.CopyFrom(src_vec)); // Validate the copied values for(int i = 0; i < vec.GetSize(); ++i) { EXPECT_EQ(vec[i], src_vec[i]); } } template void testing_clone_from(const Arguments& argus) { // Create a LocalVector and allocate some size LocalVector vec = getTestVector(argus.size); // Clone the vector LocalVector cloned_vec; EXPECT_NO_THROW(cloned_vec.CloneFrom(vec)); // Validate the cloned values for(int i = 0; i < cloned_vec.GetSize(); ++i) { EXPECT_EQ(cloned_vec[i], vec[i]); } } template void testing_binary(const Arguments& argus) { // Create a LocalVector and allocate some size LocalVector vec = getTestVector(argus.size); // Define the filename for the test const std::string filename = get_temp_dir() + "test_vector.bin"; // Write the vector to a binary file EXPECT_NO_THROW(vec.WriteFileBinary(filename)); // Read the vector from the binary file LocalVector read_vec; EXPECT_NO_THROW(read_vec.ReadFileBinary(filename)); // Validate the read values for(int i = 0; i < read_vec.GetSize(); ++i) { EXPECT_EQ(read_vec[i], vec[i]); } // Clean up the temporary file std::remove(filename.c_str()); } template void testing_add_scale(const Arguments& argus) { // Create a LocalVector and allocate some size LocalVector v = getTestVector(argus.size); LocalVector x = getTestVector(argus.size); // Define a scaling factor T alpha = static_cast(2.0); // Perform the AddScale operation EXPECT_NO_THROW(v.AddScale(x, alpha)); // Validate the result for(int i = 0; i < v.GetSize(); ++i) { EXPECT_EQ(v[i], static_cast((i + 1) * (1 + alpha))); } } template void testing_scale_add(const Arguments& argus) { // Create a LocalVector and allocate some size LocalVector v = getTestVector(argus.size); LocalVector x = getTestVector(argus.size); // Define a scaling factor T alpha = static_cast(2.0); // v = 1 initially v.Ones(); // Perform the v = alpha * v + x EXPECT_NO_THROW(v.ScaleAdd(alpha, x)); // Validate the result for(int i = 0; i < v.GetSize(); ++i) { EXPECT_EQ(v[i], alpha + x[i]); } } template void testing_scale_add_2(const Arguments& argus) { LocalVector v = getTestVector(argus.size); LocalVector x = getTestVector(argus.size); LocalVector y = getTestVector(argus.size); // Fill x and y with test values if(argus.size >= 3) { x[0] = static_cast(1); x[1] = static_cast(2); x[2] = static_cast(3); y[0] = static_cast(4); y[1] = static_cast(5); y[2] = static_cast(6); } // v = 1 initially v.Ones(); // v.ScaleAdd2(alpha, x, beta, y, gamma) T alpha = static_cast(2); T beta = static_cast(3); T gamma = static_cast(3); v.ScaleAdd2(alpha, x, beta, y, gamma); // v[i] = alpha * v[i] + beta * x[i] + gamma * y[i] for(int i = 0; i < v.GetSize(); ++i) { EXPECT_EQ(v[i], alpha + beta * x[i] + gamma * y[i]); } } template void testing_scale(const Arguments& argus) { // Create a LocalVector and allocate some size LocalVector vec = getTestVector(argus.size); // Define a scaling factor T alpha = static_cast(2.0); // Perform the Scale operation EXPECT_NO_THROW(vec.Scale(alpha)); // Validate the result for(int i = 0; i < vec.GetSize(); ++i) { EXPECT_EQ(vec[i], static_cast((i + 1) * alpha)); } } template void testing_dot(const Arguments& argus) { // Create two LocalVectors and allocate some size LocalVector vec1 = getTestVector(argus.size); LocalVector vec2 = getTestVector(argus.size); // Perform the Dot product T result = 0.0; EXPECT_NO_THROW(result = vec1.Dot(vec2)); // Validate the result T result2 = 0.0; for(int i = 0; i < vec1.GetSize(); ++i) { result2 += vec1[i] * vec2[i]; } EXPECT_EQ(result, result2); } template void testing_dot_non_conj(const Arguments& argus) { // Create two LocalVectors and allocate some size LocalVector vec1 = getTestVector(argus.size); LocalVector vec2 = getTestVector(argus.size); // Perform the Dot product without conjugation T result = 0.0; EXPECT_NO_THROW(result = vec1.DotNonConj(vec2)); // Validate the result T result2 = 0.0; for(int i = 0; i < vec1.GetSize(); ++i) { result2 += vec1[i] * vec2[i]; } EXPECT_EQ(result, result2); } template void testing_norm(const Arguments& argus) { // Create a LocalVector and allocate some size LocalVector vec = getTestVector(argus.size); // Perform the Norm operation T result = 0.0; EXPECT_NO_THROW(result = vec.Norm()); // Validate the result T result2 = 0.0; for(int i = 0; i < vec.GetSize(); ++i) { result2 += vec[i] * vec[i]; } EXPECT_NEAR(result * result, result2, 1e-6 * std::abs(result2)); } template void testing_reduce(const Arguments& argus) { // Create a LocalVector and allocate some size LocalVector vec = getTestVector(argus.size); // Perform the Reduce operation T result = 0.0; EXPECT_NO_THROW(result = vec.Reduce()); // Validate the result T result2 = 0.0; for(int i = 0; i < vec.GetSize(); ++i) { result2 += vec[i]; } EXPECT_EQ(result, result2); } template void testing_point_wise_mult(const Arguments& argus) { // Create two LocalVectors and allocate some size LocalVector vec1 = getTestVector(argus.size); LocalVector vec2 = getTestVector(argus.size); // Perform the PointwiseMult operation EXPECT_NO_THROW(vec1.PointWiseMult(vec2)); // Validate the result for(int i = 0; i < vec1.GetSize(); ++i) { EXPECT_EQ(vec1[i], static_cast((i + 1) * (i + 1))); } } template void testing_point_wise_mult_2(const Arguments& argus) { // Create two LocalVectors and allocate some size LocalVector vec1 = getTestVector(argus.size); LocalVector vec2 = getTestVector(argus.size); LocalVector vec3 = getTestVector(argus.size); // Perform the PointwiseMult operation EXPECT_NO_THROW(vec1.PointWiseMult(vec2, vec3)); // Validate the result for(int i = 0; i < vec1.GetSize(); ++i) { EXPECT_EQ(vec1[i], static_cast((i + 1) * (i + 1))); } } template void testing_leave_data_ptr(const Arguments& argus) { // Create a LocalVector and allocate some size LocalVector vec = getTestVector(argus.size); // Pointer to data (initialized to NULL) T* data_ptr = nullptr; // Attempt to leave the data pointer EXPECT_NO_THROW(vec.LeaveDataPtr(&data_ptr)); // Ensure the pointer is not NULL after the call EXPECT_NE(data_ptr, nullptr); // Ensure the vector is cleared EXPECT_EQ(vec.GetSize(), 0); } template void testing_sync(const Arguments& argus) { // Create a LocalVector and allocate some size LocalVector vec = getTestVector(argus.size); // Perform a synchronization operation EXPECT_NO_THROW(vec.Sync()); // Validate that the vector is still accessible and contains the correct values EXPECT_EQ(vec.GetSize(), argus.size); for(int i = 0; i < vec.GetSize(); ++i) { EXPECT_EQ(vec[i], static_cast(i + 1)); } } template void testing_copy_from_data(const Arguments& argus) { // Create a LocalVector and allocate some size LocalVector vec = getTestVector(argus.size); // Pointer to data T data_ptr[5] = {0, 2, 4, 8, 16}; // Attempt to copy from the data pointer EXPECT_NO_THROW(vec.CopyFromData(data_ptr)); EXPECT_EQ(vec.GetSize(), argus.size); if(argus.size >= 5) { EXPECT_EQ(vec[0], static_cast(0.0)); EXPECT_EQ(vec[1], static_cast(2.0)); EXPECT_EQ(vec[2], static_cast(4.0)); EXPECT_EQ(vec[3], static_cast(8.0)); EXPECT_EQ(vec[4], static_cast(16.0)); } } template void testing_copy_to_host_data(const Arguments& argus) { // Create a LocalVector and allocate some size LocalVector vec = getTestVector(argus.size); // Pointer to host data std::vector host_data(argus.size); // Attempt to copy to the host data pointer EXPECT_NO_THROW(vec.CopyToHostData(host_data.data())); for(int i = 0; i < argus.size; ++i) { EXPECT_EQ(host_data[i], static_cast(i + 1)); } } template void testing_restriction() { // Create a LocalVector and allocate some size LocalVector vec = getTestVector(5); // Create a mapping vector (map fine indices to coarse indices) LocalVector map; map.Allocate("MappingVector", 5); map[0] = 0; map[1] = 0; map[2] = 1; map[3] = 1; map[4] = 2; // Create a LocalVector to store the restriction LocalVector restricted_vec = getTestVector(5); // Perform the Restriction operation EXPECT_NO_THROW(restricted_vec.Restriction(vec, map)); // Validate the result size (should match the number of unique coarse indices, here 3) EXPECT_EQ(restricted_vec.GetSize(), 5); // Optionally, check the restricted values EXPECT_EQ(restricted_vec[0], static_cast(vec[0] + vec[1])); // sum of fine indices 0 and 1 EXPECT_EQ(restricted_vec[1], static_cast(vec[2] + vec[3])); // sum of fine indices 2 and 3 EXPECT_EQ(restricted_vec[2], static_cast(vec[4])); // fine index 4 } template void testing_copy_from_with_offsets(const Arguments& argus) { // Create a source LocalVector and allocate some size LocalVector src_vec = getTestVector(argus.size); // Create a destination LocalVector and allocate some size LocalVector dst_vec; dst_vec.Allocate("DstVector", argus.size); // Fill destination with zeros dst_vec.Zeros(); // Copy 3 elements from src_vec[1..3] to dst_vec[2..4] int64_t src_offset = 1; int64_t dst_offset = 2; int64_t size = 3; if(argus.size >= 5) { EXPECT_NO_THROW(dst_vec.CopyFrom(src_vec, src_offset, dst_offset, size)); // Validate the copied values // dst_vec should now be [0, 0, 2, 3, 4] EXPECT_EQ(dst_vec[0], static_cast(0)); EXPECT_EQ(dst_vec[1], static_cast(0)); EXPECT_EQ(dst_vec[2], static_cast(2)); EXPECT_EQ(dst_vec[3], static_cast(3)); EXPECT_EQ(dst_vec[4], static_cast(4)); } } template void testing_set_data_ptr_null(const Arguments& argus) { // Create a LocalVector LocalVector vec; // Pointer to data (initialized to NULL) T* data_ptr = NULL; // Attempt to set the data pointer EXPECT_NO_THROW(vec.SetDataPtr(&data_ptr, "TestVector", 0)); // Ensure the pointer is still NULL after the call EXPECT_EQ(data_ptr, nullptr); // Ensure the vector is cleared EXPECT_EQ(vec.GetSize(), 0); } template void testing_info(const Arguments& argus) { // Create a LocalVector and allocate some size LocalVector vec; vec.Allocate("TestVector", argus.size); // Redirect standard output to a stringstream to capture the Info output std::stringstream output_stream; std::streambuf* original_cout_buffer = std::cout.rdbuf(); std::cout.rdbuf(output_stream.rdbuf()); // Call the Info method vec.Info(); // Restore the original standard output buffer std::cout.rdbuf(original_cout_buffer); // Get the captured output std::string output = output_stream.str(); // Validate the output contains expected information EXPECT_NE(output.find("name=TestVector"), std::string::npos); // Check vector name EXPECT_NE(output.find("size=" + std::to_string(argus.size)), std::string::npos); // Check vector size EXPECT_NE(output.find("prec=" + std::to_string(sizeof(T) * 8) + "bit"), std::string::npos); // Check data type } template void testing_sort() { // Create a LocalVector and allocate some size LocalVector vec; vec.Allocate("TestVector", 5); LocalVector sorted_vec; sorted_vec.Allocate("TestVector", 5); // Fill the vector with unsorted values vec[0] = static_cast(3.0); vec[1] = static_cast(1.0); vec[2] = static_cast(5.0); vec[3] = static_cast(2.0); vec[4] = static_cast(4.0); // Call the Sort method EXPECT_NO_THROW(vec.Sort(&sorted_vec, nullptr)); // Validate that the vector is sorted in ascending order EXPECT_EQ(sorted_vec[0], static_cast(1.0)); EXPECT_EQ(sorted_vec[1], static_cast(2.0)); EXPECT_EQ(sorted_vec[2], static_cast(3.0)); EXPECT_EQ(sorted_vec[3], static_cast(4.0)); EXPECT_EQ(sorted_vec[4], static_cast(5.0)); } template void testing_permute_backward(const Arguments& argus) { // Create a LocalVector and allocate some size LocalVector vec = getTestVector(argus.size); // Create a permutation vector LocalVector permutation; permutation.Allocate("PermutationVector", argus.size); if(argus.size >= 5) { permutation[0] = 4; // Move element at index 4 to index 0 permutation[1] = 2; // Move element at index 2 to index 1 permutation[2] = 0; // Move element at index 0 to index 2 permutation[3] = 3; // Keep element at index 3 in place permutation[4] = 1; // Move element at index 1 to index 4 // Call the PermuteBackward method EXPECT_NO_THROW(vec.PermuteBackward(permutation)); // Validate the permuted vector EXPECT_EQ(vec[0], static_cast(5.0)); // Element at index 4 EXPECT_EQ(vec[1], static_cast(3.0)); // Element at index 2 EXPECT_EQ(vec[2], static_cast(1.0)); // Element at index 0 EXPECT_EQ(vec[3], static_cast(4.0)); // Element at index 3 EXPECT_EQ(vec[4], static_cast(2.0)); // Element at index 1 } } template void testing_inclusive_sum(const Arguments& argus) { // Create a LocalVector and allocate some size LocalVector input_vec; input_vec.Allocate("InputVector", argus.size); // Fill the input vector with values for(int i = 0; i < argus.size; ++i) { input_vec[i] = static_cast(i + 1); } // Create a LocalVector to store the result LocalVector result_vec; result_vec.Allocate("ResultVector", argus.size); // Call the InclusiveSum method EXPECT_NO_THROW(result_vec.InclusiveSum(input_vec)); // Validate the result T sum = 0; for(int i = 0; i < argus.size; ++i) { sum += static_cast(i + 1); EXPECT_EQ(result_vec[i], sum); } } template void testing_power(const Arguments& argus) { // Create a LocalVector and allocate some size LocalVector vec = getTestVector(argus.size); // Apply the Power method with power = 2.0 EXPECT_NO_THROW(vec.Power(2.0)); // Validate the results for(int i = 0; i < argus.size; ++i) { EXPECT_EQ(vec[i], static_cast((i + 1) * (i + 1))); // Squared values } // Apply the Power method with power = 0.5 (square root) EXPECT_NO_THROW(vec.Power(0.5)); // Validate the results for(int i = 0; i < argus.size; ++i) { EXPECT_EQ(vec[i], static_cast(i + 1)); // Original values restored } } template void testing_scale_add_scale(const Arguments& argus) { // Create a LocalVector and allocate some size LocalVector vec = getTestVector(argus.size); // Create another LocalVector for the operation LocalVector x; x.Allocate("XVector", argus.size); // Fill the second vector with values for(int i = 0; i < argus.size; ++i) { x[i] = static_cast(argus.size - i); } // Define scaling factors T alpha = 2.0f; T beta = 3.0f; // Perform the ScaleAddScale operation EXPECT_NO_THROW(vec.ScaleAddScale(alpha, x, beta)); // Validate the result for(int i = 0; i < argus.size; ++i) { EXPECT_EQ(vec[i], static_cast(alpha * (i + 1) + beta * (argus.size - i))); } } template void testing_operator_index_const(const Arguments& argus) { // Create a LocalVector and allocate some size LocalVector vec = getTestVector(argus.size); // Create a const reference to the vector const LocalVector& const_vec = vec; // Validate access to elements using the const operator[] for(int i = 0; i < argus.size; ++i) { EXPECT_EQ(const_vec[i], static_cast(i + 1)); } } template void testing_read_file_ascii(const Arguments& argus) { // Create a temporary ASCII file with test data std::string filename = get_temp_dir() + "test_vector.txt"; std::ofstream file(filename); ASSERT_TRUE(file.is_open()); for(int i = 0; i < argus.size; ++i) { file << static_cast(i + 1) << "\n"; } file.close(); // Create a LocalVector to read the data into LocalVector vec; // Call the ReadFileASCII method EXPECT_NO_THROW(vec.ReadFileASCII(filename)); // Validate the vector size EXPECT_EQ(vec.GetSize(), argus.size); // Validate the values in the vector for(int i = 0; i < argus.size; ++i) { EXPECT_EQ(vec[i], static_cast(i + 1)); } // Clean up the temporary file std::remove(filename.c_str()); } template void testing_copy_from_async(const Arguments& argus) { // Create a source LocalVector and allocate some size LocalVector src_vec = getTestVector(argus.size); // Create a destination LocalVector LocalVector dest_vec; // Perform the asynchronous copy EXPECT_NO_THROW(dest_vec.CopyFromAsync(src_vec)); // Synchronize to ensure the copy is complete EXPECT_NO_THROW(_rocalution_sync()); // Validate the copied values EXPECT_EQ(dest_vec.GetSize(), src_vec.GetSize()); for(int i = 0; i < argus.size; ++i) { EXPECT_EQ(dest_vec[i], static_cast(i + 1)); } } template void testing_move_to_accelerator_async(const Arguments& argus) { // Create a source LocalVector and allocate some size LocalVector vec = getTestVector(argus.size); // Perform the asynchronous move to the accelerator EXPECT_NO_THROW(vec.MoveToAcceleratorAsync()); // Synchronize to ensure the move is complete EXPECT_NO_THROW(_rocalution_sync()); // Validate that the vector is still accessible and contains the correct values EXPECT_EQ(vec.GetSize(), argus.size); for(int i = 0; i < argus.size; ++i) { EXPECT_EQ(vec[i], static_cast(i + 1)); } } template void testing_copy_from_host_data(const Arguments& argus) { // clang-format off // Create a host array with test data std::vector host_data(argus.size); for(int i = 0; i < argus.size; ++i) { host_data[i] = static_cast(i + 1); } // clang-format on // Create a LocalVector and allocate the same size LocalVector vec; vec.Allocate("TestVector", argus.size); // Copy data from the host array to the LocalVector EXPECT_NO_THROW(vec.CopyFromHostData(host_data.data())); // Validate the vector size EXPECT_EQ(vec.GetSize(), argus.size); // Validate the copied values for(int i = 0; i < argus.size; ++i) { EXPECT_EQ(vec[i], static_cast(i + 1)); } } template void testing_copy_to_data(const Arguments& argus) { // Create a LocalVector and allocate some size LocalVector vec = getTestVector(argus.size); // Create a host array to store the copied data std::vector host_data(argus.size, static_cast(0.0)); // Copy data from the LocalVector to the host array EXPECT_NO_THROW(vec.CopyToData(host_data.data())); // Validate the copied values for(int i = 0; i < argus.size; ++i) { EXPECT_EQ(host_data[i], static_cast(i + 1)); } } // Helper function to read the contents of a file into a string std::string ReadFileContents(const std::string& filename) { std::ifstream file(filename); std::stringstream buffer; buffer << file.rdbuf(); return buffer.str(); } template void testing_write_file_ascii() { // Create a LocalVector and allocate some size LocalVector vec = getTestVector(5); // Define the filename for the test const std::string filename = get_temp_dir() + "test_vector.txt"; // Write the vector to the file EXPECT_NO_THROW(vec.WriteFileASCII(filename)); // Read the contents of the file std::string file_contents = ReadFileContents(filename); // Define the expected output std::string expected_output = "1.000000e+00\n2.000000e+00\n3.000000e+00\n4.000000e+00\n5.000000e+00\n"; // Validate the file contents EXPECT_EQ(file_contents, expected_output); // Clean up the temporary file std::remove(filename.c_str()); } template void testing_scale_add_scale_with_offsets() { // Create a LocalVector and allocate some size LocalVector vec = getTestVector(10); // Create another LocalVector for the operation LocalVector x; x.Allocate("XVector", 10); // Fill the second vector with values for(int i = 0; i < 10; ++i) { x[i] = static_cast(10 - i); // Values: 10.0, 9.0, ..., 1.0 } // Define scaling factors and offsets T alpha = 2.0f; T beta = 3.0f; int64_t src_offset = 2; // Start from index 2 in x int64_t dst_offset = 4; // Start from index 4 in vec int64_t size = 3; // Operate on 3 elements // Perform the ScaleAddScale operation EXPECT_NO_THROW(vec.ScaleAddScale(alpha, x, beta, src_offset, dst_offset, size)); // Validate the results EXPECT_EQ(vec[4], static_cast(alpha * 5.0 + beta * 8.0)); // 2 * 5 + 3 * 8 = 34 EXPECT_EQ(vec[5], static_cast(alpha * 6.0 + beta * 7.0)); // 2 * 6 + 3 * 7 = 33 EXPECT_EQ(vec[6], static_cast(alpha * 7.0 + beta * 6.0)); // 2 * 7 + 3 * 6 = 32 // Ensure other elements remain unchanged EXPECT_EQ(vec[0], static_cast(1.0)); EXPECT_EQ(vec[1], static_cast(2.0)); EXPECT_EQ(vec[2], static_cast(3.0)); EXPECT_EQ(vec[3], static_cast(4.0)); EXPECT_EQ(vec[7], static_cast(8.0)); EXPECT_EQ(vec[8], static_cast(9.0)); EXPECT_EQ(vec[9], static_cast(10.0)); } template void testing_inclusive_sum_void(const Arguments& argus) { LocalVector vec = getTestVector(argus.size); T expected_sum = 0; for(int i = 0; i < argus.size; ++i) { expected_sum += static_cast(i + 1); } EXPECT_EQ(vec.InclusiveSum(), expected_sum); } template void testing_inclusive_sum_with_input(const Arguments& argus) { LocalVector input_vec = getTestVector(argus.size); LocalVector result_vec; result_vec.Allocate("ResultVector", argus.size); EXPECT_NO_THROW(result_vec.InclusiveSum(input_vec)); T sum = 0; for(int i = 0; i < argus.size; ++i) { sum += static_cast(i + 1); EXPECT_EQ(result_vec[i], sum); } } template void testing_exclusive_sum_void(const Arguments& argus) { LocalVector vec = getTestVector(argus.size); T expected_sum = 0; for(int i = 0; i < argus.size - 1; ++i) { expected_sum += static_cast(i + 1); } EXPECT_EQ(vec.ExclusiveSum(), expected_sum); } template void testing_exclusive_sum_with_input(const Arguments& argus) { LocalVector input_vec = getTestVector(argus.size); LocalVector result_vec; result_vec.Allocate("ResultVector", argus.size); EXPECT_NO_THROW(result_vec.ExclusiveSum(input_vec)); T sum = 0; for(int i = 0; i < argus.size; ++i) { EXPECT_EQ(result_vec[i], sum); sum += static_cast(i + 1); } } template void testing_asum(const Arguments& argus) { LocalVector vec = getTestVector(argus.size); T expected_sum = 0; for(int i = 0; i < argus.size; ++i) { expected_sum += std::abs(static_cast(i + 1)); } EXPECT_EQ(vec.Asum(), expected_sum); } template void testing_amax(const Arguments& argus) { LocalVector vec = getTestVector(argus.size); T max_value = 0.0; int max_index = vec.Amax(max_value); EXPECT_EQ(max_index, argus.size - 1); EXPECT_EQ(max_value, static_cast(argus.size)); } // Helper function to read binary file contents into a vector template std::vector ReadBinaryFile(const std::string& filename, size_t& size_out) { std::ifstream file(filename, std::ios::binary); // Read the size of the vector size_t size = 0; file.read(reinterpret_cast(&size), sizeof(size_t)); size_out = size; // Read the vector data std::vector data(size); file.read(reinterpret_cast(data.data()), size * sizeof(ValueType)); file.close(); return data; } template void testing_prolongation(const Arguments& argus) { // Create a coarse-level LocalVector and allocate some size int coarse_size = argus.size > 2 ? argus.size / 2 : 2; int fine_size = coarse_size * 2; LocalVector vec_coarse; vec_coarse.Allocate("CoarseVector", coarse_size); // Fill the coarse-level vector with values for(int i = 0; i < coarse_size; ++i) { vec_coarse[i] = static_cast(i + 1); } // Create a mapping vector LocalVector map; map.Allocate("MappingVector", fine_size); // Define the mapping (fine indices map to coarse indices) for(int i = 0; i < fine_size; ++i) { map[i] = i / 2; } // Create a fine-level LocalVector to store the result LocalVector vec_fine; vec_fine.Allocate("FineVector", fine_size); // Perform the prolongation operation EXPECT_NO_THROW(vec_fine.Prolongation(vec_coarse, map)); // Validate the prolonged values for(int i = 0; i < fine_size; ++i) { EXPECT_EQ(vec_fine[i], vec_coarse[map[i]]); } } template void testing_get_index_values(const Arguments& argus) { // Create a LocalVector and allocate some size LocalVector vec = getTestVector(argus.size); // Create an index vector int num_indices = std::min(3, argus.size); LocalVector index; index.Allocate("IndexVector", num_indices); for(int i = 0; i < num_indices; ++i) { index[i] = i * 2; } // Create a LocalVector to store the values LocalVector values; values.Allocate("ValuesVector", num_indices); // Call the GetIndexValues method EXPECT_NO_THROW(vec.GetIndexValues(index, &values)); // Validate the retrieved values for(int i = 0; i < num_indices; ++i) { EXPECT_EQ(values[i], static_cast(index[i] + 1)); } } template void testing_set_index_values(const Arguments& argus) { // Create a LocalVector and allocate some size LocalVector vec; vec.Allocate("TestVector", argus.size); // Create an index vector int num_indices = std::min(3, argus.size); LocalVector index; index.Allocate("IndexVector", num_indices); for(int i = 0; i < num_indices; ++i) { index[i] = i * 2; } // Create a LocalVector to store the values LocalVector values; values.Allocate("ValuesVector", num_indices); for(int i = 0; i < num_indices; ++i) { values[i] = static_cast(100.0 * (i + 1)); } // Call the SetIndexValues method EXPECT_NO_THROW(vec.SetIndexValues(index, values)); // Validate the set values for(int i = 0; i < num_indices; ++i) { EXPECT_EQ(vec[index[i]], static_cast(100.0 * (i + 1))); } } template void testing_add_index_values(const Arguments& argus) { // Create a LocalVector and allocate some size LocalVector vec; vec.Allocate("TestVector", argus.size); // Fill the vector with initial values for(int i = 0; i < argus.size; ++i) { vec[i] = static_cast(10.0 * (i + 1)); } // Create an index vector int num_indices = std::min(3, argus.size); LocalVector index; index.Allocate("IndexVector", num_indices); for(int i = 0; i < num_indices; ++i) { index[i] = i * 2; } // Create a LocalVector to store the values to be added LocalVector values; values.Allocate("ValuesVector", num_indices); for(int i = 0; i < num_indices; ++i) { values[i] = static_cast(5.0 * (i + 1)); } // Call the AddIndexValues method EXPECT_NO_THROW(vec.AddIndexValues(index, values)); // Validate the updated values for(int i = 0; i < num_indices; ++i) { EXPECT_EQ(vec[index[i]], static_cast(10.0 * (index[i] + 1) + 5.0 * (i + 1))); } } template void testing_get_continuous_values(const Arguments& argus) { // Create a LocalVector and allocate some size LocalVector vec = getTestVector(argus.size); int num_values = std::min(3, argus.size - 1); if(num_values > 0) { // Create an array to store the continuous values std::vector values(num_values); // Call the GetContinuousValues method EXPECT_NO_THROW(vec.GetContinuousValues(1, 1 + num_values, values.data())); // Validate the retrieved values for(int i = 0; i < num_values; ++i) { EXPECT_EQ(values[i], static_cast(i + 2)); } } } template void testing_set_continuous_values(const Arguments& argus) { // Create a LocalVector and allocate some size LocalVector vec; vec.Allocate("TestVector", argus.size); int num_values = std::min(3, argus.size - 1); if(num_values > 0) { // Create an array of values to set std::vector values(num_values); for(int i = 0; i < num_values; ++i) { values[i] = static_cast(100.0 * (i + 1)); } // Call the SetContinuousValues method EXPECT_NO_THROW(vec.SetContinuousValues(1, 1 + num_values, values.data())); // Validate the set values for(int i = 0; i < num_values; ++i) { EXPECT_EQ(vec[1 + i], static_cast(100.0 * (i + 1))); } } } template void testing_extract_coarse_mapping() { // Create a LocalVector and allocate some size LocalVector vec; vec.Allocate("TestVector", 5); // Create an index vector int index[3] = {0, 2, 4}; int size = 0; int map[3]; // Call the ExtractCoarseMapping method EXPECT_NO_THROW(vec.ExtractCoarseMapping(0, 5, index, 3, &size, map)); // Validate the extracted mapping EXPECT_EQ(size, 5); EXPECT_EQ(map[0], 0); EXPECT_EQ(map[1], 0); EXPECT_EQ(map[2], 0); } template void testing_move_to_host_async(const Arguments& argus) { // Create a LocalVector and allocate some size LocalVector vec = getTestVector(argus.size); // Move the vector to the accelerator EXPECT_NO_THROW(vec.MoveToAccelerator()); // Perform the asynchronous move to the host EXPECT_NO_THROW(vec.MoveToHostAsync()); // Synchronize to ensure the move is complete EXPECT_NO_THROW(_rocalution_sync()); // Validate that the vector is still accessible and contains the correct values EXPECT_EQ(vec.GetSize(), argus.size); for(int i = 0; i < argus.size; ++i) { EXPECT_EQ(vec[i], static_cast(i + 1)); } } #endif // TESTING_LOCAL_VECTOR_HPP rocALUTION-rocm-7.1.0/clients/include/testing_lu.hpp000066400000000000000000000075051507377332500222710ustar00rootroot00000000000000/* ************************************************************************ * 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_LU_HPP #define TESTING_LU_HPP #include "utility.hpp" #include using namespace rocalution; static bool check_residual(float res) { return (res < 1e-3f); } static bool check_residual(double res) { return (res < 1e-6); } template bool testing_lu(Arguments argus) { int ndim = argus.size; unsigned int format = argus.format; std::string matrix_type = argus.matrix_type; const bool use_host_and_acc = argus.use_acc; // Initialize rocALUTION platform set_device_rocalution(device); init_rocalution(); // rocALUTION structures LocalMatrix A; LocalVector x; LocalVector b; LocalVector e; // Generate A int* csr_ptr = NULL; int* csr_col = NULL; T* csr_val = NULL; int nrow = 0; int ncol = 0; if(matrix_type == "Laplacian2D") { nrow = gen_2d_laplacian(ndim, &csr_ptr, &csr_col, &csr_val); ncol = nrow; } else if(matrix_type == "PermutedIdentity") { nrow = gen_permuted_identity(ndim, &csr_ptr, &csr_col, &csr_val); ncol = nrow; } else { return false; } int nnz = csr_ptr[nrow]; A.SetDataPtrCSR(&csr_ptr, &csr_col, &csr_val, "A", nnz, nrow, nrow); // Allocate x, b and e x.Allocate("x", A.GetN()); b.Allocate("b", A.GetM()); e.Allocate("e", A.GetN()); // b = A * 1 e.Ones(); A.Apply(e, &b); // Random initial guess x.SetRandomUniform(12345ULL, -4.0, 6.0); // Solver LU, LocalVector, T> dls; dls.Verbose(0); dls.SetOperator(A); dls.Build(); dls.Print(); // Matrix format A.ConvertTo(format, format == BCSR ? argus.blockdim : 1); // Move data to accelerator dls.MoveToAccelerator(); A.MoveToAccelerator(); x.MoveToAccelerator(); b.MoveToAccelerator(); e.MoveToAccelerator(); dls.Solve(b, &x); // Verify solution x.ScaleAdd(-1.0, e); T nrm2_acc = x.Norm(); bool success = check_residual(nrm2_acc); if(use_host_and_acc) { dls.MoveToHost(); A.MoveToHost(); x.MoveToHost(); e.MoveToHost(); b.MoveToHost(); dls.Solve(b, &x); // Verify solution x.ScaleAdd(-1.0, e); T nrm2_host = x.Norm(); success = success && check_residual(nrm2_host); } // Clean up dls.Clear(); // Stop rocALUTION platform stop_rocalution(); return success; } #endif // TESTING_QR_HPP rocALUTION-rocm-7.1.0/clients/include/testing_mixed_precision.hpp000066400000000000000000000074531507377332500250340ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 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 "utility.hpp" #include template bool testing_mixed_precision(Arguments argus) { using namespace rocalution; int ndim = argus.size; std::string precond = argus.precond; unsigned int format = argus.format; std::string matrix_type = argus.matrix_type; bool rebuildnumeric = argus.rebuildnumeric; // Initialize rocALUTION platform set_device_rocalution(device); init_rocalution(); // rocALUTION structures LocalMatrix A; LocalVector x; LocalVector e; LocalVector rhs; // Generate A int* csr_ptr = NULL; int* csr_col = NULL; T* csr_val = NULL; int nrow = 0; int ncol = 0; if(matrix_type == "Laplacian2D") { nrow = gen_2d_laplacian(ndim, &csr_ptr, &csr_col, &csr_val); ncol = nrow; } else { stop_rocalution(); disable_accelerator_rocalution(false); return true; } int nnz = csr_ptr[nrow]; T* csr_val2 = NULL; if(rebuildnumeric) { csr_val2 = new T[nnz]; for(int i = 0; i < nnz; i++) { csr_val2[i] = csr_val[i]; } } A.SetDataPtrCSR(&csr_ptr, &csr_col, &csr_val, "A", nnz, nrow, nrow); // Allocate x, b and e x.Allocate("x", A.GetN()); rhs.Allocate("b", A.GetM()); e.Allocate("e", A.GetN()); // Linear Solver MixedPrecisionDC, LocalVector, T, LocalMatrix, LocalVector, float> mp; CG, LocalVector, float> cg; MultiColoredILU, LocalVector, float> p; // Initialize rhs such that A 1 = rhs e.Ones(); A.Apply(e, &rhs); // Initial zero guess x.Zeros(); // setup a lower tol for the inner solver cg.SetPreconditioner(p); cg.Init(1e-5, 1e-2, 1e+20, 100000); // setup the mixed-precision DC mp.SetOperator(A); mp.Set(cg); // Build solver mp.Build(); // Verbosity output mp.Verbose(1); // Solve A x = rhs mp.Solve(rhs, &x); // Compute error L2 norm e.ScaleAdd(-1.0, x); T error = e.Norm(); std::cout << "||e - x||_2 = " << error << std::endl; // Clear solver mp.Clear(); // Stop rocALUTION platform stop_rocalution(); return true; }rocALUTION-rocm-7.1.0/clients/include/testing_pairwise_amg.hpp000066400000000000000000000302401507377332500243100ustar00rootroot00000000000000/* ************************************************************************ * 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_PAIRWISE_AMG_HPP #define TESTING_PAIRWISE_AMG_HPP #include "utility.hpp" #include using namespace rocalution; static bool check_residual(float res) { return (res < 1e-2f); } static bool check_residual(double res) { return (res < 1e-5); } template bool testing_pairwise_amg(Arguments argus) { int ndim = argus.size; int pre_iter = argus.pre_smooth; int post_iter = argus.post_smooth; std::string smoother = argus.smoother; unsigned int format = argus.format; unsigned int ordering = argus.ordering; bool rebuildnumeric = argus.rebuildnumeric; bool disable_accelerator = !argus.use_acc; // Initialize rocALUTION platform disable_accelerator_rocalution(disable_accelerator); set_device_rocalution(device); init_rocalution(); // rocALUTION structures LocalMatrix A; LocalVector x; LocalVector b; LocalVector b2; LocalVector e; // Generate A int* csr_ptr = NULL; int* csr_col = NULL; T* csr_val = NULL; int nrow = gen_2d_laplacian(ndim, &csr_ptr, &csr_col, &csr_val); int nnz = csr_ptr[nrow]; T* csr_val2 = NULL; if(rebuildnumeric) { csr_val2 = new T[nnz]; for(int i = 0; i < nnz; i++) { csr_val2[i] = csr_val[i]; } } A.SetDataPtrCSR(&csr_ptr, &csr_col, &csr_val, "A", nnz, nrow, nrow); assert(csr_ptr == NULL); assert(csr_col == NULL); assert(csr_val == NULL); // Move data to accelerator if(!disable_accelerator) { A.MoveToAccelerator(); x.MoveToAccelerator(); b.MoveToAccelerator(); b2.MoveToAccelerator(); e.MoveToAccelerator(); } // Allocate x, b and e x.Allocate("x", A.GetN()); b.Allocate("b", A.GetM()); b2.Allocate("b2", A.GetM()); e.Allocate("e", A.GetN()); // b = A * 1 e.Ones(); A.Apply(e, &b); // Random initial guess x.SetRandomUniform(12345ULL, -4.0, 6.0); // Solver CG, LocalVector, T> ls; // AMG PairwiseAMG, LocalVector, T> p; // Setup AMG p.SetOrdering(ordering); p.SetCoarsestLevel(300); p.SetCycle(Kcycle); p.SetOperator(A); p.SetManualSmoothers(true); p.SetManualSolver(true); p.BuildHierarchy(); // Get number of hierarchy levels int levels = p.GetNumLevels(); // Coarse grid solver CG, LocalVector, T> cgs; cgs.Verbose(0); // Smoother for each level IterativeLinearSolver, LocalVector, T>** sm = new IterativeLinearSolver, LocalVector, T>*[levels - 1]; Preconditioner, LocalVector, T>** smooth = new Preconditioner, LocalVector, T>*[levels - 1]; for(int i = 0; i < levels - 1; ++i) { FixedPoint, LocalVector, T>* fp = new FixedPoint, LocalVector, T>; sm[i] = fp; if(smoother == "Jacobi") { smooth[i] = new Jacobi, LocalVector, T>; fp->SetRelaxation(0.67); } else if(smoother == "MCGS") { smooth[i] = new MultiColoredGS, LocalVector, T>; fp->SetRelaxation(1.3); } else if(smoother == "MCILU") smooth[i] = new MultiColoredILU, LocalVector, T>; else return false; sm[i]->SetPreconditioner(*(smooth[i])); sm[i]->Verbose(0); } p.SetSmoother(sm); p.SetSolver(cgs); p.SetSmootherPreIter(pre_iter); p.SetSmootherPostIter(post_iter); p.SetOperatorFormat(format, (format == BCSR ? argus.blockdim : 1)); p.InitMaxIter(1); p.Verbose(0); ls.Verbose(0); ls.SetOperator(A); ls.SetPreconditioner(p); ls.Init(1e-8, 0.0, 1e+8, 10000); ls.Build(); if(rebuildnumeric) { A.UpdateValuesCSR(csr_val2); delete[] csr_val2; // b2 = A * 1 A.Apply(e, &b2); ls.ReBuildNumeric(); } // Matrix format A.ConvertTo(format, format == BCSR ? argus.blockdim : 1); ls.Solve(rebuildnumeric ? b2 : b, &x); // Verify solution x.ScaleAdd(-1.0, e); T nrm2 = x.Norm(); bool success = check_residual(nrm2); // Clean up ls.Clear(); // TODO // Stop rocALUTION platform stop_rocalution(); disable_accelerator_rocalution(false); for(int i = 0; i < levels - 1; ++i) { delete smooth[i]; delete sm[i]; } delete[] smooth; delete[] sm; return success; } template bool testing_pairwise_amg_2(Arguments argus) { int ndim = argus.size; int pre_iter = argus.pre_smooth; int post_iter = argus.post_smooth; std::string smoother = argus.smoother; unsigned int format = argus.format; unsigned int ordering = argus.ordering; bool rebuildnumeric = argus.rebuildnumeric; // Initialize rocALUTION platform set_device_rocalution(device); init_rocalution(); // rocALUTION structures LocalMatrix A; LocalVector x; LocalVector b; LocalVector b2; LocalVector e; // Generate A int* csr_ptr = NULL; int* csr_col = NULL; T* csr_val = NULL; int nrow = gen_2d_laplacian(ndim, &csr_ptr, &csr_col, &csr_val); int nnz = csr_ptr[nrow]; T* csr_val2 = NULL; if(rebuildnumeric) { csr_val2 = new T[nnz]; for(int i = 0; i < nnz; i++) { csr_val2[i] = csr_val[i]; } } A.SetDataPtrCSR(&csr_ptr, &csr_col, &csr_val, "A", nnz, nrow, nrow); assert(csr_ptr == NULL); assert(csr_col == NULL); assert(csr_val == NULL); // Move data to accelerator A.MoveToAccelerator(); x.MoveToAccelerator(); b.MoveToAccelerator(); b2.MoveToAccelerator(); e.MoveToAccelerator(); // Allocate x, b and e x.Allocate("x", A.GetN()); b.Allocate("b", A.GetM()); b2.Allocate("b2", A.GetM()); e.Allocate("e", A.GetN()); // b = A * 1 e.Ones(); A.Apply(e, &b); // Random initial guess x.SetRandomUniform(12345ULL, -4.0, 6.0); // Solver CG, LocalVector, T> ls; // AMG PairwiseAMG, LocalVector, T> p; // Setup AMG p.SetOrdering(ordering); p.SetCoarsestLevel(300); p.SetCycle(Kcycle); p.SetOperator(A); p.SetManualSmoothers(false); p.SetManualSolver(true); p.SetBeta(0.5); p.SetCoarseningFactor(1.0); p.BuildHierarchy(); // Get number of hierarchy levels int levels = p.GetNumLevels(); // Coarse grid solver CG, LocalVector, T> cgs; cgs.Verbose(0); // Smoother for each level IterativeLinearSolver, LocalVector, T>** sm = new IterativeLinearSolver, LocalVector, T>*[levels - 1]; Preconditioner, LocalVector, T>** smooth = new Preconditioner, LocalVector, T>*[levels - 1]; for(int i = 0; i < levels - 1; ++i) { FixedPoint, LocalVector, T>* fp = new FixedPoint, LocalVector, T>; sm[i] = fp; if(smoother == "Jacobi") { smooth[i] = new Jacobi, LocalVector, T>; fp->SetRelaxation(0.67); } else if(smoother == "MCGS") { smooth[i] = new MultiColoredGS, LocalVector, T>; fp->SetRelaxation(1.3); } else if(smoother == "MCILU") smooth[i] = new MultiColoredILU, LocalVector, T>; else return false; sm[i]->SetPreconditioner(*(smooth[i])); sm[i]->Verbose(0); } p.SetSmoother(sm); p.SetSolver(cgs); p.SetSmootherPreIter(pre_iter); p.SetSmootherPostIter(post_iter); p.SetOperatorFormat(format, (format == BCSR ? argus.blockdim : 1)); p.InitMaxIter(1); p.Verbose(0); ls.Verbose(0); ls.SetOperator(A); ls.SetPreconditioner(p); ls.Init(1e-8, 0.0, 1e+8, 10000); ls.Build(); if(rebuildnumeric) { A.UpdateValuesCSR(csr_val2); delete[] csr_val2; // b2 = A * 1 A.Apply(e, &b2); ls.ReBuildNumeric(); } // Matrix format A.ConvertTo(format, format == BCSR ? argus.blockdim : 1); ls.Solve(rebuildnumeric ? b2 : b, &x); // Verify solution x.ScaleAdd(-1.0, e); T nrm2 = x.Norm(); bool success = check_residual(nrm2); // Clean up ls.Clear(); // TODO // Stop rocALUTION platform stop_rocalution(); for(int i = 0; i < levels - 1; ++i) { delete smooth[i]; delete sm[i]; } delete[] smooth; delete[] sm; return success; } template bool testing_pairwise_amg_3(Arguments argus) { // Initialize rocALUTION init_rocalution(); // Print rocALUTION info info_rocalution(); // rocALUTION objects LocalVector x; LocalVector rhs; LocalVector e; LocalMatrix mat; int ndim = argus.size; // Generate A int* csr_ptr = NULL; int* csr_col = NULL; T* csr_val = NULL; int nrow = gen_2d_laplacian(ndim, &csr_ptr, &csr_col, &csr_val); int nnz = csr_ptr[nrow]; T* csr_val2 = NULL; mat.SetDataPtrCSR(&csr_ptr, &csr_col, &csr_val, "A", nnz, nrow, nrow); // Move objects to accelerator mat.MoveToAccelerator(); x.MoveToAccelerator(); rhs.MoveToAccelerator(); e.MoveToAccelerator(); // Allocate vectors x.Allocate("x", mat.GetN()); rhs.Allocate("rhs", mat.GetM()); e.Allocate("e", mat.GetN()); // Initialize rhs such that A 1 = rhs e.Ones(); mat.Apply(e, &rhs); // Initial zero guess x.Zeros(); // Linear Solver CG, LocalVector, T> ls; // AMG Preconditioner SAAMG, LocalVector, T> p; // Disable verbosity output of AMG preconditioner p.Verbose(0); // Set solver preconditioner ls.SetPreconditioner(p); // Set solver operator ls.SetOperator(mat); // Build solver ls.Build(); // Compute 2 coarsest levels on the host p.SetHostLevels(2); // Print matrix info mat.Info(); // Initialize solver tolerances ls.Init(1e-8, 1e-8, 1e+8, 10000); // Set verbosity output ls.Verbose(1); // Solve A x = rhs ls.Solve(rhs, &x); // Clear solver ls.Clear(); // Compute error L2 norm e.ScaleAdd(-1.0, x); T error = e.Norm(); std::cout << "||e - x||_2 = " << error << std::endl; // Stop rocALUTION platform ls.Clear(); stop_rocalution(); return true; } #endif // TESTING_PAIRWISE_AMG_HPP rocALUTION-rocm-7.1.0/clients/include/testing_parallel_manager.hpp000066400000000000000000000055401507377332500251340ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2018-2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_PARALLEL_MANAGER_HPP #define TESTING_PARALLEL_MANAGER_HPP #include "utility.hpp" #include #include using namespace rocalution; template void testing_parallel_manager_bad_args(void) { int safe_size = 100; // Initialize rocALUTION set_device_rocalution(device); init_rocalution(); ParallelManager pm; int* idata = nullptr; allocate_host(safe_size, &idata); // SetMPICommunicator { void* null_ptr = nullptr; ASSERT_DEATH(pm.SetMPICommunicator(null_ptr), ".*Assertion.*comm != (NULL|__null)*"); } // SetBoundaryIndex { int* null_int = nullptr; ASSERT_DEATH(pm.SetBoundaryIndex(safe_size, null_int), ".*Assertion.*index != (NULL|__null)*"); } // SetReceivers { int* null_int = nullptr; ASSERT_DEATH(pm.SetReceivers(safe_size, null_int, idata), ".*Assertion.*recvs != (NULL|__null)*"); ASSERT_DEATH(pm.SetReceivers(safe_size, idata, null_int), ".*Assertion.*recv_offset != (NULL|__null)*"); } // SetSenders { int* null_int = nullptr; ASSERT_DEATH(pm.SetSenders(safe_size, null_int, idata), ".*Assertion.*sends != (NULL|__null)*"); ASSERT_DEATH(pm.SetSenders(safe_size, idata, null_int), ".*Assertion.*send_offset != (NULL|__null)*"); } free_host(&idata); // Stop rocALUTION stop_rocalution(); } #endif // TESTING_PARALLEL_MANAGER_HPP rocALUTION-rocm-7.1.0/clients/include/testing_preconditioner.hpp000066400000000000000000000275771507377332500247100ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 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 "utility.hpp" #include #include using namespace rocalution; template void getTestMatrix(Arguments argus, LocalMatrix& matrix) { int size = argus.size; std::string matrix_type = argus.matrix_type; // Generate A int* csr_ptr = NULL; int* csr_col = NULL; T* csr_val = NULL; int nrow = gen_2d_laplacian(size, &csr_ptr, &csr_col, &csr_val); int ncol = nrow; int nnz = csr_ptr[nrow]; matrix.SetDataPtrCSR(&csr_ptr, &csr_col, &csr_val, "TestMatrix", nnz, nrow, ncol); } template void testing_preconditioner_all(Arguments argus) { std::string precond = argus.precond; LocalMatrix matrix; getTestMatrix(argus, matrix); GMRES, LocalVector, T> ls; std::cout << "Testing preconditioner: " << precond << std::endl; std::cout << "Matrix size: " << matrix.GetM() << " x " << matrix.GetN() << std::endl; Preconditioner, LocalVector, T>* p; MultiColoredILU, LocalVector, T>* mcilu_p = NULL; Solver, LocalVector, T>** vp = NULL; ls.Verbose(0); ls.SetOperator(matrix); if(precond == "Jacobi") { p = new Jacobi, LocalVector, T>; } else if(precond == "GS") { p = new GS, LocalVector, T>; } else if(precond == "SGS") { p = new SGS, LocalVector, T>; } else if(precond == "ILU") { p = new ILU, LocalVector, T>; static_cast, LocalVector, T>*>(p)->Set(0, true); } else if(precond == "ItILU0") { p = new ItILU0, LocalVector, T>; static_cast, LocalVector, T>*>(p)->SetAlgorithm( ItILU0Algorithm::Default); static_cast, LocalVector, T>*>(p)->SetOptions( ItILU0Option::Verbose); static_cast, LocalVector, T>*>(p)->SetMaxIter(10); static_cast, LocalVector, T>*>(p)->SetTolerance(1e-6); } else if(precond == "ILUT") { p = new ILUT, LocalVector, T>; static_cast, LocalVector, T>*>(p)->Set(1.); static_cast, LocalVector, T>*>(p)->Set(1., 10); } else if(precond == "IC") { p = new IC, LocalVector, T>; } else if(precond == "AIChebyshev") { p = new AIChebyshev, LocalVector, T>; T lambda_min; T lambda_max; matrix.Gershgorin(lambda_min, lambda_max); static_cast, LocalVector, T>*>(p)->Set( 3, lambda_max / 7.0, lambda_max); } else if(precond == "FSAI") { p = new FSAI, LocalVector, T>; static_cast, LocalVector, T>*>(p)->Set(2); static_cast, LocalVector, T>*>(p)->Set(matrix); static_cast, LocalVector, T>*>(p)->SetPrecondMatrixFormat(CSR); } else if(precond == "SPAI") { p = new SPAI, LocalVector, T>; static_cast, LocalVector, T>*>(p)->SetPrecondMatrixFormat(CSR); } else if(precond == "TNS") { p = new TNS, LocalVector, T>; static_cast, LocalVector, T>*>(p)->Set(true); static_cast, LocalVector, T>*>(p)->SetPrecondMatrixFormat(CSR); } else if(precond == "AS") { p = new AS, LocalVector, T>; // Second level preconditioners Solver, LocalVector, T>** p2; int n = 2; p2 = new Solver, LocalVector, T>*[n]; for(int i = 0; i < n; ++i) { MultiColoredILU, LocalVector, T>* mc; mc = new MultiColoredILU, LocalVector, T>; p2[i] = mc; } // Initialize preconditioner static_cast, LocalVector, T>*>(p)->Set(n, 4, p2); } else if(precond == "RAS") { p = new RAS, LocalVector, T>; // Second level preconditioners Solver, LocalVector, T>** p2; int n = 2; p2 = new Solver, LocalVector, T>*[n]; for(int i = 0; i < n; ++i) { MultiColoredILU, LocalVector, T>* mc; mc = new MultiColoredILU, LocalVector, T>; p2[i] = mc; } // Initialize preconditioner static_cast, LocalVector, T>*>(p)->Set(n, 4, p2); } else if(precond == "MultiColoredSGS") { p = new MultiColoredSGS, LocalVector, T>; static_cast, LocalVector, T>*>(p)->SetRelaxation(0.9); static_cast, LocalVector, T>*>(p)->SetPrecondMatrixFormat( CSR); } else if(precond == "MultiColoredGS") { p = new MultiColoredGS, LocalVector, T>; static_cast, LocalVector, T>*>(p)->SetRelaxation(0.9); static_cast, LocalVector, T>*>(p)->SetPrecondMatrixFormat( CSR); } else if(precond == "MultiColoredILU") { p = new MultiColoredILU, LocalVector, T>; static_cast, LocalVector, T>*>(p)->Set(0); static_cast, LocalVector, T>*>(p)->Set(0, 1, true); static_cast, LocalVector, T>*>(p)->SetPrecondMatrixFormat( CSR); } else if(precond == "MultiElimination") { p = new MultiElimination, LocalVector, T>; mcilu_p = new MultiColoredILU, LocalVector, T>; mcilu_p->Set(0); static_cast, LocalVector, T>*>(p)->Set(*mcilu_p, 2, 0.4); } else if(precond == "VariablePreconditioner") { p = new VariablePreconditioner, LocalVector, T>; vp = new Solver, LocalVector, T>*[3]; // Preconditioners vp[0] = new MultiColoredSGS, LocalVector, T>; vp[1] = new MultiColoredILU, LocalVector, T>; vp[2] = new ILU, LocalVector, T>; // Set variable preconditioners static_cast, LocalVector, T>*>(p) ->SetPreconditioner(3, vp); } else { std::cerr << "Unknown preconditioner: " << precond << std::endl; exit(1); } ls.SetPreconditioner(*p); ls.Init(1e-6, 0.0, 1e+8, 10000); ls.Build(); if(precond == "Jacobi") { p->Build(); // trigger a clear of the preconditioner followed by a build p->ResetOperator(matrix); } else if(precond == "GS") { p->Build(); // trigger a clear of the preconditioner followed by a build p->ResetOperator(matrix); } else if(precond == "SGS") { p->Build(); // trigger a clear of the preconditioner followed by a build p->ResetOperator(matrix); } else if(precond == "ILU") { p->Build(); // trigger a clear of the preconditioner followed by a build p->ResetOperator(matrix); } else if(precond == "ItILU0") { p->Build(); // trigger a clear of the preconditioner followed by a build p->ResetOperator(matrix); } else if(precond == "ILUT") { p->Build(); // trigger a clear of the preconditioner followed by a build p->ResetOperator(matrix); } else if(precond == "IC") { p->Build(); // trigger a clear of the preconditioner followed by a build p->ResetOperator(matrix); } else if(precond == "AIChebyshev") { p->Build(); // trigger a clear of the preconditioner followed by a build p->ResetOperator(matrix); } else if(precond == "FSAI") { p->Build(); // trigger a clear of the preconditioner followed by a build p->ResetOperator(matrix); } else if(precond == "SPAI") { p->Build(); // trigger a clear of the preconditioner followed by a build p->ResetOperator(matrix); } else if(precond == "TNS") { p->Build(); // trigger a clear of the preconditioner followed by a build p->ResetOperator(matrix); } else if(precond == "AS") { p->ResetOperator(matrix); } else if(precond == "RAS") { p->ResetOperator(matrix); } else if(precond == "MultiColoredSGS") { p->ResetOperator(matrix); p->ReBuildNumeric(); } else if(precond == "MultiColoredGS") { p->ResetOperator(matrix); p->ReBuildNumeric(); } else if(precond == "MultiColoredILU") { p->ResetOperator(matrix); p->ReBuildNumeric(); } else if(precond == "MultiElimination") { p->ResetOperator(matrix); } p->Print(); // Test the preconditioner LocalVector x_acc, x_host, b, e; x_acc.Allocate("x", matrix.GetM()); x_host.Allocate("x", matrix.GetM()); b.Allocate("b", matrix.GetM()); e.Allocate("e", matrix.GetM()); ls.MoveToAccelerator(); matrix.MoveToAccelerator(); x_acc.MoveToAccelerator(); b.MoveToAccelerator(); e.MoveToAccelerator(); if(precond != "ILUT" && precond != "IC") { e.Ones(); matrix.Apply(e, &b); p->Solve(b, &x_acc); // Compute error L2 norm e.ScaleAdd(-1.0, x_acc); T error_acc = e.Norm(); std::cout << "error_acc =" << error_acc << std::endl; } ls.MoveToHost(); matrix.MoveToHost(); x_acc.MoveToHost(); e.MoveToHost(); b.MoveToHost(); e.Ones(); matrix.Apply(e, &b); p->Solve(b, &x_host); // Compute error L2 norm e.ScaleAdd(-1.0, x_host); T error_host = e.Norm(); std::cout << "error_host = " << error_host << std::endl; if(precond != "ILUT" && precond != "IC") { x_host.ScaleAdd(-1.0, x_acc); T diff = x_host.Norm(); std::cout << "diff = " << diff << std::endl; } ls.Clear(); delete p; if(mcilu_p != NULL) { delete mcilu_p; } if(vp != NULL) { delete[] vp; } } rocALUTION-rocm-7.1.0/clients/include/testing_qmrcgstab.hpp000066400000000000000000000123311507377332500236250ustar00rootroot00000000000000/* ************************************************************************ * 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_QMRCGSTAB_HPP #define TESTING_QMRCGSTAB_HPP #include "utility.hpp" #include using namespace rocalution; static bool check_residual(float res) { return (res < 1e-3f); } static bool check_residual(double res) { return (res < 1e-6); } template bool testing_qmrcgstab(Arguments argus) { int ndim = argus.size; std::string precond = argus.precond; unsigned int format = argus.format; bool disable_accelerator = !argus.use_acc; // Initialize rocALUTION platform disable_accelerator_rocalution(disable_accelerator); set_device_rocalution(device); init_rocalution(); // rocALUTION structures LocalMatrix A; LocalVector x; LocalVector b; LocalVector e; // Generate A int* csr_ptr = NULL; int* csr_col = NULL; T* csr_val = NULL; int nrow = gen_2d_laplacian(ndim, &csr_ptr, &csr_col, &csr_val); int nnz = csr_ptr[nrow]; A.SetDataPtrCSR(&csr_ptr, &csr_col, &csr_val, "A", nnz, nrow, nrow); // Move data to accelerator if(!disable_accelerator) { A.MoveToAccelerator(); x.MoveToAccelerator(); b.MoveToAccelerator(); e.MoveToAccelerator(); } // Allocate x, b and e x.Allocate("x", A.GetN()); b.Allocate("b", A.GetM()); e.Allocate("e", A.GetN()); // b = A * 1 e.Ones(); A.Apply(e, &b); // Random initial guess x.SetRandomUniform(12345ULL, -4.0, 6.0); // Solver QMRCGStab, LocalVector, T> ls; // Preconditioner Preconditioner, LocalVector, T>* p; if(precond == "None") p = NULL; else if(precond == "Chebyshev") { // Chebyshev preconditioner // Determine min and max eigenvalues T lambda_min; T lambda_max; A.Gershgorin(lambda_min, lambda_max); AIChebyshev, LocalVector, T>* cheb = new AIChebyshev, LocalVector, T>; cheb->Set(3, lambda_max / 7.0, lambda_max); p = cheb; } else if(precond == "FSAI") p = new FSAI, LocalVector, T>; else if(precond == "SPAI") p = new SPAI, LocalVector, T>; else if(precond == "TNS") p = new TNS, LocalVector, T>; else if(precond == "Jacobi") p = new Jacobi, LocalVector, T>; else if(precond == "GS") p = new GS, LocalVector, T>; else if(precond == "SGS") p = new SGS, LocalVector, T>; else if(precond == "ILU") p = new ILU, LocalVector, T>; else if(precond == "ItILU0") p = new ItILU0, LocalVector, T>; else if(precond == "ILUT") p = new ILUT, LocalVector, T>; else if(precond == "IC") p = new IC, LocalVector, T>; else if(precond == "MCGS") p = new MultiColoredGS, LocalVector, T>; else if(precond == "MCSGS") p = new MultiColoredSGS, LocalVector, T>; else if(precond == "MCILU") p = new MultiColoredILU, LocalVector, T>; else return false; ls.Verbose(0); ls.SetOperator(A); // Set preconditioner if(p != NULL) { ls.SetPreconditioner(*p); } ls.Init(1e-8, 0.0, 1e+8, 10000); ls.Build(); // Matrix format A.ConvertTo(format, format == BCSR ? argus.blockdim : 1); ls.Solve(b, &x); // Verify solution x.ScaleAdd(-1.0, e); T nrm2 = x.Norm(); bool success = check_residual(nrm2); // Clean up ls.Clear(); if(p != NULL) { delete p; } // Stop rocALUTION platform stop_rocalution(); disable_accelerator_rocalution(false); return success; } #endif // TESTING_QMRCGSTAB_HPP rocALUTION-rocm-7.1.0/clients/include/testing_qr.hpp000066400000000000000000000074601507377332500222730ustar00rootroot00000000000000/* ************************************************************************ * 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_QR_HPP #define TESTING_QR_HPP #include "utility.hpp" #include using namespace rocalution; static bool check_residual(float res) { return (res < 1e-3f); } static bool check_residual(double res) { return (res < 1e-6); } template bool testing_qr(Arguments argus) { int ndim = argus.size; unsigned int format = argus.format; std::string matrix_type = argus.matrix_type; const bool use_host_and_acc = argus.use_acc; // Initialize rocALUTION platform set_device_rocalution(device); init_rocalution(); // rocALUTION structures LocalMatrix A; LocalVector x; LocalVector b; LocalVector e; // Generate A int* csr_ptr = NULL; int* csr_col = NULL; T* csr_val = NULL; int nrow = 0; int ncol = 0; if(matrix_type == "Laplacian2D") { nrow = gen_2d_laplacian(ndim, &csr_ptr, &csr_col, &csr_val); ncol = nrow; } else if(matrix_type == "PermutedIdentity") { nrow = gen_permuted_identity(ndim, &csr_ptr, &csr_col, &csr_val); ncol = nrow; } else { return false; } int nnz = csr_ptr[nrow]; A.SetDataPtrCSR(&csr_ptr, &csr_col, &csr_val, "A", nnz, nrow, nrow); // Allocate x, b and e x.Allocate("x", A.GetN()); b.Allocate("b", A.GetM()); e.Allocate("e", A.GetN()); // b = A * 1 e.Ones(); A.Apply(e, &b); // Random initial guess x.SetRandomUniform(12345ULL, -4.0, 6.0); // Solver QR, LocalVector, T> dls; dls.Verbose(0); dls.SetOperator(A); dls.Build(); // Matrix format A.ConvertTo(format, format == BCSR ? argus.blockdim : 1); // Move data to accelerator dls.MoveToAccelerator(); A.MoveToAccelerator(); x.MoveToAccelerator(); b.MoveToAccelerator(); e.MoveToAccelerator(); dls.Solve(b, &x); // Verify solution x.ScaleAdd(-1.0, e); T nrm2_acc = x.Norm(); bool success = check_residual(nrm2_acc); if(use_host_and_acc) { dls.MoveToHost(); A.MoveToHost(); x.MoveToHost(); e.MoveToHost(); b.MoveToHost(); dls.Solve(b, &x); // Verify solution x.ScaleAdd(-1.0, e); T nrm2_host = x.Norm(); success = success && check_residual(nrm2_host); } // Clean up dls.Clear(); // Stop rocALUTION platform stop_rocalution(); return success; } #endif // TESTING_QR_HPP rocALUTION-rocm-7.1.0/clients/include/testing_ruge_stueben_amg.hpp000066400000000000000000000145641507377332500251670ustar00rootroot00000000000000/* ************************************************************************ * 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_RUGE_STUEBEN_AMG_HPP #define TESTING_RUGE_STUEBEN_AMG_HPP #include "utility.hpp" #include using namespace rocalution; static bool check_residual(float res) { return (res < 1e-2f); } static bool check_residual(double res) { return (res < 1e-5); } template bool testing_ruge_stueben_amg(Arguments argus) { int ndim = argus.size; int pre_iter = argus.pre_smooth; int post_iter = argus.post_smooth; std::string smoother = argus.smoother; unsigned int format = argus.format; int cycle = argus.cycle; bool scaling = argus.ordering; bool rebuildnumeric = argus.rebuildnumeric; bool disable_accelerator = !argus.use_acc; std::string coarsening_strategy = argus.coarsening_strategy; // Initialize rocALUTION platform disable_accelerator_rocalution(disable_accelerator); set_device_rocalution(device); init_rocalution(); // rocALUTION structures LocalMatrix A; LocalVector x; LocalVector b; LocalVector b2; LocalVector e; // Generate A int* csr_ptr = NULL; int* csr_col = NULL; T* csr_val = NULL; int nrow = gen_2d_laplacian(ndim, &csr_ptr, &csr_col, &csr_val); int nnz = csr_ptr[nrow]; T* csr_val2 = NULL; if(rebuildnumeric) { csr_val2 = new T[nnz]; for(int i = 0; i < nnz; i++) { csr_val2[i] = csr_val[i]; } } A.SetDataPtrCSR(&csr_ptr, &csr_col, &csr_val, "A", nnz, nrow, nrow); assert(csr_ptr == NULL); assert(csr_col == NULL); assert(csr_val == NULL); // Move data to accelerator if(!disable_accelerator) { A.MoveToAccelerator(); x.MoveToAccelerator(); b.MoveToAccelerator(); b2.MoveToAccelerator(); e.MoveToAccelerator(); } // Allocate x, b and e x.Allocate("x", A.GetN()); b.Allocate("b", A.GetM()); b2.Allocate("b2", A.GetM()); e.Allocate("e", A.GetN()); // b = A * 1 e.Ones(); A.Apply(e, &b); // Random initial guess x.SetRandomUniform(12345ULL, -4.0, 6.0); // Solver BiCGStab, LocalVector, T> ls; // AMG RugeStuebenAMG, LocalVector, T> p; // Setup AMG if(coarsening_strategy == "Greedy") { p.SetCoarseningStrategy(Greedy); p.SetInterpolationType(Direct); } else { p.SetCoarseningStrategy(PMIS); p.SetInterpolationType(ExtPI); } p.SetCoarsestLevel(300); p.SetCycle(cycle); p.SetOperator(A); p.SetManualSmoothers(true); p.SetManualSolver(true); p.SetStrengthThreshold(0.25f); p.SetInterpolationFF1Limit(false); p.SetScaling(scaling); p.BuildHierarchy(); // Get number of hierarchy levels int levels = p.GetNumLevels(); // Coarse grid solver BiCGStab, LocalVector, T> cgs; cgs.Verbose(0); // Smoother for each level IterativeLinearSolver, LocalVector, T>** sm = new IterativeLinearSolver, LocalVector, T>*[levels - 1]; Preconditioner, LocalVector, T>** smooth = new Preconditioner, LocalVector, T>*[levels - 1]; for(int i = 0; i < levels - 1; ++i) { FixedPoint, LocalVector, T>* fp = new FixedPoint, LocalVector, T>; sm[i] = fp; if(smoother == "Jacobi") { smooth[i] = new Jacobi, LocalVector, T>; fp->SetRelaxation(0.67); } else if(smoother == "MCGS") { smooth[i] = new MultiColoredGS, LocalVector, T>; fp->SetRelaxation(1.3); } else return false; sm[i]->SetPreconditioner(*(smooth[i])); sm[i]->Verbose(0); } p.SetSmoother(sm); p.SetSolver(cgs); p.SetSmootherPreIter(pre_iter); p.SetSmootherPostIter(post_iter); p.SetOperatorFormat(format, format == BCSR ? argus.blockdim : 1); p.InitMaxIter(1); p.Verbose(0); ls.Verbose(0); ls.SetOperator(A); ls.SetPreconditioner(p); ls.Init(1e-8, 0.0, 1e+8, 10000); ls.Build(); if(rebuildnumeric) { A.UpdateValuesCSR(csr_val2); delete[] csr_val2; // b2 = A * 1 A.Apply(e, &b2); ls.ReBuildNumeric(); } // Matrix format A.ConvertTo(format, format == BCSR ? argus.blockdim : 1); ls.Solve(rebuildnumeric ? b2 : b, &x); // Verify solution x.ScaleAdd(-1.0, e); T nrm2 = x.Norm(); bool success = check_residual(nrm2); // Clean up ls.Clear(); // TODO // Stop rocALUTION platform stop_rocalution(); disable_accelerator_rocalution(false); for(int i = 0; i < levels - 1; ++i) { delete smooth[i]; delete sm[i]; } delete[] smooth; delete[] sm; return success; } #endif // TESTING_RUGE_STUEBEN_AMG_HPP rocALUTION-rocm-7.1.0/clients/include/testing_saamg.hpp000066400000000000000000000151011507377332500227300ustar00rootroot00000000000000/* ************************************************************************ * 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_SAAMG_HPP #define TESTING_SAAMG_HPP #include "utility.hpp" #include using namespace rocalution; static bool check_residual(float res) { return (res < 1e-2f); } static bool check_residual(double res) { return (res < 1e-5); } template bool testing_saamg(Arguments argus) { int ndim = argus.size; int pre_iter = argus.pre_smooth; int post_iter = argus.post_smooth; std::string smoother = argus.smoother; std::string coarsening_strategy = argus.coarsening_strategy; std::string matrix_type = argus.matrix_type; unsigned int format = argus.format; int cycle = argus.cycle; bool scaling = argus.ordering; bool rebuildnumeric = argus.rebuildnumeric; bool disable_accelerator = !argus.use_acc; // Initialize rocALUTION platform disable_accelerator_rocalution(disable_accelerator); set_device_rocalution(device); init_rocalution(); // rocALUTION structures LocalMatrix A; LocalVector x; LocalVector b; LocalVector b2; LocalVector e; // Generate A int* csr_ptr = NULL; int* csr_col = NULL; T* csr_val = NULL; int nrow = 0; if(matrix_type == "Laplacian2D") { nrow = gen_2d_laplacian(ndim, &csr_ptr, &csr_col, &csr_val); } else if(matrix_type == "Laplacian3D") { nrow = gen_3d_laplacian(ndim, &csr_ptr, &csr_col, &csr_val); } else { return false; } int nnz = csr_ptr[nrow]; T* csr_val2 = NULL; if(rebuildnumeric) { csr_val2 = new T[nnz]; for(int i = 0; i < nnz; i++) { csr_val2[i] = csr_val[i]; } } A.SetDataPtrCSR(&csr_ptr, &csr_col, &csr_val, "A", nnz, nrow, nrow); assert(csr_ptr == NULL); assert(csr_col == NULL); assert(csr_val == NULL); // Move data to accelerator if(!disable_accelerator) { A.MoveToAccelerator(); x.MoveToAccelerator(); b.MoveToAccelerator(); b2.MoveToAccelerator(); e.MoveToAccelerator(); } // Allocate x, b and e x.Allocate("x", A.GetN()); b.Allocate("b", A.GetM()); b2.Allocate("b2", A.GetM()); e.Allocate("e", A.GetN()); // b = A * 1 e.Ones(); A.Apply(e, &b); // Random initial guess x.SetRandomUniform(12345ULL, -4.0, 6.0); // Solver FCG, LocalVector, T> ls; // AMG SAAMG, LocalVector, T> p; // Setup SAAMG p.SetCoarsestLevel(10); p.SetCycle(cycle); p.SetOperator(A); p.SetManualSmoothers(true); p.SetManualSolver(true); p.SetScaling(scaling); if(coarsening_strategy == "Greedy") { p.SetCoarseningStrategy(CoarseningStrategy::Greedy); } else if(coarsening_strategy == "PMIS") { p.SetCoarseningStrategy(CoarseningStrategy::PMIS); } else { return false; } p.SetLumpingStrategy(LumpingStrategy::AddWeakConnections); p.SetCouplingStrength(0.001); p.SetInterpRelax(2.0 / 3.0); p.BuildHierarchy(); // Get number of hierarchy levels int levels = p.GetNumLevels(); // Coarse grid solver FCG, LocalVector, T> cgs; cgs.Verbose(0); // Smoother for each level IterativeLinearSolver, LocalVector, T>** sm = new IterativeLinearSolver, LocalVector, T>*[levels - 1]; Preconditioner, LocalVector, T>** smooth = new Preconditioner, LocalVector, T>*[levels - 1]; for(int i = 0; i < levels - 1; ++i) { sm[i] = new FixedPoint, LocalVector, T>; if(smoother == "FSAI") smooth[i] = new FSAI, LocalVector, T>; else if(smoother == "SPAI") smooth[i] = new SPAI, LocalVector, T>; else return false; sm[i]->SetPreconditioner(*(smooth[i])); sm[i]->Verbose(0); } p.SetSmoother(sm); p.SetSolver(cgs); p.SetSmootherPreIter(pre_iter); p.SetSmootherPostIter(post_iter); p.SetOperatorFormat(format, format == BCSR ? argus.blockdim : 1); p.InitMaxIter(1); p.Verbose(0); ls.Verbose(0); ls.SetOperator(A); ls.SetPreconditioner(p); ls.Init(1e-8, 0.0, 1e+8, 10000); ls.Build(); if(rebuildnumeric) { A.UpdateValuesCSR(csr_val2); delete[] csr_val2; // b2 = A * 1 A.Apply(e, &b2); ls.ReBuildNumeric(); } // Matrix format A.ConvertTo(format, format == BCSR ? argus.blockdim : 1); ls.Solve(rebuildnumeric ? b2 : b, &x); // Verify solution x.ScaleAdd(-1.0, e); T nrm2 = x.Norm(); bool success = check_residual(nrm2); // Clean up ls.Clear(); // TODO // Stop rocALUTION platform stop_rocalution(); disable_accelerator_rocalution(false); for(int i = 0; i < levels - 1; ++i) { delete smooth[i]; delete sm[i]; } delete[] smooth; delete[] sm; if(!success) { std::cout << "nrm2: " << nrm2 << std::endl; } return success; } #endif // TESTING_SAAMG_HPP rocALUTION-rocm-7.1.0/clients/include/testing_uaamg.hpp000066400000000000000000000146461507377332500227470ustar00rootroot00000000000000/* ************************************************************************ * 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_UAAMG_HPP #define TESTING_UAAMG_HPP #include "utility.hpp" #include using namespace rocalution; static bool check_residual(float res) { return (res < 2e-2f); } static bool check_residual(double res) { return (res < 1e-5); } template bool testing_uaamg(Arguments argus) { int ndim = argus.size; int pre_iter = argus.pre_smooth; int post_iter = argus.post_smooth; std::string smoother = argus.smoother; std::string coarsening_strategy = argus.coarsening_strategy; std::string matrix_type = argus.matrix_type; unsigned int format = argus.format; int cycle = argus.cycle; bool scaling = argus.ordering; bool rebuildnumeric = argus.rebuildnumeric; bool disable_accelerator = !argus.use_acc; // Initialize rocALUTION platform disable_accelerator_rocalution(disable_accelerator); set_device_rocalution(device); init_rocalution(); // rocALUTION structures LocalMatrix A; LocalVector x; LocalVector b; LocalVector b2; LocalVector e; // Generate A int* csr_ptr = NULL; int* csr_col = NULL; T* csr_val = NULL; int nrow = 0; if(matrix_type == "Laplacian2D") { nrow = gen_2d_laplacian(ndim, &csr_ptr, &csr_col, &csr_val); } else if(matrix_type == "Laplacian3D") { nrow = gen_3d_laplacian(ndim, &csr_ptr, &csr_col, &csr_val); } else { return false; } int nnz = csr_ptr[nrow]; T* csr_val2 = NULL; if(rebuildnumeric) { csr_val2 = new T[nnz]; for(int i = 0; i < nnz; i++) { csr_val2[i] = csr_val[i]; } } A.SetDataPtrCSR(&csr_ptr, &csr_col, &csr_val, "A", nnz, nrow, nrow); assert(csr_ptr == NULL); assert(csr_col == NULL); assert(csr_val == NULL); // Move data to accelerator if(!disable_accelerator) { A.MoveToAccelerator(); x.MoveToAccelerator(); b.MoveToAccelerator(); b2.MoveToAccelerator(); e.MoveToAccelerator(); } // Allocate x, b and e x.Allocate("x", A.GetN()); b.Allocate("b", A.GetM()); b2.Allocate("b2", A.GetM()); e.Allocate("e", A.GetN()); // b = A * 1 e.Ones(); A.Apply(e, &b); // Random initial guess x.SetRandomUniform(12345ULL, -4.0, 6.0); // Solver FCG, LocalVector, T> ls; // AMG UAAMG, LocalVector, T> p; // Setup SAAMG p.SetCoarsestLevel(200); p.SetCycle(cycle); p.SetOperator(A); p.SetManualSmoothers(true); p.SetManualSolver(true); p.SetScaling(scaling); if(coarsening_strategy == "Greedy") { p.SetCoarseningStrategy(CoarseningStrategy::Greedy); } else if(coarsening_strategy == "PMIS") { p.SetCoarseningStrategy(CoarseningStrategy::PMIS); } else { return false; } p.SetCouplingStrength(0.005); p.SetOverInterp(1.2); p.BuildHierarchy(); // Get number of hierarchy levels int levels = p.GetNumLevels(); // Coarse grid solver FCG, LocalVector, T> cgs; cgs.Verbose(0); // Smoother for each level IterativeLinearSolver, LocalVector, T>** sm = new IterativeLinearSolver, LocalVector, T>*[levels - 1]; Preconditioner, LocalVector, T>** smooth = new Preconditioner, LocalVector, T>*[levels - 1]; for(int i = 0; i < levels - 1; ++i) { sm[i] = new FixedPoint, LocalVector, T>; if(smoother == "FSAI") smooth[i] = new FSAI, LocalVector, T>; else if(smoother == "ILU") smooth[i] = new ILU, LocalVector, T>; else return false; sm[i]->SetPreconditioner(*(smooth[i])); sm[i]->Verbose(0); } p.SetSmoother(sm); p.SetSolver(cgs); p.SetSmootherPreIter(pre_iter); p.SetSmootherPostIter(post_iter); p.SetOperatorFormat(format, format == BCSR ? argus.blockdim : 1); p.InitMaxIter(1); p.Verbose(0); ls.Verbose(0); ls.SetOperator(A); ls.SetPreconditioner(p); ls.Init(1e-8, 0.0, 1e+8, 10000); ls.Build(); if(rebuildnumeric) { A.UpdateValuesCSR(csr_val2); delete[] csr_val2; // b2 = A * 1 A.Apply(e, &b2); ls.ReBuildNumeric(); } // Matrix format A.ConvertTo(format, format == BCSR ? argus.blockdim : 1); ls.Solve(rebuildnumeric ? b2 : b, &x); // Verify solution x.ScaleAdd(-1.0, e); T nrm2 = x.Norm(); bool success = check_residual(nrm2); // Clean up ls.Clear(); // TODO // Stop rocALUTION platform stop_rocalution(); disable_accelerator_rocalution(false); for(int i = 0; i < levels - 1; ++i) { delete smooth[i]; delete sm[i]; } delete[] smooth; delete[] sm; return success; } #endif // TESTING_UAAMG_HPP rocALUTION-rocm-7.1.0/clients/include/utility.hpp000066400000000000000000000266511507377332500216220ustar00rootroot00000000000000/* ************************************************************************ * 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. * * ************************************************************************ */ #pragma once #ifndef TESTING_UTILITY_HPP #define TESTING_UTILITY_HPP #include #include #include "random.hpp" template static constexpr std::size_t countof(T (&)[N]) { return N; } #define rocalution_bench_errmsg std::cerr << "// rocalution_bench_error msg: " extern int device; /* ============================================================================================ */ /*! \brief Generate 2D laplacian on unit square in CSR format */ template int gen_2d_laplacian(int ndim, int** rowptr, int** col, T** val) { if(ndim == 0) { return 0; } int n = ndim * ndim; int nnz_mat = n * 5 - ndim * 4; *rowptr = new int[n + 1]; *col = new int[nnz_mat]; *val = new T[nnz_mat]; int nnz = 0; // Fill local arrays for(int i = 0; i < ndim; ++i) { for(int j = 0; j < ndim; ++j) { int idx = i * ndim + j; (*rowptr)[idx] = nnz; // if no upper boundary element, connect with upper neighbor if(i != 0) { (*col)[nnz] = idx - ndim; (*val)[nnz] = static_cast(-1); ++nnz; } // if no left boundary element, connect with left neighbor if(j != 0) { (*col)[nnz] = idx - 1; (*val)[nnz] = static_cast(-1); ++nnz; } // element itself (*col)[nnz] = idx; (*val)[nnz] = static_cast(4); ++nnz; // if no right boundary element, connect with right neighbor if(j != ndim - 1) { (*col)[nnz] = idx + 1; (*val)[nnz] = static_cast(-1); ++nnz; } // if no lower boundary element, connect with lower neighbor if(i != ndim - 1) { (*col)[nnz] = idx + ndim; (*val)[nnz] = static_cast(-1); ++nnz; } } } (*rowptr)[n] = nnz; return n; } /* ============================================================================================ */ /*! \brief Generate 3D laplacian on unit square in CSR format */ template int gen_3d_laplacian(int ndim, int** row_ptr, int** col_ind, T** val) { // Do nothing if(ndim == 0) { return 0; } int n = ndim * ndim * ndim; // Approximate 27pt stencil int nnz_mat = 27 * n; *row_ptr = new int[n + 1]; *col_ind = new int[nnz_mat]; *val = new T[nnz_mat]; int nnz = 0; (*row_ptr)[0] = 0; // Fill local arrays #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int32_t iz = 0; iz < ndim; ++iz) { for(int32_t iy = 0; iy < ndim; ++iy) { for(int32_t ix = 0; ix < ndim; ++ix) { int row = iz * ndim * ndim + iy * ndim + ix; for(int32_t sz = -1; sz <= 1; ++sz) { if(iz + sz > -1 && iz + sz < ndim) { for(int32_t sy = -1; sy <= 1; ++sy) { if(iy + sy > -1 && iy + sy < ndim) { for(int32_t sx = -1; sx <= 1; ++sx) { if(ix + sx > -1 && ix + sx < ndim) { int col = row + sz * ndim * ndim + sy * ndim + sx; (*col_ind)[nnz - 0] = col + 0; (*val)[nnz - 0] = (col == row) ? 26.0 : -1.0; ++nnz; } } } } } } (*row_ptr)[row + 1] = nnz; } } } // Adjust nnz by index base nnz -= 0; return n; } /* ============================================================================================ */ /*! \brief Generate full rank identity matrix where the row order has been permuted */ template int gen_permuted_identity(int ndim, int** rowptr, int** col, T** val) { if(ndim == 0) { return 0; } int n = ndim * ndim; int nnz_mat = n; *rowptr = new int[n + 1]; *col = new int[nnz_mat]; *val = new T[nnz_mat]; for(int i = 0; i < n + 1; i++) { (*rowptr)[i] = i; } srand(12345ULL); int r = (int)(static_cast(rand()) / RAND_MAX * (n - 0)); for(int i = 0; i < n; i++) { int index = r + i; if(r + i >= n) { index = r + i - n; } (*col)[i] = index; (*val)[i] = static_cast(1); } return n; } /* ============================================================================================ */ /*! \brief Generate random sparse matrix */ template int gen_random(int m, int n, int max_nnz_per_row, int** rowptr, int** col, T** val) { if(m == 0 || n == 0) { return 0; } int nnz = 0; int* nnz_per_row = new int[m]; for(int i = 0; i < m; i++) { nnz_per_row[i] = random_generator_exact(0, max_nnz_per_row); nnz += nnz_per_row[i]; } *rowptr = new int[m + 1]; *col = new int[nnz]; *val = new T[nnz]; (*rowptr)[0] = 0; for(int i = 1; i < m + 1; i++) { (*rowptr)[i] = (*rowptr)[i - 1] + nnz_per_row[i - 1]; } std::vector candidates(n); for(int i = 0; i < n; ++i) { candidates[i] = i; } std::random_shuffle(candidates.begin(), candidates.end()); for(int i = 0; i < m; i++) { int row_start = (*rowptr)[i]; int row_end = (*rowptr)[i + 1]; // Randomly select candidate entry point int idx = random_generator(0, n - row_end + row_start); for(int j = row_start; j < row_end; j++) { (*col)[j] = candidates[idx++]; (*val)[j] = random_generator(); } } for(int i = 0; i < m; ++i) { std::sort(&(*col)[(*rowptr)[i]], &(*col)[(*rowptr)[i + 1]]); } delete[] nnz_per_row; return m; } /* ============================================================================================ */ /*! \brief Check for environment variable to be set */ static bool is_env_var_set(const char* var, const std::string& value = "1") { const char* env_var = std::getenv(var); if(env_var && env_var == value) { return true; } return false; } /* ============================================================================================ */ /*! \brief Check for environment variables to be set */ static bool is_any_env_var_set(const std::initializer_list& vars, const std::string& value = "1") { for(const char* var : vars) { if(is_env_var_set(var, value)) { return true; } } return false; } /* ============================================================================================ */ /*! \brief Get temporary directory */ static std::string get_temp_dir() { #ifdef _WIN32 const char* temp = std::getenv("TEMP"); if(!temp) temp = std::getenv("TMP"); return temp ? std::string(temp) + "\\" : ".\\"; #else const char* temp = std::getenv("TMPDIR"); return temp ? std::string(temp) + "/" : "/tmp/"; #endif } /* ============================================================================================ */ /*! \brief Class used to parse command arguments in both client & gtest */ // has to compile with option "-std=c++11", and this rocsparse library uses c++11 everywhere // c++11 allows intilization of member of a struct class Arguments { public: // MPI variables int rank = 0; int dev_per_node = 1; // OpenMP variables int omp_nthreads = 8; int omp_affinity = true; int omp_threshold = 50000; // Accelerator variables int dev = 0; int use_acc = true; // Structure variables int size = 100; int index = 50; int chunk_size = 20; int blockdim = 4; // Computation variables double alpha = 1.0; double beta = 0.0; double gamma = 0.0; // Solver variables std::string solver = ""; std::string precond = ""; std::string smoother = ""; std::string matrix = ""; std::string coarsening_strategy = ""; std::string matrix_type = ""; int pre_smooth = 2; int post_smooth = 2; int ordering = 1; int cycle = 0; int rebuildnumeric = 0; unsigned int format; bool unit_diag = false; Arguments& operator=(const Arguments& rhs) { this->rank = rhs.rank; this->dev_per_node = rhs.dev_per_node; this->omp_nthreads = rhs.omp_nthreads; this->omp_affinity = rhs.omp_affinity; this->omp_threshold = rhs.omp_threshold; this->dev = rhs.dev; this->use_acc = rhs.use_acc; this->size = rhs.size; this->index = rhs.index; this->chunk_size = rhs.chunk_size; this->blockdim = rhs.blockdim; this->alpha = rhs.alpha; this->beta = rhs.beta; this->gamma = rhs.gamma; this->solver = rhs.solver; this->precond = rhs.precond; this->smoother = rhs.smoother; this->matrix = rhs.matrix; this->matrix_type = rhs.matrix_type; this->pre_smooth = rhs.pre_smooth; this->post_smooth = rhs.post_smooth; this->ordering = rhs.ordering; this->cycle = rhs.cycle; this->rebuildnumeric = rhs.rebuildnumeric; this->coarsening_strategy = rhs.coarsening_strategy; this->format = rhs.format; this->unit_diag = rhs.unit_diag; return *this; } }; #endif // TESTING_UTILITY_HPP rocALUTION-rocm-7.1.0/clients/include/validate.hpp000066400000000000000000000064021507377332500217000ustar00rootroot00000000000000/* ************************************************************************ * 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 #include bool valid_permutation(int m, const int* permutation) { std::vector check(m, 0); for(int i = 0; i < m; i++) { const int val = permutation[i]; if(val < 0 || val >= m) { // value is out of bounds return false; } if(check[val] > 0) { // duplicate value return false; } check[val]++; } return true; } bool valid_coloring(int m, const int* csr_ptr, const int* csr_ind, int num_colors, const int* size_colors, const int* permutation) { /* * Create Inverse Permutation */ std::vector p_inverse(m); for(int i = 0; i < m; i++) { p_inverse[permutation[i]] = i; } std::vector mark(m, 0); int perm_in = 0; for(int i = 0; i < num_colors; i++) { // mark nodes in the color group for(int j = perm_in; j < perm_in + size_colors[i]; j++) { const int check_node = p_inverse[j]; mark[check_node] = 1; } // check the node's adjacent nodes for(int j = perm_in; j < perm_in + size_colors[i]; j++) { const int parent_node = p_inverse[j]; for(int k = csr_ptr[parent_node]; k < csr_ptr[parent_node + 1]; k++) { const int adj_node = csr_ind[k]; // invalid coloring if adjacent node is in the same color if(mark[adj_node] != 0 && adj_node != parent_node) { return false; } } } // unmark nodes in the color group for(int j = perm_in; j < perm_in + size_colors[i]; j++) { const int check_node = p_inverse[j]; mark[check_node] = 0; } perm_in += size_colors[i]; } return true; } rocALUTION-rocm-7.1.0/clients/samples/000077500000000000000000000000001507377332500174155ustar00rootroot00000000000000rocALUTION-rocm-7.1.0/clients/samples/CMakeLists.txt000066400000000000000000000076141507377332500221650ustar00rootroot00000000000000# ######################################################################## # 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. # # ######################################################################## # Function to add rocalution examples function(add_rocalution_example EXAMPLE_SOURCE) get_filename_component(EXAMPLE_TARGET ${EXAMPLE_SOURCE} NAME_WE) add_executable(${EXAMPLE_TARGET} ${EXAMPLE_SOURCE} ${ROCALUTION_CLIENTS_COMMON}) # Include common client headers target_include_directories(${EXAMPLE_TARGET} PRIVATE $) # Link rocALUTION library target_link_libraries(${EXAMPLE_TARGET} PRIVATE roc::rocalution) if (BUILD_CODE_COVERAGE) target_link_libraries(${EXAMPLE_TARGET} PRIVATE -lgcov) endif() # Examples output directory if(NOT TARGET rocalution) set_target_properties(${EXAMPLE_TARGET} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/staging") else() set_target_properties(${EXAMPLE_TARGET} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/clients/staging") endif() endfunction() # Examples add_rocalution_example(amg.cpp) add_rocalution_example(sa-amg.cpp) add_rocalution_example(ua-amg.cpp) add_rocalution_example(as-precond.cpp) add_rocalution_example(async.cpp) add_rocalution_example(benchmark.cpp) add_rocalution_example(bicgstab.cpp) add_rocalution_example(block-precond.cpp) add_rocalution_example(cg-amg.cpp) add_rocalution_example(cg-rsamg.cpp) add_rocalution_example(cg-saamg.cpp) add_rocalution_example(cg.cpp) add_rocalution_example(cmk.cpp) if(BUILD_SUPPORT_COMPLEX) add_rocalution_example(complex.cpp) endif() add_rocalution_example(direct.cpp) add_rocalution_example(fcg.cpp) add_rocalution_example(fixed-point.cpp) add_rocalution_example(gmres.cpp) add_rocalution_example(fgmres.cpp) add_rocalution_example(idr.cpp) add_rocalution_example(key.cpp) add_rocalution_example(me-preconditioner.cpp) add_rocalution_example(mixed-precision.cpp) add_rocalution_example(power-method.cpp) add_rocalution_example(simple-spmv.cpp) add_rocalution_example(sp-precond.cpp) add_rocalution_example(stencil.cpp) add_rocalution_example(tns.cpp) add_rocalution_example(var-precond.cpp) add_rocalution_example(itsolve.cpp) # MPI examples if(SUPPORT_MPI) add_rocalution_example(benchmark_mpi.cpp) add_rocalution_example(bicgstab_mpi.cpp) add_rocalution_example(cg-amg_mpi.cpp) add_rocalution_example(cg-rsamg_mpi.cpp) add_rocalution_example(cg_mpi.cpp) add_rocalution_example(cg-saamg_mpi.cpp) add_rocalution_example(cg-uaamg_mpi.cpp) add_rocalution_example(fcg_mpi.cpp) add_rocalution_example(fgmres_mpi.cpp) add_rocalution_example(global-io_mpi.cpp) add_rocalution_example(idr_mpi.cpp) add_rocalution_example(qmrcgstab_mpi.cpp) add_rocalution_example(laplace_2d_weak_scaling.cpp) add_rocalution_example(laplace_3d_weak_scaling.cpp) endif() rocALUTION-rocm-7.1.0/clients/samples/amg.cpp000066400000000000000000000134441507377332500206730ustar00rootroot00000000000000/* ************************************************************************ * 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 #include #include using namespace rocalution; int main(int argc, char* argv[]) { // Time measurement double tick, tack, start, end; // Check command line parameters if(argc == 1) { std::cerr << argv[0] << " [Num threads]" << std::endl; exit(1); } // Initialize rocALUTION init_rocalution(); // Check command line parameters for number of OMP threads if(argc > 2) { set_omp_threads_rocalution(atoi(argv[2])); } // Print rocALUTION info info_rocalution(); // rocALUTION objects LocalVector x; LocalVector rhs; LocalVector e; LocalMatrix mat; // Read matrix from MTX file mat.ReadFileMTX(std::string(argv[1])); // Allocate vectors x.Allocate("x", mat.GetN()); rhs.Allocate("rhs", mat.GetM()); e.Allocate("e", mat.GetN()); // Initialize rhs such that A 1 = rhs e.Ones(); mat.Apply(e, &rhs); // Initial zero guess x.Zeros(); // Start time measurement tick = rocalution_time(); start = rocalution_time(); // Linear Solver SAAMG, LocalVector, double> ls; // Set solver operator ls.SetOperator(mat); // Set coupling strength ls.SetCouplingStrength(0.001); // Set maximal number of unknowns on coarsest level ls.SetCoarsestLevel(300); // Set relaxation parameter for smoothed interpolation aggregation ls.SetInterpRelax(2. / 3.); // Set manual smoothers ls.SetManualSmoothers(true); // Set manual course grid solver ls.SetManualSolver(true); // Set grid transfer scaling ls.SetScaling(true); // Build AMG hierarchy ls.BuildHierarchy(); // Obtain number of AMG levels int levels = ls.GetNumLevels(); // Coarse Grid Solver CG, LocalVector, double> cgs; cgs.Verbose(0); // Smoother for each level IterativeLinearSolver, LocalVector, double>** sm = new IterativeLinearSolver, LocalVector, double>*[levels - 1]; MultiColoredGS, LocalVector, double>** gs = new MultiColoredGS, LocalVector, double>*[levels - 1]; // Coarse grid solver with preconditioner // MultiColoredILU, LocalVector, double > p; // cgs->SetPreconditioner(p); // Initialize smoother for each level for(int i = 0; i < levels - 1; ++i) { // Smooth with MultiColoredGS using Fixed-Point iteration scheme FixedPoint, LocalVector, double>* fp; fp = new FixedPoint, LocalVector, double>; fp->SetRelaxation(1.3); sm[i] = fp; gs[i] = new MultiColoredGS, LocalVector, double>; sm[i]->SetPreconditioner(*gs[i]); sm[i]->Verbose(0); } // Pass smoother and coarse grid solver to AMG ls.SetSmoother(sm); ls.SetSolver(cgs); // Set number of pre and post smoothing steps ls.SetSmootherPreIter(1); ls.SetSmootherPostIter(2); // Initialize solver tolerances ls.Init(1e-10, 1e-8, 1e+8, 10000); // Verbosity output ls.Verbose(2); // Build solver ls.Build(); // Move solver to the accelerator mat.MoveToAccelerator(); x.MoveToAccelerator(); rhs.MoveToAccelerator(); e.MoveToAccelerator(); ls.MoveToAccelerator(); // Print matrix info mat.Info(); // Stop building time measurement tack = rocalution_time(); std::cout << "Building took: " << (tack - tick) / 1e6 << " sec" << std::endl; // Start solving time measurement tick = rocalution_time(); // Solve A x = rhs ls.Solve(rhs, &x); // Stop solving time measurement tack = rocalution_time(); std::cout << "Solving took: " << (tack - tick) / 1e6 << " sec" << std::endl; // Clear the solver ls.Clear(); // Free all allocated data for(int i = 0; i < levels - 1; ++i) { delete gs[i]; delete sm[i]; } delete[] gs; delete[] sm; // End time measurement end = rocalution_time(); std::cout << "Total runtime: " << (end - start) / 1e6 << " sec" << std::endl; // Compute error L2 norm e.ScaleAdd(-1.0, x); double error = e.Norm(); std::cout << "||e - x||_2 = " << error << std::endl; // Stop rocALUTION platform stop_rocalution(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/as-precond.cpp000066400000000000000000000101621507377332500221540ustar00rootroot00000000000000/* ************************************************************************ * 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 #include #include using namespace rocalution; int main(int argc, char* argv[]) { // Check command line parameters if(argc == 1) { std::cerr << argv[0] << " [Num threads]" << std::endl; exit(1); } // Initialize rocALUTION init_rocalution(); // Check command line parameters for number of OMP threads if(argc > 2) { set_omp_threads_rocalution(atoi(argv[2])); } // Print rocALUTION info info_rocalution(); // rocALUTION objects LocalVector x; LocalVector rhs; LocalVector e; LocalMatrix mat; // Read matrix from MTX file mat.ReadFileMTX(std::string(argv[1])); // Allocate vectors x.Allocate("x", mat.GetN()); rhs.Allocate("rhs", mat.GetM()); e.Allocate("e", mat.GetN()); // Initialize rhs such that A 1 = rhs e.Ones(); mat.Apply(e, &rhs); // Initial zero guess x.Zeros(); // Linear Solver GMRES, LocalVector, double> ls; // Preconditioner AS, LocalVector, double> p; // Additive Schwarz // RAS, LocalVector, double > p; // Restricted Additive Schwarz // Second level preconditioners Solver, LocalVector, double>** p2; int n = 2; p2 = new Solver, LocalVector, double>*[n]; for(int i = 0; i < n; ++i) { MultiColoredILU, LocalVector, double>* mc; mc = new MultiColoredILU, LocalVector, double>; p2[i] = mc; } double tick, tack; // Initialize preconditioner p.Set(n, 4, p2); // Set solver operator ls.SetOperator(mat); // Set solver preconditioner ls.SetPreconditioner(p); // Verbosity output // ls.Verbose(2); // Build solver ls.Build(); // Move solver to the accelerator mat.MoveToAccelerator(); x.MoveToAccelerator(); rhs.MoveToAccelerator(); e.MoveToAccelerator(); ls.MoveToAccelerator(); // Print matrix info mat.Info(); // Start solving time measurement tick = rocalution_time(); // Solve A x = rhs ls.Solve(rhs, &x); // Stop solving time measurement tack = rocalution_time(); std::cout << "Solver took: " << (tack - tick) / 1e6 << " sec" << std::endl; // Clear the solver ls.Clear(); // Free all allocated data for(int i = 0; i < n; ++i) { delete p2[i]; p2[i] = NULL; } delete[] p2; p2 = NULL; // Compute error L2 norm e.ScaleAdd(-1.0, x); double error = e.Norm(); std::cout << "||e - x||_2 = " << error << std::endl; // Stop rocALUTION platform stop_rocalution(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/async.cpp000066400000000000000000000120551507377332500212410ustar00rootroot00000000000000/* ************************************************************************ * 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 #include #include using namespace rocalution; int main(int argc, char* argv[]) { // Check command line parameters if(argc == 1) { std::cerr << argv[0] << " [Num threads]" << std::endl; exit(1); } // Initialize rocALUTION init_rocalution(); // Check command line parameters for number of OMP threads if(argc > 2) { set_omp_threads_rocalution(atoi(argv[2])); } // Print rocALUTION info info_rocalution(); // rocALUTION objects LocalVector x; LocalVector y; LocalMatrix mat; double tick, tack; double tickg, tackg; // Read matrix from MTX file mat.ReadFileMTX(std::string(argv[1])); // Allocate vectors x.Allocate("x", mat.GetN()); y.Allocate("y", mat.GetM()); // Initialize x with 1 x.Ones(); // No Async tickg = rocalution_time(); // Initialize y with 0 y.Zeros(); // Print object info mat.Info(); x.Info(); y.Info(); // CPU tick = rocalution_time(); // y += mat * x for(int i = 0; i < 100; ++i) { mat.ApplyAdd(x, 1.0, &y); } tack = rocalution_time(); std::cout << "CPU execution took: " << (tack - tick) / 1e6 << " sec" << std::endl; std::cout << "Dot product = " << x.Dot(y) << std::endl; tick = rocalution_time(); // Memory transfer mat.MoveToAccelerator(); x.MoveToAccelerator(); y.MoveToAccelerator(); // Print object info mat.Info(); x.Info(); y.Info(); tack = rocalution_time(); std::cout << "Sync transfer took: " << (tack - tick) / 1e6 << " sec" << std::endl; // Initialize y with 0 y.Zeros(); // Accelerator tick = rocalution_time(); // y += mat * x for(int i = 0; i < 100; ++i) { mat.ApplyAdd(x, 1.0, &y); } tack = rocalution_time(); std::cout << "Accelerator execution took: " << (tack - tick) / 1e6 << " sec" << std::endl; std::cout << "Dot product = " << x.Dot(y) << std::endl; tackg = rocalution_time(); std::cout << "Total execution + transfers (no async) took: " << (tackg - tickg) / 1e6 << " sec" << std::endl; // Move data to host mat.MoveToHost(); x.MoveToHost(); y.MoveToHost(); // Initialize y with 0 y.Zeros(); // Async tickg = rocalution_time(); tick = rocalution_time(); // Memory transfer mat.MoveToAcceleratorAsync(); x.MoveToAcceleratorAsync(); // Print oject info mat.Info(); x.Info(); y.Info(); tack = rocalution_time(); std::cout << "Async transfer took: " << (tack - tick) / 1e6 << " sec" << std::endl; // CPU tick = rocalution_time(); // y += mat * x for(int i = 0; i < 100; ++i) { mat.ApplyAdd(x, 1.0, &y); } tack = rocalution_time(); std::cout << "CPU execution took: " << (tack - tick) / 1e6 << " sec" << std::endl; std::cout << "Dot product = " << x.Dot(y) << std::endl; // Synchronize objects mat.Sync(); x.Sync(); // Move y to host y.MoveToAccelerator(); // Print object info mat.Info(); x.Info(); y.Info(); // Initialize y with 0 y.Zeros(); // Accelerator tick = rocalution_time(); // y += mat * x for(int i = 0; i < 100; ++i) { mat.ApplyAdd(x, 1.0, &y); } tack = rocalution_time(); std::cout << "Accelerator execution took: " << (tack - tick) / 1e6 << " sec" << std::endl; std::cout << "Dot product = " << x.Dot(y) << std::endl; tackg = rocalution_time(); std::cout << "Total execution + transfers (async) took: " << (tackg - tickg) / 1e6 << " sec" << std::endl; // Stop rocALUTION platform stop_rocalution(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/benchmark.cpp000066400000000000000000000370151507377332500220610ustar00rootroot00000000000000/* ************************************************************************ * 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 #include #include using namespace rocalution; int main(int argc, char* argv[]) { // Check command line parameters if(argc == 1) { std::cerr << argv[0] << " [Num threads]" << std::endl; exit(1); } // Initialize rocALUTION init_rocalution(); // Check command line parameters for number of OMP threads if(argc > 2) { set_omp_threads_rocalution(atoi(argv[2])); } // Print rocALUTION info info_rocalution(); // rocALUTION objects LocalVector vec1; LocalVector vec2; LocalVector vec3; LocalMatrix mat; // Time measurement double tick, tack; // Number of tests const int max_tests = 200; // Read matrix from MTX file mat.ReadFileMTX(std::string(argv[1])); // Allocate vectors vec1.Allocate("x", mat.GetN()); vec2.Allocate("y", mat.GetM()); vec3.Allocate("z", mat.GetM()); int size = mat.GetM(); int nnz = mat.GetNnz(); // Initialize objects vec1.Ones(); vec2.Zeros(); vec3.Ones(); mat.Apply(vec1, &vec2); // Move objects to accelerator mat.MoveToAccelerator(); vec1.MoveToAccelerator(); vec2.MoveToAccelerator(); vec3.MoveToAccelerator(); // Print object info mat.Info(); vec1.Info(); vec2.Info(); vec3.Info(); std::cout << "----------------------------------------------------" << std::endl; std::cout << "Number of tests = " << max_tests << std::endl; std::cout << "----------------------------------------------------" << std::endl; std::cout << "Stand alone micro benchmarks" << std::endl; // Dot product // Size = 2*size // Flop = 2 per element vec3.Dot(vec2); _rocalution_sync(); tick = rocalution_time(); for(int i = 0; i < max_tests; ++i) { vec3.Dot(vec2); _rocalution_sync(); } _rocalution_sync(); tack = rocalution_time(); std::cout << "Dot execution: " << (tack - tick) / max_tests / 1e3 << " msec" << "; " << max_tests * double(sizeof(double) * (size + size)) / (tack - tick) / 1e3 << " Gbyte/sec; " << max_tests * double((2 * size)) / (tack - tick) / 1e3 << " GFlop/sec" << std::endl; // Reduce // Size = size // Flop = 1 per element vec3.Reduce(); _rocalution_sync(); tick = rocalution_time(); for(int i = 0; i < max_tests; ++i) { vec3.Reduce(); _rocalution_sync(); } _rocalution_sync(); tack = rocalution_time(); std::cout << "Reduce execution: " << (tack - tick) / max_tests / 1e3 << " msec" << "; " << max_tests * double(sizeof(double) * (size)) / (tack - tick) / 1e3 << " Gbyte/sec; " << max_tests * double((size - 1)) / (tack - tick) / 1e3 << " GFlop/sec" << std::endl; // Norm // Size = size // Flop = 2 per element vec3.Norm(); _rocalution_sync(); tick = rocalution_time(); for(int i = 0; i < max_tests; ++i) { vec3.Norm(); _rocalution_sync(); } _rocalution_sync(); tack = rocalution_time(); std::cout << "Norm execution: " << (tack - tick) / max_tests / 1e3 << " msec" << "; " << max_tests * double(sizeof(double) * (size)) / (tack - tick) / 1e3 << " Gbyte/sec; " << max_tests * double((2 * size)) / (tack - tick) / 1e3 << " GFlop/sec" << std::endl; // Vector Update 1 // Size = 3xsize // Flop = 2 per element vec3.ScaleAdd(double(5.5), vec2); _rocalution_sync(); tick = rocalution_time(); for(int i = 0; i < max_tests; ++i) { vec3.ScaleAdd(double(5.5), vec2); _rocalution_sync(); } _rocalution_sync(); tack = rocalution_time(); std::cout << "Vector update (scaleadd) execution: " << (tack - tick) / max_tests / 1e3 << " msec" << "; " << max_tests * double(sizeof(double) * (size + size + size)) / (tack - tick) / 1e3 << " Gbyte/sec; " << max_tests * double((2 * size)) / (tack - tick) / 1e3 << " GFlop/sec" << std::endl; // Vector Update 2 // Size = 3*size // Flop = 2 per element vec3.AddScale(vec2, double(5.5)); _rocalution_sync(); tick = rocalution_time(); for(int i = 0; i < max_tests; ++i) { vec3.AddScale(vec2, double(5.5)); _rocalution_sync(); } _rocalution_sync(); tack = rocalution_time(); std::cout << "Vector update (addscale) execution: " << (tack - tick) / max_tests / 1e3 << " msec" << "; " << max_tests * double(sizeof(double) * (size + size + size)) / (tack - tick) / 1e3 << " Gbyte/sec; " << max_tests * double((2 * size)) / (tack - tick) / 1e3 << " GFlop/sec" << std::endl; mat.ConvertToCSR(); nnz = mat.GetNnz(); mat.Info(); // Matrix-Vector Multiplication // Size = int(size+nnz) [row_offset + col] + valuetype(2*size+nnz) [in + out + nnz] // Flop = 2 per entry (nnz) mat.Apply(vec1, &vec2); _rocalution_sync(); tick = rocalution_time(); for(int i = 0; i < max_tests; ++i) { mat.Apply(vec1, &vec2); _rocalution_sync(); } _rocalution_sync(); tack = rocalution_time(); std::cout << "CSR SpMV execution: " << (tack - tick) / max_tests / 1e3 << " msec" << "; " << max_tests * double((sizeof(double) * (size + size + nnz) + sizeof(int) * (size + nnz))) / (tack - tick) / 1e3 << " Gbyte/sec; " << max_tests * double((2 * nnz)) / (tack - tick) / 1e3 << " GFlop/sec" << std::endl; mat.ConvertToMCSR(); nnz = mat.GetNnz(); mat.Info(); // Matrix-Vector Multiplication // Size = int(size+(nnz-size)) [row_offset + col] + valuetype(2*size+nnz) [in + out + nnz] // Flop = 2 per entry (nnz) mat.Apply(vec1, &vec2); _rocalution_sync(); tick = rocalution_time(); for(int i = 0; i < max_tests; ++i) { mat.Apply(vec1, &vec2); _rocalution_sync(); } _rocalution_sync(); tack = rocalution_time(); std::cout << "MCSR SpMV execution: " << (tack - tick) / max_tests / 1e3 << " msec" << "; " << max_tests * double( (sizeof(double) * (size + size + nnz - size) + sizeof(int) * (size + nnz))) / (tack - tick) / 1e3 << " Gbyte/sec; " << max_tests * double((2 * nnz)) / (tack - tick) / 1e3 << " GFlop/sec" << std::endl; mat.ConvertToELL(); nnz = mat.GetNnz(); mat.Info(); // Matrix-Vector Multiplication // Size = int(nnz) [col] + valuetype(2*size+nnz) [in + out + nnz] // Flop = 2 per entry (nnz) mat.Apply(vec1, &vec2); _rocalution_sync(); tick = rocalution_time(); for(int i = 0; i < max_tests; ++i) { mat.Apply(vec1, &vec2); _rocalution_sync(); } _rocalution_sync(); tack = rocalution_time(); std::cout << "ELL SpMV execution: " << (tack - tick) / max_tests / 1e3 << " msec" << "; " << max_tests * double((sizeof(double) * (size + size + nnz) + sizeof(int) * (nnz))) / (tack - tick) / 1e3 << " Gbyte/sec; " << max_tests * double((2 * nnz)) / (tack - tick) / 1e3 << " GFlop/sec" << std::endl; mat.ConvertToCOO(); nnz = mat.GetNnz(); mat.Info(); // Matrix-Vector Multiplication // Size = int(2*nnz) + valuetype(2*size+nnz) // Flop = 2 per entry (nnz) mat.Apply(vec1, &vec2); _rocalution_sync(); tick = rocalution_time(); for(int i = 0; i < max_tests; ++i) { mat.Apply(vec1, &vec2); _rocalution_sync(); } _rocalution_sync(); tack = rocalution_time(); std::cout << "COO SpMV execution: " << (tack - tick) / max_tests / 1e3 << " msec" << "; " << max_tests * double((sizeof(double) * (size + size + nnz) + sizeof(int) * (2 * nnz))) / (tack - tick) / 1e3 << " Gbyte/sec; " << max_tests * double((2 * nnz)) / (tack - tick) / 1e3 << " GFlop/sec" << std::endl; mat.ConvertToHYB(); nnz = mat.GetNnz(); mat.Info(); // Matrix-Vector Multiplication // Size = int(nnz) [col] + valuetype(2*size+nnz) [in + out + nnz] // Flop = 2 per entry (nnz) mat.Apply(vec1, &vec2); _rocalution_sync(); tick = rocalution_time(); for(int i = 0; i < max_tests; ++i) { mat.Apply(vec1, &vec2); _rocalution_sync(); } _rocalution_sync(); tack = rocalution_time(); std::cout << "HYB SpMV execution: " << (tack - tick) / max_tests / 1e3 << " msec" << "; " // like O(ELL) << max_tests * double((sizeof(double) * (size + size + nnz) + sizeof(int) * (nnz))) / (tack - tick) / 1e3 << " Gbyte/sec; " << max_tests * double((2 * nnz)) / (tack - tick) / 1e3 << " GFlop/sec" << std::endl; mat.ConvertToDIA(); nnz = mat.GetNnz(); mat.Info(); // Matrix-Vector Multiplication // Size = int(size+nnz) + valuetype(2*size+nnz) // Flop = 2 per entry (nnz) mat.Apply(vec1, &vec2); _rocalution_sync(); tick = rocalution_time(); for(int i = 0; i < max_tests; ++i) { mat.Apply(vec1, &vec2); _rocalution_sync(); } _rocalution_sync(); tack = rocalution_time(); std::cout << "DIA SpMV execution: " << (tack - tick) / max_tests / 1e3 << " msec" << "; " // assuming ndiag << size << max_tests * double((sizeof(double) * (nnz))) / (tack - tick) / 1e3 << " Gbyte/sec; " << max_tests * double((2 * nnz)) / (tack - tick) / 1e3 << " GFlop/sec" << std::endl; mat.ConvertToCSR(); std::cout << "----------------------------------------------------" << std::endl; std::cout << "Combined micro benchmarks" << std::endl; double dot_tick = 0, dot_tack = 0; double norm_tick = 0, norm_tack = 0; double updatev1_tick = 0, updatev1_tack = 0; double updatev2_tick = 0, updatev2_tack = 0; double spmv_tick = 0, spmv_tack = 0; for(int i = 0; i < max_tests; ++i) { vec1.Ones(); vec2.Zeros(); vec3.Ones(); mat.Apply(vec1, &vec2); // Dot product // Size = 2*size // Flop = 2 per element vec3.Dot(vec2); _rocalution_sync(); dot_tick += rocalution_time(); vec3.Dot(vec2); _rocalution_sync(); dot_tack += rocalution_time(); vec1.Ones(); vec2.Zeros(); vec3.Ones(); mat.Apply(vec1, &vec2); // Norm // Size = size // Flop = 2 per element vec3.Norm(); _rocalution_sync(); norm_tick += rocalution_time(); vec3.Norm(); _rocalution_sync(); norm_tack += rocalution_time(); vec1.Ones(); vec2.Zeros(); vec3.Ones(); mat.Apply(vec1, &vec2); // Vector Update 1 // Size = 3xsize // Flop = 2 per element vec3.ScaleAdd(double(5.5), vec2); _rocalution_sync(); updatev1_tick += rocalution_time(); vec3.ScaleAdd(double(5.5), vec2); _rocalution_sync(); updatev1_tack += rocalution_time(); vec1.Ones(); vec2.Zeros(); vec3.Ones(); mat.Apply(vec1, &vec2); // Vector Update 2 // Size = 3*size // Flop = 2 per element vec3.AddScale(vec2, double(5.5)); _rocalution_sync(); updatev2_tick += rocalution_time(); vec3.AddScale(vec2, double(5.5)); _rocalution_sync(); updatev2_tack += rocalution_time(); vec1.Ones(); vec2.Zeros(); vec3.Ones(); mat.Apply(vec1, &vec2); // Matrix-Vector Multiplication // Size = int(size+nnz) + valuetype(2*size+nnz) // Flop = 2 per entry (nnz) mat.Apply(vec1, &vec2); _rocalution_sync(); spmv_tick += rocalution_time(); mat.Apply(vec1, &vec2); _rocalution_sync(); spmv_tack += rocalution_time(); } std::cout << "Dot execution: " << (dot_tack - dot_tick) / max_tests / 1e3 << " msec" << "; " << max_tests * double(sizeof(double) * (size + size)) / (dot_tack - dot_tick) / 1e3 << " Gbyte/sec; " << max_tests * double((2 * size)) / (dot_tack - dot_tick) / 1e3 << " GFlop/sec" << std::endl; std::cout << "Norm execution: " << (norm_tack - norm_tick) / max_tests / 1e3 << " msec" << "; " << max_tests * double(sizeof(double) * (size)) / (norm_tack - norm_tick) / 1e3 << " Gbyte/sec; " << max_tests * double((2 * size)) / (norm_tack - norm_tick) / 1e3 << " GFlop/sec" << std::endl; std::cout << "Vector update (scaleadd) execution: " << (updatev1_tack - updatev1_tick) / max_tests / 1e3 << " msec" << "; " << max_tests * double(sizeof(double) * (size + size + size)) / (updatev1_tack - updatev1_tick) / 1e3 << " Gbyte/sec; " << max_tests * double((2 * size)) / (updatev1_tack - updatev1_tick) / 1e3 << " GFlop/sec" << std::endl; std::cout << "Vector update (addscale) execution: " << (updatev2_tack - updatev2_tick) / max_tests / 1e3 << " msec" << "; " << max_tests * double(sizeof(double) * (size + size + size)) / (updatev2_tack - updatev2_tick) / 1e3 << " Gbyte/sec; " << max_tests * double((2 * size)) / (updatev2_tack - updatev2_tick) / 1e3 << " GFlop/sec" << std::endl; std::cout << "SpMV execution: " << (spmv_tack - spmv_tick) / max_tests / 1e3 << " msec" << "; " << max_tests * double((sizeof(double) * (size + size + nnz) + sizeof(int) * (size + nnz))) / (spmv_tack - spmv_tick) / 1e3 << " Gbyte/sec; " << max_tests * double((2 * nnz) / (spmv_tack - spmv_tick)) / 1e3 << " GFlop/sec" << std::endl; stop_rocalution(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/benchmark_mpi.cpp000066400000000000000000000434571507377332500227350ustar00rootroot00000000000000/* ************************************************************************ * 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 "common.hpp" #include #include #include #define ValueType double using namespace rocalution; int main(int argc, char* argv[]) { // Initialize MPI MPI_Init(&argc, &argv); MPI_Comm comm = MPI_COMM_WORLD; int rank; int num_procs; MPI_Comm_rank(comm, &rank); MPI_Comm_size(comm, &num_procs); // Check command line parameters if(num_procs < 2) { std::cerr << "Expecting at least 2 MPI processes" << std::endl; return -1; } if(argc < 2) { std::cerr << argv[0] << " " << std::endl; return -1; } // Disable OpenMP thread affinity set_omp_affinity_rocalution(false); // Initialize platform with rank and # of accelerator devices in the node init_rocalution(rank, 2); // Disable OpenMP set_omp_threads_rocalution(1); // Print platform info_rocalution(); // Load undistributed matrix LocalMatrix lmat; lmat.ReadFileMTX(argv[1]); // Global structures ParallelManager manager; GlobalMatrix mat; // Distribute matrix - lmat will be destroyed distribute_matrix(&comm, &lmat, &mat, &manager); // rocALUTION vectors GlobalVector v1(manager); GlobalVector v2(manager); // Move structures to accelerator, if available mat.MoveToAccelerator(); v1.MoveToAccelerator(); v2.MoveToAccelerator(); // Allocate memory v1.Allocate("v1", mat.GetN()); v2.Allocate("v2", mat.GetM()); size_t size = mat.GetM(); size_t nnz; // Initialize objects v1.Ones(); v2.Zeros(); mat.Apply(v1, &v2); // Print object info mat.Info(); v1.Info(); v2.Info(); // Number of tests int tests = 200; double time; if(rank == 0) { std::cout << "--------------------------------------- BENCHMARKS " "--------------------------------------" << std::endl; } // Dot product // Size = 2*size // Flop = 2 per element v1.Dot(v2); _rocalution_sync(); time = rocalution_time(); for(int i = 0; i < tests; ++i) { v1.Dot(v2); _rocalution_sync(); } _rocalution_sync(); time = rocalution_time() - time; if(rank == 0) { std::cout << "Dot execution: " << time / 1e3 / tests << " msec" << "; " << tests * double(sizeof(ValueType) * (2 * size)) / time / 1e3 << " GByte/sec; " << tests * double(2 * size) / time / 1e3 << " GFlop/sec" << std::endl; } // L2 Norm // Size = size // Flop = 2 per element v1.Norm(); _rocalution_sync(); time = rocalution_time(); for(int i = 0; i < tests; ++i) { v1.Norm(); _rocalution_sync(); } _rocalution_sync(); time = rocalution_time() - time; if(rank == 0) { std::cout << "Norm2 execution: " << time / 1e3 / tests << " msec" << "; " << tests * double(sizeof(ValueType) * (size)) / time / 1e3 << " GByte/sec; " << tests * double(2 * size) / time / 1e3 << " GFlop/sec" << std::endl; } // Reduction // Size = size // Flop = 1 per element v1.Reduce(); _rocalution_sync(); time = rocalution_time(); for(int i = 0; i < tests; ++i) { v1.Reduce(); _rocalution_sync(); } _rocalution_sync(); time = rocalution_time() - time; if(rank == 0) { std::cout << "Reduce execution: " << time / 1e3 / tests << " msec" << "; " << tests * double(sizeof(ValueType) * (size)) / time / 1e3 << " GByte/sec; " << tests * double(size) / time / 1e3 << " GFlop/sec" << std::endl; } if(rank == 0) { std::cout << "----------------------------------------------------" "-------------------------------------" << std::endl; } // Vector Update 1 // Size = 3*size // Flop = 2 per element v1.ScaleAdd((ValueType)3.1, v2); _rocalution_sync(); time = rocalution_time(); for(int i = 0; i < tests; ++i) { v1.ScaleAdd((ValueType)3.1, v2); _rocalution_sync(); } _rocalution_sync(); time = rocalution_time() - time; if(rank == 0) { std::cout << "Vector update (ScaleAdd) execution: " << time / 1e3 / tests << " msec" << "; " << tests * double(sizeof(ValueType) * (3 * size)) / time / 1e3 << " GByte/sec; " << tests * double(2 * size) / time / 1e3 << " GFlop/sec" << std::endl; } // Vector Update 2 // Size = 3*size // Flop = 2 per element v1.AddScale(v2, (ValueType)3.1); _rocalution_sync(); time = rocalution_time(); for(int i = 0; i < tests; ++i) { v1.AddScale(v2, (ValueType)3.1); _rocalution_sync(); } _rocalution_sync(); time = rocalution_time() - time; if(rank == 0) { std::cout << "Vector update (AddScale) execution: " << time / 1e3 / tests << " msec" << "; " << tests * double(sizeof(ValueType) * (3 * size)) / time / 1e3 << " GByte/sec; " << tests * double(2 * size) / time / 1e3 << " GFlop/sec" << std::endl; } if(rank == 0) { std::cout << "----------------------------------------------------" "-------------------------------------" << std::endl; } // Matrix vector multiplication CSR // Size = int(size+1+nnz) [row_offset + col] + ValueType(2*size+nnz) [in + out + nnz] // Flop = 2 per entry (nnz) mat.ConvertToCSR(); nnz = mat.GetNnz(); mat.Info(); mat.Apply(v1, &v2); _rocalution_sync(); time = rocalution_time(); for(int i = 0; i < tests; ++i) { mat.Apply(v1, &v2); _rocalution_sync(); } _rocalution_sync(); time = rocalution_time() - time; if(rank == 0) { std::cout << "CSR SpMV execution: " << time / 1e3 / tests << " msec" << "; " << tests * double((sizeof(ValueType) * (2 * size + nnz) + sizeof(int) * (size + 1 + nnz))) / time / 1e3 << " GByte/sec; " << tests * double(2 * nnz) / time / 1e3 << " GFlop/sec" << std::endl; } if(rank == 0) { std::cout << "----------------------------------------------------" "-------------------------------------" << std::endl; } // Matrix vector multiplication MCSR // Size = int(size+(nnz-size)) [row_offset + col] + valuetype(2*size+nnz) [in + out + nnz] // Flop = 2 per entry (nnz) mat.ConvertToMCSR(); nnz = mat.GetNnz(); mat.Info(); mat.Apply(v1, &v2); _rocalution_sync(); time = rocalution_time(); for(int i = 0; i < tests; ++i) { mat.Apply(v1, &v2); _rocalution_sync(); } _rocalution_sync(); time = rocalution_time() - time; if(rank == 0) { std::cout << "MCSR SpMV execution: " << time / 1e3 / tests << " msec" << "; " << tests * double((sizeof(ValueType) * (2 * size + nnz - size) + sizeof(int) * (size + 1 + nnz))) / time / 1e3 << " GByte/sec; " << tests * double(2 * nnz) / time / 1e3 << " GFlop/sec" << std::endl; } if(rank == 0) { std::cout << "----------------------------------------------------" "-------------------------------------" << std::endl; } // Matrix vector multiplication ELL // Size = int(nnz) [col] + ValueType(2*size+nnz) [in + out + nnz] // Flop = 2 per entry (nnz) mat.ConvertToELL(); nnz = mat.GetNnz(); mat.Info(); mat.Apply(v1, &v2); _rocalution_sync(); time = rocalution_time(); for(int i = 0; i < tests; ++i) { mat.Apply(v1, &v2); _rocalution_sync(); } _rocalution_sync(); time = rocalution_time() - time; if(rank == 0) { std::cout << "ELL SpMV execution: " << time / 1e3 / tests << " msec" << "; " << tests * double((sizeof(ValueType) * (2 * size + nnz) + sizeof(int) * (nnz))) / time / 1e3 << " GByte/sec; " << tests * double(2 * nnz) / time / 1e3 << " GFlop/sec" << std::endl; } if(rank == 0) { std::cout << "----------------------------------------------------" "-------------------------------------" << std::endl; } // Matrix vector multiplication COO // Size = int(2*nnz) [col+row] + ValueType(2*size+nnz) [in + out + nnz] // Flop = 2 per entry (nnz) mat.ConvertToCOO(); nnz = mat.GetNnz(); mat.Info(); mat.Apply(v1, &v2); _rocalution_sync(); time = rocalution_time(); for(int i = 0; i < tests; ++i) { mat.Apply(v1, &v2); _rocalution_sync(); } _rocalution_sync(); time = rocalution_time() - time; if(rank == 0) { std::cout << "COO SpMV execution: " << time / 1e3 / tests << " msec" << "; " << tests * double((sizeof(ValueType) * (2 * size + nnz) + sizeof(int) * (2 * nnz))) / time / 1e3 << " GByte/sec; " << tests * double(2 * nnz) / time / 1e3 << " GFlop/sec" << std::endl; } if(rank == 0) { std::cout << "----------------------------------------------------" "-------------------------------------" << std::endl; } // Matrix vector multiplication HYB // Size = int(nnz) [col] + valuetype(2*size+nnz) [in + out + nnz] // Flop = 2 per entry (nnz) mat.ConvertToHYB(); nnz = mat.GetNnz(); mat.Info(); mat.Apply(v1, &v2); _rocalution_sync(); time = rocalution_time(); for(int i = 0; i < tests; ++i) { mat.Apply(v1, &v2); _rocalution_sync(); } _rocalution_sync(); time = rocalution_time() - time; if(rank == 0) { std::cout << "HYB SpMV execution: " << time / 1e3 / tests << " msec" << "; " << tests * double((sizeof(ValueType) * (2 * size + nnz) + sizeof(int) * (nnz))) / time / 1e3 << " GByte/sec; " << tests * double(2 * nnz) / time / 1e3 << " GFlop/sec" << std::endl; } if(rank == 0) { std::cout << "----------------------------------------------------" "-------------------------------------" << std::endl; } // Matrix vector multiplication DIA // Size = int(size+nnz) + valuetype(2*size+nnz) // Flop = 2 per entry (nnz) mat.ConvertToDIA(); nnz = mat.GetNnz(); mat.Info(); mat.Apply(v1, &v2); _rocalution_sync(); time = rocalution_time(); for(int i = 0; i < tests; ++i) { mat.Apply(v1, &v2); _rocalution_sync(); } _rocalution_sync(); time = rocalution_time() - time; if(rank == 0) { std::cout << "DIA SpMV execution: " << time / 1e3 / tests << " msec" << "; " << tests * double((sizeof(ValueType) * (nnz))) / time / 1e3 << " GByte/sec; " << tests * double(2 * nnz) / time / 1e3 << " GFlop/sec" << std::endl; } if(rank == 0) { std::cout << "----------------------------------------------------" "-------------------------------------" << std::endl; } mat.ConvertToCSR(); if(rank == 0) { std::cout << "----------------------------------------------------" << std::endl; std::cout << "Combined micro benchmarks" << std::endl; } double dot_tick = 0, dot_tack = 0; double norm_tick = 0, norm_tack = 0; double red_tick = 0, red_tack = 0; double updatev1_tick = 0, updatev1_tack = 0; double updatev2_tick = 0, updatev2_tack = 0; double spmv_tick = 0, spmv_tack = 0; for(int i = 0; i < tests; ++i) { v1.Ones(); v2.Zeros(); mat.Apply(v1, &v2); // Dot product // Size = 2*size // Flop = 2 per element v1.Dot(v2); dot_tick += rocalution_time(); v1.Dot(v2); dot_tack += rocalution_time(); v1.Ones(); v2.Zeros(); mat.Apply(v1, &v2); // Norm // Size = size // Flop = 2 per element v1.Norm(); norm_tick += rocalution_time(); v1.Norm(); norm_tack += rocalution_time(); v1.Ones(); v2.Zeros(); mat.Apply(v1, &v2); // Reduce // Size = size // Flop = 1 per element v1.Reduce(); red_tick += rocalution_time(); v1.Reduce(); red_tack += rocalution_time(); v1.Ones(); v2.Zeros(); mat.Apply(v1, &v2); // Vector Update 1 // Size = 3xsize // Flop = 2 per element v1.ScaleAdd(double(5.5), v2); updatev1_tick += rocalution_time(); v1.ScaleAdd(double(5.5), v2); updatev1_tack += rocalution_time(); v1.Ones(); v2.Zeros(); mat.Apply(v1, &v2); // Vector Update 2 // Size = 3*size // Flop = 2 per element v1.AddScale(v2, double(5.5)); updatev2_tick += rocalution_time(); v1.AddScale(v2, double(5.5)); updatev2_tack += rocalution_time(); v1.Ones(); v2.Zeros(); mat.Apply(v1, &v2); // Matrix-Vector Multiplication // Size = int(size+nnz) + valuetype(2*size+nnz) // Flop = 2 per entry (nnz) mat.Apply(v1, &v2); spmv_tick += rocalution_time(); mat.Apply(v1, &v2); spmv_tack += rocalution_time(); } if(rank == 0) { std::cout << "Dot execution: " << (dot_tack - dot_tick) / tests / 1e3 << " msec" << "; " << tests * double(sizeof(double) * (size + size)) / (dot_tack - dot_tick) / 1e3 << " Gbyte/sec; " << tests * double(2 * size) / (dot_tack - dot_tick) / 1e3 << " GFlop/sec" << std::endl; std::cout << "Norm execution: " << (norm_tack - norm_tick) / tests / 1e3 << " msec" << "; " << tests * double(sizeof(double) * (size)) / (norm_tack - norm_tick) / 1e3 << " Gbyte/sec; " << tests * double(2 * size) / (norm_tack - norm_tick) / 1e3 << " GFlop/sec" << std::endl; std::cout << "Reduce execution: " << (red_tack - red_tick) / tests / 1e3 << " msec" << "; " << tests * double(sizeof(double) * (size)) / (red_tack - red_tick) / 1e3 << " Gbyte/sec; " << tests * double(size) / (red_tack - red_tick) / 1e3 << " GFlop/sec" << std::endl; std::cout << "Vector update (scaleadd) execution: " << (updatev1_tack - updatev1_tick) / tests / 1e3 << " msec" << "; " << tests * double(sizeof(double) * (size + size + size)) / (updatev1_tack - updatev1_tick) / 1e3 << " Gbyte/sec; " << tests * double(2 * size) / (updatev1_tack - updatev1_tick) / 1e3 << " GFlop/sec" << std::endl; std::cout << "Vector update (addscale) execution: " << (updatev2_tack - updatev2_tick) / tests / 1e3 << " msec" << "; " << tests * double(sizeof(double) * (size + size + size)) / (updatev2_tack - updatev2_tick) / 1e3 << " Gbyte/sec; " << tests * double(2 * size) / (updatev2_tack - updatev2_tick) / 1e3 << " GFlop/sec" << std::endl; std::cout << "SpMV execution: " << (spmv_tack - spmv_tick) / tests / 1e3 << " msec" << "; " << tests * double( (sizeof(double) * (size + size + nnz) + sizeof(int) * (size + nnz))) / (spmv_tack - spmv_tick) / 1e3 << " Gbyte/sec; " << tests * double((2 * nnz) / (spmv_tack - spmv_tick)) / 1e3 << " GFlop/sec" << std::endl; } stop_rocalution(); MPI_Finalize(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/bicgstab.cpp000066400000000000000000000065351507377332500217100ustar00rootroot00000000000000/* ************************************************************************ * 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 #include #include using namespace rocalution; int main(int argc, char* argv[]) { // Check command line parameters if(argc == 1) { std::cerr << argv[0] << " [Num threads]" << std::endl; exit(1); } // Initialize rocALUTION init_rocalution(); // Check command line parameters for number of OMP threads if(argc > 2) { set_omp_threads_rocalution(atoi(argv[2])); } // Print rocALUTION info info_rocalution(); // rocALUTION objects LocalVector x; LocalVector rhs; LocalVector e; LocalMatrix mat; // Read matrix from MTX file mat.ReadFileMTX(std::string(argv[1])); // Move objects to accelerator mat.MoveToAccelerator(); x.MoveToAccelerator(); rhs.MoveToAccelerator(); e.MoveToAccelerator(); // Allocate vectors x.Allocate("x", mat.GetN()); rhs.Allocate("rhs", mat.GetM()); e.Allocate("e", mat.GetN()); // Linear Solver BiCGStab, LocalVector, double> ls; // Preconditioner MultiColoredGS, LocalVector, double> p; // Initialize rhs such that A 1 = rhs e.Ones(); mat.Apply(e, &rhs); // Initial zero guess x.Zeros(); // Set solver operator ls.SetOperator(mat); // Set solver preconditioner ls.SetPreconditioner(p); // Build solver ls.Build(); // Verbosity output ls.Verbose(1); // Print matrix info mat.Info(); // Start time measurement double tick, tack; tick = rocalution_time(); // Solve A x = rhs ls.Solve(rhs, &x); // Stop time measurement tack = rocalution_time(); std::cout << "Solver execution:" << (tack - tick) / 1e6 << " sec" << std::endl; // Clear solver ls.Clear(); // Compute error L2 norm e.ScaleAdd(-1.0, x); double error = e.Norm(); std::cout << "||e - x||_2 = " << error << std::endl; // Stop rocALUTION platform stop_rocalution(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/bicgstab_mpi.cpp000066400000000000000000000103151507377332500225440ustar00rootroot00000000000000/* ************************************************************************ * 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 "common.hpp" #include #include #include #define ValueType double using namespace rocalution; int main(int argc, char* argv[]) { // Initialize MPI MPI_Init(&argc, &argv); MPI_Comm comm = MPI_COMM_WORLD; int rank; int num_procs; MPI_Comm_rank(comm, &rank); MPI_Comm_size(comm, &num_procs); // Check command line parameters if(num_procs < 2) { std::cerr << "Expecting at least 2 MPI processes" << std::endl; return -1; } if(argc < 2) { std::cerr << argv[0] << " " << std::endl; return -1; } // Disable OpenMP thread affinity set_omp_affinity_rocalution(false); // Initialize platform with rank and # of accelerator devices in the node init_rocalution(rank, 2); // Disable OpenMP set_omp_threads_rocalution(1); // Print platform info_rocalution(); // Load undistributed matrix LocalMatrix lmat; lmat.ReadFileMTX(argv[1]); // Global structures ParallelManager manager; GlobalMatrix mat; // Distribute matrix - lmat will be destroyed distribute_matrix(&comm, &lmat, &mat, &manager); // rocALUTION vectors GlobalVector rhs(manager); GlobalVector x(manager); GlobalVector e(manager); // Move structures to accelerator, if available mat.MoveToAccelerator(); rhs.MoveToAccelerator(); x.MoveToAccelerator(); e.MoveToAccelerator(); // Allocate memory rhs.Allocate("rhs", mat.GetM()); x.Allocate("x", mat.GetN()); e.Allocate("sol", mat.GetN()); // Initialize rhs such that A 1 = rhs e.Ones(); mat.Apply(e, &rhs); // Initial zero guess x.Zeros(); // Linear solver BiCGStab, GlobalVector, double> ls; // Block jacobi global preconditioner BlockJacobi, GlobalVector, double> bj; // Local preconditioner MultiColoredGS, LocalVector, double> p; // Set local preconditioner bj.Set(p); // Set solver preconditioner ls.SetPreconditioner(bj); // Set solver operator ls.SetOperator(mat); // Build solver ls.Build(); // Verbosity output ls.Verbose(1); // Print matrix info mat.Info(); // Start time measurement double time = rocalution_time(); // Solve A x = rhs ls.Solve(rhs, &x); // Stop time measurement time = rocalution_time() - time; if(rank == 0) { std::cout << "Solving: " << time / 1e6 << " sec" << std::endl; } // Compute error L2 norm e.ScaleAdd(-1.0, x); double nrm2 = e.Norm(); if(rank == 0) { std::cout << "||e - x||_2 = " << nrm2 << std::endl; } // Clear solver ls.Clear(); // Stop rocALUTION platform stop_rocalution(); MPI_Finalize(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/block-precond.cpp000066400000000000000000000105411507377332500226440ustar00rootroot00000000000000/* ************************************************************************ * 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 #include #include using namespace rocalution; int main(int argc, char* argv[]) { // Check command line parameters if(argc == 1) { std::cerr << argv[0] << " [Num threads]" << std::endl; exit(1); } // Initialize rocALUTION init_rocalution(); // Check command line parameters for number of OMP threads if(argc > 2) { set_omp_threads_rocalution(atoi(argv[2])); } // Print rocALUTION info info_rocalution(); // rocALUTION objects LocalVector x; LocalVector rhs; LocalVector e; LocalMatrix mat; // Read matrix from MTX file mat.ReadFileMTX(std::string(argv[1])); // Move objects to accelerator // mat.MoveToAccelerator(); // x.MoveToAccelerator(); // rhs.MoveToAccelerator(); // e.MoveToAccelerator(); // Allocate vectors x.Allocate("x", mat.GetN()); rhs.Allocate("rhs", mat.GetM()); e.Allocate("e", mat.GetN()); // Linear Solver GMRES, LocalVector, double> ls; // Preconditioner BlockPreconditioner, LocalVector, double> p; Solver, LocalVector, double>** p2; // Setup blocks int n = 2; int* size; size = new int[n]; p2 = new Solver, LocalVector, double>*[n]; for(int i = 0; i < n; ++i) { size[i] = mat.GetM() / n; MultiColoredILU, LocalVector, double>* mc; mc = new MultiColoredILU, LocalVector, double>; p2[i] = mc; // AMG, LocalVector, double > *amg; // amg = new AMG, LocalVector, double >; // amg->InitMaxIter(2); // amg->Verbose(0); // p2[i] = amg; } double tick, tack; // Initialize rhs such that A 1 = rhs e.Ones(); mat.Apply(e, &rhs); // Initial zero guess x.Zeros(); // Set blocks and diagonal solver p.Set(n, size, p2); p.SetDiagonalSolver(); // Set solver operator ls.SetOperator(mat); // Set solver preconditioner ls.SetPreconditioner(p); // Verbosity output // ls.Verbose(2); // Build solver ls.Build(); // Print matrix info mat.Info(); // Start time measurement tick = rocalution_time(); // Solve A x = rhs ls.Solve(rhs, &x); // Stop time measurement tack = rocalution_time(); std::cout << "Solver execution:" << (tack - tick) / 1e6 << " sec" << std::endl; // Clear solver ls.Clear(); // Clear all allocated data for(int i = 0; i < n; ++i) { delete p2[i]; p2[i] = NULL; } delete[] size; delete[] p2; p2 = NULL; // Compute error L2 norm e.ScaleAdd(-1.0, x); double error = e.Norm(); std::cout << "||e - x||_2 = " << error << std::endl; // Stop rocALUTION platform stop_rocalution(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/cg-amg.cpp000066400000000000000000000073561507377332500212670ustar00rootroot00000000000000/* ************************************************************************ * 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. * * ************************************************************************ */ #include #include #include using namespace rocalution; int main(int argc, char* argv[]) { // Check command line parameters if(argc == 1) { std::cerr << argv[0] << " [Num threads]" << std::endl; exit(1); } // Initialize rocALUTION init_rocalution(); // Check command line parameters for number of OMP threads if(argc > 2) { set_omp_threads_rocalution(atoi(argv[2])); } // Print rocALUTION info info_rocalution(); // rocALUTION objects LocalVector x; LocalVector rhs; LocalVector e; LocalMatrix mat; // Move objects to accelerator mat.MoveToAccelerator(); x.MoveToAccelerator(); rhs.MoveToAccelerator(); e.MoveToAccelerator(); // Read matrix from MTX file mat.ReadFileMTX(std::string(argv[1])); // Allocate vectors x.Allocate("x", mat.GetN()); rhs.Allocate("rhs", mat.GetM()); e.Allocate("e", mat.GetN()); // Initialize rhs such that A 1 = rhs e.Ones(); mat.Apply(e, &rhs); // Initial zero guess x.Zeros(); // Start time measurement double tick = rocalution_time(); // Linear Solver CG, LocalVector, double> ls; // AMG Preconditioner SAAMG, LocalVector, double> p; // Disable verbosity output of AMG preconditioner p.Verbose(0); // Set solver preconditioner ls.SetPreconditioner(p); // Set solver operator ls.SetOperator(mat); // Build solver ls.Build(); // Compute 2 coarsest levels on the host p.SetHostLevels(2); // Stop time measurement double tack = rocalution_time(); std::cout << "Building took: " << (tack - tick) / 1e6 << " sec" << std::endl; // Print matrix info mat.Info(); // Initialize solver tolerances ls.Init(1e-8, 1e-8, 1e+8, 10000); // Set verbosity output ls.Verbose(1); // Start time measurement tick = rocalution_time(); // Solve A x = rhs ls.Solve(rhs, &x); // Stop time measurement tack = rocalution_time(); std::cout << "Solver took: " << (tack - tick) / 1e6 << " sec" << std::endl; // Clear solver ls.Clear(); // Compute error L2 norm e.ScaleAdd(-1.0, x); double error = e.Norm(); std::cout << "||e - x||_2 = " << error << std::endl; // Stop rocALUTION platform stop_rocalution(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/cg-amg_mpi.cpp000066400000000000000000000100501507377332500221150ustar00rootroot00000000000000/* ************************************************************************ * 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 "common.hpp" #include #include #include #define ValueType double using namespace rocalution; int main(int argc, char* argv[]) { // Initialize MPI MPI_Init(&argc, &argv); MPI_Comm comm = MPI_COMM_WORLD; int rank; int num_procs; MPI_Comm_rank(comm, &rank); MPI_Comm_size(comm, &num_procs); if(argc < 2) { std::cerr << argv[0] << " " << std::endl; return -1; } // Disable OpenMP thread affinity set_omp_affinity_rocalution(false); // Initialize platform with rank and # of accelerator devices in the node init_rocalution(rank, 2); // Disable OpenMP set_omp_threads_rocalution(1); // Print platform info_rocalution(); // Load undistributed matrix LocalMatrix lmat; lmat.ReadFileMTX(argv[1]); // Global structures ParallelManager manager; GlobalMatrix mat; // Distribute matrix - lmat will be destroyed distribute_matrix(&comm, &lmat, &mat, &manager); // rocALUTION vectors GlobalVector rhs(manager); GlobalVector x(manager); GlobalVector e(manager); // Allocate memory rhs.Allocate("rhs", mat.GetM()); x.Allocate("x", mat.GetN()); e.Allocate("sol", mat.GetN()); // Initialize rhs such that A 1 = rhs e.Ones(); mat.Apply(e, &rhs); // Initial zero guess x.Zeros(); // Linear solver CG, GlobalVector, double> ls; // Preconditioner PairwiseAMG, GlobalVector, double> p; // Disable AMG preconditioner verbosity output p.Verbose(0); // Set solver preconditioner ls.SetPreconditioner(p); // Set solver operator ls.SetOperator(mat); // Build solver ls.Build(); // Move structures to accelerator, if available mat.MoveToAccelerator(); rhs.MoveToAccelerator(); x.MoveToAccelerator(); e.MoveToAccelerator(); ls.MoveToAccelerator(); // Set verbosity output ls.Verbose(2); // Set host levels (requires solver built) p.SetHostLevels(2); // Print matrix info mat.Info(); // Start time measurement double time = rocalution_time(); // Solve A x = rhs ls.Solve(rhs, &x); // Stop time measurement time = rocalution_time() - time; if(rank == 0) { std::cout << "Solving: " << time / 1e6 << " sec" << std::endl; } // Compute error L2 norm e.ScaleAdd(-1.0, x); double nrm2 = e.Norm(); if(rank == 0) { std::cout << "||e - x||_2 = " << nrm2 << std::endl; } // Clear solver ls.Clear(); // Stop rocALUTION platform stop_rocalution(); MPI_Finalize(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/cg-rsamg.cpp000066400000000000000000000102521507377332500216210ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2022-2023 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include #include #include using namespace rocalution; int main(int argc, char* argv[]) { // Check command line parameters if(argc == 1) { std::cerr << argv[0] << " [Num threads]" << std::endl; exit(1); } // Initialize rocALUTION init_rocalution(); // Check command line parameters for number of OMP threads if(argc > 2) { set_omp_threads_rocalution(atoi(argv[2])); } // Print rocALUTION info info_rocalution(); // rocALUTION objects LocalVector x; LocalVector rhs; LocalVector e; LocalMatrix mat; // Move objects to accelerator mat.MoveToAccelerator(); x.MoveToAccelerator(); rhs.MoveToAccelerator(); e.MoveToAccelerator(); // Read matrix from MTX file mat.ReadFileMTX(std::string(argv[1])); // Start time measurement double tick, tack, start, end; start = rocalution_time(); // Allocate vectors x.Allocate("x", mat.GetN()); rhs.Allocate("rhs", mat.GetM()); e.Allocate("e", mat.GetN()); // Initialize rhs such that A 1 = rhs e.Ones(); mat.Apply(e, &rhs); // Initial zero guess x.Zeros(); // Start time measurement tick = rocalution_time(); // Linear Solver CG, LocalVector, double> ls; // AMG Preconditioner RugeStuebenAMG, LocalVector, double> p; p.SetCoarseningStrategy(CoarseningStrategy::PMIS); p.SetInterpolationType(InterpolationType::ExtPI); p.SetCoarsestLevel(20); // Limit operator complexity p.SetInterpolationFF1Limit(false); // Disable verbosity output of AMG preconditioner p.Verbose(0); // Set solver preconditioner ls.SetPreconditioner(p); // Set solver operator ls.SetOperator(mat); // Build solver ls.Build(); // Compute 2 coarsest levels on the host p.SetHostLevels(2); // Stop time measurement tack = rocalution_time(); std::cout << "Building took: " << (tack - tick) / 1e6 << " sec" << std::endl; // Print matrix info mat.Info(); // Initialize solver tolerances ls.Init(1e-8, 1e-8, 1e+8, 10000); // Set verbosity output ls.Verbose(2); // Start time measurement tick = rocalution_time(); // Solve A x = rhs ls.Solve(rhs, &x); // Stop time measurement tack = rocalution_time(); std::cout << "Solver took: " << (tack - tick) / 1e6 << " sec" << std::endl; // Clear solver ls.Clear(); // Compute error L2 norm e.ScaleAdd(-1.0, x); double error = e.Norm(); std::cout << "||e - x||_2 = " << error << std::endl; // Stop time measurement end = rocalution_time(); std::cout << "Total runtime: " << (end - start) / 1e6 << " sec" << std::endl; // Stop rocALUTION platform stop_rocalution(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/cg-rsamg_mpi.cpp000066400000000000000000000111111507377332500224610ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2023 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "common.hpp" #include #include #include using namespace rocalution; int main(int argc, char* argv[]) { // Initialize MPI MPI_Init(&argc, &argv); MPI_Comm comm = MPI_COMM_WORLD; int rank; int num_procs; MPI_Comm_rank(comm, &rank); MPI_Comm_size(comm, &num_procs); if(argc < 2) { std::cerr << argv[0] << " " << std::endl; return -1; } // Disable OpenMP thread affinity set_omp_affinity_rocalution(false); // Initialize platform with rank and # of accelerator devices in the node init_rocalution(rank, 8); // Disable OpenMP set_omp_threads_rocalution(1); // Print rocALUTION info info_rocalution(); // Load undistributed matrix LocalMatrix lmat; lmat.ReadFileMTX(argv[1]); // Global structures ParallelManager manager; GlobalMatrix mat; // Distribute matrix - lmat will be destroyed distribute_matrix(&comm, &lmat, &mat, &manager); // rocALUTION vectors GlobalVector rhs(manager); GlobalVector x(manager); GlobalVector e(manager); // Move objects to accelerator mat.MoveToAccelerator(); x.MoveToAccelerator(); rhs.MoveToAccelerator(); e.MoveToAccelerator(); // Start time measurement double tick, tack, start, end; start = rocalution_time(); // Allocate vectors x.Allocate("x", mat.GetN()); rhs.Allocate("rhs", mat.GetM()); e.Allocate("e", mat.GetN()); // Initialize rhs such that A 1 = rhs e.Ones(); mat.Apply(e, &rhs); // Initial zero guess x.Zeros(); // Start time measurement tick = rocalution_time(); // Linear Solver CG, GlobalVector, double> ls; // AMG Preconditioner RugeStuebenAMG, GlobalVector, double> p; p.SetCoarseningStrategy(CoarseningStrategy::PMIS); p.SetInterpolationType(InterpolationType::ExtPI); p.SetCoarsestLevel(20); // Limit operator complexity p.SetInterpolationFF1Limit(false); // Disable verbosity output of AMG preconditioner p.Verbose(0); // Set solver preconditioner ls.SetPreconditioner(p); // Set solver operator ls.SetOperator(mat); // Build solver ls.Build(); // Compute 2 coarsest levels on the host p.SetHostLevels(2); // Stop time measurement tack = rocalution_time(); if(rank == 0) { std::cout << "Building took: " << (tack - tick) / 1e6 << " sec" << std::endl; } // Print matrix info mat.Info(); // Initialize solver tolerances ls.Init(1e-8, 1e-8, 1e+8, 10000); // Set verbosity output ls.Verbose(2); // Start time measurement tick = rocalution_time(); // Solve A x = rhs ls.Solve(rhs, &x); // Stop time measurement tack = rocalution_time(); if(rank == 0) { std::cout << "Solver took: " << (tack - tick) / 1e6 << " sec" << std::endl; } // Clear solver ls.Clear(); // Compute error L2 norm e.ScaleAdd(-1.0, x); double error = e.Norm(); if(rank == 0) { std::cout << "||e - x||_2 = " << error << std::endl; } // Stop rocALUTION platform stop_rocalution(); MPI_Finalize(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/cg-saamg.cpp000066400000000000000000000101761507377332500216050ustar00rootroot00000000000000/* ************************************************************************ * 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 #include #include using namespace rocalution; int main(int argc, char* argv[]) { // Check command line parameters if(argc == 1) { std::cerr << argv[0] << " [Num threads]" << std::endl; exit(1); } // Initialize rocALUTION init_rocalution(); // Check command line parameters for number of OMP threads if(argc > 2) { set_omp_threads_rocalution(atoi(argv[2])); } // Print rocALUTION info info_rocalution(); // rocALUTION objects LocalVector x; LocalVector rhs; LocalVector e; LocalMatrix mat; // Move objects to accelerator mat.MoveToAccelerator(); x.MoveToAccelerator(); rhs.MoveToAccelerator(); e.MoveToAccelerator(); // Read matrix from MTX file mat.ReadFileMTX(std::string(argv[1])); // Start time measurement double tick, tack, start, end; start = rocalution_time(); // Allocate vectors x.Allocate("x", mat.GetN()); rhs.Allocate("rhs", mat.GetM()); e.Allocate("e", mat.GetN()); // Initialize rhs such that A 1 = rhs e.Ones(); mat.Apply(e, &rhs); // Initial zero guess x.Zeros(); // Start time measurement tick = rocalution_time(); // Linear Solver CG, LocalVector, double> ls; // AMG Preconditioner SAAMG, LocalVector, double> p; p.SetCoarseningStrategy(CoarseningStrategy::PMIS); p.SetLumpingStrategy(LumpingStrategy::AddWeakConnections); p.SetCoarsestLevel(200); p.SetCouplingStrength(0.001); // Disable verbosity output of AMG preconditioner p.Verbose(0); // Set solver preconditioner ls.SetPreconditioner(p); // Set solver operator ls.SetOperator(mat); // Build solver ls.Build(); // Compute 2 coarsest levels on the host p.SetHostLevels(2); // Stop time measurement tack = rocalution_time(); std::cout << "Building took: " << (tack - tick) / 1e6 << " sec" << std::endl; // Print matrix info mat.Info(); // Initialize solver tolerances ls.Init(1e-8, 1e-8, 1e+8, 10000); // Set verbosity output ls.Verbose(2); // Start time measurement tick = rocalution_time(); // Solve A x = rhs ls.Solve(rhs, &x); // Stop time measurement tack = rocalution_time(); std::cout << "Solver took: " << (tack - tick) / 1e6 << " sec" << std::endl; // Clear solver ls.Clear(); // Compute error L2 norm e.ScaleAdd(-1.0, x); double error = e.Norm(); std::cout << "||e - x||_2 = " << error << std::endl; // Stop time measurement end = rocalution_time(); std::cout << "Total runtime: " << (end - start) / 1e6 << " sec" << std::endl; // Stop rocALUTION platform stop_rocalution(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/cg-saamg_mpi.cpp000066400000000000000000000110671507377332500224520ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2023 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "common.hpp" #include "utility.hpp" #include #include #include using namespace rocalution; int main(int argc, char* argv[]) { // Initialize MPI MPI_Init(&argc, &argv); MPI_Comm comm = MPI_COMM_WORLD; int rank; int num_procs; MPI_Comm_rank(comm, &rank); MPI_Comm_size(comm, &num_procs); if(argc < 2) { std::cerr << argv[0] << " " << std::endl; return -1; } // Disable OpenMP thread affinity set_omp_affinity_rocalution(false); // Initialize platform with rank and # of accelerator devices in the node init_rocalution(rank, 8); // Disable OpenMP set_omp_threads_rocalution(1); // Print rocALUTION info info_rocalution(); // Load undistributed matrix LocalMatrix lmat; lmat.ReadFileMTX(argv[1]); // Global structures ParallelManager manager; GlobalMatrix mat; // Distribute matrix - lmat will be destroyed distribute_matrix(&comm, &lmat, &mat, &manager); // rocALUTION vectors GlobalVector rhs(manager); GlobalVector x(manager); GlobalVector e(manager); // Move objects to accelerator mat.MoveToAccelerator(); x.MoveToAccelerator(); rhs.MoveToAccelerator(); e.MoveToAccelerator(); // Start time measurement double tick, tack, start, end; start = rocalution_time(); // Allocate vectors x.Allocate("x", mat.GetN()); rhs.Allocate("rhs", mat.GetM()); e.Allocate("e", mat.GetN()); // Initialize rhs such that A 1 = rhs e.Ones(); mat.Apply(e, &rhs); // Initial zero guess x.Zeros(); // Start time measurement tick = rocalution_time(); // Linear Solver CG, GlobalVector, double> ls; // AMG Preconditioner SAAMG, GlobalVector, double> p; p.SetCoarseningStrategy(CoarseningStrategy::PMIS); p.SetLumpingStrategy(LumpingStrategy::AddWeakConnections); p.SetCoarsestLevel(2); p.SetCouplingStrength(0.001); // Disable verbosity output of AMG preconditioner p.Verbose(0); // Set solver preconditioner ls.SetPreconditioner(p); // Set solver operator ls.SetOperator(mat); // Build solver ls.Build(); // Compute 2 coarsest levels on the host p.SetHostLevels(2); // Stop time measurement tack = rocalution_time(); if(rank == 0) { std::cout << "Building took: " << (tack - tick) / 1e6 << " sec" << std::endl; } // Print matrix info mat.Info(); // Initialize solver tolerances ls.Init(1e-8, 1e-8, 1e+8, 10000); // Set verbosity output ls.Verbose(2); // Start time measurement tick = rocalution_time(); // Solve A x = rhs ls.Solve(rhs, &x); // Stop time measurement tack = rocalution_time(); if(rank == 0) { std::cout << "Solver took: " << (tack - tick) / 1e6 << " sec" << std::endl; } // Clear solver ls.Clear(); // Compute error L2 norm e.ScaleAdd(-1.0, x); double error = e.Norm(); if(rank == 0) { std::cout << "||e - x||_2 = " << error << std::endl; } // Stop rocALUTION platform stop_rocalution(); MPI_Finalize(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/cg-uaamg_mpi.cpp000066400000000000000000000107701507377332500224540ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2023 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "common.hpp" #include "utility.hpp" #include #include #include using namespace rocalution; int main(int argc, char* argv[]) { // Initialize MPI MPI_Init(&argc, &argv); MPI_Comm comm = MPI_COMM_WORLD; int rank; int num_procs; MPI_Comm_rank(comm, &rank); MPI_Comm_size(comm, &num_procs); if(argc < 2) { std::cerr << argv[0] << " " << std::endl; return -1; } // Disable OpenMP thread affinity set_omp_affinity_rocalution(false); // Initialize platform with rank and # of accelerator devices in the node init_rocalution(rank, 8); // Disable OpenMP set_omp_threads_rocalution(1); // Print rocALUTION info info_rocalution(); // Load undistributed matrix LocalMatrix lmat; lmat.ReadFileMTX(argv[1]); // Global structures ParallelManager manager; GlobalMatrix mat; // Distribute matrix - lmat will be destroyed distribute_matrix(&comm, &lmat, &mat, &manager); // rocALUTION vectors GlobalVector rhs(manager); GlobalVector x(manager); GlobalVector e(manager); // Move objects to accelerator mat.MoveToAccelerator(); x.MoveToAccelerator(); rhs.MoveToAccelerator(); e.MoveToAccelerator(); // Start time measurement double tick, tack, start, end; start = rocalution_time(); // Allocate vectors x.Allocate("x", mat.GetN()); rhs.Allocate("rhs", mat.GetM()); e.Allocate("e", mat.GetN()); // Initialize rhs such that A 1 = rhs e.Ones(); mat.Apply(e, &rhs); // Initial zero guess x.Zeros(); // Start time measurement tick = rocalution_time(); // Linear Solver CG, GlobalVector, double> ls; // AMG Preconditioner UAAMG, GlobalVector, double> p; p.SetCoarseningStrategy(CoarseningStrategy::PMIS); p.SetCoarsestLevel(2); p.SetCouplingStrength(0.001); // Disable verbosity output of AMG preconditioner p.Verbose(0); // Set solver preconditioner ls.SetPreconditioner(p); // Set solver operator ls.SetOperator(mat); // Build solver ls.Build(); // Compute 2 coarsest levels on the host p.SetHostLevels(2); // Stop time measurement tack = rocalution_time(); if(rank == 0) { std::cout << "Building took: " << (tack - tick) / 1e6 << " sec" << std::endl; } // Print matrix info mat.Info(); // Initialize solver tolerances ls.Init(1e-8, 1e-8, 1e+8, 10000); // Set verbosity output ls.Verbose(2); // Start time measurement tick = rocalution_time(); // Solve A x = rhs ls.Solve(rhs, &x); // Stop time measurement tack = rocalution_time(); if(rank == 0) { std::cout << "Solver took: " << (tack - tick) / 1e6 << " sec" << std::endl; } // Clear solver ls.Clear(); // Compute error L2 norm e.ScaleAdd(-1.0, x); double error = e.Norm(); if(rank == 0) { std::cout << "||e - x||_2 = " << error << std::endl; } // Stop rocALUTION platform stop_rocalution(); MPI_Finalize(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/cg.cpp000066400000000000000000000065171507377332500205230ustar00rootroot00000000000000/* ************************************************************************ * 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 #include #include using namespace rocalution; int main(int argc, char* argv[]) { // Check command line parameters if(argc == 1) { std::cerr << argv[0] << " [Num threads]" << std::endl; exit(1); } // Initialize rocALUTION init_rocalution(); // Check command line parameters for number of OMP threads if(argc > 2) { set_omp_threads_rocalution(atoi(argv[2])); } // Print rocALUTION info info_rocalution(); // rocALUTION objects LocalVector x; LocalVector rhs; LocalVector e; LocalMatrix mat; // Read matrix from MTX file mat.ReadFileMTX(std::string(argv[1])); // Move objects to accelerator mat.MoveToAccelerator(); x.MoveToAccelerator(); rhs.MoveToAccelerator(); e.MoveToAccelerator(); // Allocate vectors x.Allocate("x", mat.GetN()); rhs.Allocate("rhs", mat.GetM()); e.Allocate("e", mat.GetN()); // Linear Solver CG, LocalVector, double> ls; // Preconditioner Jacobi, LocalVector, double> p; // Initialize rhs such that A 1 = rhs e.Ones(); mat.Apply(e, &rhs); // Initial zero guess x.Zeros(); // Set solver operator ls.SetOperator(mat); // Set solver preconditioner ls.SetPreconditioner(p); // Build solver ls.Build(); // Verbosity output ls.Verbose(1); // Print matrix info mat.Info(); // Start time measurement double tick, tack; tick = rocalution_time(); // Solve A x = rhs ls.Solve(rhs, &x); // Stop time measurement tack = rocalution_time(); std::cout << "Solver execution:" << (tack - tick) / 1e6 << " sec" << std::endl; // Clear solver ls.Clear(); // Compute error L2 norm e.ScaleAdd(-1.0, x); double error = e.Norm(); std::cout << "||e - x||_2 = " << error << std::endl; // Stop rocALUTION platform stop_rocalution(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/cg_mpi.cpp000066400000000000000000000067431507377332500213710ustar00rootroot00000000000000/* ************************************************************************ * 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 "common.hpp" #include #include #include #define ValueType double using namespace rocalution; int main(int argc, char* argv[]) { // Initialize MPI MPI_Init(&argc, &argv); MPI_Comm comm = MPI_COMM_WORLD; int rank; int num_procs; MPI_Comm_rank(comm, &rank); MPI_Comm_size(comm, &num_procs); if(argc < 2) { std::cerr << argv[0] << " " << std::endl; return -1; } // Disable OpenMP thread affinity set_omp_affinity_rocalution(false); // Initialize platform with rank and # of accelerator devices in the node init_rocalution(rank, 2); // Disable OpenMP set_omp_threads_rocalution(1); // Print platform info_rocalution(); // Load undistributed matrix LocalMatrix lmat; lmat.ReadFileMTX(argv[1]); // Global structures ParallelManager manager; GlobalMatrix mat; // Distribute matrix - lmat will be destroyed distribute_matrix(&comm, &lmat, &mat, &manager); // rocALUTION vectors GlobalVector rhs(manager); GlobalVector x(manager); GlobalVector e(manager); // Move structures to accelerator, if available mat.MoveToAccelerator(); rhs.MoveToAccelerator(); x.MoveToAccelerator(); e.MoveToAccelerator(); // Allocate memory rhs.Allocate("rhs", mat.GetM()); x.Allocate("x", mat.GetN()); e.Allocate("sol", mat.GetN()); e.Ones(); mat.Apply(e, &rhs); x.Zeros(); CG, GlobalVector, double> ls; Jacobi, GlobalVector, double> p; ls.SetPreconditioner(p); ls.SetOperator(mat); ls.Build(); ls.Verbose(1); mat.Info(); double time = rocalution_time(); ls.Solve(rhs, &x); time = rocalution_time() - time; if(rank == 0) { std::cout << "Solving: " << time / 1e6 << " sec" << std::endl; } e.ScaleAdd(-1.0, x); double nrm2 = e.Norm(); if(rank == 0) { std::cout << "||e - x||_2 = " << nrm2 << std::endl; } ls.Clear(); stop_rocalution(); MPI_Finalize(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/cmk.cpp000066400000000000000000000070411507377332500206750ustar00rootroot00000000000000/* ************************************************************************ * 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 #include #include using namespace rocalution; int main(int argc, char* argv[]) { // Check command line parameters if(argc == 1) { std::cerr << argv[0] << " [Num threads]" << std::endl; exit(1); } // Initialize rocALUTION init_rocalution(); // Check command line parameters for number of OMP threads if(argc > 2) { set_omp_threads_rocalution(atoi(argv[2])); } // Print rocALUTION info info_rocalution(); // rocALUTION objects LocalVector x; LocalVector rhs; LocalVector e; LocalMatrix mat; // Read matrix from MTX file mat.ReadFileMTX(std::string(argv[1])); // Compute (R)CMK ordering LocalVector cmk; // mat.CMK(&cmk); mat.RCMK(&cmk); // Move objects to accelerator mat.MoveToAccelerator(); x.MoveToAccelerator(); rhs.MoveToAccelerator(); cmk.MoveToAccelerator(); e.MoveToAccelerator(); // Apply (R)CMK ordering mat.Permute(cmk); // Allocate vectors x.Allocate("x", mat.GetN()); rhs.Allocate("rhs", mat.GetM()); e.Allocate("e", mat.GetN()); // Linear Solver CG, LocalVector, double> ls; // Preconditioner ILU, LocalVector, double> p; // Initialize rhs such that A 1 = rhs e.Ones(); mat.Apply(e, &rhs); // Initial zero guess x.Zeros(); // Set solver operator ls.SetOperator(mat); // Set solver preconditioner ls.SetPreconditioner(p); // Build solver ls.Build(); // Print matrix info mat.Info(); // Start time measurement double tick, tack; tick = rocalution_time(); // Solve A x = rhs ls.Solve(rhs, &x); // Stop time measurement tack = rocalution_time(); std::cout << "Solver execution:" << (tack - tick) / 1e6 << " sec" << std::endl; // Revert CMK ordering on solution vector x.PermuteBackward(cmk); // Clear solver ls.Clear(); // Compute error L2 norm e.ScaleAdd(-1.0, x); double error = e.Norm(); std::cout << "||e - x||_2 = " << error << std::endl; // Stop rocALUTION platform stop_rocalution(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/complex.cpp000066400000000000000000000072171507377332500215770ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF 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 using namespace rocalution; int main(int argc, char* argv[]) { // Check command line parameters if(argc == 1) { std::cerr << argv[0] << " [Num threads]" << std::endl; exit(1); } // Initialize rocALUTION init_rocalution(); // Check command line parameters for number of OMP threads if(argc > 2) { set_omp_threads_rocalution(atoi(argv[2])); } // Print rocALUTION info info_rocalution(); // rocALUTION objects LocalVector> x; LocalVector> rhs; LocalVector> e; LocalMatrix> mat; // Read matrix from MTX file mat.ReadFileMTX(std::string(argv[1])); // Move objects to accelerator mat.MoveToAccelerator(); x.MoveToAccelerator(); rhs.MoveToAccelerator(); // Allocate vectors x.Allocate("x", mat.GetN()); rhs.Allocate("rhs", mat.GetM()); e.Allocate("e", mat.GetN()); // Initialize e with some values for(int i = 0; i < mat.GetN(); ++i) e[i] = std::complex(1.0, -1.0); e.MoveToAccelerator(); // Linear Solver IDR>, LocalVector>, std::complex> ls; // Preconditioner Jacobi>, LocalVector>, std::complex> p; // Initialize rhs such that A 1 = rhs mat.Apply(e, &rhs); // Initial zero guess x.Zeros(); // Set solver operator ls.SetOperator(mat); // Set solver preconditioner ls.SetPreconditioner(p); // Build solver ls.Build(); // Verbosity output ls.Verbose(1); // Print matrix info mat.Info(); // Start time measurement double tick, tack; tick = rocalution_time(); // Solve A x = rhs ls.Solve(rhs, &x); // Stop time measurement tack = rocalution_time(); std::cout << "Solver execution:" << (tack - tick) / 1e6 << " sec" << std::endl; // Clear solver ls.Clear(); // Compute error L2 norm e.ScaleAdd(-1.0, x); std::complex error = e.Norm(); std::cout << "||e - x||_2 = " << error << std::endl; // Stop rocALUTION platform stop_rocalution(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/direct.cpp000066400000000000000000000057311507377332500214010ustar00rootroot00000000000000/* ************************************************************************ * 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 #include #include using namespace rocalution; int main(int argc, char* argv[]) { // Check command line parameters if(argc == 1) { std::cerr << argv[0] << " " << std::endl; exit(1); } // Initialize rocALUTION init_rocalution(); // Print rocALUTION info info_rocalution(); // rocALUTION objects LocalVector x; LocalVector rhs; LocalVector e; LocalMatrix mat; // Read matrix from MTX file mat.ReadFileMTX(std::string(argv[1])); // Move objects to accelerator // mat.MoveToAccelerator(); // x.MoveToAccelerator(); // rhs.MoveToAccelerator(); // e.MoveToAccelerator(); // Allocate vectors x.Allocate("x", mat.GetN()); rhs.Allocate("rhs", mat.GetM()); e.Allocate("e", mat.GetN()); // Direct solver Inversion, LocalVector, double> ds; // Initialize rhs such that A 1 = rhs e.Ones(); mat.Apply(e, &rhs); // Set solver operator ds.SetOperator(mat); // Build solver ds.Build(); // Print matrix info mat.Info(); // Start time measurement double tick, tack; tick = rocalution_time(); // Solve A x = rhs ds.Solve(rhs, &x); // Stop time measurement tack = rocalution_time(); std::cout << "Solver execution:" << (tack - tick) / 1e6 << " sec" << std::endl; // Clear solver ds.Clear(); // Compute error L2 norm e.ScaleAdd(-1.0, x); double error = e.Norm(); std::cout << "||e - x||_2 = " << error << std::endl; // Stop rocALUTION platform stop_rocalution(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/fcg.cpp000066400000000000000000000065071507377332500206700ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF 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 using namespace rocalution; int main(int argc, char* argv[]) { // Check command line parameters if(argc == 1) { std::cerr << argv[0] << " [Num threads]" << std::endl; exit(1); } // Initialize rocALUTION init_rocalution(); // Check command line parameters for number of OMP threads if(argc > 2) { set_omp_threads_rocalution(atoi(argv[2])); } // Print rocALUTION info info_rocalution(); // rocALUTION objects LocalVector x; LocalVector rhs; LocalVector e; LocalMatrix mat; // Read matrix from MTX file mat.ReadFileMTX(std::string(argv[1])); // Move objects to accelerator mat.MoveToAccelerator(); x.MoveToAccelerator(); rhs.MoveToAccelerator(); e.MoveToAccelerator(); // Allocate vectors x.Allocate("x", mat.GetN()); rhs.Allocate("rhs", mat.GetM()); e.Allocate("e", mat.GetN()); // Linear Solver FCG, LocalVector, double> ls; // Preconditioner IC, LocalVector, double> p; // Initialize rhs such that A 1 = rhs e.Ones(); mat.Apply(e, &rhs); // Initial zero guess x.Zeros(); // Set solver operator ls.SetOperator(mat); // Set solver preconditioner ls.SetPreconditioner(p); // Build solver ls.Build(); // Verbosity output ls.Verbose(1); // Print matrix info mat.Info(); // Start time measurement double tick, tack; tick = rocalution_time(); // Solve A x = rhs ls.Solve(rhs, &x); // Stop time measurement tack = rocalution_time(); std::cout << "Solver execution:" << (tack - tick) / 1e6 << " sec" << std::endl; // Clear solver ls.Clear(); // Compute error L2 norm e.ScaleAdd(-1.0, x); double error = e.Norm(); std::cout << "||e - x||_2 = " << error << std::endl; // Stop rocALUTION platform stop_rocalution(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/fcg_mpi.cpp000066400000000000000000000073511507377332500215330ustar00rootroot00000000000000/* ************************************************************************ * 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 "common.hpp" #include #include #include #define ValueType double using namespace rocalution; int main(int argc, char* argv[]) { // Initialize MPI MPI_Init(&argc, &argv); MPI_Comm comm = MPI_COMM_WORLD; int rank; int num_procs; MPI_Comm_rank(comm, &rank); MPI_Comm_size(comm, &num_procs); // Check command line parameters if(num_procs < 2) { std::cerr << "Expecting at least 2 MPI processes" << std::endl; return -1; } if(argc < 2) { std::cerr << argv[0] << " " << std::endl; return -1; } // Disable OpenMP thread affinity set_omp_affinity_rocalution(false); // Initialize platform with rank and # of accelerator devices in the node init_rocalution(rank, 2); // Disable OpenMP set_omp_threads_rocalution(1); // Print platform info_rocalution(); // Load undistributed matrix LocalMatrix lmat; lmat.ReadFileMTX(argv[1]); // Global structures ParallelManager manager; GlobalMatrix mat; // Distribute matrix - lmat will be destroyed distribute_matrix(&comm, &lmat, &mat, &manager); // rocALUTION vectors GlobalVector rhs(manager); GlobalVector x(manager); GlobalVector e(manager); // Move structures to accelerator, if available mat.MoveToAccelerator(); rhs.MoveToAccelerator(); x.MoveToAccelerator(); e.MoveToAccelerator(); // Allocate memory rhs.Allocate("rhs", mat.GetM()); x.Allocate("x", mat.GetN()); e.Allocate("sol", mat.GetN()); e.Ones(); mat.Apply(e, &rhs); x.Zeros(); FCG, GlobalVector, double> ls; BlockJacobi, GlobalVector, double> bj; ILU, LocalVector, double> p; bj.Set(p); ls.SetPreconditioner(bj); ls.SetOperator(mat); ls.Build(); ls.Verbose(1); mat.Info(); double time = rocalution_time(); ls.Solve(rhs, &x); time = rocalution_time() - time; if(rank == 0) { std::cout << "Solving: " << time / 1e6 << " sec" << std::endl; } e.ScaleAdd(-1.0, x); double nrm2 = e.Norm(); if(rank == 0) { std::cout << "||e - x||_2 = " << nrm2 << std::endl; } ls.Clear(); stop_rocalution(); MPI_Finalize(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/fgmres.cpp000066400000000000000000000066221507377332500214120ustar00rootroot00000000000000/* ************************************************************************ * 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 #include #include using namespace rocalution; int main(int argc, char* argv[]) { // Check command line parameters if(argc == 1) { std::cerr << argv[0] << " [Num threads]" << std::endl; exit(1); } // Initialize rocALUTION init_rocalution(); // Check command line parameters for number of OMP threads if(argc > 2) { set_omp_threads_rocalution(atoi(argv[2])); } // Print rocALUTION info info_rocalution(); // rocALUTION objects LocalVector x; LocalVector rhs; LocalVector e; LocalMatrix mat; // Read matrix from MTX file mat.ReadFileMTX(std::string(argv[1])); // Move objects to accelerator mat.MoveToAccelerator(); x.MoveToAccelerator(); rhs.MoveToAccelerator(); e.MoveToAccelerator(); // Allocate vectors x.Allocate("x", mat.GetN()); rhs.Allocate("rhs", mat.GetM()); e.Allocate("e", mat.GetN()); // Linear Solver FGMRES, LocalVector, double> ls; // Preconditioner MultiColoredGS, LocalVector, double> p; // Initialize rhs such that A 1 = rhs e.Ones(); mat.Apply(e, &rhs); // Initial zero guess x.Zeros(); // Set solver operator ls.SetOperator(mat); // Set solver preconditioner ls.SetPreconditioner(p); // Set FGMRES basis size ls.SetBasisSize(15); // Build solver ls.Build(); // Verbosity output ls.Verbose(1); // Print matrix info mat.Info(); // Start time measurement double tick, tack; tick = rocalution_time(); // Solve A x = rhs ls.Solve(rhs, &x); // Stop time measurement tack = rocalution_time(); std::cout << "Solver execution:" << (tack - tick) / 1e6 << " sec" << std::endl; // Clear solver ls.Clear(); // Compute error L2 norm e.ScaleAdd(-1.0, x); double error = e.Norm(); std::cout << "||e - x||_2 = " << error << std::endl; // Stop rocALUTION platform stop_rocalution(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/fgmres_mpi.cpp000066400000000000000000000073511507377332500222570ustar00rootroot00000000000000/* ************************************************************************ * 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 "common.hpp" #include #include #include #define ValueType double using namespace rocalution; int main(int argc, char* argv[]) { // Initialize MPI MPI_Init(&argc, &argv); MPI_Comm comm = MPI_COMM_WORLD; int rank; int num_procs; MPI_Comm_rank(comm, &rank); MPI_Comm_size(comm, &num_procs); // Check command line parameters if(num_procs < 2) { std::cerr << "Expecting at least 2 MPI processes" << std::endl; return -1; } if(argc < 2) { std::cerr << argv[0] << " " << std::endl; return -1; } // Disable OpenMP thread affinity set_omp_affinity_rocalution(false); // Initialize platform with rank and # of accelerator devices in the node init_rocalution(rank, 2); // Disable OpenMP set_omp_threads_rocalution(1); // Print platform info_rocalution(); // Load undistributed matrix LocalMatrix lmat; lmat.ReadFileMTX(argv[1]); // Global structures ParallelManager manager; GlobalMatrix mat; // Distribute matrix - lmat will be destroyed distribute_matrix(&comm, &lmat, &mat, &manager); // rocALUTION vectors GlobalVector rhs(manager); GlobalVector x(manager); GlobalVector e(manager); // Move structures to accelerator, if available mat.MoveToAccelerator(); rhs.MoveToAccelerator(); x.MoveToAccelerator(); e.MoveToAccelerator(); // Allocate memory rhs.Allocate("rhs", mat.GetM()); x.Allocate("x", mat.GetN()); e.Allocate("sol", mat.GetN()); e.Ones(); mat.Apply(e, &rhs); x.Zeros(); FGMRES, GlobalVector, double> ls; BlockJacobi, GlobalVector, double> bj; SPAI, LocalVector, double> p; bj.Set(p); ls.SetPreconditioner(bj); ls.SetOperator(mat); ls.Build(); ls.Verbose(1); mat.Info(); double time = rocalution_time(); ls.Solve(rhs, &x); time = rocalution_time() - time; if(rank == 0) { std::cout << "Solving: " << time / 1e6 << " sec" << std::endl; } e.ScaleAdd(-1.0, x); double nrm2 = e.Norm(); if(rank == 0) { std::cout << "||e - x||_2 = " << nrm2 << std::endl; } ls.Clear(); stop_rocalution(); MPI_Finalize(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/fixed-point.cpp000066400000000000000000000072621507377332500223560ustar00rootroot00000000000000/* ************************************************************************ * 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 #include #include using namespace rocalution; int main(int argc, char* argv[]) { // Check command line parameters if(argc == 1) { std::cerr << argv[0] << " [Num threads]" << std::endl; exit(1); } // Initialize rocALUTION init_rocalution(); // Check command line parameters for number of OMP threads if(argc > 2) { set_omp_threads_rocalution(atoi(argv[2])); } // Print rocALUTION info info_rocalution(); // rocALUTION objects LocalVector x; LocalVector rhs; LocalVector e; LocalMatrix mat; // Read matrix from MTX file mat.ReadFileMTX(std::string(argv[1])); // Move objects to accelerator mat.MoveToAccelerator(); rhs.MoveToAccelerator(); x.MoveToAccelerator(); e.MoveToAccelerator(); // Allocate vectors x.Allocate("x", mat.GetN()); rhs.Allocate("rhs", mat.GetM()); e.Allocate("e", mat.GetN()); // Linear Solver FixedPoint, LocalVector, double> fp; Jacobi, LocalVector, double> p; // MultiColoredILU, LocalVector, double > p; // ILU, LocalVector, double > p; // MultiColoredGS, LocalVector, double > p; // MultiColoredSGS, LocalVector, double > p; // Initialize rhs such that A 1 = rhs e.Ones(); mat.Apply(e, &rhs); // Initial zero guess x.Zeros(); // Set solver operator fp.SetOperator(mat); // Set solver preconditioner fp.SetPreconditioner(p); // Set relaxation parameter omega fp.SetRelaxation(2. / 3.); // Verbosity output fp.Verbose(1); // Build solver fp.Build(); // Print matrix info mat.Info(); // Start time measurement double tick, tack; tick = rocalution_time(); // Solve A x = rhs fp.Solve(rhs, &x); // Stop time measurement tack = rocalution_time(); std::cout << "Solver execution:" << (tack - tick) / 1e6 << " sec" << std::endl; // Clear solver fp.Clear(); // Compute error L2 norm e.ScaleAdd(-1.0, x); double error = e.Norm(); std::cout << "||e - x||_2 = " << error << std::endl; // Stop rocALUTION platform stop_rocalution(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/global-io_mpi.cpp000066400000000000000000000072031507377332500226350ustar00rootroot00000000000000/* ************************************************************************ * 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 #include #include using namespace rocalution; int main(int argc, char* argv[]) { if(argc < 2) { std::cerr << argv[0] << " " << std::endl; exit(1); } // Initialize MPI MPI_Init(&argc, &argv); MPI_Comm comm = MPI_COMM_WORLD; int rank; int num_procs; MPI_Comm_rank(comm, &rank); MPI_Comm_size(comm, &num_procs); if(num_procs < 2) { std::cerr << "Expecting more than 1 MPI process\n"; MPI_Finalize(); return -1; } // Disable OpenMP thread affinity set_omp_affinity_rocalution(false); // Initialize platform with rank and # of accelerator devices in the node init_rocalution(rank, 2); // Disable OpenMP set_omp_threads_rocalution(1); // Print platform info_rocalution(); // Parallel Manager ParallelManager pm; // Initialize Parallel Manager pm.SetMPICommunicator(&comm); // Read Parallel Manager from file pm.ReadFileASCII(std::string(argv[1])); // Create global structures GlobalMatrix mat(pm); GlobalVector rhs(pm); GlobalVector x(pm); GlobalVector e(pm); // Move structures to accelerator, if available mat.MoveToAccelerator(); rhs.MoveToAccelerator(); x.MoveToAccelerator(); e.MoveToAccelerator(); // Read from file mat.ReadFileMTX(std::string(argv[2])); rhs.Allocate("rhs", mat.GetM()); x.Allocate("x", mat.GetN()); e.Allocate("sol", mat.GetN()); e.Ones(); mat.Apply(e, &rhs); x.Zeros(); CG, GlobalVector, double> ls; BlockJacobi, GlobalVector, double> bj; FSAI, LocalVector, double> p; bj.Set(p); ls.SetPreconditioner(bj); ls.SetOperator(mat); ls.Build(); ls.Verbose(1); mat.Info(); double time = rocalution_time(); ls.Solve(rhs, &x); time = rocalution_time() - time; if(rank == 0) { std::cout << "Solving: " << time / 1e6 << " sec" << std::endl; } e.ScaleAdd(-1.0, x); double nrm2 = e.Norm(); if(rank == 0) { std::cout << "||e - x||_2 = " << nrm2 << std::endl; } ls.Clear(); stop_rocalution(); MPI_Finalize(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/gmres.cpp000066400000000000000000000066201507377332500212420ustar00rootroot00000000000000/* ************************************************************************ * 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 #include #include using namespace rocalution; int main(int argc, char* argv[]) { // Check command line parameters if(argc == 1) { std::cerr << argv[0] << " [Num threads]" << std::endl; exit(1); } // Initialize rocALUTION init_rocalution(); // Check command line parameters for number of OMP threads if(argc > 2) { set_omp_threads_rocalution(atoi(argv[2])); } // Print rocALUTION info info_rocalution(); // rocALUTION objects LocalVector x; LocalVector rhs; LocalVector e; LocalMatrix mat; // Read matrix from MTX file mat.ReadFileMTX(std::string(argv[1])); // Move objects to accelerator mat.MoveToAccelerator(); x.MoveToAccelerator(); rhs.MoveToAccelerator(); e.MoveToAccelerator(); // Allocate vectors x.Allocate("x", mat.GetN()); rhs.Allocate("rhs", mat.GetM()); e.Allocate("e", mat.GetN()); // Linear Solver GMRES, LocalVector, double> ls; // Preconditioner MultiColoredGS, LocalVector, double> p; // Initialize rhs such that A 1 = rhs e.Ones(); mat.Apply(e, &rhs); // Initial zero guess x.Zeros(); // Set solver operator ls.SetOperator(mat); // Set solver preconditioner ls.SetPreconditioner(p); // Set GMRES basis size ls.SetBasisSize(15); // Build solver ls.Build(); // Verbosity output ls.Verbose(1); // Print matrix info mat.Info(); // Start time measurement double tick, tack; tick = rocalution_time(); // Solve A x = rhs ls.Solve(rhs, &x); // Stop time measurement tack = rocalution_time(); std::cout << "Solver execution:" << (tack - tick) / 1e6 << " sec" << std::endl; // Clear solver ls.Clear(); // Compute error L2 norm e.ScaleAdd(-1.0, x); double error = e.Norm(); std::cout << "||e - x||_2 = " << error << std::endl; // Stop rocALUTION platform stop_rocalution(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/idr.cpp000066400000000000000000000067041507377332500207060ustar00rootroot00000000000000/* ************************************************************************ * 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 #include #include using namespace rocalution; int main(int argc, char* argv[]) { // Check command line parameters if(argc == 1) { std::cerr << argv[0] << " [Num threads]" << std::endl; exit(1); } // Initialize rocALUTION init_rocalution(); // Check command line parameters for number of OMP threads if(argc > 2) { set_omp_threads_rocalution(atoi(argv[2])); } // Print rocALUTION info info_rocalution(); // rocALUTION objects LocalVector x; LocalVector rhs; LocalVector e; LocalMatrix mat; // Read matrix from MTX file mat.ReadFileMTX(std::string(argv[1])); // Move objects to accelerator mat.MoveToAccelerator(); x.MoveToAccelerator(); rhs.MoveToAccelerator(); e.MoveToAccelerator(); // Allocate vectors x.Allocate("x", mat.GetN()); rhs.Allocate("rhs", mat.GetM()); e.Allocate("e", mat.GetN()); // Linear Solver IDR, LocalVector, double> ls; // Preconditioner Jacobi, LocalVector, double> p; // Initialize rhs such that A 1 = rhs e.Ones(); mat.Apply(e, &rhs); // Initial zero guess x.Zeros(); // Set solver operator ls.SetOperator(mat); // Set solver preconditioner ls.SetPreconditioner(p); // Set IDR shadow space ls.SetShadowSpace(4); // Set IDR random seed ls.SetRandomSeed(123456ULL); // Build solver ls.Build(); // Verbosity output ls.Verbose(1); // Print matrix info mat.Info(); // Start time measurement double tick, tack; tick = rocalution_time(); // Solve A x = rhs ls.Solve(rhs, &x); // Stop time measurement tack = rocalution_time(); std::cout << "Solver execution:" << (tack - tick) / 1e6 << " sec" << std::endl; // Clear solver ls.Clear(); // Compute error L2 norm e.ScaleAdd(-1.0, x); double error = e.Norm(); std::cout << "||e - x||_2 = " << error << std::endl; // Stop rocALUTION platform stop_rocalution(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/idr_mpi.cpp000066400000000000000000000073511507377332500215520ustar00rootroot00000000000000/* ************************************************************************ * 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 "common.hpp" #include #include #include #define ValueType double using namespace rocalution; int main(int argc, char* argv[]) { // Initialize MPI MPI_Init(&argc, &argv); MPI_Comm comm = MPI_COMM_WORLD; int rank; int num_procs; MPI_Comm_rank(comm, &rank); MPI_Comm_size(comm, &num_procs); // Check command line parameters if(num_procs < 2) { std::cerr << "Expecting at least 2 MPI processes" << std::endl; return -1; } if(argc < 2) { std::cerr << argv[0] << " " << std::endl; return -1; } // Disable OpenMP thread affinity set_omp_affinity_rocalution(false); // Initialize platform with rank and # of accelerator devices in the node init_rocalution(rank, 2); // Disable OpenMP set_omp_threads_rocalution(1); // Print platform info_rocalution(); // Load undistributed matrix LocalMatrix lmat; lmat.ReadFileMTX(argv[1]); // Global structures ParallelManager manager; GlobalMatrix mat; // Distribute matrix - lmat will be destroyed distribute_matrix(&comm, &lmat, &mat, &manager); // rocALUTION vectors GlobalVector rhs(manager); GlobalVector x(manager); GlobalVector e(manager); // Move structures to accelerator, if available mat.MoveToAccelerator(); rhs.MoveToAccelerator(); x.MoveToAccelerator(); e.MoveToAccelerator(); // Allocate memory rhs.Allocate("rhs", mat.GetM()); x.Allocate("x", mat.GetN()); e.Allocate("sol", mat.GetN()); e.Ones(); mat.Apply(e, &rhs); x.Zeros(); IDR, GlobalVector, double> ls; BlockJacobi, GlobalVector, double> bj; FSAI, LocalVector, double> p; bj.Set(p); ls.SetPreconditioner(bj); ls.SetOperator(mat); ls.Build(); ls.Verbose(1); mat.Info(); double time = rocalution_time(); ls.Solve(rhs, &x); time = rocalution_time() - time; if(rank == 0) { std::cout << "Solving: " << time / 1e6 << " sec" << std::endl; } e.ScaleAdd(-1.0, x); double nrm2 = e.Norm(); if(rank == 0) { std::cout << "||e - x||_2 = " << nrm2 << std::endl; } ls.Clear(); stop_rocalution(); MPI_Finalize(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/itsolve.cpp000066400000000000000000000112351507377332500216100ustar00rootroot00000000000000/* ************************************************************************ * 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 #include #include using namespace rocalution; int main(int argc, char* argv[]) { // Check command line parameters if(argc == 1) { std::cerr << argv[0] << " [Num threads]" << std::endl; exit(1); } // Initialize rocALUTION init_rocalution(); // Check command line parameters for number of OMP threads if(argc > 2) { set_omp_threads_rocalution(atoi(argv[2])); } // Print rocALUTION info info_rocalution(); // rocALUTION objects LocalVector x; LocalVector rhs; LocalVector e; LocalMatrix mat; // Read matrix from MTX file mat.ReadFileMTX(std::string(argv[1])); // Move objects to accelerator mat.MoveToAccelerator(); x.MoveToAccelerator(); rhs.MoveToAccelerator(); e.MoveToAccelerator(); // Allocate vectors x.Allocate("x", mat.GetN()); rhs.Allocate("rhs", mat.GetM()); e.Allocate("e", mat.GetN()); // Linear Solver FixedPoint, LocalVector, double> fp; // Preconditioner ItILU0, LocalVector, double> p; // Set iterative ILU stopping criteria p.SetTolerance(1e-8); p.SetMaxIter(50); const int option = ItILU0Option::Verbose | ItILU0Option::StoppingCriteria | ItILU0Option::ComputeNrmCorrection | ItILU0Option::ComputeNrmResidual | ItILU0Option::ConvergenceHistory; p.SetOptions(option); p.SetAlgorithm(ItILU0Algorithm::SyncSplit); // Set up iterative triangular solve SolverDescr descr; descr.SetTriSolverAlg(TriSolverAlg_Iterative); descr.SetIterativeSolverMaxIteration(30); descr.SetIterativeSolverTolerance(1e-8); p.SetSolverDescriptor(descr); // Initialize rhs such that A 1 = rhs e.Ones(); mat.Apply(e, &rhs); // Initial zero guess x.Zeros(); // Set solver operator fp.SetOperator(mat); // Set solver preconditioner fp.SetPreconditioner(p); // Build solver fp.Build(); // Verbosity output fp.Verbose(1); // Print matrix info mat.Info(); // Start time measurement double tick, tack; tick = rocalution_time(); // Solve A x = rhs fp.Solve(rhs, &x); // Stop time measurement tack = rocalution_time(); std::cout << "Solver execution:" << (tack - tick) / 1e6 << " sec" << std::endl; int niter_preconditioner; const double* history = p.GetConvergenceHistory(&niter_preconditioner); std::cout << "ItILU0::niter = " << niter_preconditioner << std::endl; if((option & ItILU0Option::ComputeNrmCorrection) > 0) { for(int i = 0; i < niter_preconditioner; ++i) { std::cout << "ItILU0::CorrectionNrm[" << i << "] = " << history[i] << std::endl; } } if((option & ItILU0Option::ComputeNrmResidual) > 0) { for(int i = 0; i < niter_preconditioner; ++i) { std::cout << "ItILU0::ResidualNrm[" << i << "] = " << history[niter_preconditioner + i] << std::endl; } } // Clear solver fp.Clear(); // Compute error L2 norm e.ScaleAdd(-1.0, x); double error = e.Norm(); std::cout << "||e - x||_2 = " << error << std::endl; // Stop rocALUTION platform stop_rocalution(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/key.cpp000066400000000000000000000042121507377332500207100ustar00rootroot00000000000000/* ************************************************************************ * 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 #include using namespace rocalution; int main(int argc, char* argv[]) { // Check command line parameters if(argc == 1) { std::cerr << argv[0] << " " << std::endl; exit(1); } // Initialize rocALUTION init_rocalution(); // rocALUTION objects LocalMatrix mat; // Read matrix from MTX file mat.ReadFileMTX(std::string(argv[1])); // Print matrix info mat.Info(); long int row_key; long int col_key; long int val_key; // Compute keys mat.Key(row_key, col_key, val_key); // Print keys std::cout << "Row key = " << row_key << std::endl << "Col key = " << col_key << std::endl << "Val key = " << val_key << std::endl; // Stop rocALUTION platform stop_rocalution(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/laplace_2d_weak_scaling.cpp000066400000000000000000000104171507377332500246210ustar00rootroot00000000000000/* ************************************************************************ * 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 "common.hpp" #include #include #include #define ValueType double using namespace rocalution; int main(int argc, char* argv[]) { // Initialize MPI MPI_Init(&argc, &argv); MPI_Comm comm = MPI_COMM_WORLD; int rank; int num_procs; MPI_Comm_rank(comm, &rank); MPI_Comm_size(comm, &num_procs); if(argc < 3) { std::cerr << argv[0] << " " << std::endl; return -1; } // Disable OpenMP thread affinity set_omp_affinity_rocalution(false); // Initialize platform with rank and # of accelerator devices in the node init_rocalution(rank, 8); // Disable OpenMP set_omp_threads_rocalution(1); // Print platform info_rocalution(); // Global structures ParallelManager manager; GlobalMatrix mat; // Generate distributed 2D laplacian if(rank == 0) { std::cout << "Generating 2D laplacian..." << std::endl; } generate_2d_laplacian(atoi(argv[1]), atoi(argv[2]), &comm, &mat, &manager, rank, num_procs, 9); // rocALUTION vectors GlobalVector rhs(manager); GlobalVector x(manager); GlobalVector e(manager); // Move structures to accelerator, if available mat.MoveToAccelerator(); rhs.MoveToAccelerator(); x.MoveToAccelerator(); e.MoveToAccelerator(); // Allocate memory rhs.Allocate("rhs", mat.GetM()); x.Allocate("x", mat.GetN()); e.Allocate("sol", mat.GetN()); // Initialize rhs such that A 1 = rhs e.Ones(); mat.Apply(e, &rhs); // Initial zero guess x.Zeros(); // Print matrix info mat.Info(); // Linear solver CG, GlobalVector, ValueType> ls; // Preconditioner RugeStuebenAMG, GlobalVector, ValueType> p; // Disable AMG preconditioner verbosity output p.Verbose(0); p.SetCoarseningStrategy(CoarseningStrategy::PMIS); p.SetInterpolationType(InterpolationType::ExtPI); p.SetCoarsestLevel(20); // Limit operator complexity p.SetInterpolationFF1Limit(false); // Set solver preconditioner ls.SetPreconditioner(p); // Set solver operator ls.SetOperator(mat); // Build solver ls.Build(); // Set verbosity output ls.Verbose(2); // Set host levels (requires solver built) p.SetHostLevels(2); // Start time measurement double time = rocalution_time(); // Solve A x = rhs ls.Solve(rhs, &x); // Stop time measurement time = rocalution_time() - time; if(rank == 0) { std::cout << "Solving: " << time / 1e6 << " sec" << std::endl; } // Compute error L2 norm e.ScaleAdd(-1.0, x); ValueType nrm2 = e.Norm(); if(rank == 0) { std::cout << "||e - x||_2 = " << nrm2 << std::endl; } // Clear solver ls.Clear(); // Stop rocALUTION platform stop_rocalution(); MPI_Finalize(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/laplace_3d_weak_scaling.cpp000066400000000000000000000104501507377332500246170ustar00rootroot00000000000000/* ************************************************************************ * 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 "common.hpp" #include #include #include #define ValueType double using namespace rocalution; int main(int argc, char* argv[]) { // Initialize MPI MPI_Init(&argc, &argv); MPI_Comm comm = MPI_COMM_WORLD; int rank; int num_procs; MPI_Comm_rank(comm, &rank); MPI_Comm_size(comm, &num_procs); if(argc < 4) { std::cerr << argv[0] << " " << std::endl; return -1; } // Disable OpenMP thread affinity set_omp_affinity_rocalution(false); // Initialize platform with rank and # of accelerator devices in the node init_rocalution(rank, 8); // Disable OpenMP set_omp_threads_rocalution(1); // Print platform info_rocalution(); // Global structures ParallelManager manager; GlobalMatrix mat; // Generate distributed 3D laplacian if(rank == 0) { std::cout << "Generating 3D laplacian..." << std::endl; } generate_3d_laplacian( atoi(argv[1]), atoi(argv[2]), atoi(argv[3]), &comm, &mat, &manager, rank, num_procs); // rocALUTION vectors GlobalVector rhs(manager); GlobalVector x(manager); GlobalVector e(manager); // Move structures to accelerator, if available mat.MoveToAccelerator(); rhs.MoveToAccelerator(); x.MoveToAccelerator(); e.MoveToAccelerator(); // Allocate memory rhs.Allocate("rhs", mat.GetM()); x.Allocate("x", mat.GetN()); e.Allocate("sol", mat.GetN()); // Initialize rhs such that A 1 = rhs e.Ones(); mat.Apply(e, &rhs); // Initial zero guess x.Zeros(); // Print matrix info mat.Info(); // Linear solver CG, GlobalVector, ValueType> ls; // Preconditioner RugeStuebenAMG, GlobalVector, ValueType> p; // Disable AMG preconditioner verbosity output p.Verbose(0); p.SetCoarseningStrategy(CoarseningStrategy::PMIS); p.SetInterpolationType(InterpolationType::ExtPI); p.SetCoarsestLevel(20); // Limit operator complexity p.SetInterpolationFF1Limit(false); // Set solver preconditioner ls.SetPreconditioner(p); // Set solver operator ls.SetOperator(mat); // Build solver ls.Build(); // Set verbosity output ls.Verbose(2); // Set host levels (requires solver built) p.SetHostLevels(2); // Start time measurement double time = rocalution_time(); // Solve A x = rhs ls.Solve(rhs, &x); // Stop time measurement time = rocalution_time() - time; if(rank == 0) { std::cout << "Solving: " << time / 1e6 << " sec" << std::endl; } // Compute error L2 norm e.ScaleAdd(-1.0, x); ValueType nrm2 = e.Norm(); if(rank == 0) { std::cout << "||e - x||_2 = " << nrm2 << std::endl; } // Clear solver ls.Clear(); // Stop rocALUTION platform stop_rocalution(); MPI_Finalize(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/me-preconditioner.cpp000066400000000000000000000070021507377332500235430ustar00rootroot00000000000000/* ************************************************************************ * 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 #include #include using namespace rocalution; int main(int argc, char* argv[]) { // Check command line parameters if(argc == 1) { std::cerr << argv[0] << " [Num threads]" << std::endl; exit(1); } // Initialize rocALUTION init_rocalution(); // Check command line parameters for number of OMP threads if(argc > 2) { set_omp_threads_rocalution(atoi(argv[2])); } // Print rocALUTION info info_rocalution(); // rocALUTION objects LocalVector x; LocalVector rhs; LocalVector e; LocalMatrix mat; // Read matrix from MTX file mat.ReadFileMTX(std::string(argv[1])); // Move objects to accelerator mat.MoveToAccelerator(); x.MoveToAccelerator(); rhs.MoveToAccelerator(); e.MoveToAccelerator(); // Allocate vectors x.Allocate("x", mat.GetN()); rhs.Allocate("rhs", mat.GetM()); e.Allocate("e", mat.GetN()); // Linear Solver CG, LocalVector, double> cg; // Preconditioner (main) MultiElimination, LocalVector, double> p; // Last block-preconditioner MultiColoredILU, LocalVector, double> mcilu_p; mcilu_p.Set(0); p.Set(mcilu_p, 2, 0.4); // Initialize rhs such that A 1 = rhs e.Ones(); mat.Apply(e, &rhs); // Initial zero guess x.Zeros(); // Set solver operator cg.SetOperator(mat); // Set solver preconditioner cg.SetPreconditioner(p); // Build solver cg.Build(); // Verbosity output cg.Verbose(1); // Print matrix info mat.Info(); // Start time measurement double tick, tack; tick = rocalution_time(); // Solve A x = rhs cg.Solve(rhs, &x); // Stop time measurement tack = rocalution_time(); std::cout << "Solver execution:" << (tack - tick) / 1e6 << " sec" << std::endl; // Clear solver cg.Clear(); // Compute error L2 norm e.ScaleAdd(-1.0, x); double error = e.Norm(); std::cout << "||e - x||_2 = " << error << std::endl; // Stop rocALUTION platform stop_rocalution(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/mixed-precision.cpp000066400000000000000000000067571507377332500232370ustar00rootroot00000000000000/* ************************************************************************ * 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 #include #include using namespace rocalution; int main(int argc, char* argv[]) { // Check command line parameters if(argc == 1) { std::cerr << argv[0] << " [Num threads]" << std::endl; exit(1); } // Initialize rocALUTION init_rocalution(); // Check command line parameters for number of OMP threads if(argc > 2) { set_omp_threads_rocalution(atoi(argv[2])); } // Print rocALUTION info info_rocalution(); // rocALUTION objects LocalVector x; LocalVector rhs; LocalVector e; LocalMatrix mat; // Read matrix from MTX file mat.ReadFileMTX(std::string(argv[1])); // Allocate vectors x.Allocate("x", mat.GetN()); rhs.Allocate("rhs", mat.GetM()); e.Allocate("e", mat.GetN()); // Linear Solver MixedPrecisionDC, LocalVector, double, LocalMatrix, LocalVector, float> mp; CG, LocalVector, float> cg; MultiColoredILU, LocalVector, float> p; // Initialize rhs such that A 1 = rhs e.Ones(); mat.Apply(e, &rhs); // Initial zero guess x.Zeros(); // setup a lower tol for the inner solver cg.SetPreconditioner(p); cg.Init(1e-5, 1e-2, 1e+20, 100000); // setup the mixed-precision DC mp.SetOperator(mat); mp.Set(cg); // Build solver mp.Build(); // Verbosity output mp.Verbose(1); // Print matrix info mat.Info(); // Start time measurement double tick, tack; tick = rocalution_time(); // Solve A x = rhs mp.Solve(rhs, &x); // Stop time measurement tack = rocalution_time(); std::cout << "Solver execution:" << (tack - tick) / 1e6 << " sec" << std::endl; // Clear solver mp.Clear(); // Compute error L2 norm e.ScaleAdd(-1.0, x); double error = e.Norm(); std::cout << "||e - x||_2 = " << error << std::endl; // Stop rocALUTION platform stop_rocalution(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/power-method.cpp000066400000000000000000000147311507377332500225410ustar00rootroot00000000000000/* ************************************************************************ * 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 #include #include using namespace rocalution; int main(int argc, char* argv[]) { // Check command line parameters if(argc == 1) { std::cerr << argv[0] << " [Num threads]" << std::endl; exit(1); } // Initialize rocALUTION init_rocalution(); // Check command line parameters for number of OMP threads if(argc > 2) { set_omp_threads_rocalution(atoi(argv[2])); } // Print rocALUTION info info_rocalution(); LocalVector b; LocalVector b_old; LocalVector* b_k; LocalVector* b_k1; LocalVector* b_tmp; LocalMatrix mat; // Read matrix from MTX file mat.ReadFileMTX(std::string(argv[1])); // Gershgorin spectrum approximation double glambda_min, glambda_max; // Power method spectrum approximation double plambda_min, plambda_max; // Maximum number of iteration for the power method int iter_max = 10000; // Gershgorin approximation of the eigenvalues mat.Gershgorin(glambda_min, glambda_max); std::cout << "Gershgorin : Lambda min = " << glambda_min << "; Lambda max = " << glambda_max << std::endl; // Move objects to accelerator mat.MoveToAccelerator(); b.MoveToAccelerator(); b_old.MoveToAccelerator(); // Allocate vectors b.Allocate("b_k+1", mat.GetM()); b_k1 = &b; b_old.Allocate("b_k", mat.GetM()); b_k = &b_old; // Set b_k to 1 b_k->Ones(); // Print matrix info mat.Info(); // Start time measurement double tick, tack; tick = rocalution_time(); // compute lambda max for(int i = 0; i <= iter_max; ++i) { mat.Apply(*b_k, b_k1); // std::cout << b_k1->Dot(*b_k) << std::endl; b_k1->Scale(double(1.0) / b_k1->Norm()); b_tmp = b_k1; b_k1 = b_k; b_k = b_tmp; } // get lambda max (Rayleigh quotient) mat.Apply(*b_k, b_k1); plambda_max = b_k1->Dot(*b_k); tack = rocalution_time(); std::cout << "Power method (lambda max) execution:" << (tack - tick) / 1e6 << " sec" << std::endl; mat.AddScalarDiagonal(double(-1.0) * plambda_max); b_k->Ones(); tick = rocalution_time(); // compute lambda min for(int i = 0; i <= iter_max; ++i) { mat.Apply(*b_k, b_k1); // std::cout << b_k1->Dot(*b_k) + plambda_max << std::endl; b_k1->Scale(double(1.0) / b_k1->Norm()); b_tmp = b_k1; b_k1 = b_k; b_k = b_tmp; } // get lambda min (Rayleigh quotient) mat.Apply(*b_k, b_k1); plambda_min = (b_k1->Dot(*b_k) + plambda_max); // back to the original matrix mat.AddScalarDiagonal(plambda_max); tack = rocalution_time(); std::cout << "Power method (lambda min) execution:" << (tack - tick) / 1e6 << " sec" << std::endl; std::cout << "Power method Lambda min = " << plambda_min << "; Lambda max = " << plambda_max << "; iter=2x" << iter_max << std::endl; LocalVector x; LocalVector e; LocalVector rhs; x.CloneBackend(mat); e.CloneBackend(mat); rhs.CloneBackend(mat); x.Allocate("x", mat.GetN()); e.Allocate("e", mat.GetN()); rhs.Allocate("rhs", mat.GetM()); // Chebyshev iteration Chebyshev, LocalVector, double> ls; // Initialize rhs such that A 1 = rhs e.Ones(); mat.Apply(e, &rhs); // Initial zero guess x.Zeros(); // Set solver operator ls.SetOperator(mat); // Set eigenvalues ls.Set(plambda_min, plambda_max); // Build solver ls.Build(); // Start time measurement tick = rocalution_time(); // Solve A x = rhs ls.Solve(rhs, &x); // Stop time measurement tack = rocalution_time(); std::cout << "Solver execution:" << (tack - tick) / 1e6 << " sec" << std::endl; // Clear solver ls.Clear(); // Compute error L2 norm e.ScaleAdd(-1.0, x); double error = e.Norm(); std::cout << "Chebyshev iteration ||e - x||_2 = " << error << std::endl; // PCG + Chebyshev polynomial CG, LocalVector, double> cg; AIChebyshev, LocalVector, double> p; // damping factor plambda_min = plambda_max / 7; // Set preconditioner p.Set(3, plambda_min, plambda_max); // Initialize rhs such that A 1 = rhs e.Ones(); mat.Apply(e, &rhs); // Initial zero guess x.Zeros(); // Set solver operator cg.SetOperator(mat); // Set solver preconditioner cg.SetPreconditioner(p); // Build solver cg.Build(); // Start time measurement tick = rocalution_time(); // Solve A x = rhs cg.Solve(rhs, &x); // Stop time measurement tack = rocalution_time(); std::cout << "Solver execution:" << (tack - tick) / 1e6 << " sec" << std::endl; // Clear solver cg.Clear(); // Compute error L2 norm e.ScaleAdd(-1.0, x); error = e.Norm(); std::cout << "CG + AIChebyshev ||e - x||_2 = " << error << std::endl; // Stop rocALUTION platform stop_rocalution(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/qmrcgstab_mpi.cpp000066400000000000000000000073511507377332500227570ustar00rootroot00000000000000/* ************************************************************************ * 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 "common.hpp" #include #include #include #define ValueType double using namespace rocalution; int main(int argc, char* argv[]) { // Initialize MPI MPI_Init(&argc, &argv); MPI_Comm comm = MPI_COMM_WORLD; int rank; int num_procs; MPI_Comm_rank(comm, &rank); MPI_Comm_size(comm, &num_procs); // Check command line parameters if(num_procs < 2) { std::cerr << "Expecting at least 2 MPI processes" << std::endl; return -1; } if(argc < 2) { std::cerr << argv[0] << " " << std::endl; return -1; } // Disable OpenMP thread affinity set_omp_affinity_rocalution(false); // Initialize platform with rank and # of accelerator devices in the node init_rocalution(rank, 2); // Disable OpenMP set_omp_threads_rocalution(1); // Print platform info_rocalution(); // Load undistributed matrix LocalMatrix lmat; lmat.ReadFileMTX(argv[1]); // Global structures ParallelManager manager; GlobalMatrix mat; // Distribute matrix - lmat will be destroyed distribute_matrix(&comm, &lmat, &mat, &manager); // rocALUTION vectors GlobalVector rhs(manager); GlobalVector x(manager); GlobalVector e(manager); // Move structures to accelerator, if available mat.MoveToAccelerator(); rhs.MoveToAccelerator(); x.MoveToAccelerator(); e.MoveToAccelerator(); // Allocate memory rhs.Allocate("rhs", mat.GetM()); x.Allocate("x", mat.GetN()); e.Allocate("sol", mat.GetN()); e.Ones(); mat.Apply(e, &rhs); x.Zeros(); QMRCGStab, GlobalVector, double> ls; BlockJacobi, GlobalVector, double> bj; ILUT, LocalVector, double> p; bj.Set(p); ls.SetPreconditioner(bj); ls.SetOperator(mat); ls.Build(); ls.Verbose(1); mat.Info(); double time = rocalution_time(); ls.Solve(rhs, &x); time = rocalution_time() - time; if(rank == 0) { std::cout << "Solving: " << time / 1e6 << " sec" << std::endl; } e.ScaleAdd(-1.0, x); double nrm2 = e.Norm(); if(rank == 0) { std::cout << "||e - x||_2 = " << nrm2 << std::endl; } ls.Clear(); stop_rocalution(); MPI_Finalize(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/sa-amg.cpp000066400000000000000000000153111507377332500212670ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include #include #include using namespace rocalution; int main(int argc, char* argv[]) { // Check command line parameters if(argc == 1) { std::cerr << argv[0] << " [Num threads]" << std::endl; exit(1); } // Initialize rocALUTION init_rocalution(); // Check command line parameters for number of OMP threads if(argc > 2) { set_omp_threads_rocalution(atoi(argv[2])); } // Print rocALUTION info info_rocalution(); // rocALUTION objects LocalVector x; LocalVector rhs; LocalVector e; LocalMatrix mat; // Read matrix from MTX file mat.ReadFileMTX(std::string(argv[1])); // Allocate vectors x.Allocate("x", mat.GetN()); rhs.Allocate("rhs", mat.GetM()); e.Allocate("e", mat.GetN()); // Initialize rhs such that A 1 = rhs e.Ones(); mat.Apply(e, &rhs); // Initial zero guess x.Zeros(); // Time measurement double tick, tack, start, end; // Start time measurement tick = rocalution_time(); start = rocalution_time(); // Linear Solver SAAMG, LocalVector, double> ls; // Set solver operator ls.SetOperator(mat); // Set coupling strength ls.SetCouplingStrength(0.001); // Set maximal number of unknowns on coarsest level ls.SetCoarsestLevel(200); // Set relaxation parameter for smoothed interpolation aggregation ls.SetInterpRelax(2. / 3.); // Set manual smoothers ls.SetManualSmoothers(true); // Set manual course grid solver ls.SetManualSolver(true); // Set grid transfer scaling ls.SetScaling(true); // Set coarsening strategy ls.SetCoarseningStrategy(CoarseningStrategy::Greedy); //ls.SetCoarseningStrategy(CoarseningStrategy::PMIS); // Move solver to the accelerator mat.MoveToAccelerator(); x.MoveToAccelerator(); rhs.MoveToAccelerator(); e.MoveToAccelerator(); ls.MoveToAccelerator(); // Build AMG hierarchy ls.BuildHierarchy(); // Stop build hierarchy time measurement tack = rocalution_time(); std::cout << "Build Hierarchy took: " << (tack - tick) / 1e6 << " sec" << std::endl; // Start smoother time measurement tick = rocalution_time(); // Obtain number of AMG levels int levels = ls.GetNumLevels(); // Coarse Grid Solver CG, LocalVector, double> cgs; cgs.Verbose(0); // Smoother for each level IterativeLinearSolver, LocalVector, double>** sm = new IterativeLinearSolver, LocalVector, double>*[levels - 1]; Preconditioner, LocalVector, double>** p = new Preconditioner, LocalVector, double>*[levels - 1]; std::string preconditioner = "Jacobi"; // Initialize smoother for each level for(int i = 0; i < levels - 1; ++i) { FixedPoint, LocalVector, double>* fp; fp = new FixedPoint, LocalVector, double>; fp->SetRelaxation(1.3); sm[i] = fp; if(preconditioner == "GS") { p[i] = new GS, LocalVector, double>; } else if(preconditioner == "SGS") { p[i] = new SGS, LocalVector, double>; } else if(preconditioner == "ILU") { p[i] = new ILU, LocalVector, double>; } else if(preconditioner == "IC") { p[i] = new IC, LocalVector, double>; } else { p[i] = new Jacobi, LocalVector, double>; } sm[i]->SetPreconditioner(*p[i]); sm[i]->Verbose(0); } // Pass smoother and coarse grid solver to AMG ls.SetSmoother(sm); ls.SetSolver(cgs); // Set number of pre and post smoothing steps ls.SetSmootherPreIter(1); ls.SetSmootherPostIter(2); // Initialize solver tolerances ls.Init(1e-10, 1e-8, 1e+8, 10000); // Verbosity output ls.Verbose(2); // Build solver ls.Build(); // Move solver to the accelerator mat.MoveToAccelerator(); x.MoveToAccelerator(); rhs.MoveToAccelerator(); e.MoveToAccelerator(); ls.MoveToAccelerator(); // Print matrix info mat.Info(); // Stop building time measurement tack = rocalution_time(); std::cout << "Build took: " << (tack - tick) / 1e6 << " sec" << std::endl; // Start solving time measurement tick = rocalution_time(); // Solve A x = rhs ls.Solve(rhs, &x); // Stop solving time measurement tack = rocalution_time(); std::cout << "Solving took: " << (tack - tick) / 1e6 << " sec" << std::endl; // Clear the solver ls.Clear(); // Free all allocated data for(int i = 0; i < levels - 1; ++i) { delete p[i]; delete sm[i]; } delete[] p; delete[] sm; // End time measurement end = rocalution_time(); std::cout << "Total runtime: " << (end - start) / 1e6 << " sec" << std::endl; // Compute error L2 norm e.ScaleAdd(-1.0, x); double error = e.Norm(); std::cout << "||e - x||_2 = " << error << std::endl; // Stop rocALUTION platform stop_rocalution(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/simple-spmv.cpp000066400000000000000000000055501507377332500224020ustar00rootroot00000000000000/* ************************************************************************ * 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 #include #include using namespace rocalution; int main(int argc, char* argv[]) { // Check command line parameters if(argc == 1) { std::cerr << argv[0] << " [Num threads]" << std::endl; exit(1); } // Initialize rocALUTION init_rocalution(); // Check command line parameters for number of OMP threads if(argc > 2) { set_omp_threads_rocalution(atoi(argv[2])); } // Print rocALUTION info info_rocalution(); // rocALUTION objects LocalVector x; LocalVector rhs; LocalMatrix mat; // Read matrix from MTX file mat.ReadFileMTX(std::string(argv[1])); // Print matrix info mat.Info(); // Allocate vectors x.Allocate("x", mat.GetN()); rhs.Allocate("rhs", mat.GetM()); // Print vector info x.Info(); rhs.Info(); // Set rhs to 1 rhs.Ones(); // x = mat * rhs mat.Apply(rhs, &x); // Print dot product std::cout << "dot=" << x.Dot(rhs) << std::endl; // Convert matrix to ELL format mat.ConvertToELL(); // Print matrix info mat.Info(); // Move objects to accelerator mat.MoveToAccelerator(); x.MoveToAccelerator(); rhs.MoveToAccelerator(); // Print matrix info mat.Info(); // Set rhs to 1 rhs.Ones(); // x = mat * rhs mat.Apply(rhs, &x); // Print dot product std::cout << "dot=" << x.Dot(rhs) << std::endl; // Stop rocALUTION platform stop_rocalution(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/sp-precond.cpp000066400000000000000000000071601507377332500221770ustar00rootroot00000000000000/* ************************************************************************ * 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 #include #include using namespace rocalution; int main(int argc, char* argv[]) { // Check command line parameters if(argc == 1) { std::cerr << argv[0] << " [Num threads]" << std::endl; exit(1); } // Initialize rocALUTION init_rocalution(); // Check command line parameters for number of OMP threads if(argc > 2) { set_omp_threads_rocalution(atoi(argv[2])); } // Print rocALUTION info info_rocalution(); // rocALUTION objects LocalVector x; LocalVector rhs; LocalVector e; LocalMatrix mat; // Read matrix from MTX file mat.ReadFileMTX(std::string(argv[1])); // Move objects to accelerator mat.MoveToAccelerator(); x.MoveToAccelerator(); rhs.MoveToAccelerator(); e.MoveToAccelerator(); // Allocate vectors x.Allocate("x", mat.GetN()); rhs.Allocate("rhs", mat.GetM()); e.Allocate("e", mat.GetN()); // Linear Solver BiCGStab, LocalVector, double> ls; // Preconditioner DiagJacobiSaddlePointPrecond, LocalVector, double> p; MultiColoredILU, LocalVector, double> p1; MultiColoredILU, LocalVector, double> p2; // Initialize rhs such that A 1 = rhs e.Ones(); mat.Apply(e, &rhs); // Initial zero guess x.Zeros(); // Set up preconditioner // p1.Set(1); // p2.Set(1); p.Set(p1, p2); // Set solver operator ls.SetOperator(mat); // Set solver preconditioner ls.SetPreconditioner(p); // Build solver ls.Build(); // Verbosity output ls.Verbose(2); // Print matrix info mat.Info(); // Start time measurement double tick, tack; tick = rocalution_time(); // Solve A x = rhs ls.Solve(rhs, &x); // Stop time measurement tack = rocalution_time(); std::cout << "Solver execution:" << (tack - tick) / 1e6 << " sec" << std::endl; // Clear solver ls.Clear(); // Compute error L2 norm e.ScaleAdd(-1.0, x); double error = e.Norm(); std::cout << "||e - x||_2 = " << error << std::endl; // Stop rocALUTION platform stop_rocalution(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/stencil.cpp000066400000000000000000000053571507377332500215740ustar00rootroot00000000000000/* ************************************************************************ * 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 #include #include using namespace rocalution; int main(int argc, char* argv[]) { // Initialize rocALUTION init_rocalution(); // Print rocALUTION info info_rocalution(); // rocALUTION objects LocalVector x; LocalVector rhs; LocalVector e; LocalStencil stencil(Laplace2D); // Set up stencil grid stencil.SetGrid(100); // 100x100 // Allocate vectors x.Allocate("x", stencil.GetN()); rhs.Allocate("rhs", stencil.GetM()); e.Allocate("e", stencil.GetN()); // Linear Solver CG, LocalVector, double> ls; // Initialize rhs such that A 1 = rhs e.Ones(); stencil.Apply(e, &rhs); // Initial zero guess x.Zeros(); // Set solver operator ls.SetOperator(stencil); // Build solver ls.Build(); // Print stencil info stencil.Info(); // Start time measurement double tick, tack; tick = rocalution_time(); // Solve A x = rhs ls.Solve(rhs, &x); // Stop time measurement tack = rocalution_time(); std::cout << "Solver execution:" << (tack - tick) / 1e6 << " sec" << std::endl; // Clear solver ls.Clear(); // Compute error L2 norm e.ScaleAdd(-1.0, x); double error = e.Norm(); std::cout << "||e - x||_2 = " << error << std::endl; // Stop rocALUTION platform stop_rocalution(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/tns.cpp000066400000000000000000000065201507377332500207300ustar00rootroot00000000000000/* ************************************************************************ * 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 #include #include using namespace rocalution; int main(int argc, char* argv[]) { // Check command line parameters if(argc == 1) { std::cerr << argv[0] << " [Num threads]" << std::endl; exit(1); } // Initialize rocALUTION init_rocalution(); // Check command line parameters for number of OMP threads if(argc > 2) { set_omp_threads_rocalution(atoi(argv[2])); } // Print rocALUTION info info_rocalution(); // rocALUTION objects LocalVector x; LocalVector rhs; LocalVector e; LocalMatrix mat; // Read matrix from MTX file mat.ReadFileMTX(std::string(argv[1])); // Move objects to accelerator mat.MoveToAccelerator(); x.MoveToAccelerator(); rhs.MoveToAccelerator(); e.MoveToAccelerator(); // Allocate vectors x.Allocate("x", mat.GetN()); rhs.Allocate("rhs", mat.GetM()); e.Allocate("e", mat.GetN()); // Linear Solver CG, LocalVector, double> ls; // Preconditioner TNS, LocalVector, double> p; // Initialize rhs such that A 1 = rhs e.Ones(); mat.Apply(e, &rhs); // Initial zero guess x.Zeros(); // Set solver operator ls.SetOperator(mat); // Set solver preconditioner ls.SetPreconditioner(p); // Build solver ls.Build(); // Verbosity output // ls.Verbose(2); // Print matrix info mat.Info(); // Start time measurement double tick, tack; tick = rocalution_time(); // Solve A x = rhs ls.Solve(rhs, &x); // Stop time measurement tack = rocalution_time(); std::cout << "Solver execution:" << (tack - tick) / 1e6 << " sec" << std::endl; // Clear solver ls.Clear(); // Compute error L2 norm e.ScaleAdd(-1.0, x); double error = e.Norm(); std::cout << "||e - x||_2 = " << error << std::endl; // Stop rocALUTION platform stop_rocalution(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/ua-amg.cpp000066400000000000000000000137501507377332500212760ustar00rootroot00000000000000/* ************************************************************************ * 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 #include #include using namespace rocalution; int main(int argc, char* argv[]) { // Check command line parameters if(argc == 1) { std::cerr << argv[0] << " [Num threads]" << std::endl; exit(1); } // Initialize rocALUTION init_rocalution(); // Check command line parameters for number of OMP threads if(argc > 2) { set_omp_threads_rocalution(atoi(argv[2])); } // Print rocALUTION info info_rocalution(); // rocALUTION objects LocalVector x; LocalVector rhs; LocalVector e; LocalMatrix mat; // Read matrix from MTX file mat.ReadFileMTX(std::string(argv[1])); // Allocate vectors x.Allocate("x", mat.GetN()); rhs.Allocate("rhs", mat.GetM()); e.Allocate("e", mat.GetN()); // Initialize rhs such that A 1 = rhs e.Ones(); mat.Apply(e, &rhs); // Initial zero guess x.Zeros(); // Time measurement double tick, tack, start, end; // Start time measurement tick = rocalution_time(); start = rocalution_time(); // Linear Solver UAAMG, LocalVector, double> ls; // Set solver operator ls.SetOperator(mat); // Set coupling strength ls.SetCouplingStrength(0.001); // Set maximal number of unknowns on coarsest level ls.SetCoarsestLevel(200); // Set manual smoothers ls.SetManualSmoothers(true); // Set manual course grid solver ls.SetManualSolver(true); // Set grid transfer scaling ls.SetScaling(true); // Set coarsening strategy //ls.SetCoarseningStrategy(CoarseningStrategy::Greedy); ls.SetCoarseningStrategy(CoarseningStrategy::PMIS); // Move solver to the accelerator mat.MoveToAccelerator(); x.MoveToAccelerator(); rhs.MoveToAccelerator(); e.MoveToAccelerator(); ls.MoveToAccelerator(); // Build AMG hierarchy ls.BuildHierarchy(); // Stop build hierarchy time measurement tack = rocalution_time(); std::cout << "Build Hierarchy took: " << (tack - tick) / 1e6 << " sec" << std::endl; // Start smoother time measurement tick = rocalution_time(); // Obtain number of AMG levels int levels = ls.GetNumLevels(); // Coarse Grid Solver CG, LocalVector, double> cgs; cgs.Verbose(0); // Smoother for each level IterativeLinearSolver, LocalVector, double>** sm = new IterativeLinearSolver, LocalVector, double>*[levels - 1]; Jacobi, LocalVector, double>** js = new Jacobi, LocalVector, double>*[levels - 1]; // Initialize smoother for each level for(int i = 0; i < levels - 1; ++i) { FixedPoint, LocalVector, double>* fp; fp = new FixedPoint, LocalVector, double>; fp->SetRelaxation(1.3); sm[i] = fp; js[i] = new Jacobi, LocalVector, double>; sm[i]->SetPreconditioner(*js[i]); sm[i]->Verbose(0); } // Pass smoother and coarse grid solver to AMG ls.SetSmoother(sm); ls.SetSolver(cgs); // Set number of pre and post smoothing steps ls.SetSmootherPreIter(1); ls.SetSmootherPostIter(2); // Initialize solver tolerances ls.Init(1e-10, 1e-8, 1e+8, 10000); // Verbosity output ls.Verbose(2); // Build solver ls.Build(); // Move solver to the accelerator mat.MoveToAccelerator(); x.MoveToAccelerator(); rhs.MoveToAccelerator(); e.MoveToAccelerator(); ls.MoveToAccelerator(); // Print matrix info mat.Info(); // Stop building time measurement tack = rocalution_time(); std::cout << "Build took: " << (tack - tick) / 1e6 << " sec" << std::endl; // Start solving time measurement tick = rocalution_time(); // Solve A x = rhs ls.Solve(rhs, &x); // Stop solving time measurement tack = rocalution_time(); std::cout << "Solving took: " << (tack - tick) / 1e6 << " sec" << std::endl; // Clear the solver ls.Clear(); // Free all allocated data for(int i = 0; i < levels - 1; ++i) { delete js[i]; delete sm[i]; } delete[] js; delete[] sm; // End time measurement end = rocalution_time(); std::cout << "Total runtime: " << (end - start) / 1e6 << " sec" << std::endl; // Compute error L2 norm e.ScaleAdd(-1.0, x); double error = e.Norm(); std::cout << "||e - x||_2 = " << error << std::endl; // Stop rocALUTION platform stop_rocalution(); return 0; } rocALUTION-rocm-7.1.0/clients/samples/var-precond.cpp000066400000000000000000000075741507377332500223560ustar00rootroot00000000000000/* ************************************************************************ * 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 #include #include using namespace rocalution; int main(int argc, char* argv[]) { // Check command line parameters if(argc == 1) { std::cerr << argv[0] << " [Num threads]" << std::endl; exit(1); } // Initialize rocALUTION init_rocalution(); // Check command line parameters for number of OMP threads if(argc > 2) { set_omp_threads_rocalution(atoi(argv[2])); } // Print rocALUTION info info_rocalution(); // rocALUTION objects LocalVector x; LocalVector rhs; LocalVector e; LocalMatrix mat; // Read matrix from MTX file mat.ReadFileMTX(std::string(argv[1])); // Move objects to accelerator mat.MoveToAccelerator(); x.MoveToAccelerator(); rhs.MoveToAccelerator(); e.MoveToAccelerator(); // Allocate vectors x.Allocate("x", mat.GetN()); rhs.Allocate("rhs", mat.GetM()); e.Allocate("e", mat.GetN()); // Linear Solver FGMRES, LocalVector, double> ls; // Variable Preconditioner VariablePreconditioner, LocalVector, double> p; Solver, LocalVector, double>** vp; vp = new Solver, LocalVector, double>*[3]; // Preconditioners MultiColoredSGS, LocalVector, double> p1; MultiColoredILU, LocalVector, double> p2; ILU, LocalVector, double> p3; vp[0] = &p1; vp[1] = &p2; vp[2] = &p3; // Initialize rhs such that A 1 = rhs e.Ones(); mat.Apply(e, &rhs); // Initial zero guess x.Zeros(); // Set variable preconditioners p.SetPreconditioner(3, vp); // Set solver operator ls.SetOperator(mat); // Set solver preconditioner ls.SetPreconditioner(p); // Build solver ls.Build(); // Verbosity output ls.Verbose(1); // Print matrix info mat.Info(); // Start time measurement double tick, tack; tick = rocalution_time(); // Solve A x = rhs ls.Solve(rhs, &x); // Stop time measurement tack = rocalution_time(); std::cout << "Solver execution:" << (tack - tick) / 1e6 << " sec" << std::endl; // Clear solver ls.Clear(); delete[] vp; // Compute error L2 norm e.ScaleAdd(-1.0, x); double error = e.Norm(); std::cout << "||e - x||_2 = " << error << std::endl; // Stop rocALUTION platform stop_rocalution(); return 0; } rocALUTION-rocm-7.1.0/clients/tests/000077500000000000000000000000001507377332500171135ustar00rootroot00000000000000rocALUTION-rocm-7.1.0/clients/tests/CMakeLists.txt000066400000000000000000000100521507377332500216510ustar00rootroot00000000000000# ######################################################################## # 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. # # ######################################################################## # Find google test and its dependencies find_package(GTest REQUIRED) set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) # Non MPI tests set(ROCALUTION_TEST_SOURCES rocalution_host_gtest_main.cpp # Direct solvers test_qr.cpp test_lu.cpp test_inversion.cpp # Krylov solvers test_backend.cpp test_bicgstab.cpp test_bicgstabl.cpp test_cg.cpp test_cr.cpp test_fcg.cpp test_fgmres.cpp test_gmres.cpp test_idr.cpp test_qmrcgstab.cpp # AMG test_pairwise_amg.cpp test_ruge_stueben_amg.cpp test_saamg.cpp test_uaamg.cpp # Other tests test_preconditioner.cpp test_itersolver.cpp test_chebyshev.cpp test_mixed_precision.cpp ) if(NOT WIN32) # Local structures - skip on Windows, as google test does not support union for death tests list(APPEND ROCALUTION_TEST_SOURCES test_local_matrix.cpp test_local_matrix_multicoloring.cpp test_local_matrix_itsolve.cpp test_local_matrix_solve.cpp test_local_stencil.cpp test_local_vector.cpp ) endif() # MPI tests if(SUPPORT_MPI) list(APPEND ROCALUTION_TEST_SOURCES test_global_matrix.cpp # test_global_stencil.cpp test_global_vector.cpp test_parallel_manager.cpp ) endif() # Common list(APPEND ROCALUTION_TEST_SOURCES ../include/random.cpp ) add_executable(rocalution-test ${ROCALUTION_TEST_SOURCES} ${ROCALUTION_CLIENTS_COMMON}) # Google test target_compile_definitions(rocalution-test PRIVATE GOOGLE_TEST) target_include_directories(rocalution-test SYSTEM PRIVATE $) target_link_libraries(rocalution-test PRIVATE ${GTEST_BOTH_LIBRARIES} Threads::Threads) # Include common client headers target_include_directories(rocalution-test PRIVATE $) # Link rocALUTION library target_link_libraries(rocalution-test PRIVATE roc::rocalution) if(NOT TARGET rocalution) set_target_properties(rocalution-test PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/staging") else() set_target_properties(rocalution-test PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/clients/staging") endif() # Add tests add_test(rocalution-test rocalution-test) rocm_install(TARGETS rocalution-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 ${HIP_DIR}/bin/*.dll ${HIP_DIR}/bin/hipinfo.exe ${CMAKE_SOURCE_DIR}/rtest.* $ENV{rocsparse_DIR}/bin/*.dll $ENV{rocrand_DIR}/bin/*.dll $ENV{rocblas_DIR}/bin/*.dll C:/Windows/System32/libomp140*.dll ) foreach( file_i ${third_party_dlls}) add_custom_command( TARGET rocalution-test POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy ${file_i} ${PROJECT_BINARY_DIR}/staging/ ) endforeach( file_i ) endif() rocALUTION-rocm-7.1.0/clients/tests/rocalution_host_gtest_main.cpp000066400000000000000000000050251507377332500252470ustar00rootroot00000000000000/* ************************************************************************ * 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 "utility.hpp" #include #include #include #define VAL(str) #str #define TOSTRING(str) VAL(str) int device; /* ===================================================================== Main function: =================================================================== */ int main(int argc, char** argv) { // Get device id from command line device = 0; for(int i = 1; i < argc; ++i) { if(strcmp(argv[i], "--device") == 0 && argc > i + 1) { device = atoi(argv[i + 1]); } if(strcmp(argv[i], "--version") == 0) { // Print version and exit, if requested std::cout << "rocALUTION version: " << __ROCALUTION_VER_MAJOR << "." << __ROCALUTION_VER_MINOR << "." << __ROCALUTION_VER_PATCH << "-" << TOSTRING(__ROCALUTION_VER_TWEAK) << std::endl; return 0; } } rocalution::set_device_rocalution(device); rocalution::init_rocalution(); rocalution::info_rocalution(); rocalution::stop_rocalution(); ::testing::InitGoogleTest(&argc, argv); ::testing::FLAGS_gtest_death_test_style = "threadsafe"; return RUN_ALL_TESTS(); } rocALUTION-rocm-7.1.0/clients/tests/test_backend.cpp000066400000000000000000000071541507377332500222540ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_backend.hpp" #include "utility.hpp" #include typedef std::tuple backend_tuple; int backend_rank[] = {-1, 0, 13}; int backend_dev_node[] = {-1, 0, 13}; int backend_dev[] = {-1, 0, 13}; int backend_omp_threads[] = {-1, 0, 8}; bool backend_affinity[] = {true, false}; int backend_omp_threshold[] = {-1, 0, 20000}; bool backend_disable_acc[] = {true, false}; class parameterized_backend : public testing::TestWithParam { protected: parameterized_backend() {} virtual ~parameterized_backend() {} virtual void SetUp() override { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED"})) { GTEST_SKIP(); } } virtual void TearDown() {} }; Arguments setup_backend_arguments(backend_tuple tup) { Arguments arg; arg.rank = std::get<0>(tup); arg.dev_per_node = std::get<1>(tup); arg.dev = std::get<2>(tup); arg.omp_nthreads = std::get<3>(tup); arg.omp_affinity = std::get<4>(tup); arg.omp_threshold = std::get<5>(tup); arg.use_acc = std::get<6>(tup); return arg; } TEST(backend_init_order, backend) { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED"})) { GTEST_SKIP(); } testing_backend_init_order(); } TEST_P(parameterized_backend, backend) { Arguments arg = setup_backend_arguments(GetParam()); testing_backend(arg); } INSTANTIATE_TEST_CASE_P(backend, parameterized_backend, testing::Combine(testing::ValuesIn(backend_rank), testing::ValuesIn(backend_dev_node), testing::ValuesIn(backend_dev), testing::ValuesIn(backend_omp_threads), testing::ValuesIn(backend_affinity), testing::ValuesIn(backend_omp_threshold), testing::ValuesIn(backend_disable_acc))); rocALUTION-rocm-7.1.0/clients/tests/test_bicgstab.cpp000066400000000000000000000111751507377332500224410ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_bicgstab.hpp" #include "utility.hpp" #include #include typedef std::tuple bicgstab_tuple; std::vector bicgstab_size = {7, 63}; std::vector bicgstab_precond = {"None", "Chebyshev", "TNS", "Jacobi", "ItILU0", "ILUT", "MCGS", "MCILU"}; std::vector bicgstab_format = {1, 2, 4, 6}; std::vector bicgstab_use_acc = {1}; // Function to update tests if environment variable is set void update_bicgstab() { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED", "ROCALUTION_CODE_COVERAGE"})) { bicgstab_size.clear(); bicgstab_precond.clear(); bicgstab_format.clear(); } if(is_env_var_set("ROCALUTION_CODE_COVERAGE")) { bicgstab_size.push_back(7); bicgstab_precond.insert( bicgstab_precond.end(), {"None", "Chebyshev", "TNS", "Jacobi", "ItILU0", "ILUT", "MCGS", "MCILU"}); bicgstab_format.insert(bicgstab_format.end(), {1, 2, 4, 6}); bicgstab_use_acc.push_back(0); } if(is_env_var_set("ROCALUTION_EMULATION_SMOKE")) { bicgstab_size.push_back(63); bicgstab_precond.insert(bicgstab_precond.end(), {"None", "Chebyshev"}); bicgstab_format.push_back(2); } else if(is_env_var_set("ROCALUTION_EMULATION_REGRESSION")) { bicgstab_size.insert(bicgstab_size.end(), {7, 63}); bicgstab_precond.insert(bicgstab_precond.end(), {"TNS", "MCILU"}); bicgstab_format.insert(bicgstab_format.end(), {1, 4}); } else if(is_env_var_set("ROCALUTION_EMULATION_EXTENDED")) { bicgstab_size.insert(bicgstab_size.end(), {7, 63}); bicgstab_precond.insert(bicgstab_precond.end(), {"ItILU0", "ILUT"}); bicgstab_format.push_back(6); } } struct BiCGStabInitializer { BiCGStabInitializer() { update_bicgstab(); } }; // Create a global instance of the initializer, so the environment is checked and updated before tests. BiCGStabInitializer bicgstab_initializer; class parameterized_bicgstab : public testing::TestWithParam { protected: parameterized_bicgstab() {} virtual ~parameterized_bicgstab() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_bicgstab_arguments(bicgstab_tuple tup) { Arguments arg; arg.size = std::get<0>(tup); arg.precond = std::get<1>(tup); arg.format = std::get<2>(tup); arg.use_acc = std::get<3>(tup); return arg; } TEST_P(parameterized_bicgstab, bicgstab_float) { Arguments arg = setup_bicgstab_arguments(GetParam()); ASSERT_EQ(testing_bicgstab(arg), true); } TEST_P(parameterized_bicgstab, bicgstab_double) { Arguments arg = setup_bicgstab_arguments(GetParam()); ASSERT_EQ(testing_bicgstab(arg), true); } INSTANTIATE_TEST_CASE_P(bicgstab, parameterized_bicgstab, testing::Combine(testing::ValuesIn(bicgstab_size), testing::ValuesIn(bicgstab_precond), testing::ValuesIn(bicgstab_format), testing::ValuesIn(bicgstab_use_acc))); rocALUTION-rocm-7.1.0/clients/tests/test_bicgstabl.cpp000066400000000000000000000120011507377332500226020ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_bicgstabl.hpp" #include "utility.hpp" #include #include typedef std::tuple bicgstabl_tuple; std::vector bicgstabl_size = {7, 63}; std::vector bicgstabl_precond = {"None", "SPAI", "TNS", "Jacobi", "GS", "ILU", "ItILU0", "ILUT", "IC", "MCGS", "MCILU"}; std::vector bicgstabl_format = {1, 4, 5, 6, 7}; std::vector bicgstabl_level = {1, 2, 4}; std::vector bicgstabl_use_acc = {1}; // Function to update tests if environment variable is set void update_bicgstabl() { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED", "ROCALUTION_CODE_COVERAGE"})) { bicgstabl_size.clear(); bicgstabl_precond.clear(); bicgstabl_format.clear(); bicgstabl_level.clear(); } if(is_env_var_set("ROCALUTION_CODE_COVERAGE")) { bicgstabl_size.push_back(7); bicgstabl_precond.insert(bicgstabl_precond.end(), {"None", "Jacobi"}); bicgstabl_format.push_back(1); bicgstabl_level.push_back(1); bicgstabl_use_acc.push_back(0); } if(is_env_var_set("ROCALUTION_EMULATION_SMOKE")) { bicgstabl_size.push_back(63); bicgstabl_precond.insert(bicgstabl_precond.end(), {"None", "Jacobi"}); bicgstabl_format.push_back(1); bicgstabl_level.push_back(4); } else if(is_env_var_set("ROCALUTION_EMULATION_REGRESSION")) { bicgstabl_size.insert(bicgstabl_size.end(), {7, 63}); bicgstabl_precond.insert(bicgstabl_precond.end(), {"SPAI", "TNS"}); bicgstabl_format.insert(bicgstabl_format.end(), {4, 5}); bicgstabl_level.insert(bicgstabl_level.end(), {1, 2}); } else if(is_env_var_set("ROCALUTION_EMULATION_EXTENDED")) { bicgstabl_size.insert(bicgstabl_size.end(), {7, 63}); bicgstabl_precond.insert(bicgstabl_precond.end(), {"ILU", "IC"}); bicgstabl_format.insert(bicgstabl_format.end(), {6, 7}); bicgstabl_level.insert(bicgstabl_level.end(), {2, 4}); } } struct BiCGStabLInitializer { BiCGStabLInitializer() { update_bicgstabl(); } }; // Create a global instance of the initializer, so the environment is checked and updated before tests. BiCGStabLInitializer bicgstabl_initializer; class parameterized_bicgstabl : public testing::TestWithParam { protected: parameterized_bicgstabl() {} virtual ~parameterized_bicgstabl() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_bicgstabl_arguments(bicgstabl_tuple tup) { Arguments arg; arg.size = std::get<0>(tup); arg.precond = std::get<1>(tup); arg.format = std::get<2>(tup); arg.index = std::get<3>(tup); arg.use_acc = std::get<4>(tup); return arg; } TEST_P(parameterized_bicgstabl, bicgstabl_float) { Arguments arg = setup_bicgstabl_arguments(GetParam()); ASSERT_EQ(testing_bicgstabl(arg), true); } TEST_P(parameterized_bicgstabl, bicgstabl_double) { Arguments arg = setup_bicgstabl_arguments(GetParam()); ASSERT_EQ(testing_bicgstabl(arg), true); } INSTANTIATE_TEST_CASE_P(bicgstabl, parameterized_bicgstabl, testing::Combine(testing::ValuesIn(bicgstabl_size), testing::ValuesIn(bicgstabl_precond), testing::ValuesIn(bicgstabl_format), testing::ValuesIn(bicgstabl_level), testing::ValuesIn(bicgstabl_use_acc))); rocALUTION-rocm-7.1.0/clients/tests/test_cg.cpp000066400000000000000000000104161507377332500212510ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_cg.hpp" #include "utility.hpp" #include #include typedef std::tuple cg_tuple; std::vector cg_size = {7, 63}; std::vector cg_precond = {"None", "FSAI", "SPAI", "TNS", "Jacobi", "IC", "MCSGS"}; std::vector cg_format = {1, 3, 4, 6}; std::vector cg_use_acc = {1}; // Function to update tests if environment variable is set void update_cg() { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED", "ROCALUTION_CODE_COVERAGE"})) { cg_size.clear(); cg_precond.clear(); cg_format.clear(); } if(is_env_var_set("ROCALUTION_CODE_COVERAGE")) { cg_size.push_back(7); cg_precond.insert(cg_precond.end(), {"None", "FSAI", "SPAI", "TNS", "Jacobi", "IC", "MCSGS"}); cg_format.insert(cg_format.end(), {1, 3, 4, 6}); cg_use_acc.push_back(0); } if(is_env_var_set("ROCALUTION_EMULATION_SMOKE")) { cg_size.push_back(63); cg_precond.insert(cg_precond.end(), {"None", "FSAI"}); cg_format.push_back(3); } else if(is_env_var_set("ROCALUTION_EMULATION_REGRESSION")) { cg_size.insert(cg_size.end(), {7, 63}); cg_precond.insert(cg_precond.end(), {"SPAI", "TNS"}); cg_format.push_back(1); } else if(is_env_var_set("ROCALUTION_EMULATION_EXTENDED")) { cg_size.insert(cg_size.end(), {7, 63}); cg_precond.insert(cg_precond.end(), {"Jacobi", "IC", "MCSGS"}); cg_format.insert(cg_format.end(), {4, 6}); } } struct CGInitializer { CGInitializer() { update_cg(); } }; // Create a global instance of the initializer, so the environment is checked and updated before tests. CGInitializer cg_initializer; class parameterized_cg : public testing::TestWithParam { protected: parameterized_cg() {} virtual ~parameterized_cg() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_cg_arguments(cg_tuple tup) { Arguments arg; arg.size = std::get<0>(tup); arg.precond = std::get<1>(tup); arg.format = std::get<2>(tup); arg.use_acc = std::get<3>(tup); return arg; } TEST_P(parameterized_cg, cg_float) { Arguments arg = setup_cg_arguments(GetParam()); ASSERT_EQ(testing_cg(arg), true); } TEST_P(parameterized_cg, cg_double) { Arguments arg = setup_cg_arguments(GetParam()); ASSERT_EQ(testing_cg(arg), true); } INSTANTIATE_TEST_CASE_P(cg, parameterized_cg, testing::Combine(testing::ValuesIn(cg_size), testing::ValuesIn(cg_precond), testing::ValuesIn(cg_format), testing::ValuesIn(cg_use_acc))); rocALUTION-rocm-7.1.0/clients/tests/test_chebyshev.cpp000066400000000000000000000074671507377332500226540ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "testing_chebyshev.hpp" #include "utility.hpp" #include #include typedef std::tuple chebyshev_tuple; std::vector chebyshev_size = {7}; std::vector chebyshev_format = {1, 2, 3, 4, 5, 6, 7}; std::vector chebyshev_matrix_type = {"Laplacian2D"}; std::vector chebyshev_precond = {"None", "FSAI"}; std::vector chebyshev_rebuildnumeric = {0}; std::vector chebyshev_use_acc = {0, 1}; // Function to update tests if environment variable is set void update_chebyshev() {} struct ChebyshevInitializer { ChebyshevInitializer() { update_chebyshev(); } }; // Create a global instance of the initializer, so the environment is checked and updated before tests. ChebyshevInitializer chebyshev_initializer; class parameterized_chebyshev : public testing::TestWithParam { protected: parameterized_chebyshev() {} virtual ~parameterized_chebyshev() {} virtual void SetUp() { if(!is_env_var_set("ROCALUTION_CODE_COVERAGE")) { GTEST_SKIP() << "Skipping Chebyshev tests as ROCLUTION_CODE_COVERAGE is not set."; } } virtual void TearDown() {} }; Arguments setup_chebyshev_arguments(chebyshev_tuple tup) { Arguments arg; arg.size = std::get<0>(tup); arg.format = std::get<1>(tup); arg.matrix_type = std::get<2>(tup); arg.precond = std::get<3>(tup); arg.rebuildnumeric = std::get<4>(tup); arg.use_acc = std::get<5>(tup); return arg; } TEST_P(parameterized_chebyshev, chebyshev_float) { Arguments arg = setup_chebyshev_arguments(GetParam()); ASSERT_EQ(testing_chebyshev(arg), true); } TEST_P(parameterized_chebyshev, chebyshev_double) { Arguments arg = setup_chebyshev_arguments(GetParam()); ASSERT_EQ(testing_chebyshev(arg), true); } INSTANTIATE_TEST_CASE_P(chebyshev, parameterized_chebyshev, testing::Combine(testing::ValuesIn(chebyshev_size), testing::ValuesIn(chebyshev_format), testing::ValuesIn(chebyshev_matrix_type), testing::ValuesIn(chebyshev_precond), testing::ValuesIn(chebyshev_rebuildnumeric), testing::ValuesIn(chebyshev_use_acc))); rocALUTION-rocm-7.1.0/clients/tests/test_cr.cpp000066400000000000000000000105561507377332500212710ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_cr.hpp" #include "utility.hpp" #include #include typedef std::tuple cr_tuple; std::vector cr_size = {7, 63}; std::vector cr_precond = {"None", "Chebyshev", "FSAI", "Jacobi", "SGS", "ILU", "ItILU0", "IC", "MCSGS"}; std::vector cr_format = {2, 4, 7}; std::vector cr_use_acc = {1}; // Function to update tests if environment variable is set void update_cr() { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED", "ROCALUTION_CODE_COVERAGE"})) { cr_size.clear(); cr_precond.clear(); cr_format.clear(); } if(is_env_var_set("ROCALUTION_CODE_COVERAGE")) { cr_size.push_back(7); cr_precond.insert( cr_precond.end(), {"None", "Chebyshev", "FSAI", "Jacobi", "SGS", "ILU", "ItILU0", "IC", "MCSGS"}); cr_format.insert(cr_format.end(), {2, 4, 7}); cr_use_acc.push_back(0); } if(is_env_var_set("ROCALUTION_EMULATION_SMOKE")) { cr_size.push_back(63); cr_precond.insert(cr_precond.end(), {"None", "SGS"}); cr_format.push_back(4); } else if(is_env_var_set("ROCALUTION_EMULATION_REGRESSION")) { cr_size.insert(cr_size.end(), {7, 63}); cr_precond.insert(cr_precond.end(), {"Chebyshev", "FSAI", "Jacobi"}); cr_format.push_back(2); } else if(is_env_var_set("ROCALUTION_EMULATION_EXTENDED")) { cr_size.insert(cr_size.end(), {7, 63}); cr_precond.insert(cr_precond.end(), {"ILU", "ItILU0", "IC", "MCSGS"}); cr_format.push_back(7); } } struct CRInitializer { CRInitializer() { update_cr(); } }; // Create a global instance of the initializer, so the environment is checked and updated before tests. CRInitializer cr_initializer; class parameterized_cr : public testing::TestWithParam { protected: parameterized_cr() {} virtual ~parameterized_cr() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_cr_arguments(cr_tuple tup) { Arguments arg; arg.size = std::get<0>(tup); arg.precond = std::get<1>(tup); arg.format = std::get<2>(tup); arg.use_acc = std::get<3>(tup); return arg; } /* TODO there _MIGHT_ be some issue with float accuracy TEST_P(parameterized_cr, cr_float) { Arguments arg = setup_cr_arguments(GetParam()); ASSERT_EQ(testing_cr(arg), true); } */ TEST_P(parameterized_cr, cr_double) { Arguments arg = setup_cr_arguments(GetParam()); ASSERT_EQ(testing_cr(arg), true); } INSTANTIATE_TEST_CASE_P(cr, parameterized_cr, testing::Combine(testing::ValuesIn(cr_size), testing::ValuesIn(cr_precond), testing::ValuesIn(cr_format), testing::ValuesIn(cr_use_acc))); rocALUTION-rocm-7.1.0/clients/tests/test_fcg.cpp000066400000000000000000000105211507377332500214140ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_fcg.hpp" #include "utility.hpp" #include #include typedef std::tuple fcg_tuple; std::vector fcg_size = {7, 63}; std::vector fcg_precond = {"None", "Chebyshev", "SPAI", "TNS", "ItILU0", "ILUT", "MCSGS"}; std::vector fcg_format = {2, 5, 6, 7}; std::vector fcg_use_acc = {1}; // Function to update tests if environment variable is set void update_fcg() { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED", "ROCALUTION_CODE_COVERAGE"})) { fcg_size.clear(); fcg_precond.clear(); fcg_format.clear(); } if(is_env_var_set("ROCALUTION_CODE_COVERAGE")) { fcg_size.push_back(7); fcg_precond.insert(fcg_precond.end(), {"None", "Chebyshev", "SPAI", "TNS", "ItILU0", "ILUT", "MCSGS"}); fcg_format.insert(fcg_format.end(), {2, 5, 6, 7}); fcg_use_acc.push_back(0); } if(is_env_var_set("ROCALUTION_EMULATION_SMOKE")) { fcg_size.push_back(63); fcg_precond.insert(fcg_precond.end(), {"None", "SPAI"}); fcg_format.push_back(2); } else if(is_env_var_set("ROCALUTION_EMULATION_REGRESSION")) { fcg_size.insert(fcg_size.end(), {7, 63}); fcg_precond.insert(fcg_precond.end(), {"TNS", "MCSGS"}); fcg_format.push_back(5); } else if(is_env_var_set("ROCALUTION_EMULATION_EXTENDED")) { fcg_size.insert(fcg_size.end(), {7, 63}); fcg_precond.insert(fcg_precond.end(), {"ILUT", "Chebyshev"}); fcg_format.insert(fcg_format.end(), {6, 7}); } } struct FCGInitializer { FCGInitializer() { update_fcg(); } }; // Create a global instance of the initializer, so the environment is checked and updated before tests. FCGInitializer fcg_initializer; class parameterized_fcg : public testing::TestWithParam { protected: parameterized_fcg() {} virtual ~parameterized_fcg() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_fcg_arguments(fcg_tuple tup) { Arguments arg; arg.size = std::get<0>(tup); arg.precond = std::get<1>(tup); arg.format = std::get<2>(tup); arg.use_acc = std::get<3>(tup); return arg; } TEST_P(parameterized_fcg, fcg_float) { Arguments arg = setup_fcg_arguments(GetParam()); ASSERT_EQ(testing_fcg(arg), true); } TEST_P(parameterized_fcg, fcg_double) { Arguments arg = setup_fcg_arguments(GetParam()); ASSERT_EQ(testing_fcg(arg), true); } INSTANTIATE_TEST_CASE_P(fcg, parameterized_fcg, testing::Combine(testing::ValuesIn(fcg_size), testing::ValuesIn(fcg_precond), testing::ValuesIn(fcg_format), testing::ValuesIn(fcg_use_acc))); rocALUTION-rocm-7.1.0/clients/tests/test_fgmres.cpp000066400000000000000000000114221507377332500221410ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_fgmres.hpp" #include "utility.hpp" #include #include typedef std::tuple fgmres_tuple; std::vector fgmres_size = {7, 63}; std::vector fgmres_basis = {20, 60}; std::vector fgmres_precond = {"None", "SPAI", "TNS", "Jacobi", "GS", "ILUT", "MCGS"}; std::vector fgmres_format = {1, 4, 5, 7}; std::vector fgmres_use_acc = {1}; // Function to update tests if environment variable is set void update_fgmres() { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED", "ROCALUTION_CODE_COVERAGE"})) { fgmres_size.clear(); fgmres_basis.clear(); fgmres_precond.clear(); fgmres_format.clear(); } if(is_env_var_set("ROCALUTION_CODE_COVERAGE")) { fgmres_size.push_back(7); fgmres_basis.push_back(20); fgmres_precond.insert(fgmres_precond.end(), {"None", "SPAI", "TNS", "Jacobi", "GS", "ILUT", "MCGS"}); fgmres_format.insert(fgmres_format.end(), {1, 4, 5, 7}); fgmres_use_acc.push_back(0); } if(is_env_var_set("ROCALUTION_EMULATION_SMOKE")) { fgmres_size.push_back(7); fgmres_basis.push_back(20); fgmres_precond.insert(fgmres_precond.end(), {"None", "TNS"}); fgmres_format.push_back(5); } else if(is_env_var_set("ROCALUTION_EMULATION_REGRESSION")) { fgmres_size.push_back(63); fgmres_basis.push_back(60); fgmres_precond.insert(fgmres_precond.end(), {"SPAI", "Jacobi"}); fgmres_format.push_back(1); } else if(is_env_var_set("ROCALUTION_EMULATION_EXTENDED")) { fgmres_size.push_back(63); fgmres_basis.push_back(60); fgmres_precond.insert(fgmres_precond.end(), {"GS", "ILUT"}); fgmres_format.insert(fgmres_format.end(), {4, 7}); } } struct FGMRESInitializer { FGMRESInitializer() { update_fgmres(); } }; // Create a global instance of the initializer, so the environment is checked and updated before tests. FGMRESInitializer fgmres_initializer; class parameterized_fgmres : public testing::TestWithParam { protected: parameterized_fgmres() {} virtual ~parameterized_fgmres() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_fgmres_arguments(fgmres_tuple tup) { Arguments arg; arg.size = std::get<0>(tup); arg.index = std::get<1>(tup); arg.precond = std::get<2>(tup); arg.format = std::get<3>(tup); arg.use_acc = std::get<4>(tup); return arg; } TEST_P(parameterized_fgmres, fgmres_float) { Arguments arg = setup_fgmres_arguments(GetParam()); ASSERT_EQ(testing_fgmres(arg), true); } TEST_P(parameterized_fgmres, fgmres_double) { Arguments arg = setup_fgmres_arguments(GetParam()); ASSERT_EQ(testing_fgmres(arg), true); } INSTANTIATE_TEST_CASE_P(fgmres, parameterized_fgmres, testing::Combine(testing::ValuesIn(fgmres_size), testing::ValuesIn(fgmres_basis), testing::ValuesIn(fgmres_precond), testing::ValuesIn(fgmres_format), testing::ValuesIn(fgmres_use_acc))); rocALUTION-rocm-7.1.0/clients/tests/test_global_matrix.cpp000066400000000000000000000065541507377332500235140ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_global_matrix.hpp" #include "utility.hpp" #include /* typedef std::tuple backend_tuple; int backend_rank[] = {-1, 0, 13}; int backend_dev_node[] = {-1, 0, 13}; int backend_dev[] = {-1, 0, 13}; int backend_omp_threads[] = {-1, 0, 8}; bool backend_affinity[] = {true, false}; int backend_omp_threshold[] = {-1, 0, 20000}; bool backend_disable_acc[] = {true, false}; class parameterized_backend : public testing::TestWithParam { protected: parameterized_backend() {} virtual ~parameterized_backend() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_backend_arguments(backend_tuple tup) { Arguments arg; arg.rank = std::get<0>(tup); arg.dev_per_node = std::get<1>(tup); arg.dev = std::get<2>(tup); arg.omp_nthreads = std::get<3>(tup); arg.omp_affinity = std::get<4>(tup); arg.omp_threshold = std::get<5>(tup); arg.use_acc = std::get<6>(tup); return arg; } */ TEST(global_matrix_bad_args, global_matrix) { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED"})) { GTEST_SKIP(); } testing_global_matrix_bad_args(); } /* TEST_P(parameterized_backend, backend) { Arguments arg = setup_backend_arguments(GetParam()); testing_backend(arg); } INSTANTIATE_TEST_CASE_P(backend, parameterized_backend, testing::Combine(testing::ValuesIn(backend_rank), testing::ValuesIn(backend_dev_node), testing::ValuesIn(backend_dev), testing::ValuesIn(backend_omp_threads), testing::ValuesIn(backend_affinity), testing::ValuesIn(backend_omp_threshold), testing::ValuesIn(backend_disable_acc))); */ rocALUTION-rocm-7.1.0/clients/tests/test_global_vector.cpp000066400000000000000000000065541507377332500235120ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_global_vector.hpp" #include "utility.hpp" #include /* typedef std::tuple backend_tuple; int backend_rank[] = {-1, 0, 13}; int backend_dev_node[] = {-1, 0, 13}; int backend_dev[] = {-1, 0, 13}; int backend_omp_threads[] = {-1, 0, 8}; bool backend_affinity[] = {true, false}; int backend_omp_threshold[] = {-1, 0, 20000}; bool backend_disable_acc[] = {true, false}; class parameterized_backend : public testing::TestWithParam { protected: parameterized_backend() {} virtual ~parameterized_backend() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_backend_arguments(backend_tuple tup) { Arguments arg; arg.rank = std::get<0>(tup); arg.dev_per_node = std::get<1>(tup); arg.dev = std::get<2>(tup); arg.omp_nthreads = std::get<3>(tup); arg.omp_affinity = std::get<4>(tup); arg.omp_threshold = std::get<5>(tup); arg.use_acc = std::get<6>(tup); return arg; } */ TEST(global_vector_bad_args, global_vector) { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED"})) { GTEST_SKIP(); } testing_global_vector_bad_args(); } /* TEST_P(parameterized_backend, backend) { Arguments arg = setup_backend_arguments(GetParam()); testing_backend(arg); } INSTANTIATE_TEST_CASE_P(backend, parameterized_backend, testing::Combine(testing::ValuesIn(backend_rank), testing::ValuesIn(backend_dev_node), testing::ValuesIn(backend_dev), testing::ValuesIn(backend_omp_threads), testing::ValuesIn(backend_affinity), testing::ValuesIn(backend_omp_threshold), testing::ValuesIn(backend_disable_acc))); */ rocALUTION-rocm-7.1.0/clients/tests/test_gmres.cpp000066400000000000000000000145421507377332500220010ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_gmres.hpp" #include "utility.hpp" #include #include typedef std::tuple gmres_tuple; std::vector gmres_size = {7, 63}; std::vector gmres_basis = {20, 60}; std::vector gmres_matrix = {"laplacian"}; std::vector gmres_bad_precond_matrix = {"permuted_identity"}; std::vector gmres_precond = {"None", "Chebyshev", "GS", "ILU", "ItILU0", "ILUT", "MCGS", "MCILU"}; std::vector gmres_bad_precond = {"MCGS"}; std::vector gmres_format = {1, 2, 5, 6}; std::vector gmres_use_acc = {1}; // Function to update tests if environment variable is set void update_gmres() { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED", "ROCALUTION_CODE_COVERAGE"})) { gmres_size.clear(); gmres_basis.clear(); gmres_precond.clear(); gmres_format.clear(); } if(is_env_var_set("ROCALUTION_CODE_COVERAGE")) { gmres_size.push_back(7); gmres_basis.push_back(20); gmres_precond.insert(gmres_precond.end(), {"None", "Chebyshev", "GS", "ILU", "ItILU0", "ILUT", "MCGS", "MCILU"}); gmres_format.insert(gmres_format.end(), {1, 2, 5, 6}); gmres_use_acc.push_back(0); } if(is_env_var_set("ROCALUTION_EMULATION_SMOKE")) { gmres_size.push_back(7); gmres_basis.push_back(20); gmres_precond.insert(gmres_precond.end(), {"None", "ILU"}); gmres_format.push_back(6); } else if(is_env_var_set("ROCALUTION_EMULATION_REGRESSION")) { gmres_size.push_back(7); gmres_basis.push_back(60); gmres_precond.insert(gmres_precond.end(), {"Chebyshev", "GS"}); gmres_format.push_back(1); } else if(is_env_var_set("ROCALUTION_EMULATION_EXTENDED")) { gmres_size.push_back(63); gmres_basis.push_back(60); gmres_precond.insert(gmres_precond.end(), {"ILUT", "MCILU"}); gmres_format.insert(gmres_format.end(), {2, 5}); } } struct GMRESInitializer { GMRESInitializer() { update_gmres(); } }; // Create a global instance of the initializer, so the environment is checked and updated before tests. GMRESInitializer gmres_initializer; class parameterized_gmres : public testing::TestWithParam { protected: parameterized_gmres() {} virtual ~parameterized_gmres() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_gmres_bad_precond : public testing::TestWithParam { protected: parameterized_gmres_bad_precond() {} virtual ~parameterized_gmres_bad_precond() {} virtual void SetUp() override { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED"}) && !is_env_var_set("ROCALUTION_CODE_COVERAGE")) { GTEST_SKIP(); } } virtual void TearDown() {} }; Arguments setup_gmres_arguments(gmres_tuple tup) { Arguments arg; arg.size = std::get<0>(tup); arg.index = std::get<1>(tup); arg.matrix = std::get<2>(tup); arg.precond = std::get<3>(tup); arg.format = std::get<4>(tup); arg.use_acc = std::get<5>(tup); return arg; } TEST_P(parameterized_gmres, gmres_float) { Arguments arg = setup_gmres_arguments(GetParam()); ASSERT_EQ(testing_gmres(arg), true); } TEST_P(parameterized_gmres, gmres_double) { Arguments arg = setup_gmres_arguments(GetParam()); ASSERT_EQ(testing_gmres(arg), true); } TEST_P(parameterized_gmres_bad_precond, gmres_float) { Arguments arg = setup_gmres_arguments(GetParam()); ASSERT_EQ(testing_gmres(arg, false), true); } INSTANTIATE_TEST_CASE_P(gmres, parameterized_gmres, testing::Combine(testing::ValuesIn(gmres_size), testing::ValuesIn(gmres_basis), testing::ValuesIn(gmres_matrix), testing::ValuesIn(gmres_precond), testing::ValuesIn(gmres_format), testing::ValuesIn(gmres_use_acc))); INSTANTIATE_TEST_CASE_P(gmres_bad_precond, parameterized_gmres_bad_precond, testing::Combine(testing::ValuesIn(gmres_size), testing::ValuesIn(gmres_basis), testing::ValuesIn(gmres_bad_precond_matrix), testing::ValuesIn(gmres_bad_precond), testing::ValuesIn(gmres_format), testing::ValuesIn(gmres_use_acc))); rocALUTION-rocm-7.1.0/clients/tests/test_idr.cpp000066400000000000000000000111401507377332500214310ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_idr.hpp" #include "utility.hpp" #include #include typedef std::tuple idr_tuple; std::vector idr_size = {7, 63}; std::vector idr_precond = {"None", "SPAI", "GS", "ILU", "MCILU"}; std::vector idr_format = {1, 4, 5, 6}; std::vector idr_level = {1, 2}; std::vector idr_use_acc = {1}; // Function to update tests if environment variable is set void update_idr() { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED", "ROCALUTION_CODE_COVERAGE"})) { idr_size.clear(); idr_precond.clear(); idr_format.clear(); idr_level.clear(); } if(is_env_var_set("ROCALUTION_CODE_COVERAGE")) { idr_size.push_back(7); idr_precond.insert(idr_precond.end(), {"None", "SPAI", "GS", "ILU", "MCILU"}); idr_format.insert(idr_format.end(), {1, 4, 5, 6}); idr_level.insert(idr_level.end(), {1, 2}); idr_use_acc.push_back(0); } if(is_env_var_set("ROCALUTION_EMULATION_SMOKE")) { idr_size.push_back(63); idr_precond.insert(idr_precond.end(), {"None", "MCILU"}); idr_format.push_back(6); idr_level.push_back(2); } else if(is_env_var_set("ROCALUTION_EMULATION_REGRESSION")) { idr_size.insert(idr_size.end(), {7, 63}); idr_precond.insert(idr_precond.end(), {"MCILU"}); idr_format.push_back(1); idr_level.push_back(2); } else if(is_env_var_set("ROCALUTION_EMULATION_EXTENDED")) { idr_size.insert(idr_size.end(), {7, 63}); idr_precond.insert(idr_precond.end(), {"SPAI", "GS", "ILU"}); idr_format.insert(idr_format.end(), {4, 5}); idr_level.insert(idr_level.end(), {1, 2}); } } struct IDRInitializer { IDRInitializer() { update_idr(); } }; // Create a global instance of the initializer, so the environment is checked and updated before tests. IDRInitializer idr_initializer; class parameterized_idr : public testing::TestWithParam { protected: parameterized_idr() {} virtual ~parameterized_idr() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_idr_arguments(idr_tuple tup) { Arguments arg; arg.size = std::get<0>(tup); arg.precond = std::get<1>(tup); arg.format = std::get<2>(tup); arg.index = std::get<3>(tup); arg.use_acc = std::get<4>(tup); return arg; } TEST_P(parameterized_idr, idr_float) { Arguments arg = setup_idr_arguments(GetParam()); ASSERT_EQ(testing_idr(arg), true); } TEST_P(parameterized_idr, idr_double) { Arguments arg = setup_idr_arguments(GetParam()); ASSERT_EQ(testing_idr(arg), true); } INSTANTIATE_TEST_CASE_P(idr, parameterized_idr, testing::Combine(testing::ValuesIn(idr_size), testing::ValuesIn(idr_precond), testing::ValuesIn(idr_format), testing::ValuesIn(idr_level), testing::ValuesIn(idr_use_acc))); rocALUTION-rocm-7.1.0/clients/tests/test_inversion.cpp000066400000000000000000000120731507377332500226750ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_inversion.hpp" #include "utility.hpp" #include #include typedef std::tuple inversion_tuple; std::vector inversion_size = {7, 16, 21}; std::vector inversion_format = {1, 2, 3, 4, 5, 6, 7}; std::vector inversion_matrix_type = {"Laplacian2D", "PermutedIdentity"}; std::vector inversion_use_host_and_acc = {0}; // Function to update tests if environment variable is set void update_inversion() { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED", "ROCALUTION_CODE_COVERAGE"})) { inversion_size.clear(); inversion_format.clear(); inversion_matrix_type.clear(); inversion_use_host_and_acc.clear(); } if(is_env_var_set("ROCALUTION_CODE_COVERAGE")) { inversion_size.push_back(7); inversion_format.insert(inversion_format.end(), {1, 2, 3, 4, 5, 6, 7}); inversion_matrix_type.push_back("Laplacian2D"); inversion_use_host_and_acc.push_back(1); } else if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED"})) { inversion_use_host_and_acc.push_back(0); } if(is_env_var_set("ROCALUTION_EMULATION_SMOKE")) { inversion_size.push_back(16); inversion_format.push_back(1); inversion_matrix_type.push_back("Laplacian2D"); } else if(is_env_var_set("ROCALUTION_EMULATION_REGRESSION")) { inversion_size.insert(inversion_size.end(), {7, 16}); inversion_format.insert(inversion_format.end(), {2, 3}); inversion_matrix_type.insert(inversion_matrix_type.end(), {"Laplacian2D", "PermutedIdentity"}); } else if(is_env_var_set("ROCALUTION_EMULATION_EXTENDED")) { inversion_size.insert(inversion_size.end(), {21}); inversion_format.insert(inversion_format.end(), {4, 5, 6, 7}); inversion_matrix_type.insert(inversion_matrix_type.end(), {"Laplacian2D", "PermutedIdentity"}); } } struct InversionInitializer { InversionInitializer() { update_inversion(); } }; // Create a global instance of the initializer, so the environment is checked and updated before tests. InversionInitializer inversion_initializer; class parameterized_inversion : public testing::TestWithParam { protected: parameterized_inversion() {} virtual ~parameterized_inversion() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_inversion_arguments(inversion_tuple tup) { Arguments arg; arg.size = std::get<0>(tup); arg.format = std::get<1>(tup); arg.matrix_type = std::get<2>(tup); arg.use_acc = std::get<3>(tup); return arg; } TEST_P(parameterized_inversion, inversion_float) { Arguments arg = setup_inversion_arguments(GetParam()); ASSERT_EQ(testing_inversion(arg), true); } TEST_P(parameterized_inversion, inversion_double) { Arguments arg = setup_inversion_arguments(GetParam()); ASSERT_EQ(testing_inversion(arg), true); } INSTANTIATE_TEST_CASE_P(inversion, parameterized_inversion, testing::Combine(testing::ValuesIn(inversion_size), testing::ValuesIn(inversion_format), testing::ValuesIn(inversion_matrix_type), testing::ValuesIn(inversion_use_host_and_acc))); rocALUTION-rocm-7.1.0/clients/tests/test_itersolver.cpp000066400000000000000000000065501507377332500230620ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "testing_itsolver.hpp" #include "utility.hpp" #include #include typedef std::tuple itsolver_tuple; std::vector itsolver_size = {7}; std::vector itsolver_format = {1, 2, 3, 4, 5, 6, 7}; std::vector itsolver_matrix_type = {"Laplacian2D"}; std::vector itsolver_use_acc = {0, 1}; // Function to update tests if environment variable is set void update_itsolver() {} struct ItsolverInitializer { ItsolverInitializer() { update_itsolver(); } }; // Create a global instance of the initializer, so the environment is checked and updated before tests. ItsolverInitializer itsolver_initializer; class parameterized_itsolver : public testing::TestWithParam { protected: parameterized_itsolver() {} virtual ~parameterized_itsolver() {} virtual void SetUp() { if(!is_env_var_set("ROCALUTION_CODE_COVERAGE")) { GTEST_SKIP() << "Skipping tests as ROCALUTION_CODE_COVERAGE is not set."; } } virtual void TearDown() {} }; Arguments setup_itsolver_arguments(itsolver_tuple tup) { Arguments arg; arg.size = std::get<0>(tup); arg.format = std::get<1>(tup); arg.matrix_type = std::get<2>(tup); arg.use_acc = std::get<3>(tup); return arg; } TEST_P(parameterized_itsolver, itsolver_float) { Arguments arg = setup_itsolver_arguments(GetParam()); ASSERT_EQ(testing_itsolver(arg), true); } TEST_P(parameterized_itsolver, itsolver_double) { Arguments arg = setup_itsolver_arguments(GetParam()); ASSERT_EQ(testing_itsolver(arg), true); } INSTANTIATE_TEST_CASE_P(itsolver, parameterized_itsolver, testing::Combine(testing::ValuesIn(itsolver_size), testing::ValuesIn(itsolver_format), testing::ValuesIn(itsolver_matrix_type), testing::ValuesIn(itsolver_use_acc))); rocALUTION-rocm-7.1.0/clients/tests/test_local_matrix.cpp000066400000000000000000000502751507377332500233450ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_local_matrix.hpp" #include "utility.hpp" #include typedef std::tuple local_matrix_conversions_tuple; typedef std::tuple local_matrix_allocations_tuple; typedef std::tuple local_matrix_zero_tuple; int local_matrix_conversions_size[] = {10, 17, 21}; int local_matrix_conversions_blockdim[] = {4, 7, 11}; std::string local_matrix_type[] = {"Laplacian2D", "PermutedIdentity", "Random"}; int local_matrix_allocations_size[] = {100, 1475, 2524}; int local_matrix_allocations_blockdim[] = {4, 7, 11}; class parameterized_local_matrix_conversions : public testing::TestWithParam { protected: parameterized_local_matrix_conversions() {} virtual ~parameterized_local_matrix_conversions() {} virtual void SetUp() override { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED"})) { GTEST_SKIP(); } } virtual void TearDown() {} }; Arguments setup_local_matrix_conversions_arguments(local_matrix_conversions_tuple tup) { Arguments arg; arg.size = std::get<0>(tup); arg.blockdim = std::get<1>(tup); arg.matrix_type = std::get<2>(tup); return arg; } class parameterized_local_matrix_allocations : public testing::TestWithParam { protected: parameterized_local_matrix_allocations() {} virtual ~parameterized_local_matrix_allocations() {} virtual void SetUp() override { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED"})) { GTEST_SKIP(); } } virtual void TearDown() {} }; Arguments setup_local_matrix_allocations_arguments(local_matrix_allocations_tuple tup) { Arguments arg; arg.size = std::get<0>(tup); arg.blockdim = std::get<1>(tup); return arg; } TEST(local_matrix_bad_args, local_matrix) { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED"})) { GTEST_SKIP(); } testing_local_matrix_bad_args(); } TEST_P(parameterized_local_matrix_conversions, local_matrix_conversions_float) { Arguments arg = setup_local_matrix_conversions_arguments(GetParam()); ASSERT_EQ(testing_local_matrix_conversions(arg), true); } TEST_P(parameterized_local_matrix_conversions, local_matrix_conversions_double) { Arguments arg = setup_local_matrix_conversions_arguments(GetParam()); ASSERT_EQ(testing_local_matrix_conversions(arg), true); } INSTANTIATE_TEST_CASE_P(local_matrix_conversions, parameterized_local_matrix_conversions, testing::Combine(testing::ValuesIn(local_matrix_conversions_size), testing::ValuesIn(local_matrix_conversions_blockdim), testing::ValuesIn(local_matrix_type))); TEST_P(parameterized_local_matrix_allocations, local_matrix_allocations_float) { Arguments arg = setup_local_matrix_allocations_arguments(GetParam()); ASSERT_EQ(testing_local_matrix_allocations(arg), true); } TEST_P(parameterized_local_matrix_allocations, local_matrix_allocations_double) { Arguments arg = setup_local_matrix_allocations_arguments(GetParam()); ASSERT_EQ(testing_local_matrix_allocations(arg), true); } INSTANTIATE_TEST_CASE_P(local_matrix_allocations, parameterized_local_matrix_allocations, testing::Combine(testing::ValuesIn(local_matrix_allocations_size), testing::ValuesIn(local_matrix_allocations_blockdim))); TEST_P(parameterized_local_matrix_allocations, local_matrix_zero_float) { Arguments arg = setup_local_matrix_allocations_arguments(GetParam()); ASSERT_EQ(testing_local_matrix_zero(arg), true); } TEST_P(parameterized_local_matrix_allocations, local_matrix_zero_double) { Arguments arg = setup_local_matrix_allocations_arguments(GetParam()); ASSERT_EQ(testing_local_matrix_zero(arg), true); } INSTANTIATE_TEST_CASE_P(local_matrix_zero, parameterized_local_matrix_allocations, testing::Combine(testing::ValuesIn(local_matrix_allocations_size), testing::ValuesIn(local_matrix_allocations_blockdim))); TEST_P(parameterized_local_matrix_allocations, local_matrix_set_data_ptr_float) { Arguments arg = setup_local_matrix_allocations_arguments(GetParam()); ASSERT_EQ(testing_local_matrix_set_data_ptr(arg), true); } TEST_P(parameterized_local_matrix_allocations, local_matrix_set_data_ptr_double) { Arguments arg = setup_local_matrix_allocations_arguments(GetParam()); ASSERT_EQ(testing_local_matrix_set_data_ptr(arg), true); } INSTANTIATE_TEST_CASE_P(local_matrix_set_data_ptr, parameterized_local_matrix_allocations, testing::Combine(testing::ValuesIn(local_matrix_allocations_size), testing::ValuesIn(local_matrix_allocations_blockdim))); // Test fixture for LocalMatrix class local_matrix_test : public testing::TestWithParam { protected: void SetUp() override { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED"})) { GTEST_SKIP(); } } virtual void TearDown() {} }; class parameterized_local_matrix_test : public testing::TestWithParam { protected: parameterized_local_matrix_test() {} virtual ~parameterized_local_matrix_test() {} virtual void SetUp() override { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED"})) { GTEST_SKIP(); } } virtual void TearDown() {} }; #define TEST_CASE(function, type, disable_accelerator) \ disable_accelerator_rocalution(disable_accelerator); \ set_device_rocalution(0); \ init_rocalution(); \ function(); \ stop_rocalution(); \ disable_accelerator_rocalution(false); #define GENERATE_TEST_CASES_DEVICE(test_fixture, function, name) \ TEST_F(test_fixture, name##_device_float) \ { \ TEST_CASE(function, float, false); \ } \ TEST_F(test_fixture, name##_device_double) \ { \ TEST_CASE(function, double, false); \ } #define GENERATE_TEST_CASES_HOST(test_fixture, function, name) \ TEST_F(test_fixture, name##_host_float) \ { \ TEST_CASE(function, float, true); \ } \ TEST_F(test_fixture, name##_host_double) \ { \ TEST_CASE(function, double, true); \ } #define GENERATE_TEST_CASES(test_fixture, function, name) \ GENERATE_TEST_CASES_DEVICE(test_fixture, function, name) \ GENERATE_TEST_CASES_HOST(test_fixture, function, name) #define TEST_P_CASE(function, type, disable_accelerator) \ disable_accelerator_rocalution(disable_accelerator); \ set_device_rocalution(0); \ init_rocalution(); \ Arguments arg = setup_local_matrix_conversions_arguments(GetParam()); \ function(arg); \ stop_rocalution(); \ disable_accelerator_rocalution(false); #define GENERATE_P_TEST_CASES_DEVICE(test_fixture, function, name) \ TEST_P(test_fixture, name##_device_float) \ { \ TEST_P_CASE(function, float, false); \ } \ TEST_P(test_fixture, name##_device_double) \ { \ TEST_P_CASE(function, double, false); \ } #define GENERATE_P_TEST_CASES_HOST(test_fixture, function, name) \ TEST_P(test_fixture, name##_host_float) \ { \ TEST_P_CASE(function, float, true); \ } \ TEST_P(test_fixture, name##_host_double) \ { \ TEST_P_CASE(function, double, true); \ } #define GENERATE_P_TEST_CASES(test_fixture, function, name) \ GENERATE_P_TEST_CASES_DEVICE(test_fixture, function, name) \ GENERATE_P_TEST_CASES_HOST(test_fixture, function, name) // Test for matrix allocation GENERATE_TEST_CASES(local_matrix_test, testing_local_allocate, allocate_matrix) // Test for matrix check with empty matrix GENERATE_TEST_CASES(local_matrix_test, testing_check_with_empty_matrix, check_with_empty_matrix) // Test for matrix clearing GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_local_clear, clear_matrix) // Test for zeros matrix GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_local_zeros, zeros_matrix) // Test for matrix copy GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_local_copy, copy_matrix) // Test for matrix scaling GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_local_scale, scale_matrix) // Test for extracting diagonal GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_local_extract_diagonal, extract_diagonal) // Test for extracting inverse diagonal GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_local_extract_inverse_diagonal, extract_inverse_diagonal) // Test for matrix transpose GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_local_transpose, transpose_matrix) // Test for matrix clone GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_clone_matrix, clone_matrix) // Test for matrix inversion GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_invert_matrix, invert_matrix) // Test for setting data pointers GENERATE_TEST_CASES(local_matrix_test, testing_set_data_pointer, set_data_pointer) // Test for leaving data pointers GENERATE_TEST_CASES(local_matrix_test, testing_leave_data_pointer, leave_data_pointer) // Test for MaximalIndependentSet GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_maximal_independent_set, maximal_independent_set) // Test for ZeroBlockPermutation GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_zero_block_permutation, zero_block_permutation) // Test for Householder GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_Householder, householder) // Test for CMK GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_CMK, CMK) // Test for RCMK GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_RCMK, RCMK) // Test for ConnectivityOrder GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_connectivity_order, connectivity_order) // Test for SymbolicPower GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_symbolic_power, symbolic_power) // Test for ScaleOffDiagonal GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_scale_off_diagonal, scale_off_diagonal) // Test for AddScalar GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_add_scalar, add_scalar) // Test for ReplaceColumnVector GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_replace_column_vector, replace_column_vector) // Test for ExtractColumnVector GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_extract_column_vector, extract_column_vector) // Test for SetDataPtrDIA GENERATE_TEST_CASES(local_matrix_test, testing_set_data_ptr_DIA, set_data_ptr_dia) // Test for LeaveDataPtrDIA GENERATE_TEST_CASES(local_matrix_test, testing_leave_data_ptr_DIA, leave_data_ptr_dia) // Test for CopyFromCOO GENERATE_TEST_CASES(local_matrix_test, testing_copy_from_COO, copy_from_coo) // Test for CopyToCOO GENERATE_TEST_CASES(local_matrix_test, testing_copy_to_COO, copy_to_coo) // Test for CopyFromHostCSR GENERATE_TEST_CASES(local_matrix_test, testing_copy_from_host_CSR, copy_from_host_csr) // Test for ReadFileMTX GENERATE_TEST_CASES(local_matrix_test, testing_read_file_MTX, read_file_mtx_to_csr) // Test case for LocalMatrix::WriteFileMTX GENERATE_TEST_CASES(local_matrix_test, testing_write_file_MTX, write_file_mtx_to_csr) // Test case for LocalMatrix::WriteFileRSIO GENERATE_TEST_CASES(local_matrix_test, testing_write_file_RSIO, write_file_RSIO) // Test case for LocalMatrix::CopyFromAsync GENERATE_TEST_CASES_DEVICE(local_matrix_test, testing_local_copy_from_async, local_copy_from_async) // Test case for LocalMatrix::CopyToAsync GENERATE_TEST_CASES(local_matrix_test, testing_local_update_values_csr, local_update_values_csr) // Test case for LocalMatrix::CopyFromHostAsync GENERATE_TEST_CASES_DEVICE(local_matrix_test, testing_local_move_to_accelerator, local_move_to_accelerator) // Test case for LocalMatrix::CopyToHostAsync GENERATE_TEST_CASES_DEVICE(local_matrix_test, testing_local_move_to_accelerator_async, local_move_to_accelerator_async) // Test case for LocalMatrix::CopyFromHostAsync GENERATE_TEST_CASES_DEVICE(local_matrix_test, testing_local_move_to_host_async, local_move_to_host_async) // Test case for LocalMatrix::Apply GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_local_apply, local_apply) // Test case for LocalMatrix::ApplyAdd GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_local_apply_add, local_apply_add) // Test case for LocalMatrix::ExtractSubmatrix GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_local_extract_submatrix, local_extract_submatrix) // Test case for LocalMatrix::ExtractU GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_local_extract_u, local_extract_u) // Test case for LocalMatrix::ExtractL GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_local_extract_l, local_extract_l) // Test case for LocalMatrix::MatrixAdd GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_local_matrix_add, local_matrix_add) // Test case for LocalMatrix::Gershgorin GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_local_gershgorin, local_gershgorin) // Test case for LocalMatrix::ScaleDiagonal GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_local_scale_diagonal, local_scale_diagonal) // Test case for LocalMatrix::AddScalarDiagonal GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_local_add_scalar_diagonal, local_add_scalar_diagonal) // Test case for LocalMatrix::AddScalarOffDiagonal GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_local_add_scalar_off_diagonal, local_add_scalar_off_diagonal) // Test case for LocalMatrix::MatrixMult GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_local_matrix_mult, local_matrix_mult) // Test case for LocalMatrix::TripleMatrixProduct GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_local_triple_matrix_product, local_triple_matrix_product) // Test case for LocalMatrix::DiagonalMatrixMultR GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_local_diagonal_matrix_mult_r, local_diagonal_matrix_mult_r) // Test case for LocalMatrix::DiagonalMatrixMult GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_local_diagonal_matrix_mult, local_diagonal_matrix_mult) // Test case for LocalMatrix::DiagonalMatrixMultL GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_local_diagonal_matrix_mult_l, local_diagonal_matrix_mult_l) // Test case for LocalMatrix::Compress GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_local_compress, local_compress) // Test case for LocalMatrix::ReplaceRowVector GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_local_replace_row_vector, local_replace_row_vector) // Test case for LocalMatrix::ExtractRowVector GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_local_extract_row_vector, local_extract_row_vector) // Test case for LocalMatrix::Key GENERATE_P_TEST_CASES(parameterized_local_matrix_test, testing_local_key, local_key) // Test case for LocalMatrix::InitialPairwiseAggregation GENERATE_TEST_CASES(local_matrix_test, testing_initial_pairwise_aggregation, initial_pairwise_aggregation) // Test case for LocalMatrix::InitialPairwiseAggregation GENERATE_TEST_CASES(local_matrix_test, testing_initial_pairwise_aggregation_2, initial_pairwise_aggregation_2) INSTANTIATE_TEST_CASE_P(local_matrix_test, parameterized_local_matrix_test, testing::Combine(testing::ValuesIn(local_matrix_conversions_size), testing::ValuesIn(local_matrix_conversions_blockdim), testing::ValuesIn(local_matrix_type)));rocALUTION-rocm-7.1.0/clients/tests/test_local_matrix_itsolve.cpp000066400000000000000000000163211507377332500251040ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2023-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 "testing_local_matrix_itsolve.hpp" #include "utility.hpp" #include typedef std::tuple local_matrix_gen_solve_tuple; typedef std::tuple local_matrix_tri_solve_tuple; static const int local_matrix_solve_size[] = {10, 17, 21}; static const unsigned int local_matrix_solve_format[] = {1}; static const bool local_matrix_solve_unit_diag[] = {false, true}; class parameterized_local_matrix_itlusolve : public testing::TestWithParam { protected: parameterized_local_matrix_itlusolve() {} virtual ~parameterized_local_matrix_itlusolve() {} virtual void SetUp() override { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED"})) { GTEST_SKIP(); } } virtual void TearDown() {} }; class parameterized_local_matrix_itllsolve : public testing::TestWithParam { protected: parameterized_local_matrix_itllsolve() {} virtual ~parameterized_local_matrix_itllsolve() {} virtual void SetUp() override { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED"})) { GTEST_SKIP(); } } virtual void TearDown() {} }; class parameterized_local_matrix_itlsolve : public testing::TestWithParam { protected: parameterized_local_matrix_itlsolve() {} virtual ~parameterized_local_matrix_itlsolve() {} virtual void SetUp() override { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED"})) { GTEST_SKIP(); } } virtual void TearDown() {} }; class parameterized_local_matrix_itusolve : public testing::TestWithParam { protected: parameterized_local_matrix_itusolve() {} virtual ~parameterized_local_matrix_itusolve() {} virtual void SetUp() override { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED"})) { GTEST_SKIP(); } } virtual void TearDown() {} }; static Arguments setup_local_matrix_solve_arguments(local_matrix_gen_solve_tuple tup) { Arguments arg; arg.size = std::get<0>(tup); arg.format = std::get<1>(tup); return arg; } static Arguments setup_local_matrix_solve_arguments(local_matrix_tri_solve_tuple tup) { Arguments arg; arg.size = std::get<0>(tup); arg.format = std::get<1>(tup); arg.unit_diag = std::get<2>(tup); return arg; } TEST_P(parameterized_local_matrix_itlusolve, local_matrix_itlusolve_float) { Arguments arg = setup_local_matrix_solve_arguments(GetParam()); ASSERT_EQ(testing_local_matrix_itlusolve(arg), true); } TEST_P(parameterized_local_matrix_itlusolve, local_matrix_itlusolve_double) { Arguments arg = setup_local_matrix_solve_arguments(GetParam()); ASSERT_EQ(testing_local_matrix_itlusolve(arg), true); } TEST_P(parameterized_local_matrix_itllsolve, local_matrix_itllsolve_float) { Arguments arg = setup_local_matrix_solve_arguments(GetParam()); ASSERT_EQ(testing_local_matrix_itllsolve(arg), true); } TEST_P(parameterized_local_matrix_itllsolve, local_matrix_itllsolve_double) { Arguments arg = setup_local_matrix_solve_arguments(GetParam()); ASSERT_EQ(testing_local_matrix_itllsolve(arg), true); } TEST_P(parameterized_local_matrix_itlsolve, local_matrix_itlsolve_float) { Arguments arg = setup_local_matrix_solve_arguments(GetParam()); ASSERT_EQ(testing_local_matrix_itlsolve(arg), true); } TEST_P(parameterized_local_matrix_itlsolve, local_matrix_itlsolve_double) { Arguments arg = setup_local_matrix_solve_arguments(GetParam()); ASSERT_EQ(testing_local_matrix_itlsolve(arg), true); } TEST_P(parameterized_local_matrix_itusolve, local_matrix_itusolve_float) { Arguments arg = setup_local_matrix_solve_arguments(GetParam()); ASSERT_EQ(testing_local_matrix_itusolve(arg), true); } TEST_P(parameterized_local_matrix_itusolve, local_matrix_itusolve_double) { Arguments arg = setup_local_matrix_solve_arguments(GetParam()); ASSERT_EQ(testing_local_matrix_itusolve(arg), true); } INSTANTIATE_TEST_CASE_P(local_matrix_itsolve, parameterized_local_matrix_itlusolve, testing::Combine(testing::ValuesIn(local_matrix_solve_size), testing::ValuesIn(local_matrix_solve_format))); INSTANTIATE_TEST_CASE_P(local_matrix_itsolve, parameterized_local_matrix_itllsolve, testing::Combine(testing::ValuesIn(local_matrix_solve_size), testing::ValuesIn(local_matrix_solve_format))); INSTANTIATE_TEST_CASE_P(local_matrix_itsolve, parameterized_local_matrix_itlsolve, testing::Combine(testing::ValuesIn(local_matrix_solve_size), testing::ValuesIn(local_matrix_solve_format), testing::ValuesIn(local_matrix_solve_unit_diag))); INSTANTIATE_TEST_CASE_P(local_matrix_itsolve, parameterized_local_matrix_itusolve, testing::Combine(testing::ValuesIn(local_matrix_solve_size), testing::ValuesIn(local_matrix_solve_format), testing::ValuesIn(local_matrix_solve_unit_diag))); rocALUTION-rocm-7.1.0/clients/tests/test_local_matrix_multicoloring.cpp000066400000000000000000000065051507377332500263110ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2023-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 "testing_local_matrix_multicoloring.hpp" #include "utility.hpp" #include typedef std::tuple local_matrix_multicoloring_tuple; int local_matrix_multicoloring_size[] = {10, 17, 21}; std::string local_matrix_multicoloring_type[] = {"Laplacian2D", "PermutedIdentity", "Random"}; unsigned int local_matrix_multicoloring_format[] = {1}; class parameterized_local_matrix_multicoloring : public testing::TestWithParam { protected: parameterized_local_matrix_multicoloring() {} virtual ~parameterized_local_matrix_multicoloring() {} virtual void SetUp() override { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED"})) { GTEST_SKIP(); } } virtual void TearDown() {} }; Arguments setup_local_matrix_multicoloring_arguments(local_matrix_multicoloring_tuple tup) { Arguments arg; arg.size = std::get<0>(tup); arg.matrix_type = std::get<1>(tup); arg.format = std::get<2>(tup); return arg; } TEST_P(parameterized_local_matrix_multicoloring, local_matrix_multicoloring_float) { Arguments arg = setup_local_matrix_multicoloring_arguments(GetParam()); ASSERT_EQ(testing_local_matrix_multicoloring(arg), true); } TEST_P(parameterized_local_matrix_multicoloring, local_matrix_multicoloring_double) { Arguments arg = setup_local_matrix_multicoloring_arguments(GetParam()); ASSERT_EQ(testing_local_matrix_multicoloring(arg), true); } INSTANTIATE_TEST_CASE_P(local_matrix_multicoloring, parameterized_local_matrix_multicoloring, testing::Combine(testing::ValuesIn(local_matrix_multicoloring_size), testing::ValuesIn(local_matrix_multicoloring_type), testing::ValuesIn(local_matrix_multicoloring_format))); rocALUTION-rocm-7.1.0/clients/tests/test_local_matrix_solve.cpp000066400000000000000000000161731507377332500245540ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2023-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 "testing_local_matrix_solve.hpp" #include "utility.hpp" #include typedef std::tuple local_matrix_gen_solve_tuple; typedef std::tuple local_matrix_tri_solve_tuple; static const int local_matrix_solve_size[] = {10, 17, 21}; static const unsigned int local_matrix_solve_format[] = {1}; static const bool local_matrix_solve_unit_diag[] = {false, true}; class parameterized_local_matrix_lusolve : public testing::TestWithParam { protected: parameterized_local_matrix_lusolve() {} virtual ~parameterized_local_matrix_lusolve() {} virtual void SetUp() override { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED"})) { GTEST_SKIP(); } } virtual void TearDown() {} }; class parameterized_local_matrix_llsolve : public testing::TestWithParam { protected: parameterized_local_matrix_llsolve() {} virtual ~parameterized_local_matrix_llsolve() {} virtual void SetUp() override { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED"})) { GTEST_SKIP(); } } virtual void TearDown() {} }; class parameterized_local_matrix_lsolve : public testing::TestWithParam { protected: parameterized_local_matrix_lsolve() {} virtual ~parameterized_local_matrix_lsolve() {} virtual void SetUp() override { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED"})) { GTEST_SKIP(); } } virtual void TearDown() {} }; class parameterized_local_matrix_usolve : public testing::TestWithParam { protected: parameterized_local_matrix_usolve() {} virtual ~parameterized_local_matrix_usolve() {} virtual void SetUp() override { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED"})) { GTEST_SKIP(); } } virtual void TearDown() {} }; static Arguments setup_local_matrix_solve_arguments(local_matrix_gen_solve_tuple tup) { Arguments arg; arg.size = std::get<0>(tup); arg.format = std::get<1>(tup); return arg; } static Arguments setup_local_matrix_solve_arguments(local_matrix_tri_solve_tuple tup) { Arguments arg; arg.size = std::get<0>(tup); arg.format = std::get<1>(tup); arg.unit_diag = std::get<2>(tup); return arg; } TEST_P(parameterized_local_matrix_lusolve, local_matrix_lusolve_float) { Arguments arg = setup_local_matrix_solve_arguments(GetParam()); ASSERT_EQ(testing_local_matrix_lusolve(arg), true); } TEST_P(parameterized_local_matrix_lusolve, local_matrix_lusolve_double) { Arguments arg = setup_local_matrix_solve_arguments(GetParam()); ASSERT_EQ(testing_local_matrix_lusolve(arg), true); } TEST_P(parameterized_local_matrix_llsolve, local_matrix_llsolve_float) { Arguments arg = setup_local_matrix_solve_arguments(GetParam()); ASSERT_EQ(testing_local_matrix_llsolve(arg), true); } TEST_P(parameterized_local_matrix_llsolve, local_matrix_llsolve_double) { Arguments arg = setup_local_matrix_solve_arguments(GetParam()); ASSERT_EQ(testing_local_matrix_llsolve(arg), true); } TEST_P(parameterized_local_matrix_lsolve, local_matrix_lsolve_float) { Arguments arg = setup_local_matrix_solve_arguments(GetParam()); ASSERT_EQ(testing_local_matrix_lsolve(arg), true); } TEST_P(parameterized_local_matrix_lsolve, local_matrix_lsolve_double) { Arguments arg = setup_local_matrix_solve_arguments(GetParam()); ASSERT_EQ(testing_local_matrix_lsolve(arg), true); } TEST_P(parameterized_local_matrix_usolve, local_matrix_usolve_float) { Arguments arg = setup_local_matrix_solve_arguments(GetParam()); ASSERT_EQ(testing_local_matrix_usolve(arg), true); } TEST_P(parameterized_local_matrix_usolve, local_matrix_usolve_double) { Arguments arg = setup_local_matrix_solve_arguments(GetParam()); ASSERT_EQ(testing_local_matrix_usolve(arg), true); } INSTANTIATE_TEST_CASE_P(local_matrix_solve, parameterized_local_matrix_lusolve, testing::Combine(testing::ValuesIn(local_matrix_solve_size), testing::ValuesIn(local_matrix_solve_format))); INSTANTIATE_TEST_CASE_P(local_matrix_solve, parameterized_local_matrix_llsolve, testing::Combine(testing::ValuesIn(local_matrix_solve_size), testing::ValuesIn(local_matrix_solve_format))); INSTANTIATE_TEST_CASE_P(local_matrix_solve, parameterized_local_matrix_lsolve, testing::Combine(testing::ValuesIn(local_matrix_solve_size), testing::ValuesIn(local_matrix_solve_format), testing::ValuesIn(local_matrix_solve_unit_diag))); INSTANTIATE_TEST_CASE_P(local_matrix_solve, parameterized_local_matrix_usolve, testing::Combine(testing::ValuesIn(local_matrix_solve_size), testing::ValuesIn(local_matrix_solve_format), testing::ValuesIn(local_matrix_solve_unit_diag))); rocALUTION-rocm-7.1.0/clients/tests/test_local_stencil.cpp000066400000000000000000000065541507377332500235030ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_local_stencil.hpp" #include "utility.hpp" #include /* typedef std::tuple backend_tuple; int backend_rank[] = {-1, 0, 13}; int backend_dev_node[] = {-1, 0, 13}; int backend_dev[] = {-1, 0, 13}; int backend_omp_threads[] = {-1, 0, 8}; bool backend_affinity[] = {true, false}; int backend_omp_threshold[] = {-1, 0, 20000}; bool backend_disable_acc[] = {true, false}; class parameterized_backend : public testing::TestWithParam { protected: parameterized_backend() {} virtual ~parameterized_backend() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_backend_arguments(backend_tuple tup) { Arguments arg; arg.rank = std::get<0>(tup); arg.dev_per_node = std::get<1>(tup); arg.dev = std::get<2>(tup); arg.omp_nthreads = std::get<3>(tup); arg.omp_affinity = std::get<4>(tup); arg.omp_threshold = std::get<5>(tup); arg.use_acc = std::get<6>(tup); return arg; } */ TEST(local_stencil_bad_args, local_stencil) { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED"})) { GTEST_SKIP(); } testing_local_stencil_bad_args(); } /* TEST_P(parameterized_backend, backend) { Arguments arg = setup_backend_arguments(GetParam()); testing_backend(arg); } INSTANTIATE_TEST_CASE_P(backend, parameterized_backend, testing::Combine(testing::ValuesIn(backend_rank), testing::ValuesIn(backend_dev_node), testing::ValuesIn(backend_dev), testing::ValuesIn(backend_omp_threads), testing::ValuesIn(backend_affinity), testing::ValuesIn(backend_omp_threshold), testing::ValuesIn(backend_disable_acc))); */ rocALUTION-rocm-7.1.0/clients/tests/test_local_vector.cpp000066400000000000000000000426231507377332500233410ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_local_vector.hpp" #include "utility.hpp" #include typedef std::tuple local_vector_tuple; int local_vector_size[] = {10, 17, 21}; /* typedef std::tuple backend_tuple; int backend_rank[] = {-1, 0, 13}; int backend_dev_node[] = {-1, 0, 13}; int backend_dev[] = {-1, 0, 13}; int backend_omp_threads[] = {-1, 0, 8}; bool backend_affinity[] = {true, false}; int backend_omp_threshold[] = {-1, 0, 20000}; bool backend_disable_acc[] = {true, false}; class parameterized_backend : public testing::TestWithParam { protected: parameterized_backend() {} virtual ~parameterized_backend() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_backend_arguments(backend_tuple tup) { Arguments arg; arg.rank = std::get<0>(tup); arg.dev_per_node = std::get<1>(tup); arg.dev = std::get<2>(tup); arg.omp_nthreads = std::get<3>(tup); arg.omp_affinity = std::get<4>(tup); arg.omp_threshold = std::get<5>(tup); arg.use_acc = std::get<6>(tup); return arg; } */ TEST(local_vector_bad_args, local_vector) { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED"})) { GTEST_SKIP(); } testing_local_vector_bad_args(); } /* TEST_P(parameterized_backend, backend) { Arguments arg = setup_backend_arguments(GetParam()); testing_backend(arg); } INSTANTIATE_TEST_CASE_P(backend, parameterized_backend, testing::Combine(testing::ValuesIn(backend_rank), testing::ValuesIn(backend_dev_node), testing::ValuesIn(backend_dev), testing::ValuesIn(backend_omp_threads), testing::ValuesIn(backend_affinity), testing::ValuesIn(backend_omp_threshold), testing::ValuesIn(backend_disable_acc))); */ // Test fixture for LocalVector class local_vector_test : public ::testing::Test { protected: void SetUp() override { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED"})) { GTEST_SKIP(); } } virtual void TearDown() {} }; class parameterized_local_vector_test : public testing::TestWithParam { protected: parameterized_local_vector_test() {} virtual ~parameterized_local_vector_test() {} virtual void SetUp() override { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED"})) { GTEST_SKIP(); } } virtual void TearDown() {} }; #define TEST_CASE(function, type, disable_accelerator) \ disable_accelerator_rocalution(disable_accelerator); \ set_device_rocalution(0); \ init_rocalution(); \ function(); \ stop_rocalution(); \ disable_accelerator_rocalution(false); #define GENERATE_TEST_CASES_DEVICE(test_fixture, function, name) \ TEST_F(test_fixture, name##_device_float) \ { \ TEST_CASE(function, float, false); \ } \ TEST_F(test_fixture, name##_device_double) \ { \ TEST_CASE(function, double, false); \ } #define GENERATE_TEST_CASES_HOST(test_fixture, function, name) \ TEST_F(test_fixture, name##_host_float) \ { \ TEST_CASE(function, float, true); \ } \ TEST_F(test_fixture, name##_host_double) \ { \ TEST_CASE(function, double, true); \ } #define GENERATE_TEST_CASES(test_fixture, function, name) \ GENERATE_TEST_CASES_DEVICE(test_fixture, function, name) \ GENERATE_TEST_CASES_HOST(test_fixture, function, name) Arguments setup_local_vector_arguments(local_vector_tuple tup) { Arguments arg; arg.size = std::get<0>(tup); return arg; } #define TEST_P_CASE(function, type, disable_accelerator) \ disable_accelerator_rocalution(disable_accelerator); \ set_device_rocalution(0); \ init_rocalution(); \ Arguments arg = setup_local_vector_arguments(GetParam()); \ function(arg); \ stop_rocalution(); \ disable_accelerator_rocalution(false); #define GENERATE_P_TEST_CASES_DEVICE(test_fixture, function, name) \ TEST_P(test_fixture, name##_device_float) \ { \ TEST_P_CASE(function, float, false); \ } \ TEST_P(test_fixture, name##_device_double) \ { \ TEST_P_CASE(function, double, false); \ } #define GENERATE_P_TEST_CASES_HOST(test_fixture, function, name) \ TEST_P(test_fixture, name##_host_float) \ { \ TEST_P_CASE(function, float, true); \ } \ TEST_P(test_fixture, name##_host_double) \ { \ TEST_P_CASE(function, double, true); \ } #define GENERATE_P_TEST_CASES(test_fixture, function, name) \ GENERATE_P_TEST_CASES_DEVICE(test_fixture, function, name) \ GENERATE_P_TEST_CASES_HOST(test_fixture, function, name) // Test for GetInterior GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_get_interior, get_interior) GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_const_get_interior, const_get_interior) // Test for LocalVector::Check GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_check, check) // Test for LocalVector::SetDataPtr when *ptr == NULL GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_set_data_ptr_null, set_data_ptr_null) // Test for LocalVector::ScaleAdd2 GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_scale_add_2, scale_add_2) // Test for LocalVector::CopyFrom GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_copy_from, copy_from) // Test for LocalVector::CloneFrom GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_clone_from, clone_from) // Test for Binary GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_binary, file_binary) // Test for LocalVector::AddScale GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_add_scale, add_scale) // Test for LocalVector::ScaleAdd GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_scale_add, scale_add) // Test for LocalVector::Scale GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_scale, scale) // Test for LocalVector::Dot GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_dot, dot) // Test for LocalVector::DotNonConj GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_dot_non_conj, dot_nonconj) // Test for LocalVector::Norm GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_norm, norm) // Test for LocalVector::Reduce GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_reduce, reduce) // Test for LocalVector::PointWiseMult GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_point_wise_mult, point_wise_mult) GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_point_wise_mult_2, point_wise_mult_2) // Test for LocalVector::LeaveDataPtr GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_leave_data_ptr, leave_data_ptr) // Test for LocalVector::Sync GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_sync, sync) // Test for LocalVector::CopyFromData GENERATE_P_TEST_CASES_HOST(parameterized_local_vector_test, testing_copy_from_data, copy_from_data) // Test for LocalVector::CopyToHostData GENERATE_P_TEST_CASES_HOST(parameterized_local_vector_test, testing_copy_to_host_data, copy_to_host_data) // Test for LocalVector::Restriction GENERATE_TEST_CASES(local_vector_test, testing_restriction, restriction) // Test for LocalVector::CopyFromWithOffsets GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_copy_from_with_offsets, copy_from_with_offsets) // Test for LocalVector::CopyFromFloat TEST_F(local_vector_test, copy_from_float) { disable_accelerator_rocalution(false); set_device_rocalution(0); init_rocalution(); // Create a LocalVector and allocate some size LocalVector src_vec = getTestVector(5); // Create a LocalVector to copy the data into LocalVector dest_vec; // Perform the copy EXPECT_NO_THROW(dest_vec.CopyFromFloat(src_vec)); // Validate the copied values for(int i = 0; i < 5; ++i) { EXPECT_DOUBLE_EQ(dest_vec[i], static_cast(i + 1)); } // Ensure the destination vector has the correct size EXPECT_EQ(dest_vec.GetSize(), src_vec.GetSize()); stop_rocalution(); } // Test for LocalVector::CopyFromDouble TEST_F(local_vector_test, copy_from_double) { disable_accelerator_rocalution(false); set_device_rocalution(0); init_rocalution(); // Create a LocalVector and allocate some size LocalVector src_vec = getTestVector(5); // Create a LocalVector to copy the data into LocalVector dest_vec; // Perform the copy EXPECT_NO_THROW(dest_vec.CopyFromDouble(src_vec)); // Validate the copied values for(int i = 0; i < 5; ++i) { EXPECT_FLOAT_EQ(dest_vec[i], static_cast(i + 1)); } // Ensure the destination vector has the correct size EXPECT_EQ(dest_vec.GetSize(), src_vec.GetSize()); stop_rocalution(); } // Test for LocalVector::Info GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_info, info) // Test for LocalVector::Zeros GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_zeros, zeros) // Test for LocalVector::Ones GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_ones, ones) // Test for LocalVector::SetValue GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_set_values, set_value) // Test for LocalVector::SetRandom GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_set_random_uniform, set_random_uniform) // Test for LocalVector::SetUniform GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_set_random_normal, set_random_normal) // Test for LocalVector::Power GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_power, power) // Test for LocalVector::Sort GENERATE_TEST_CASES(local_vector_test, testing_sort, sort) // Test for LocalVector::PermuteBackward GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_permute_backward, permute_backward) // Test for LocalVector::InclusiveSum GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_inclusive_sum, inclusive_sum) // Test for LocalVector::ScaleAddScale GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_scale_add_scale, scale_add_scale) // Test for LocalVector::operator[] (const version) GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_operator_index_const, operator_index_const) // Test for LocalVector::ReadFileASCII GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_read_file_ascii, read_file_ascii) // Test for LocalVector::CopyFromAsync GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_copy_from_async, copy_from_async) // Test for LocalVector::MoveToAcceleratorAsync GENERATE_P_TEST_CASES_DEVICE(parameterized_local_vector_test, testing_move_to_accelerator_async, move_to_accelerator_async) // Test for LocalVector::CopyFromHostData GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_copy_from_host_data, copy_from_host_data) // Test for LocalVector::CopyToData GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_copy_to_data, copy_to_data) // Test for LocalVector::WriteFileASCII GENERATE_TEST_CASES(local_vector_test, testing_write_file_ascii, write_file_ascii) // Test for LocalVector::ScaleAddScale with offsets GENERATE_TEST_CASES(local_vector_test, testing_scale_add_scale_with_offsets, scale_add_scale_with_offsets) // Test for LocalVector::InclusiveSum(void) GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_inclusive_sum_void, inclusive_sum_void) // Test for LocalVector::InclusiveSum(const LocalVector& vec) GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_inclusive_sum_with_input, inclusive_sum_with_input) // Test for LocalVector::ExclusiveSum(void) GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_exclusive_sum_void, exclusive_sum_void) // Test for LocalVector::ExclusiveSum(const LocalVector& vec) GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_exclusive_sum_with_input, exclusive_sum_with_input) // Test for LocalVector::Asum(void) const GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_asum, asum) // Test for LocalVector::Amax(ValueType& value) const GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_amax, amax) // Test for LocalVector::Prolongation GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_prolongation, prolongation) // Test for LocalVector::GetIndexValues GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_get_index_values, get_index_values) // Test for LocalVector::SetIndexValues GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_set_index_values, set_index_values) // Test for LocalVector::AddIndexValues GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_add_index_values, add_index_values) // Test for LocalVector::GetContinuousValues GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_get_continuous_values, get_continuous_values) // Test for LocalVector::SetContinuousValues GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_set_continuous_values, set_continuous_values) // Test for LocalVector::ExtractCoarseMapping TEST_F(local_vector_test, extract_coarse_mapping_int) { disable_accelerator_rocalution(false); set_device_rocalution(0); init_rocalution(); testing_extract_coarse_mapping(); stop_rocalution(); } GENERATE_P_TEST_CASES(parameterized_local_vector_test, testing_move_to_host_async, move_to_host_async) INSTANTIATE_TEST_CASE_P(local_vector, parameterized_local_vector_test, testing::Combine(testing::ValuesIn(local_vector_size))); rocALUTION-rocm-7.1.0/clients/tests/test_lu.cpp000066400000000000000000000106211507377332500212760ustar00rootroot00000000000000/* ************************************************************************ * 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. * * ************************************************************************ */ #include "testing_lu.hpp" #include "utility.hpp" #include #include typedef std::tuple lu_tuple; std::vector lu_size = {7, 16, 21}; std::vector lu_format = {1, 2, 3, 4, 5, 6, 7}; std::vector lu_matrix_type = {"Laplacian2D"}; std::vector lu_use_host_and_acc = {0}; // Function to update tests if environment variable is set void update_lu() { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED", "ROCALUTION_CODE_COVERAGE"})) { lu_size.clear(); lu_format.clear(); lu_use_host_and_acc.clear(); lu_size.push_back(16); lu_format.push_back(2); } if(is_env_var_set("ROCALUTION_CODE_COVERAGE")) { lu_size.clear(); lu_format.clear(); lu_size.push_back(7); lu_format.insert(lu_format.end(), {1, 2, 3, 4, 5, 6, 7}); lu_use_host_and_acc.push_back(1); } else if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED"})) { lu_use_host_and_acc.push_back(0); } if(is_env_var_set("ROCALUTION_EMULATION_SMOKE")) { lu_size.push_back(16); lu_format.push_back(2); } else if(is_env_var_set("ROCALUTION_EMULATION_REGRESSION")) { lu_size.insert(lu_size.end(), {7, 16}); lu_format.insert(lu_format.end(), {1, 3}); } else if(is_env_var_set("ROCALUTION_EMULATION_EXTENDED")) { lu_size.insert(lu_size.end(), {16, 21}); lu_format.insert(lu_format.end(), {4, 5, 6, 7}); } } struct LUInitializer { LUInitializer() { update_lu(); } }; // Create a global instance of the initializer, so the environment is checked and updated before tests. LUInitializer lu_initializer; class parameterized_lu : public testing::TestWithParam { protected: parameterized_lu() {} virtual ~parameterized_lu() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_lu_arguments(lu_tuple tup) { Arguments arg; arg.size = std::get<0>(tup); arg.format = std::get<1>(tup); arg.matrix_type = std::get<2>(tup); arg.use_acc = std::get<3>(tup); return arg; } TEST_P(parameterized_lu, lu_float) { Arguments arg = setup_lu_arguments(GetParam()); ASSERT_EQ(testing_lu(arg), true); } TEST_P(parameterized_lu, lu_double) { Arguments arg = setup_lu_arguments(GetParam()); ASSERT_EQ(testing_lu(arg), true); } INSTANTIATE_TEST_CASE_P(lu, parameterized_lu, testing::Combine(testing::ValuesIn(lu_size), testing::ValuesIn(lu_format), testing::ValuesIn(lu_matrix_type), testing::ValuesIn(lu_use_host_and_acc))); rocALUTION-rocm-7.1.0/clients/tests/test_mixed_precision.cpp000066400000000000000000000072001507377332500240360ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "testing_mixed_precision.hpp" #include "utility.hpp" #include #include typedef std::tuple mixed_precision_tuple; std::vector mixed_precision_size = {7}; std::vector mixed_precision_format = {1, 2, 3, 4, 5, 6, 7}; std::vector mixed_precision_matrix_type = {"Laplacian2D"}; std::vector mixed_precision_precond = {"None", "FSAI"}; std::vector mixed_precision_rebuildnumeric = {0}; // Function to update tests if environment variable is set void update_mixed_precision() {} struct MPInitializer { MPInitializer() { update_mixed_precision(); } }; // Create a global instance of the initializer, so the environment is checked and updated before tests. MPInitializer mixed_precision_initializer; class parameterized_mixed_precision : public testing::TestWithParam { protected: parameterized_mixed_precision() {} virtual ~parameterized_mixed_precision() {} virtual void SetUp() { if(!is_env_var_set("ROCALUTION_CODE_COVERAGE")) { GTEST_SKIP() << "Skipping mixed precision tests as ROCALUTION_CODE_COVERAGE is not set."; } } virtual void TearDown() {} }; Arguments setup_mixed_precision_arguments(mixed_precision_tuple tup) { Arguments arg; arg.size = std::get<0>(tup); arg.format = std::get<1>(tup); arg.matrix_type = std::get<2>(tup); arg.precond = std::get<3>(tup); arg.rebuildnumeric = std::get<4>(tup); return arg; } TEST_P(parameterized_mixed_precision, mixed_precision_double_float) { Arguments arg = setup_mixed_precision_arguments(GetParam()); ASSERT_EQ(testing_mixed_precision(arg), true); } INSTANTIATE_TEST_CASE_P(mixed_precision, parameterized_mixed_precision, testing::Combine(testing::ValuesIn(mixed_precision_size), testing::ValuesIn(mixed_precision_format), testing::ValuesIn(mixed_precision_matrix_type), testing::ValuesIn(mixed_precision_precond), testing::ValuesIn(mixed_precision_rebuildnumeric))); rocALUTION-rocm-7.1.0/clients/tests/test_pairwise_amg.cpp000066400000000000000000000153271507377332500233350ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_pairwise_amg.hpp" #include "utility.hpp" #include #include typedef std::tuple pwamg_tuple; std::vector pwamg_size = {63, 134}; std::vector pwamg_smoother = {"Jacobi"}; //, "MCILU"}; std::vector pwamg_format = {1, 7}; std::vector pwamg_pre_iter = {1, 2}; std::vector pwamg_post_iter = {1, 2}; std::vector pwamg_ordering = {0, 1, 2, 3, 4, 5}; std::vector pwamg_rebuildnumeric = {0, 1}; std::vector pwamg_use_acc = {1}; // Function to update tests if environment variable is set void update_pwamg() { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED", "ROCALUTION_CODE_COVERAGE"})) { pwamg_size.clear(); pwamg_smoother.clear(); pwamg_format.clear(); pwamg_pre_iter.clear(); pwamg_post_iter.clear(); pwamg_ordering.clear(); pwamg_rebuildnumeric.clear(); } if(is_env_var_set("ROCALUTION_CODE_COVERAGE")) { pwamg_size.push_back(63); pwamg_smoother.push_back("Jacobi"); pwamg_format.insert(pwamg_format.end(), {1, 7}); pwamg_pre_iter.insert(pwamg_pre_iter.end(), {1, 2}); pwamg_post_iter.insert(pwamg_post_iter.end(), {1, 2}); pwamg_ordering.insert(pwamg_ordering.end(), {0, 1, 2, 3, 4, 5}); pwamg_rebuildnumeric.insert(pwamg_rebuildnumeric.end(), {0, 1}); pwamg_use_acc.push_back(0); } if(is_env_var_set("ROCALUTION_EMULATION_SMOKE")) { pwamg_size.push_back(134); pwamg_smoother.push_back("Jacobi"); pwamg_format.push_back(1); pwamg_pre_iter.push_back(1); pwamg_post_iter.push_back(1); pwamg_ordering.push_back(1); pwamg_rebuildnumeric.push_back(0); } else if(is_env_var_set("ROCALUTION_EMULATION_REGRESSION")) { pwamg_size.push_back(63); pwamg_smoother.push_back("Jacobi"); pwamg_format.push_back(7); pwamg_pre_iter.push_back(2); pwamg_post_iter.push_back(2); pwamg_ordering.insert(pwamg_ordering.end(), {1, 2, 3}); pwamg_rebuildnumeric.push_back(0); } else if(is_env_var_set("ROCALUTION_EMULATION_EXTENDED")) { pwamg_size.push_back(134); pwamg_smoother.push_back("Jacobi"); pwamg_format.push_back(1); pwamg_pre_iter.push_back(1); pwamg_post_iter.push_back(2); pwamg_ordering.insert(pwamg_ordering.end(), {4, 5}); pwamg_rebuildnumeric.insert(pwamg_rebuildnumeric.end(), {0, 1}); } } struct PWAMGInitializer { PWAMGInitializer() { update_pwamg(); } }; // Create a global instance of the initializer, so the environment is checked and updated before tests. PWAMGInitializer pwamg_initializer; class parameterized_pairwise_amg : public testing::TestWithParam { protected: parameterized_pairwise_amg() {} virtual ~parameterized_pairwise_amg() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_pwamg_arguments(pwamg_tuple tup) { Arguments arg; arg.size = std::get<0>(tup); arg.smoother = std::get<1>(tup); arg.format = std::get<2>(tup); arg.pre_smooth = std::get<3>(tup); arg.post_smooth = std::get<4>(tup); arg.ordering = std::get<5>(tup); arg.rebuildnumeric = std::get<6>(tup); arg.use_acc = std::get<7>(tup); return arg; } TEST_P(parameterized_pairwise_amg, pairwise_amg_float) { Arguments arg = setup_pwamg_arguments(GetParam()); ASSERT_EQ(testing_pairwise_amg(arg), true); } TEST_P(parameterized_pairwise_amg, pairwise_amg_double) { Arguments arg = setup_pwamg_arguments(GetParam()); ASSERT_EQ(testing_pairwise_amg(arg), true); } TEST_P(parameterized_pairwise_amg, pairwise_amg_2_double) { if(!is_env_var_set("ROCALUTION_CODE_COVERAGE")) { // Skip this test if not in code coverage mode GTEST_SKIP() << "Skipping pairwise_amg_2_double test unless in code coverage mode."; } Arguments arg = setup_pwamg_arguments(GetParam()); ASSERT_EQ(testing_pairwise_amg_2(arg), true); } TEST_P(parameterized_pairwise_amg, pairwise_amg_3_double) { if(!is_env_var_set("ROCALUTION_CODE_COVERAGE")) { // Skip this test if not in code coverage mode GTEST_SKIP() << "Skipping pairwise_amg_3_double test unless in code coverage mode."; } Arguments arg = setup_pwamg_arguments(GetParam()); ASSERT_EQ(testing_pairwise_amg_3(arg), true); } INSTANTIATE_TEST_CASE_P(pairwise_amg, parameterized_pairwise_amg, testing::Combine(testing::ValuesIn(pwamg_size), testing::ValuesIn(pwamg_smoother), testing::ValuesIn(pwamg_format), testing::ValuesIn(pwamg_pre_iter), testing::ValuesIn(pwamg_post_iter), testing::ValuesIn(pwamg_ordering), testing::ValuesIn(pwamg_rebuildnumeric), testing::ValuesIn(pwamg_use_acc))); rocALUTION-rocm-7.1.0/clients/tests/test_parallel_manager.cpp000066400000000000000000000065701507377332500241540ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_parallel_manager.hpp" #include "utility.hpp" #include /* typedef std::tuple backend_tuple; int backend_rank[] = {-1, 0, 13}; int backend_dev_node[] = {-1, 0, 13}; int backend_dev[] = {-1, 0, 13}; int backend_omp_threads[] = {-1, 0, 8}; bool backend_affinity[] = {true, false}; int backend_omp_threshold[] = {-1, 0, 20000}; bool backend_disable_acc[] = {true, false}; class parameterized_backend : public testing::TestWithParam { protected: parameterized_backend() {} virtual ~parameterized_backend() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_backend_arguments(backend_tuple tup) { Arguments arg; arg.rank = std::get<0>(tup); arg.dev_per_node = std::get<1>(tup); arg.dev = std::get<2>(tup); arg.omp_nthreads = std::get<3>(tup); arg.omp_affinity = std::get<4>(tup); arg.omp_threshold = std::get<5>(tup); arg.use_acc = std::get<6>(tup); return arg; } */ TEST(parallel_manager_bad_args, parallel_manager) { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED"})) { GTEST_SKIP(); } testing_parallel_manager_bad_args(); } /* TEST_P(parameterized_backend, backend) { Arguments arg = setup_backend_arguments(GetParam()); testing_backend(arg); } INSTANTIATE_TEST_CASE_P(backend, parameterized_backend, testing::Combine(testing::ValuesIn(backend_rank), testing::ValuesIn(backend_dev_node), testing::ValuesIn(backend_dev), testing::ValuesIn(backend_omp_threads), testing::ValuesIn(backend_affinity), testing::ValuesIn(backend_omp_threshold), testing::ValuesIn(backend_disable_acc))); */ rocALUTION-rocm-7.1.0/clients/tests/test_preconditioner.cpp000066400000000000000000000121301507377332500236770ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "testing_preconditioner.hpp" #include "utility.hpp" #include typedef std::tuple preconditioner_tuple; int preconditioner_size[] = {7}; std::string preconditioner_type[] = {"Jacobi", "GS", "SGS", "ILU", "ILUT", "IC", "ItILU0", "AIChebyshev", "FSAI", "SPAI", "TNS", "AS", "RAS", "MultiColoredSGS", "MultiColoredGS", "MultiColoredILU", "MultiElimination", "VariablePreconditioner"}; class parameterized_preconditioner : public testing::TestWithParam { protected: parameterized_preconditioner() {} virtual ~parameterized_preconditioner() {} virtual void SetUp() override { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED"})) { GTEST_SKIP(); } } virtual void TearDown() {} }; Arguments setup_preconditioner_arguments(preconditioner_tuple tup) { Arguments arg; arg.size = std::get<0>(tup); arg.precond = std::get<1>(tup); return arg; } #define TEST_P_CASE(function, type, disable_accelerator) \ disable_accelerator_rocalution(disable_accelerator); \ set_device_rocalution(0); \ init_rocalution(); \ Arguments arg = setup_preconditioner_arguments(GetParam()); \ function(arg); \ stop_rocalution(); \ disable_accelerator_rocalution(false); #define GENERATE_P_TEST_CASES_DEVICE(test_fixture, function, name) \ TEST_P(test_fixture, name##_device_float) \ { \ TEST_P_CASE(function, float, false); \ } \ TEST_P(test_fixture, name##_device_double) \ { \ TEST_P_CASE(function, double, false); \ } #define GENERATE_P_TEST_CASES_HOST(test_fixture, function, name) \ TEST_P(test_fixture, name##_host_float) \ { \ TEST_P_CASE(function, float, true); \ } \ TEST_P(test_fixture, name##_host_double) \ { \ TEST_P_CASE(function, double, true); \ } #define GENERATE_P_TEST_CASES(test_fixture, function, name) \ GENERATE_P_TEST_CASES_DEVICE(test_fixture, function, name) \ GENERATE_P_TEST_CASES_HOST(test_fixture, function, name) GENERATE_P_TEST_CASES_DEVICE(parameterized_preconditioner, testing_preconditioner_all, all); INSTANTIATE_TEST_CASE_P(preconditioner, parameterized_preconditioner, testing::Combine(testing::ValuesIn(preconditioner_size), testing::ValuesIn(preconditioner_type))); rocALUTION-rocm-7.1.0/clients/tests/test_qmrcgstab.cpp000066400000000000000000000112761507377332500226500ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_qmrcgstab.hpp" #include "utility.hpp" #include #include typedef std::tuple qmrcgstab_tuple; std::vector qmrcgstab_size = {7, 63}; std::vector qmrcgstab_precond = {"None", "Chebyshev", "SPAI", "Jacobi", "GS", "ILU", "ItILU0"}; std::vector qmrcgstab_format = {1, 2, 3, 7}; std::vector qmrcgstab_use_acc = {1}; // Function to update tests if environment variable is set void update_qmrcgstab() { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED", "ROCALUTION_CODE_COVERAGE"})) { qmrcgstab_size.clear(); qmrcgstab_precond.clear(); qmrcgstab_format.clear(); } if(is_env_var_set("ROCALUTION_CODE_COVERAGE")) { qmrcgstab_size.push_back(7); qmrcgstab_precond.insert(qmrcgstab_precond.end(), {"None", "Chebyshev", "SPAI", "Jacobi", "GS", "ILU", "ItILU0"}); qmrcgstab_format.insert(qmrcgstab_format.end(), {1, 2, 3, 7}); qmrcgstab_use_acc.push_back(0); } if(is_env_var_set("ROCALUTION_EMULATION_SMOKE")) { qmrcgstab_size.push_back(63); qmrcgstab_precond.insert(qmrcgstab_precond.end(), {"None", "GS"}); qmrcgstab_format.push_back(7); } else if(is_env_var_set("ROCALUTION_EMULATION_REGRESSION")) { qmrcgstab_size.insert(qmrcgstab_size.end(), {7, 63}); qmrcgstab_precond.insert(qmrcgstab_precond.end(), {"Chebyshev", "ItILU0"}); qmrcgstab_format.insert(qmrcgstab_format.end(), {1, 2}); } else if(is_env_var_set("ROCALUTION_EMULATION_EXTENDED")) { qmrcgstab_size.insert(qmrcgstab_size.end(), {7, 63}); qmrcgstab_precond.insert(qmrcgstab_precond.end(), {"SPAI", "ILU"}); qmrcgstab_format.insert(qmrcgstab_format.end(), {1, 3}); } } struct QMRCGStabInitializer { QMRCGStabInitializer() { update_qmrcgstab(); } }; // Create a global instance of the initializer, so the environment is checked and updated before tests. QMRCGStabInitializer qmrcgstab_initializer; class parameterized_qmrcgstab : public testing::TestWithParam { protected: parameterized_qmrcgstab() {} virtual ~parameterized_qmrcgstab() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_qmrcgstab_arguments(qmrcgstab_tuple tup) { Arguments arg; arg.size = std::get<0>(tup); arg.precond = std::get<1>(tup); arg.format = std::get<2>(tup); arg.use_acc = std::get<3>(tup); return arg; } TEST_P(parameterized_qmrcgstab, qmrcgstab_float) { Arguments arg = setup_qmrcgstab_arguments(GetParam()); ASSERT_EQ(testing_qmrcgstab(arg), true); } TEST_P(parameterized_qmrcgstab, qmrcgstab_double) { Arguments arg = setup_qmrcgstab_arguments(GetParam()); ASSERT_EQ(testing_qmrcgstab(arg), true); } INSTANTIATE_TEST_CASE_P(qmrcgstab, parameterized_qmrcgstab, testing::Combine(testing::ValuesIn(qmrcgstab_size), testing::ValuesIn(qmrcgstab_precond), testing::ValuesIn(qmrcgstab_format), testing::ValuesIn(qmrcgstab_use_acc))); rocALUTION-rocm-7.1.0/clients/tests/test_qr.cpp000066400000000000000000000111461507377332500213030ustar00rootroot00000000000000/* ************************************************************************ * 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. * * ************************************************************************ */ #include "testing_qr.hpp" #include "utility.hpp" #include #include typedef std::tuple qr_tuple; std::vector qr_size = {7, 16, 21}; std::vector qr_format = {1, 2, 3, 4, 5, 6, 7}; std::vector qr_matrix_type = {"Laplacian2D", "PermutedIdentity"}; std::vector qr_use_host_and_acc = {0}; // Function to update tests if environment variable is set void update_qr() { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED", "ROCALUTION_CODE_COVERAGE"})) { qr_size.clear(); qr_format.clear(); qr_matrix_type.clear(); qr_use_host_and_acc.clear(); } if(is_env_var_set("ROCALUTION_CODE_COVERAGE")) { qr_size.push_back(7); qr_format.insert(qr_format.end(), {1, 2, 3, 4, 5, 6, 7}); qr_matrix_type.push_back("Laplacian2D"); qr_use_host_and_acc.push_back(1); } else if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED"})) { qr_use_host_and_acc.push_back(0); } if(is_env_var_set("ROCALUTION_EMULATION_SMOKE")) { qr_size.push_back(16); qr_format.push_back(2); qr_matrix_type.push_back("Laplacian2D"); } else if(is_env_var_set("ROCALUTION_EMULATION_REGRESSION")) { qr_size.insert(qr_size.end(), {7, 16}); qr_format.insert(qr_format.end(), {1, 3}); qr_matrix_type.insert(qr_matrix_type.end(), {"Laplacian2D", "PermutedIdentity"}); } else if(is_env_var_set("ROCALUTION_EMULATION_EXTENDED")) { qr_size.insert(qr_size.end(), {16, 21}); qr_format.insert(qr_format.end(), {4, 5, 6, 7}); qr_matrix_type.insert(qr_matrix_type.end(), {"Laplacian2D", "PermutedIdentity"}); } } struct QRInitializer { QRInitializer() { update_qr(); } }; // Create a global instance of the initializer, so the environment is checked and updated before tests. QRInitializer qr_initializer; class parameterized_qr : public testing::TestWithParam { protected: parameterized_qr() {} virtual ~parameterized_qr() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_qr_arguments(qr_tuple tup) { Arguments arg; arg.size = std::get<0>(tup); arg.format = std::get<1>(tup); arg.matrix_type = std::get<2>(tup); arg.use_acc = std::get<3>(tup); return arg; } TEST_P(parameterized_qr, qr_float) { Arguments arg = setup_qr_arguments(GetParam()); ASSERT_EQ(testing_qr(arg), true); } TEST_P(parameterized_qr, qr_double) { Arguments arg = setup_qr_arguments(GetParam()); ASSERT_EQ(testing_qr(arg), true); } INSTANTIATE_TEST_CASE_P(qr, parameterized_qr, testing::Combine(testing::ValuesIn(qr_size), testing::ValuesIn(qr_format), testing::ValuesIn(qr_matrix_type), testing::ValuesIn(qr_use_host_and_acc))); rocALUTION-rocm-7.1.0/clients/tests/test_ruge_stueben_amg.cpp000066400000000000000000000153141507377332500241750ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_ruge_stueben_amg.hpp" #include "utility.hpp" #include #include typedef std::tuple rsamg_tuple; std::vector rsamg_size = {63, 134}; std::vector rsamg_smoother = {"Jacobi"}; std::vector rsamg_format = {1, 7}; std::vector rsamg_pre_iter = {1, 2}; std::vector rsamg_post_iter = {1, 2}; std::vector rsamg_cycle = {0, 1}; std::vector rsamg_scaling = {0, 1}; std::vector rsamg_rebuildnumeric = {0, 1}; std::vector rsamg_use_acc = {1}; std::vector rsamg_coarsening_strategy = {"PMIS"}; // Function to update tests if environment variable is set void update_rsamg() { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED", "ROCALUTION_CODE_COVERAGE"})) { rsamg_size.clear(); rsamg_smoother.clear(); rsamg_format.clear(); rsamg_pre_iter.clear(); rsamg_post_iter.clear(); rsamg_cycle.clear(); rsamg_scaling.clear(); rsamg_rebuildnumeric.clear(); } if(is_env_var_set("ROCALUTION_CODE_COVERAGE")) { rsamg_size.push_back(63); rsamg_smoother.push_back("Jacobi"); rsamg_format.insert(rsamg_format.end(), {1, 7}); rsamg_pre_iter.insert(rsamg_pre_iter.end(), {1, 2}); rsamg_post_iter.insert(rsamg_post_iter.end(), {1, 2}); rsamg_cycle.insert(rsamg_cycle.end(), {0, 1}); rsamg_scaling.insert(rsamg_scaling.end(), {0, 1}); rsamg_rebuildnumeric.insert(rsamg_rebuildnumeric.end(), {0, 1}); rsamg_use_acc.push_back(0); rsamg_coarsening_strategy.push_back("Greedy"); } if(is_env_var_set("ROCALUTION_EMULATION_SMOKE")) { rsamg_size.push_back(63); rsamg_smoother.push_back("Jacobi"); rsamg_format.push_back(3); rsamg_pre_iter.push_back(1); rsamg_post_iter.push_back(1); rsamg_cycle.push_back(0); rsamg_scaling.push_back(0); rsamg_rebuildnumeric.push_back(0); } else if(is_env_var_set("ROCALUTION_EMULATION_REGRESSION")) { rsamg_size.push_back(134); rsamg_smoother.push_back("Jacobi"); rsamg_format.push_back(1); rsamg_pre_iter.push_back(2); rsamg_post_iter.push_back(2); rsamg_cycle.insert(rsamg_cycle.end(), {0, 1}); rsamg_scaling.insert(rsamg_scaling.end(), {0, 1}); rsamg_rebuildnumeric.push_back(0); } else if(is_env_var_set("ROCALUTION_EMULATION_EXTENDED")) { rsamg_size.push_back(134); rsamg_smoother.push_back("Jacobi"); rsamg_format.push_back(7); rsamg_pre_iter.push_back(1); rsamg_post_iter.push_back(2); rsamg_cycle.insert(rsamg_cycle.end(), {0, 1}); rsamg_scaling.insert(rsamg_scaling.end(), {0, 1}); rsamg_rebuildnumeric.insert(rsamg_rebuildnumeric.end(), {0, 1}); } } struct RSAMGInitializer { RSAMGInitializer() { update_rsamg(); } }; // Create a global instance of the initializer, so the environment is checked and updated before tests. RSAMGInitializer rsamg_initializer; class parameterized_ruge_stueben_amg : public testing::TestWithParam { protected: parameterized_ruge_stueben_amg() {} virtual ~parameterized_ruge_stueben_amg() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_rsamg_arguments(rsamg_tuple tup) { Arguments arg; arg.size = std::get<0>(tup); arg.smoother = std::get<1>(tup); arg.format = std::get<2>(tup); arg.pre_smooth = std::get<3>(tup); arg.post_smooth = std::get<4>(tup); arg.cycle = std::get<5>(tup); arg.ordering = std::get<6>(tup); arg.rebuildnumeric = std::get<7>(tup); arg.use_acc = std::get<8>(tup); arg.coarsening_strategy = std::get<9>(tup); return arg; } TEST_P(parameterized_ruge_stueben_amg, ruge_stueben_amg_float) { Arguments arg = setup_rsamg_arguments(GetParam()); ASSERT_EQ(testing_ruge_stueben_amg(arg), true); } TEST_P(parameterized_ruge_stueben_amg, ruge_stueben_amg_double) { Arguments arg = setup_rsamg_arguments(GetParam()); ASSERT_EQ(testing_ruge_stueben_amg(arg), true); } INSTANTIATE_TEST_CASE_P(ruge_stueben_amg, parameterized_ruge_stueben_amg, testing::Combine(testing::ValuesIn(rsamg_size), testing::ValuesIn(rsamg_smoother), testing::ValuesIn(rsamg_format), testing::ValuesIn(rsamg_pre_iter), testing::ValuesIn(rsamg_post_iter), testing::ValuesIn(rsamg_cycle), testing::ValuesIn(rsamg_scaling), testing::ValuesIn(rsamg_rebuildnumeric), testing::ValuesIn(rsamg_use_acc), testing::ValuesIn(rsamg_coarsening_strategy))); rocALUTION-rocm-7.1.0/clients/tests/test_saamg.cpp000066400000000000000000000156451507377332500217610ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_saamg.hpp" #include "utility.hpp" #include #include typedef std:: tuple saamg_tuple; std::vector saamg_size = {22, 63, 134, 207}; std::vector saamg_pre_iter = {2}; std::vector saamg_post_iter = {2}; std::vector saamg_smoother = {"FSAI", "SPAI"}; std::vector saamg_coarsening_strat = {"Greedy", "PMIS"}; std::vector saamg_matrix_type = {"Laplacian2D"}; std::vector saamg_format = {1, 6}; std::vector saamg_cycle = {2}; std::vector saamg_scaling = {1}; std::vector saamg_rebuildnumeric = {0, 1}; std::vector saamg_use_acc = {1}; // Function to update tests if environment variable is set void update_saamg() { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED", "ROCALUTION_CODE_COVERAGE"})) { saamg_size.clear(); saamg_smoother.clear(); saamg_format.clear(); saamg_pre_iter.clear(); saamg_post_iter.clear(); saamg_cycle.clear(); saamg_scaling.clear(); saamg_rebuildnumeric.clear(); saamg_coarsening_strat.clear(); } if(is_env_var_set("ROCALUTION_CODE_COVERAGE")) { saamg_size.push_back(22); saamg_smoother.insert(saamg_smoother.end(), {"FSAI", "SPAI"}); saamg_format.insert(saamg_format.end(), {1, 6}); saamg_pre_iter.push_back(2); saamg_post_iter.push_back(2); saamg_cycle.push_back(2); saamg_scaling.push_back(1); saamg_rebuildnumeric.insert(saamg_rebuildnumeric.end(), {0, 1}); saamg_coarsening_strat.insert(saamg_coarsening_strat.end(), {"Greedy", "PMIS"}); saamg_use_acc.push_back(0); } if(is_env_var_set("ROCALUTION_EMULATION_SMOKE")) { saamg_size.push_back(63); saamg_smoother.push_back("FSAI"); saamg_format.push_back(6); saamg_pre_iter.push_back(2); saamg_post_iter.push_back(2); saamg_cycle.push_back(2); saamg_scaling.push_back(1); saamg_rebuildnumeric.push_back(0); saamg_coarsening_strat.insert(saamg_coarsening_strat.end(), {"Greedy", "PMIS"}); } else if(is_env_var_set("ROCALUTION_EMULATION_REGRESSION")) { saamg_size.push_back(63); saamg_smoother.push_back("SPAI"); saamg_format.push_back(1); saamg_pre_iter.push_back(1); saamg_post_iter.push_back(1); saamg_cycle.push_back(2); saamg_scaling.push_back(1); saamg_rebuildnumeric.push_back(1); saamg_coarsening_strat.insert(saamg_coarsening_strat.end(), {"Greedy", "PMIS"}); } else if(is_env_var_set("ROCALUTION_EMULATION_EXTENDED")) { saamg_size.push_back(134); saamg_smoother.push_back("FSAI"); saamg_format.push_back(1); saamg_pre_iter.push_back(1); saamg_post_iter.push_back(2); saamg_cycle.push_back(0); saamg_scaling.push_back(0); saamg_rebuildnumeric.push_back(0); saamg_coarsening_strat.insert(saamg_coarsening_strat.end(), {"Greedy", "PMIS"}); } } struct SAAMGInitializer { SAAMGInitializer() { update_saamg(); } }; // Create a global instance of the initializer, so the environment is checked and updated before tests. SAAMGInitializer saamg_initializer; class parameterized_saamg : public testing::TestWithParam { protected: parameterized_saamg() {} virtual ~parameterized_saamg() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_saamg_arguments(saamg_tuple tup) { Arguments arg; arg.size = std::get<0>(tup); arg.pre_smooth = std::get<1>(tup); arg.post_smooth = std::get<2>(tup); arg.smoother = std::get<3>(tup); arg.coarsening_strategy = std::get<4>(tup); arg.matrix_type = std::get<5>(tup); arg.format = std::get<6>(tup); arg.cycle = std::get<7>(tup); arg.ordering = std::get<8>(tup); arg.rebuildnumeric = std::get<9>(tup); arg.use_acc = std::get<10>(tup); return arg; } TEST_P(parameterized_saamg, saamg_float) { Arguments arg = setup_saamg_arguments(GetParam()); ASSERT_EQ(testing_saamg(arg), true); } TEST_P(parameterized_saamg, saamg_double) { Arguments arg = setup_saamg_arguments(GetParam()); ASSERT_EQ(testing_saamg(arg), true); } INSTANTIATE_TEST_CASE_P(saamg, parameterized_saamg, testing::Combine(testing::ValuesIn(saamg_size), testing::ValuesIn(saamg_pre_iter), testing::ValuesIn(saamg_post_iter), testing::ValuesIn(saamg_smoother), testing::ValuesIn(saamg_coarsening_strat), testing::ValuesIn(saamg_matrix_type), testing::ValuesIn(saamg_format), testing::ValuesIn(saamg_cycle), testing::ValuesIn(saamg_scaling), testing::ValuesIn(saamg_rebuildnumeric), testing::ValuesIn(saamg_use_acc))); rocALUTION-rocm-7.1.0/clients/tests/test_uaamg.cpp000066400000000000000000000156341507377332500217610ustar00rootroot00000000000000/* ************************************************************************ * 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 "testing_uaamg.hpp" #include "utility.hpp" #include #include typedef std:: tuple uaamg_tuple; std::vector uaamg_size = {22, 63, 134, 157}; std::vector uaamg_pre_iter = {2}; std::vector uaamg_post_iter = {2}; std::vector uaamg_smoother = {"FSAI" /*, "ILU"*/}; std::vector uaamg_coarsening_strat = {"Greedy", "PMIS"}; std::vector uaamg_matrix_type = {"Laplacian2D", "Laplacian3D"}; std::vector uaamg_format = {1, 6}; std::vector uaamg_cycle = {2}; std::vector uaamg_scaling = {1}; std::vector uaamg_rebuildnumeric = {0, 1}; std::vector uaamg_use_acc = {1}; // Function to update tests if environment variable is set void update_uaamg() { if(is_any_env_var_set({"ROCALUTION_EMULATION_SMOKE", "ROCALUTION_EMULATION_REGRESSION", "ROCALUTION_EMULATION_EXTENDED", "ROCALUTION_CODE_COVERAGE"})) { uaamg_size.clear(); uaamg_smoother.clear(); uaamg_format.clear(); uaamg_pre_iter.clear(); uaamg_post_iter.clear(); uaamg_cycle.clear(); uaamg_scaling.clear(); uaamg_rebuildnumeric.clear(); uaamg_coarsening_strat.clear(); } if(is_env_var_set("ROCALUTION_CODE_COVERAGE")) { uaamg_size.push_back(22); uaamg_smoother.push_back("FSAI"); uaamg_format.insert(uaamg_format.end(), {1, 6}); uaamg_pre_iter.push_back(2); uaamg_post_iter.push_back(2); uaamg_cycle.push_back(2); uaamg_scaling.push_back(1); uaamg_rebuildnumeric.insert(uaamg_rebuildnumeric.end(), {0, 1}); uaamg_coarsening_strat.insert(uaamg_coarsening_strat.end(), {"Greedy", "PMIS"}); uaamg_use_acc.push_back(0); } if(is_env_var_set("ROCALUTION_EMULATION_SMOKE")) { uaamg_size.push_back(63); uaamg_smoother.push_back("FSAI"); uaamg_format.push_back(1); uaamg_pre_iter.push_back(2); uaamg_post_iter.push_back(2); uaamg_cycle.push_back(0); uaamg_scaling.push_back(0); uaamg_rebuildnumeric.push_back(0); uaamg_coarsening_strat.insert(uaamg_coarsening_strat.end(), {"Greedy", "PMIS"}); } else if(is_env_var_set("ROCALUTION_EMULATION_REGRESSION")) { uaamg_size.push_back(134); uaamg_smoother.push_back("FSAI"); uaamg_format.push_back(6); uaamg_pre_iter.push_back(2); uaamg_post_iter.push_back(2); uaamg_cycle.push_back(2); uaamg_scaling.push_back(1); uaamg_rebuildnumeric.push_back(1); uaamg_coarsening_strat.insert(uaamg_coarsening_strat.end(), {"Greedy", "PMIS"}); } else if(is_env_var_set("ROCALUTION_EMULATION_EXTENDED")) { uaamg_size.push_back(157); uaamg_smoother.push_back("FSAI"); uaamg_format.push_back(6); uaamg_pre_iter.push_back(2); uaamg_post_iter.push_back(2); uaamg_cycle.push_back(2); uaamg_scaling.push_back(1); uaamg_rebuildnumeric.push_back(0); uaamg_coarsening_strat.insert(uaamg_coarsening_strat.end(), {"Greedy", "PMIS"}); } } struct UAAMGInitializer { UAAMGInitializer() { update_uaamg(); } }; // Create a global instance of the initializer, so the environment is checked and updated before tests. UAAMGInitializer uaamg_initializer; class parameterized_uaamg : public testing::TestWithParam { protected: parameterized_uaamg() {} virtual ~parameterized_uaamg() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_uaamg_arguments(uaamg_tuple tup) { Arguments arg; arg.size = std::get<0>(tup); arg.pre_smooth = std::get<1>(tup); arg.post_smooth = std::get<2>(tup); arg.smoother = std::get<3>(tup); arg.coarsening_strategy = std::get<4>(tup); arg.matrix_type = std::get<5>(tup); arg.format = std::get<6>(tup); arg.cycle = std::get<7>(tup); arg.ordering = std::get<8>(tup); arg.rebuildnumeric = std::get<9>(tup); arg.use_acc = std::get<10>(tup); return arg; } TEST_P(parameterized_uaamg, uaamg_float) { Arguments arg = setup_uaamg_arguments(GetParam()); ASSERT_EQ(testing_uaamg(arg), true); } TEST_P(parameterized_uaamg, uaamg_double) { Arguments arg = setup_uaamg_arguments(GetParam()); ASSERT_EQ(testing_uaamg(arg), true); } INSTANTIATE_TEST_CASE_P(uaamg, parameterized_uaamg, testing::Combine(testing::ValuesIn(uaamg_size), testing::ValuesIn(uaamg_pre_iter), testing::ValuesIn(uaamg_post_iter), testing::ValuesIn(uaamg_smoother), testing::ValuesIn(uaamg_coarsening_strat), testing::ValuesIn(uaamg_matrix_type), testing::ValuesIn(uaamg_format), testing::ValuesIn(uaamg_cycle), testing::ValuesIn(uaamg_scaling), testing::ValuesIn(uaamg_rebuildnumeric), testing::ValuesIn(uaamg_use_acc))); rocALUTION-rocm-7.1.0/cmake/000077500000000000000000000000001507377332500153705ustar00rootroot00000000000000rocALUTION-rocm-7.1.0/cmake/Dependencies.cmake000066400000000000000000000077021507377332500207660ustar00rootroot00000000000000# ######################################################################## # Copyright (C) 2018-2025 Advanced Micro Devices, Inc. All rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # # ######################################################################## # Dependencies include(FetchContent) # Find OpenMP package find_package(OpenMP) if (NOT OPENMP_FOUND) message("-- OpenMP not found. Compiling WITHOUT OpenMP support.") else() option(SUPPORT_OMP "Compile WITH OpenMP support." ON) if(NOT TARGET OpenMP::OpenMP_CXX) # cmake fix for cmake <= 3.9 find_package(Threads REQUIRED) 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() # MPI set(MPI_HOME ${ROCALUTION_MPI_DIR}) find_package(MPI) if (NOT MPI_FOUND) message("-- MPI not found. Compiling WITHOUT MPI support.") if (SUPPORT_MPI) message(FATAL_ERROR "Cannot build with MPI support.") endif() else() option(SUPPORT_MPI "Compile WITH MPI support." OFF) if(NOT TARGET MPI::MPI_CXX) # cmake fix for cmake <= 3.9 add_library(MPI::MPI_CXX IMPORTED INTERFACE) set_property(TARGET MPI::MPI_CXX PROPERTY INTERFACE_COMPILE_OPTIONS "${MPI_CXX_COMPILE_OPTIONS}") set_property(TARGET MPI::MPI_CXX PROPERTY INTERFACE_COMPILE_DEFINITIONS "${MPI_CXX_COMPILE_DEFINITIONS}") set_property(TARGET MPI::MPI_CXX PROPERTY INTERFACE_LINK_LIBRARIES "") if(MPI_CXX_LINK_FLAGS) set_property(TARGET MPI::MPI_CXX APPEND PROPERTY INTERFACE_LINK_LIBRARIES "${MPI_CXX_LINK_FLAGS}") endif() if(MPI_CXX_LIBRARIES) set_property(TARGET MPI::MPI_CXX APPEND PROPERTY INTERFACE_LINK_LIBRARIES "${MPI_CXX_LIBRARIES}") endif() set_property(TARGET MPI::MPI_CXX PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${MPI_CXX_INCLUDE_DIRS}") endif() endif() # ROCm cmake package find_package(ROCmCMakeBuildTools 0.11.0 CONFIG QUIET PATHS ${CMAKE_PREFIX_PATH}) if(NOT ROCmCMakeBuildTools_FOUND) find_package(ROCM 0.7.3 CONFIG QUIET PATHS ${CMAKE_PREFIX_PATH}) # deprecated fallback if(NOT ROCM_FOUND) message(STATUS "ROCmCMakeBuildTools not found. Fetching...") set(PROJECT_EXTERN_DIR ${CMAKE_CURRENT_BINARY_DIR}/extern) set(rocm_cmake_tag "rocm-6.4.0" CACHE STRING "rocm-cmake tag to download") FetchContent_Declare( rocm-cmake GIT_REPOSITORY https://github.com/ROCm/rocm-cmake.git GIT_TAG ${rocm_cmake_tag} SOURCE_SUBDIR "DISABLE ADDING TO BUILD" ) FetchContent_MakeAvailable(rocm-cmake) find_package(ROCmCMakeBuildTools CONFIG REQUIRED NO_DEFAULT_PATH PATHS "${rocm-cmake_SOURCE_DIR}") endif() endif() include(ROCMSetupVersion) include(ROCMCreatePackage) include(ROCMInstallTargets) include(ROCMPackageConfigHelpers) include(ROCMInstallSymlinks) include(ROCMCheckTargetIds) include(ROCMClients) include(ROCMHeaderWrapper) rocALUTION-rocm-7.1.0/cmake/Packaging.cmake000066400000000000000000000057241507377332500202660ustar00rootroot00000000000000# ######################################################################## # Copyright (C) 2019-2020 Advanced Micro Devices, Inc. All rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # # ######################################################################## # Client packaging include(CMakeParseArguments) function(rocm_create_package_clients) set(options) set(oneValueArgs LIB_NAME DESCRIPTION SECTION MAINTAINER VERSION) set(multiValueArgs DEPENDS) cmake_parse_arguments(PARSE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) string(CONCAT PACKAGE_NAME ${PARSE_LIB_NAME} "-clients-" ${PARSE_VERSION} "-Linux.deb") string(CONCAT DEB_CONTROL_FILE_CONTENT "Package: " ${PARSE_LIB_NAME} "-clients" "\nVersion: " ${PARSE_VERSION} "\nSection: " ${PARSE_SECTION} "\nPriority: optional" "\nArchitecture: amd64" "\nMaintainer: " ${PARSE_MAINTAINER} "\nDescription: " ${PARSE_DESCRIPTION} "\nDepends: " ${PARSE_LIB_NAME} "(>=" ${PARSE_VERSION} ")\n\n") if(EXISTS "${PROJECT_BINARY_DIR}/package") file(REMOVE_RECURSE "${PROJECT_BINARY_DIR}/package") endif() file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/package/${ROCM_PATH}/${PARSE_LIB_NAME}/bin") file(WRITE "${PROJECT_BINARY_DIR}/package/DEBIAN/control" ${DEB_CONTROL_FILE_CONTENT}) add_custom_target(package_clients COMMAND ${CMAKE_COMMAND} -E remove -f "${PROJECT_BINARY_DIR}/package/${ROCM_PATH}/${PARSE_LIB_NAME}/bin/*" COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_BINARY_DIR}/staging/*" "${PROJECT_BINARY_DIR}/package/${ROCM_PATH}/${PARSE_LIB_NAME}/bin" COMMAND dpkg -b "${PROJECT_BINARY_DIR}/package/" ${PACKAGE_NAME}) endfunction(rocm_create_package_clients) rocALUTION-rocm-7.1.0/cmake/Verbose.cmake000066400000000000000000000104311507377332500177760ustar00rootroot00000000000000# ######################################################################## # 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. # # ######################################################################## message(STATUS "==========================================") message(STATUS "\t==>rocalution_VERSION : ${rocalution_VERSION}") message(STATUS "\t==>CMAKE_BUILD_TYPE : ${CMAKE_BUILD_TYPE}") message(STATUS "\t==>BUILD_SHARED_LIBS : ${BUILD_SHARED_LIBS}") message(STATUS "\t==>CMAKE_INSTALL_PREFIX link : ${CMAKE_INSTALL_PREFIX}") message(STATUS "\t==>CMAKE_MODULE_PATH link : ${CMAKE_MODULE_PATH}") message(STATUS "\t==>CMAKE_PREFIX_PATH link : ${CMAKE_PREFIX_PATH}") message(STATUS "==============") message(STATUS "\t==>CMAKE_SYSTEM_NAME : ${CMAKE_SYSTEM_NAME}") message(STATUS "\t>>=HIP_ROOT_DIR : ${HIP_ROOT_DIR}") message(STATUS "\t==>CMAKE_CXX_COMPILER : ${CMAKE_CXX_FLAGS}") message(STATUS "\t==>CMAKE_CXX_COMPILER_VERSION : ${CMAKE_CXX_COMPILER_VERSION}") message(STATUS "\t==>CMAKE_CXX_COMPILER debug : ${CMAKE_CXX_FLAGS_DEBUG}") message(STATUS "\t==>CMAKE_CXX_COMPILER release : ${CMAKE_CXX_FLAGS_RELEASE}") message(STATUS "\t==>CMAKE_CXX_COMPILER relwithdebinfo : ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") message(STATUS "\t==>CMAKE_EXE_LINKER_FLAGS : ${CMAKE_EXE_LINKER_FLAGS}") message(STATUS "\t==>CMAKE_EXE_LINKER_FLAGS_RELEASE : ${CMAKE_EXE_LINKER_FLAGS_RELEASE}") message(STATUS "\t==>CMAKE_SHARED_LINKER_FLAGS : ${CMAKE_SHARED_LINKER_FLAGS}") message(STATUS "\t==>CMAKE_SHARED_LINKER_FLAGS_RELEASE : ${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") message(STATUS "==============" ) message(STATUS "\t==>CMAKE_SHARED_LIBRARY_C_FLAGS : ${CMAKE_SHARED_LIBRARY_C_FLAGS}") message(STATUS "\t==>CMAKE_SHARED_LIBRARY_CXX_FLAGS : ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}") message(STATUS "\t==>CMAKE_SHARED_LINKER_FLAGS : ${CMAKE_SHARED_LINKER_FLAGS}") message(STATUS "\t==>CMAKE_SHARED_LINKER_FLAGS_DEBUG : ${CMAKE_SHARED_LINKER_FLAGS_DEBUG}") message(STATUS "\t==>CMAKE_SHARED_LINKER_FLAGS_RELEASE : ${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") message(STATUS "==============" ) message(STATUS "\t==>SUPPORT_HIP : ${SUPPORT_HIP}") if(SUPPORT_HIP) message(STATUS "\t\t-->HIP_VERSION : ${HIP_VERSION}") endif() message(STATUS "\t==>SUPPORT_OMP : ${SUPPORT_OMP}") if(SUPPORT_OMP) message(STATUS "\t\t-->OpenMP_CXX_VERSION : ${OpenMP_CXX_VERSION}") message(STATUS "\t\t-->OpenMP_CXX_LIBRARIES : ${OpenMP_CXX_LIBRARIES}") endif() message(STATUS "\t==>SUPPORT_MPI : ${SUPPORT_MPI}") if(SUPPORT_MPI) message(STATUS "\t\t-->MPI_CXX_VERSION : ${MPI_CXX_VERSION}") message(STATUS "\t\t-->MPI_CXX_LIBRARIES : ${MPI_CXX_LIBRARIES}") endif() message(STATUS "==============" ) message(STATUS "\t==>BUILD_CLIENTS_TESTS : ${BUILD_CLIENTS_TESTS}") message(STATUS "\t==>BUILD_CLIENTS_SAMPLES : ${BUILD_CLIENTS_SAMPLES}") message(STATUS "==============" ) message(STATUS "==========================================") message(STATUS "\t==>AMDGPU_TARGETS : ${AMDGPU_TARGETS}") rocALUTION-rocm-7.1.0/cmake/get-cli-arguments.cmake000066400000000000000000000020001507377332500217110ustar00rootroot00000000000000# Attempt (best effort) to return a list of user specified parameters cmake was invoked with # NOTE: Even if the user specifies CMAKE_INSTALL_PREFIX on the command line, the parameter is # not returned because it does not have the matching helpstring function( append_cmake_cli_arguments initial_cli_args return_cli_args ) # Retrieves the contents of CMakeCache.txt get_cmake_property( cmake_properties CACHE_VARIABLES ) foreach( property ${cmake_properties} ) get_property(help_string CACHE ${property} PROPERTY HELPSTRING ) # Properties specified on the command line have boilerplate text if( help_string MATCHES "variable specified on the command line" ) # message( STATUS "property: ${property}") # message( STATUS "value: ${${property}}") list( APPEND cli_args "-D${property}=${${property}}") endif( ) endforeach( ) # message( STATUS "get_command_line_arguments: ${cli_args}") set( ${return_cli_args} ${${initial_cli_args}} ${cli_args} PARENT_SCOPE ) endfunction( ) rocALUTION-rocm-7.1.0/custom.properties000066400000000000000000000001411507377332500177340ustar00rootroot00000000000000booktitle=rocALUTION API Guide spreadsheet.xml=docs/classification-map.xml document.locale=enusrocALUTION-rocm-7.1.0/deps/000077500000000000000000000000001507377332500152435ustar00rootroot00000000000000rocALUTION-rocm-7.1.0/deps/CMakeLists.txt000066400000000000000000000066231507377332500200120ustar00rootroot00000000000000# ######################################################################## # 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. # # ######################################################################## # Helper cmake script to automate building dependencies for rocsparse # This script can be invoked manually by the user with 'cmake -P' # The ROCm platform requires Ubuntu 16.04 or Fedora 24, which has cmake 3.5 cmake_minimum_required( VERSION 3.5 ) list( APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../cmake ) # Consider removing this in the future # It can be annoying for visual studio developers to build a project that tries to install into 'program files' if( WIN32 AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT ) set( CMAKE_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/package" CACHE PATH "Install path prefix, prepended onto install directories" FORCE ) endif( ) # This has to be initialized before the project() command appears # Set the default of CMAKE_BUILD_TYPE to be release, unless user specifies with -D. MSVC_IDE does not use CMAKE_BUILD_TYPE if( NOT DEFINED CMAKE_CONFIGURATION_TYPES AND NOT DEFINED CMAKE_BUILD_TYPE ) set( CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." ) endif() # The superbuild does not build anything itself; all compiling is done in external projects project( rocsparse-dependencies NONE ) option( BUILD_GTEST "Download and build googletest library" OFF ) # option( BUILD_VERBOSE "Print helpful build debug information" OFF ) # This module scrapes the CMakeCache.txt file and attempts to get all the cli options the user specified to cmake invocation include( get-cli-arguments ) # The following is a series of super-build projects; this cmake project will download and build if( BUILD_GTEST ) include( external-gtest ) list( APPEND rocsparse_dependencies googletest ) set( gtest_custom_target COMMAND cd ${GTEST_BINARY_ROOT}$ ${CMAKE_COMMAND} --build . --target install ) endif( ) # POLICY CMP0037 - "Target names should not be reserved and should match a validity pattern" # Familiar target names like 'install' should be OK at the super-build level if( POLICY CMP0037 ) cmake_policy( SET CMP0037 OLD ) endif( ) add_custom_target( install ${gtest_custom_target} DEPENDS ${rocsparse_dependencies} ) rocALUTION-rocm-7.1.0/deps/external-gtest.cmake000066400000000000000000000115231507377332500212150ustar00rootroot00000000000000# ######################################################################## # 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. # # ######################################################################## message( STATUS "Configuring gtest external dependency" ) include( ExternalProject ) # set( gtest_cmake_args -DCMAKE_INSTALL_PREFIX=/package ) set( PREFIX_GTEST ${CMAKE_INSTALL_PREFIX} CACHE PATH "Location where boost should install, defaults to /usr/local" ) set( gtest_cmake_args -DCMAKE_INSTALL_PREFIX=${PREFIX_GTEST} -DBUILD_SHARED_LIBS=OFF ) append_cmake_cli_arguments( gtest_cmake_args gtest_cmake_args ) set( gtest_git_repository "https://github.com/google/googletest.git" CACHE STRING "URL to download gtest from" ) set( gtest_git_tag "release-1.8.0" CACHE STRING "URL to download gtest from" ) if( MSVC ) list( APPEND gtest_cmake_args -Dgtest_force_shared_crt=ON -DCMAKE_DEBUG_POSTFIX=d ) # else( ) # GTEST_USE_OWN_TR1_TUPLE necessary to compile with hipcc # list( APPEND gtest_cmake_args -DGTEST_USE_OWN_TR1_TUPLE=1 ) endif( ) if( CMAKE_CONFIGURATION_TYPES ) set( gtest_make COMMAND ${CMAKE_COMMAND} --build --config Release COMMAND ${CMAKE_COMMAND} --build --config Debug ) else( ) # Add build thread in addition to the number of cores that we have include( ProcessorCount ) ProcessorCount( Cores ) # If we are not using an IDE, assume nmake with visual studio if( MSVC ) set( gtest_make "nmake" ) else( ) set( gtest_make "make" ) # The -j paramter does not work with nmake if( NOT Cores EQUAL 0 ) math( EXPR Cores "${Cores} + 1 " ) list( APPEND gtest_make -j ${Cores} ) else( ) # If we could not detect # of cores, assume 1 core and add an additional build thread list( APPEND gtest_make -j 2 ) endif( ) endif( ) message( STATUS "ExternalGmock using ( " ${Cores} " ) cores to build with" ) endif( ) # message( STATUS "gtest_make ( " ${gtest_make} " ) " ) # message( STATUS "gtest_cmake_args ( " ${gtest_cmake_args} " ) " ) # Master branch has a new structure that combines googletest with googlemock ExternalProject_Add( googletest PREFIX ${CMAKE_BINARY_DIR}/gtest GIT_REPOSITORY ${gtest_git_repository} GIT_TAG ${gtest_git_tag} CMAKE_ARGS ${gtest_cmake_args} BUILD_COMMAND ${gtest_make} LOG_BUILD 1 INSTALL_COMMAND "" LOG_INSTALL 1 ) ExternalProject_Get_Property( googletest source_dir ) # For visual studio, the path 'debug' is hardcoded because that is the default VS configuration for a build. # Doesn't matter if its the gtest or gtestd project above set( package_dir "${PREFIX_GTEST}" ) if( CMAKE_CONFIGURATION_TYPES ) # Create a package by bundling libraries and header files if( BUILD_64 ) set( LIB_DIR lib64 ) else( ) set( LIB_DIR lib ) endif( ) set( gtest_lib_dir "/${LIB_DIR}" ) ExternalProject_Add_Step( googletest createPackage COMMAND ${CMAKE_COMMAND} -E copy_directory ${gtest_lib_dir}/Debug ${package_dir}/${LIB_DIR} COMMAND ${CMAKE_COMMAND} -E copy_directory ${gtest_lib_dir}/Release ${package_dir}/${LIB_DIR} COMMAND ${CMAKE_COMMAND} -E copy_directory ${gtest_lib_dir}/Debug ${package_dir}/${LIB_DIR} COMMAND ${CMAKE_COMMAND} -E copy_directory ${gtest_lib_dir}/Release ${package_dir}/${LIB_DIR} COMMAND ${CMAKE_COMMAND} -E copy_directory /include ${package_dir}/include COMMAND ${CMAKE_COMMAND} -E copy_directory /gtest/include/gtest ${package_dir}/include/gtest DEPENDEES install ) endif( ) set_property( TARGET googletest PROPERTY FOLDER "extern") ExternalProject_Get_Property( googletest install_dir ) ExternalProject_Get_Property( googletest binary_dir ) # For use by the user of ExternalGtest.cmake set( GTEST_INSTALL_ROOT ${install_dir} ) set( GTEST_BINARY_ROOT ${binary_dir} ) rocALUTION-rocm-7.1.0/docs/000077500000000000000000000000001507377332500152405ustar00rootroot00000000000000rocALUTION-rocm-7.1.0/docs/.gitignore000066400000000000000000000001031507377332500172220ustar00rootroot00000000000000_build/ _doxygen/ doxygen/html/ doxygen/xml/ /sphinx/_toc.yml rocALUTION-rocm-7.1.0/docs/classification-map.xml000066400000000000000000000211431507377332500215310ustar00rootroot00000000000000 Kanika Yadav (external) Microsoft Office User 2020-09-25T06:54:04Z 2021-12-22T19:07:50Z 16.00 true 2021-02-23T09:13:03Z Standard 90c2fedb-0da6-4717-8531-d16a1b9930f4 45597f60-6e37-4be7-acfb-4c9e23b261ea 0 true 2022-01-14T16:33:39Z Privileged AMD Official Use Only-AIP 2.0 3dd8961f-e488-4e60-8e11-a82d994e183d 3ab6c0f7-c658-4f6f-bd9d-6ef921551ff7 1 14235 32767 32767 32767 False False Filename Title Categories Version Doc Type MAP rocm;hip-sdk;hip;gpu;amd;alution;rocalution 4-5 apply-ALL default rocALUTION API Guide reference