From 0f755dbc6bff95355b243e6de9c932f60d7ab150 Mon Sep 17 00:00:00 2001 From: gcapodagAMD Date: Mon, 9 Dec 2024 18:11:43 -0600 Subject: [PATCH] Added hipifly module --- extras/scripts/hipfort_setup.sh | 2 +- extras/scripts/hipifly_setup.sh | 97 ++++++++++++++++++++++++++++++++ extras/sources/hipifly/hipifly.h | 89 +++++++++++++++++++++++++++++ 3 files changed, 187 insertions(+), 1 deletion(-) create mode 100755 extras/scripts/hipifly_setup.sh create mode 100644 extras/sources/hipifly/hipifly.h diff --git a/extras/scripts/hipfort_setup.sh b/extras/scripts/hipfort_setup.sh index 2f53d00..a07082b 100755 --- a/extras/scripts/hipfort_setup.sh +++ b/extras/scripts/hipfort_setup.sh @@ -18,7 +18,7 @@ usage() echo "Usage:" echo " --module-path [ MODULE_PATH ] default $MODULE_PATH" echo " --rocm-version [ ROCM_VERSION ] default $ROCM_VERSION" - echo " --build-hipfort [ BUILD_HIPFORT ], set to 1 to build hipfort, default is 0" + echo " --build-hipfort [ BUILD_HIPFORT ], set to 1 to build hipfort, default is $BUILD_HIPFORT" echo " --use-flang-new [ USE_FLANGNEW ], , default is $USE_FLANGNEW" echo " --help: this usage information" exit 1 diff --git a/extras/scripts/hipifly_setup.sh b/extras/scripts/hipifly_setup.sh new file mode 100755 index 0000000..27e0f37 --- /dev/null +++ b/extras/scripts/hipifly_setup.sh @@ -0,0 +1,97 @@ +#/bin/bash + +# Variables controlling setup process +MODULE_PATH=/etc/lmod/modules/misc/hipifly +HIPIFLY_MODULE=0 +ROCM_VERSION=6.0 + +SUDO="sudo" + +if [ -f /.singularity.d/Singularity ]; then + SUDO="" +fi + +usage() +{ + echo "Usage:" + echo " --module-path [ MODULE_PATH ] default $MODULE_PATH" + echo " --rocm-version [ ROCM_VERSION ] default $ROCM_VERSION" + echo " --hipifly-module [ HIPIFLY_MODULE ], set to 1 to create hipifly, default is $HIPIFLY_MODULE" + echo " --help: this usage information" + exit 1 +} + +send-error() +{ + usage + echo -e "\nError: ${@}" + exit 1 +} + +reset-last() +{ + last() { send-error "Unsupported argument :: ${1}"; } +} + +n=0 +while [[ $# -gt 0 ]] +do + case "${1}" in + "--hipifly-module") + shift + HIPIFLY_MODULE=${1} + reset-last + ;; + "--help") + usage + ;; + "--rocm-version") + shift + ROCM_VERSION=${1} + reset-last + ;; + "--module-path") + shift + MODULE_PATH=${1} + reset-last + ;; + "--*") + send-error "Unsupported argument at position $((${n} + 1)) :: ${1}" + ;; + *) + last ${1} + ;; + esac + n=$((${n} + 1)) + shift +done + +echo "" +echo "===================================" +echo "Setting Up the HIPIFLY Module" +echo "HIPIFLY_MODULE: $HIPIFLY_MODULE" +echo "===================================" +echo "" + +if [ "${HIPIFLY_MODULE}" = "0" ]; then + + echo "Hipifly module will not be created, according to the specified value of HIPIFLY_MODULE" + echo "HIPIFLY_MODULE: $HIPIFLY_MODULE" + exit + +else + HIPIFLY_PATH=/opt/rocmplus-${ROCM_VERSION}/hipifly + ${SUDO} mkdir -p ${HIPIFLY_PATH} + ${SUDO} cp extras/sources/hipifly/hipifly.h ${HIPIFLY_PATH} + + ${SUDO} mkdir -p ${MODULE_PATH} + + # The - option suppresses tabs + cat <<-EOF | ${SUDO} tee ${MODULE_PATH}/dev.lua + whatis(" Hipifly header file ") + load("rocm/${ROCM_VERSION}") + setenv("HIPIFLY_PATH","${HIPIFLY_PATH}") +EOF + +fi + diff --git a/extras/sources/hipifly/hipifly.h b/extras/sources/hipifly/hipifly.h new file mode 100644 index 0000000..3cc90e2 --- /dev/null +++ b/extras/sources/hipifly/hipifly.h @@ -0,0 +1,89 @@ +/* +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. +*/ + +#ifndef CUDA_TO_HIP_H +#define CUDA_TO_HIP_H + +#include + +#define WARPSIZE 64 +static constexpr int maxWarpsPerBlock = 1024/WARPSIZE; + +#define CUFFT_D2Z HIPFFT_D2Z +#define CUFFT_FORWARD HIPFFT_FORWARD +#define CUFFT_INVERSE HIPFFT_BACKWARD +#define CUFFT_Z2D HIPFFT_Z2D +#define CUFFT_Z2Z HIPFFT_Z2Z + +#define cudaDeviceSynchronize hipDeviceSynchronize +#define cudaError hipError_t +#define cudaError_t hipError_t +#define cudaErrorInsufficientDriver hipErrorInsufficientDriver +#define cudaErrorNoDevice hipErrorNoDevice +#define cudaEvent_t hipEvent_t +#define cudaEventCreate hipEventCreate +#define cudaEventElapsedTime hipEventElapsedTime +#define cudaEventRecord hipEventRecord +#define cudaEventSynchronize hipEventSynchronize +#define cudaFree hipFree +#define cudaFreeHost hipHostFree +#define cudaGetDevice hipGetDevice +#define cudaGetDeviceCount hipGetDeviceCount +#define cudaGetErrorString hipGetErrorString +#define cudaGetLastError hipGetLastError +#define cudaHostAlloc hipHostMalloc +#define cudaHostAllocDefault hipHostMallocDefault +#define cudaMalloc hipMalloc +#define cudaMemcpy hipMemcpy +#define cudaMemcpyAsync hipMemcpyAsync +#define cudaMemcpyDeviceToHost hipMemcpyDeviceToHost +#define cudaMemcpyDeviceToDevice hipMemcpyDeviceToDevice +#define cudaMemcpyHostToDevice hipMemcpyHostToDevice +#define cudaMemGetInfo hipMemGetInfo +#define cudaMemset hipMemset +#define cudaReadModeElementType hipReadModeElementType +#define cudaSetDevice hipSetDevice +#define cudaSuccess hipSuccess +#define cudaDeviceProp hipDeviceProp_t +#define cudaGetDeviceProperties hipGetDeviceProperties +#define cudaThreadSynchronize hipDeviceSynchronize + + +#define cufftDestroy hipfftDestroy +#define cufftDoubleComplex hipfftDoubleComplex +#define cufftDoubleReal hipfftDoubleReal +#define cufftExecD2Z hipfftExecD2Z +#define cufftExecZ2D hipfftExecZ2D +#define cufftExecZ2Z hipfftExecZ2Z +#define cufftHandle hipfftHandle +#define cufftPlan3d hipfftPlan3d +#define cufftPlanMany hipfftPlanMany + +static void __attribute__((unused)) check(const hipError_t err, const char *const file, const int line) +{ + if (err == hipSuccess) return; + fprintf(stderr,"HIP ERROR AT LINE %d OF FILE '%s': %s %s\n",line,file,hipGetErrorName(err),hipGetErrorString(err)); + fflush(stderr); + exit(err); +} + +#endif //CUDA_TO_HIP_H