diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..a04f49beb --- /dev/null +++ b/.clang-format @@ -0,0 +1,120 @@ +# 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: true +AlignConsecutiveAssignments: true +AlignConsecutiveDeclarations: true +AlignEscapedNewlinesLeft: true +AlignOperands: true +AlignTrailingComments: false +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: { + 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 +#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 +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 +#IndentPPDirectives: AfterHash +--- diff --git a/.githooks/install b/.githooks/install new file mode 100755 index 000000000..cbb0569bf --- /dev/null +++ b/.githooks/install @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +cd $(git rev-parse --git-dir) +cd hooks + +echo "Installing hooks..." +ln -s ../../.githooks/pre-commit pre-commit +echo "Done!" diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 000000000..7ca327ad5 --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,58 @@ +#!/bin/sh +# +# This pre-commit hook checks if any versions of clang-format +# are installed, and if so, uses the installed version to format +# the staged changes. + +base=clang-format-3.8 +format="" + +# Redirect output to stderr. +exec 1>&2 + + # check if clang-format is installed +type "$base" >/dev/null 2>&1 && format="$base" + +# no versions of clang-format are installed +if [ -z "$format" ] +then + echo "$base is not installed. Commit is cancelled. Delete the hook to force commit." + exit 1 +fi + +# Do everything from top - level +cd $(git rev-parse --show-toplevel) + +if git rev-parse --verify HEAD >/dev/null 2>&1 +then + against=HEAD +else + # Initial commit: diff against an empty tree object + against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 +fi + +exitCode=0 + +# do the formatting +for file in $(git diff-index --cached --name-only $against | grep -E '\.h$|\.hpp$|\.cpp$|\.cl$|\.h\.in$|\.hpp\.in$|\.cpp\.in$') +do + if [ -e "$file" ] + then + # echo "$format $file" + "$format" -style=file -output-replacements-xml "$file" | grep "\" >/dev/null + if [ $? -ne 1 ]; then + echo "$format" -i -style=file "$file" + exitCode=1 + fi + + fi +done + +if [ $exitCode -eq 1 ]; then + echo "Please fix the errors by running the commands listed above." + echo "Commit is cancelled. You may force by deleting the hook in .githook" +else + echo "Clang format checks passed" +fi + +exit $exitCode diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 000000000..cf39a277d --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,62 @@ +#!/usr/bin/env groovy +@Library('rocJenkins') _ +import com.amd.project.* +import com.amd.docker.* + +//////////////////////////////////////////////////////////////////////// +import java.nio.file.Path; + +rocprimCI: +{ + + def rocprim = new rocProject('rocprim') + + def nodes = new dockerNodes(['gfx803', 'gfx900', 'gfx906'], rocprim) + + boolean formatCheck = false + + def compileCommand = + { + platform, project-> + + project.paths.construct_build_prefix() + def command = """#!/usr/bin/env bash + set -x + cd ${project.paths.project_build_prefix} + LD_LIBRARY_PATH=/opt/rocm/hcc/lib CXX=${project.compiler.compiler_path} ${project.paths.build_command} + """ + platform.runCommand(this, command) + } + + def testCommand = + { + platform, project-> + + def testCommand = 'ctest --output-on-failure -E rocprim.hip.device_merge_sort' + + def command = """#!/usr/bin/env bash + set -x + cd ${project.paths.project_build_prefix} + cd ${project.testDirectory} + LD_LIBRARY_PATH=/opt/rocm/hcc/lib ${testCommand} + """ + + platform.runCommand(this, command) + } + + def packageCommand = + { + platform, project-> + + def command = """ + echo "rocPRIM is a header only library and does not need packaging" + """ + + platform.runCommand(this, command) + } + + buildProject(rocprim, formatCheck, nodes.dockerArray, compileCommand, testCommand, packageCommand) + +} + + diff --git a/docker/dockerfile-build-ubuntu-rock b/docker/dockerfile-build-ubuntu-rock new file mode 100644 index 000000000..fc06aa089 --- /dev/null +++ b/docker/dockerfile-build-ubuntu-rock @@ -0,0 +1,50 @@ +# Parameters related to building hip +ARG base_image + +FROM ${base_image} +LABEL maintainer="kent.knox@amd" + +ARG user_uid + +# Install dependent packages +# Dependencies: +# * hcc-config.cmake: pkg-config +# * tensile: python2.7, python-yaml +# * rocblas-test: gfortran, googletest +# * rocblas-bench: libboost-program-options-dev +# * libhsakmt.so: libnuma1 +RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + rock-dkms \ + sudo \ + ca-certificates \ + git \ + make \ + cmake \ + clang-format-3.8 \ + pkg-config \ + python2.7 \ + python-yaml \ + gfortran \ + libboost-program-options-dev \ + libnuma1 \ + && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# docker pipeline runs containers with particular uid +# create a jenkins user with this specific uid so it can use sudo priviledges +# Grant any member of sudo group password-less sudo privileges +RUN useradd --create-home -u ${user_uid} -o -G sudo --shell /bin/bash jenkins && \ + mkdir -p /etc/sudoers.d/ && \ + echo '%sudo ALL=(ALL) NOPASSWD:ALL' | tee /etc/sudoers.d/sudo-nopasswd + +ARG ROCBLAS_SRC_ROOT=/usr/local/src/rocBLAS + +# Clone rocblas repo +# Build client dependencies and install into /usr/local (LAPACK & GTEST) +RUN mkdir -p ${ROCBLAS_SRC_ROOT} && cd ${ROCBLAS_SRC_ROOT} && \ + git clone -b saad/develop --depth=1 https://github.com/saadrahim/rocPRIM . #&& \ + #mkdir -p build/deps && cd build/deps && \ + #cmake -DBUILD_BOOST=OFF ${ROCBLAS_SRC_ROOT}/deps && \ + #make -j $(nproc) install && \ + #rm -rf ${ROCBLAS_SRC_ROOT} diff --git a/docker/dockerfile-install-ubuntu b/docker/dockerfile-install-ubuntu new file mode 100755 index 000000000..7d20aad61 --- /dev/null +++ b/docker/dockerfile-install-ubuntu @@ -0,0 +1,54 @@ +# Parameters related to building hip +ARG base_image + +FROM ${base_image} +LABEL maintainer="kent.knox@amd" + +ARG user_uid + +# Install dependent packages +# Dependencies: +# * hcc-config.cmake: pkg-config +# * tensile: python2.7, python-yaml +# * rocblas-test: gfortran, googletest +# * rocblas-bench: libboost-program-options-dev +# * libhsakmt.so: libnuma1 + +USER root + +RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + python2.7-minimal +RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + sudo \ + ca-certificates \ + git \ + make \ + cmake \ + clang-format-3.8 \ + pkg-config \ + python2.7 \ + python-yaml \ + gfortran \ + libboost-program-options-dev \ + libnuma1 \ + && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# docker pipeline runs containers with particular uid +# create a jenkins user with this specific uid so it can use sudo priviledges +# Grant any member of sudo group password-less sudo privileges +RUN useradd --create-home -u ${user_uid} -o -G sudo --shell /bin/bash jenkins && \ + mkdir -p /etc/sudoers.d/ && \ + echo '%sudo ALL=(ALL) NOPASSWD:ALL' | tee /etc/sudoers.d/sudo-nopasswd + +ARG ROCBLAS_SRC_ROOT=/usr/local/src/rocBLAS + +# Clone rocblas repo +# Build client dependencies and install into /usr/local (LAPACK & GTEST) +RUN mkdir -p ${ROCBLAS_SRC_ROOT} && cd ${ROCBLAS_SRC_ROOT} && \ + git clone -b develop --depth=1 https://github.com/ROCmSoftwarePlatform/rocBLAS . && \ + mkdir -p build/deps && cd build/deps && \ + cmake -DBUILD_BOOST=OFF ${ROCBLAS_SRC_ROOT}/deps && \ + make -j $(nproc) install +# rm -rf ${ROCBLAS_SRC_ROOT} diff --git a/install b/install new file mode 100755 index 000000000..819029eb2 --- /dev/null +++ b/install @@ -0,0 +1,112 @@ +#!/bin/bash + + +# ################################################# +# helper functions +# ################################################# +function display_help() +{ + echo "rocPRIM build & installation helper script" + echo "./install [-h|--help] " + echo " [-h|--help] prints this help message" + echo " [-i|--install] install after build" + #Not implemented yet + # echo " [-d|--dependencies] install build dependencies" + echo " [-c|--clients] build library clients too (combines with -i & -d)" + echo " [-g|--debug] -DCMAKE_BUILD_TYPE=Debug (default is =Release)" +} + + +# ################################################# +# global variables +# ################################################# +install_package=false +build_clients=false +build_release=true +run_tests=false +rocm_path=/opt/rocm/bin +# ################################################# +# Parameter parsing +# ################################################# + +# check if we have a modern version of getopt that can handle whitespace and long parameters +getopt -T +if [[ $? -eq 4 ]]; then + GETOPT_PARSE=$(getopt --name "${0}" --longoptions help,install,clients,debug,test --options hicdt -- "$@") +else + echo "Need a new version of getopt" + exit 1 +fi + +if [[ $? -ne 0 ]]; then + echo "getopt invocation failed; could not parse the command line"; + exit 1 +fi + +eval set -- "${GETOPT_PARSE}" + + +while true; do + case "${1}" in + -h|--help) + display_help + exit 0 + ;; + -i|--install) + install_package=true + shift ;; + -c|--clients) + build_clients=true + shift ;; + -g|--debug) + build_release=false + shift ;; + -t|--test) + run_tests=true + shift ;; + --) shift ; break ;; + *) echo "Unexpected command line parameter received; aborting"; + exit 1 + ;; + esac + done + + +# Instal the pre-commit hook +bash ./githooks/install + + +# Go to rocPRIM directory, create and go to the build directory. +mkdir -p build; cd build + +if ($build_release); then + mkdir -p release; cd release +else + mkdir -p debug; cd debug +fi + +# Configure rocPRIM, setup options for your system. +# Build options: +# BUILD_TEST - on by default, +# BUILD_BENCHMARK - off by default. +# +# ! IMPORTANT ! +# On ROCm platform set C++ compiler to HCC. You can do it by adding 'CXX=' +# before 'cmake' or setting cmake option 'CMAKE_CXX_COMPILER' to path to the HCC compiler. +# + + +CXX=$rocm_path/hcc cmake -DBUILD_BENCHMARK=ON ../../. # or cmake-gui ../. + +# Build +make -j32 + +if ($run_tests); then +# Optionally, run tests if they're enabled. +ctest --output-on-failure +fi + +if ($install_package); then +# Install +make install +fi diff --git a/rocprim/include/rocprim/device/device_histogram_config.hpp b/rocprim/include/rocprim/device/device_histogram_config.hpp index c90d2a808..17180d810 100644 --- a/rocprim/include/rocprim/device/device_histogram_config.hpp +++ b/rocprim/include/rocprim/device/device_histogram_config.hpp @@ -55,6 +55,21 @@ struct histogram_config #endif }; +#ifndef DOXYGEN_SHOULD_SKIP_THIS +template< + class HistogramConfig, + unsigned int MaxGridSize, + unsigned int SharedImplMaxBins +> constexpr unsigned int +histogram_config::max_grid_size; +template< + class HistogramConfig, + unsigned int MaxGridSize, + unsigned int SharedImplMaxBins +> constexpr unsigned int +histogram_config::shared_impl_max_bins; +#endif + namespace detail {