From b3ab733f14c927167c2bad573b2db4540d5d083d Mon Sep 17 00:00:00 2001 From: Evgeny Mankov Date: Fri, 13 Sep 2024 17:27:17 +0200 Subject: [PATCH] [HIPIFY][#1474][Linux][feature] Added a filtering ability for the supplementary hipification scripts - Part 1 - hipconvertinplace-perl.sh + Introduced a new option -filter=all|headers|sources|custom with corresponding sh files + Updated and packaging files correspondingly + [ToDo] Do the same for the rest of supplementary hipification scripts --- CMakeLists.txt | 6 ++++++ bin/findcode.sh | 4 ++-- bin/findcode_custom.sh | 6 ++++++ bin/findcode_headers.sh | 7 +++++++ bin/findcode_sources.sh | 8 ++++++++ bin/hipconvertinplace-perl.sh | 22 ++++++++++++++++++++-- packaging/hipify-clang.postinst | 3 +++ packaging/hipify-clang.prerm | 3 +++ packaging/hipify-clang.rpm_post | 3 +++ packaging/hipify-clang.rpm_postun | 3 +++ packaging/hipify-clang.txt | 3 +++ 11 files changed, 64 insertions(+), 4 deletions(-) mode change 100644 => 100755 CMakeLists.txt create mode 100755 bin/findcode_custom.sh create mode 100755 bin/findcode_headers.sh create mode 100755 bin/findcode_sources.sh mode change 100644 => 100755 packaging/hipify-clang.postinst mode change 100644 => 100755 packaging/hipify-clang.prerm mode change 100644 => 100755 packaging/hipify-clang.rpm_post mode change 100644 => 100755 packaging/hipify-clang.rpm_postun mode change 100644 => 100755 packaging/hipify-clang.txt diff --git a/CMakeLists.txt b/CMakeLists.txt old mode 100644 new mode 100755 index 2aec5767..5088c36a --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -180,12 +180,18 @@ if (NOT HIPIFY_CLANG_TESTS_ONLY) PATTERN "hipify-perl" PATTERN "*.sh" PATTERN "findcode.sh" EXCLUDE + PATTERN "findcode_headers.sh" EXCLUDE + PATTERN "findcode_sources.sh" EXCLUDE + PATTERN "findcode_custom.sh" EXCLUDE PATTERN "finduncodep.sh" EXCLUDE) set(HIPIFY_LIBEXEC_INSTALL_PATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBEXECDIR}/hipify") install( PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bin/findcode.sh + PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bin/findcode_headers.sh + PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bin/findcode_sources.sh + PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bin/findcode_custom.sh PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bin/finduncodep.sh DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/hipify) diff --git a/bin/findcode.sh b/bin/findcode.sh index 71f9520b..48c0811c 100755 --- a/bin/findcode.sh +++ b/bin/findcode.sh @@ -6,5 +6,5 @@ find $SEARCH_DIRS -name '*.cu' -o -name '*.CU' find $SEARCH_DIRS -name '*.cpp' -o -name '*.cxx' -o -name '*.c' -o -name '*.cc' find $SEARCH_DIRS -name '*.CPP' -o -name '*.CXX' -o -name '*.C' -o -name '*.CC' find $SEARCH_DIRS -name '*.cuh' -o -name '*.CUH' -find $SEARCH_DIRS -name '*.h' -o -name '*.hpp' -o -name '*.inc' -o -name '*.inl' -o -name '*.hxx' -o -name '*.hdl' -find $SEARCH_DIRS -name '*.H' -o -name '*.HPP' -o -name '*.INC' -o -name '*.INL' -o -name '*.HXX' -o -name '*.HDL' +find $SEARCH_DIRS -name '*.h' -o -name '*.hpp' -o -name '*.hh' -o -name '*.inc' -o -name '*.inl' -o -name '*.hxx' -o -name '*.hdl' +find $SEARCH_DIRS -name '*.H' -o -name '*.HPP' -o -name '*.HH' -o -name '*.INC' -o -name '*.INL' -o -name '*.HXX' -o -name '*.HDL' diff --git a/bin/findcode_custom.sh b/bin/findcode_custom.sh new file mode 100755 index 00000000..d0153fff --- /dev/null +++ b/bin/findcode_custom.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +SEARCH_DIRS=$@ + +find $SEARCH_DIRS -name '*.cu' -and -not -name '*.cuh' +find $SEARCH_DIRS -name '*.CU' -and -not -name '*.CUH' diff --git a/bin/findcode_headers.sh b/bin/findcode_headers.sh new file mode 100755 index 00000000..d8d5c493 --- /dev/null +++ b/bin/findcode_headers.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +SEARCH_DIRS=$@ + +find $SEARCH_DIRS -name '*.cuh' -o -name '*.CUH' +find $SEARCH_DIRS -name '*.h' -o -name '*.hpp' -o -name '*.hh' -o -name '*.inc' -o -name '*.inl' -o -name '*.hxx' -o -name '*.hdl' +find $SEARCH_DIRS -name '*.H' -o -name '*.HPP' -o -name '*.HH' -o -name '*.INC' -o -name '*.INL' -o -name '*.HXX' -o -name '*.HDL' diff --git a/bin/findcode_sources.sh b/bin/findcode_sources.sh new file mode 100755 index 00000000..bfb15e13 --- /dev/null +++ b/bin/findcode_sources.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +SEARCH_DIRS=$@ + +find $SEARCH_DIRS -name '*.cu' -and -not -name '*.cuh' +find $SEARCH_DIRS -name '*.CU' -and -not -name '*.CUH' +find $SEARCH_DIRS -name '*.cpp' -o -name '*.cxx' -o -name '*.c' -o -name '*.cc' +find $SEARCH_DIRS -name '*.CPP' -o -name '*.CXX' -o -name '*.C' -o -name '*.CC' diff --git a/bin/hipconvertinplace-perl.sh b/bin/hipconvertinplace-perl.sh index 0d4202fa..a896e2cd 100755 --- a/bin/hipconvertinplace-perl.sh +++ b/bin/hipconvertinplace-perl.sh @@ -1,6 +1,6 @@ #!/bin/bash -#usage : hipconvertinplace-perl.sh DIRNAME [hipify-perl options] +#usage : hipconvertinplace-perl.sh DIRNAME [-filter=all|headers|sources|custom] [hipify-perl options] #hipify "inplace" all code files in specified directory. # This can be quite handy when dealing with an existing CUDA code base since the script @@ -12,7 +12,25 @@ # (this is useful for testing improvements to the hipify-perl toolset). SCRIPT_DIR="$(dirname "$(realpath "$0")")" +SCRIPT_NAME=findcode.sh PRIV_SCRIPT_DIR="$SCRIPT_DIR/../libexec/hipify" SEARCH_DIR=$1 +if [ "$2" = "-filter=all" ] +then shift -$SCRIPT_DIR/hipify-perl -inplace -print-stats "$@" `$PRIV_SCRIPT_DIR/findcode.sh $SEARCH_DIR` +elif [ "$2" = "-filter=headers" ] +then +SCRIPT_NAME=findcode_headers.sh +shift +elif [ "$2" = "-filter=sources" ] +then +SCRIPT_NAME=findcode_sources.sh +shift +elif [ "$2" = "-filter=custom" ] +then +SCRIPT_NANE=findcode_custom.sh +shift +fi +shift + +$SCRIPT_DIR/hipify-perl -inplace -print-stats "$@" `$PRIV_SCRIPT_DIR/$SCRIPT_NAME $SEARCH_DIR` diff --git a/packaging/hipify-clang.postinst b/packaging/hipify-clang.postinst old mode 100644 new mode 100755 index a4933c72..2b9224db --- a/packaging/hipify-clang.postinst +++ b/packaging/hipify-clang.postinst @@ -19,6 +19,9 @@ case "$1" in ln -r -s -f @HIPBINDIR@/hipexamine-perl.sh @ROCMBINDIR@/hipexamine-perl.sh ln -r -s -f @HIPBINDIR@/hipexamine.sh @ROCMBINDIR@/hipexamine.sh ln -r -s -f @HIPBINDIR@/findcode.sh @ROCMBINDIR@/findcode.sh + ln -r -s -f @HIPBINDIR@/findcode_headers.sh @ROCMBINDIR@/findcode_headers.sh + ln -r -s -f @HIPBINDIR@/findcode_sources.sh @ROCMBINDIR@/findcode_sources.sh + ln -r -s -f @HIPBINDIR@/findcode_custom.sh @ROCMBINDIR@/findcode_custom.sh ln -r -s -f @HIPBINDIR@/finduncodep.sh @ROCMBINDIR@/finduncodep.sh cd $CURRENTDIR ;; diff --git a/packaging/hipify-clang.prerm b/packaging/hipify-clang.prerm old mode 100644 new mode 100755 index b1cee2d2..7e707472 --- a/packaging/hipify-clang.prerm +++ b/packaging/hipify-clang.prerm @@ -17,6 +17,9 @@ case "$1" in rm -f @ROCMBINDIR@/hipexamine-perl.sh rm -f @ROCMBINDIR@/hipexamine.sh rm -f @ROCMBINDIR@/findcode.sh + rm -f @ROCMBINDIR@/findcode_headers.sh + rm -f @ROCMBINDIR@/findcode_sources.sh + rm -f @ROCMBINDIR@/findcode_custom.sh rm -f @ROCMBINDIR@/finduncodep.sh rmdir --ignore-fail-on-non-empty @ROCMBINDIR@ ;; diff --git a/packaging/hipify-clang.rpm_post b/packaging/hipify-clang.rpm_post old mode 100644 new mode 100755 index 4be23d44..44e232e0 --- a/packaging/hipify-clang.rpm_post +++ b/packaging/hipify-clang.rpm_post @@ -10,5 +10,8 @@ ln -r -s -f @HIPBINDIR@/hipconvertinplace.sh @ROCMBINDIR@/hipconvertinplace.sh ln -r -s -f @HIPBINDIR@/hipexamine-perl.sh @ROCMBINDIR@/hipexamine-perl.sh ln -r -s -f @HIPBINDIR@/hipexamine.sh @ROCMBINDIR@/hipexamine.sh ln -r -s -f @HIPBINDIR@/findcode.sh @ROCMBINDIR@/findcode.sh +ln -r -s -f @HIPBINDIR@/findcode_headers.sh @ROCMBINDIR@/findcode_headers.sh +ln -r -s -f @HIPBINDIR@/findcode_sources.sh @ROCMBINDIR@/findcode_sources.sh +ln -r -s -f @HIPBINDIR@/findcode_custom.sh @ROCMBINDIR@/findcode_custom.sh ln -r -s -f @HIPBINDIR@/finduncodep.sh @ROCMBINDIR@/finduncodep.sh cd $CURRENTDIR diff --git a/packaging/hipify-clang.rpm_postun b/packaging/hipify-clang.rpm_postun old mode 100644 new mode 100755 index 75247255..35d416d9 --- a/packaging/hipify-clang.rpm_postun +++ b/packaging/hipify-clang.rpm_postun @@ -7,6 +7,9 @@ if [ $1 -le 1 ]; then rm -f @ROCMBINDIR@/hipexamine-perl.sh rm -f @ROCMBINDIR@/hipexamine.sh rm -f @ROCMBINDIR@/findcode.sh + rm -f @ROCMBINDIR@/findcode_headers.sh + rm -f @ROCMBINDIR@/findcode_sources.sh + rm -f @ROCMBINDIR@/findcode_custom.sh rm -f @ROCMBINDIR@/finduncodep.sh rmdir --ignore-fail-on-non-empty @ROCMBINDIR@ rmdir --ignore-fail-on-non-empty @HIPBINDIR@ diff --git a/packaging/hipify-clang.txt b/packaging/hipify-clang.txt old mode 100644 new mode 100755 index 4bebd599..a274c5f1 --- a/packaging/hipify-clang.txt +++ b/packaging/hipify-clang.txt @@ -4,6 +4,9 @@ project(hipify-clang) install(PROGRAMS @HIPIFY_BIN_INSTALL_PATH@/hipify-clang DESTINATION @CMAKE_INSTALL_BINDIR@) install(PROGRAMS @HIPIFY_BIN_INSTALL_PATH@/hipify-perl DESTINATION @CMAKE_INSTALL_BINDIR@) install(PROGRAMS @HIPIFY_LIBEXEC_INSTALL_PATH@/findcode.sh DESTINATION @CMAKE_INSTALL_LIBEXECDIR@/hipify) +install(PROGRAMS @HIPIFY_LIBEXEC_INSTALL_PATH@/findcode_headers.sh DESTINATION @CMAKE_INSTALL_LIBEXECDIR@/hipify) +install(PROGRAMS @HIPIFY_LIBEXEC_INSTALL_PATH@/findcode_sources.sh DESTINATION @CMAKE_INSTALL_LIBEXECDIR@/hipify) +install(PROGRAMS @HIPIFY_LIBEXEC_INSTALL_PATH@/findcode_custom.sh DESTINATION @CMAKE_INSTALL_LIBEXECDIR@/hipify) install(PROGRAMS @HIPIFY_LIBEXEC_INSTALL_PATH@/finduncodep.sh DESTINATION @CMAKE_INSTALL_LIBEXECDIR@/hipify) install(PROGRAMS @HIPIFY_BIN_INSTALL_PATH@/hipconvertinplace-perl.sh DESTINATION @CMAKE_INSTALL_BINDIR@) install(PROGRAMS @HIPIFY_BIN_INSTALL_PATH@/hipconvertinplace.sh DESTINATION @CMAKE_INSTALL_BINDIR@)