Added new unit tests for src/transport/p2p.cc (#1774)
[ROCm/rccl commit: 81ec6bff4c]
This commit is contained in:
@@ -733,10 +733,40 @@ if (BUILD_TESTS)
|
||||
set(TEST_NONSTATIC_SOURCE_FILES
|
||||
${HIPIFY_SRC_DIR}/misc/alt_rsmi.cc
|
||||
${HIPIFY_SRC_DIR}/transport/shm.cc
|
||||
${HIPIFY_SRC_DIR}/transport/p2p.cc
|
||||
)
|
||||
|
||||
set(EXCLUDE_STATIC_FILE "${CMAKE_SOURCE_DIR}/tools/scripts/exclude_static_list.txt")
|
||||
# Read the exclude list file into a CMake variable
|
||||
file(READ "${EXCLUDE_STATIC_FILE}" EXCLUDE_STATIC_CONTENTS)
|
||||
string(REPLACE "\n" ";" EXCLUDE_STATIC_LINES "${EXCLUDE_STATIC_CONTENTS}")
|
||||
# Create a mapping from full/relative filename to exclude list
|
||||
unset(EXCLUDE_MAP)
|
||||
foreach(line ${EXCLUDE_STATIC_LINES})
|
||||
if(line MATCHES "^([a-zA-Z0-9_./-]+):([a-zA-Z0-9_,]*)")
|
||||
set(fname "${CMAKE_MATCH_1}")
|
||||
set(exlist "${CMAKE_MATCH_2}")
|
||||
# Map both the basename and the full/relative path for flexibility
|
||||
get_filename_component(basename "${fname}" NAME)
|
||||
set(EXCLUDE_MAP_${fname} "${exlist}")
|
||||
set(EXCLUDE_MAP_${basename} "${exlist}")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# Now, for each file, get the exclude list and pass to the script
|
||||
# Create a custom command to backup the original files and remove static
|
||||
# Always run replace script on hipified files, but preserve original backups
|
||||
foreach(srcfile ${TEST_NONSTATIC_SOURCE_FILES})
|
||||
# Try to match using the full/relative path first, then fallback to basename
|
||||
set(exclude_list "")
|
||||
if(DEFINED EXCLUDE_MAP_${srcfile})
|
||||
set(exclude_list "${EXCLUDE_MAP_${srcfile}}")
|
||||
else()
|
||||
get_filename_component(basename "${srcfile}" NAME)
|
||||
if(DEFINED EXCLUDE_MAP_${basename})
|
||||
set(exclude_list "${EXCLUDE_MAP_${basename}}")
|
||||
endif()
|
||||
endif()
|
||||
add_custom_command(
|
||||
OUTPUT "${srcfile}.staticbak"
|
||||
COMMAND bash -c "\
|
||||
|
||||
@@ -65,6 +65,20 @@ if(BUILD_TESTS)
|
||||
list(APPEND RCCL_COMMON_LINK_LIBS "${OpenMP_CXX_FLAGS}")
|
||||
endif()
|
||||
|
||||
# Get the compile definitions from the main rccl target
|
||||
# These helps to keep the test compile definitions in sync with the main rccl target
|
||||
# Also, all the structure layout remains the same across all the targets
|
||||
get_target_property(RCCL_COMPILE_DEFINITIONS rccl COMPILE_DEFINITIONS)
|
||||
if(RCCL_COMPILE_DEFINITIONS)
|
||||
list(APPEND RCCL_COMMON_COMPILE_DEFS ${RCCL_COMPILE_DEFINITIONS})
|
||||
endif()
|
||||
|
||||
# Also get interface compile definitions
|
||||
get_target_property(RCCL_INTERFACE_COMPILE_DEFINITIONS rccl INTERFACE_COMPILE_DEFINITIONS)
|
||||
if(RCCL_INTERFACE_COMPILE_DEFINITIONS)
|
||||
list(APPEND RCCL_COMMON_COMPILE_DEFS ${RCCL_INTERFACE_COMPILE_DEFINITIONS})
|
||||
endif()
|
||||
|
||||
# Collect testing framework source files
|
||||
set(TEST_SOURCE_FILES
|
||||
AllGatherTests.cpp
|
||||
@@ -103,83 +117,45 @@ if(BUILD_TESTS)
|
||||
)
|
||||
endif()
|
||||
|
||||
# Add rccl-UnitTests binary
|
||||
add_executable(rccl-UnitTests ${TEST_SOURCE_FILES})
|
||||
|
||||
set(RCCL_TEST_EXECUTABLES rccl-UnitTests)
|
||||
|
||||
# Create rccl-UnitTests binary
|
||||
add_executable(rccl-UnitTests ${TEST_SOURCE_FILES})
|
||||
add_dependencies(rccl-UnitTests replace_static_in_hipify)
|
||||
|
||||
# Create rccl-UnitTestsFixtures binary if ROCm version is 4.6.0 or greater
|
||||
# and build type is Debug
|
||||
if (ROCM_VERSION VERSION_GREATER_EQUAL "60400" AND CMAKE_BUILD_TYPE MATCHES "Debug")
|
||||
# Add rccl-UnitTestsFixtures binary
|
||||
list(APPEND RCCL_TEST_EXECUTABLES rccl-UnitTestsFixtures)
|
||||
|
||||
set(TEST_FIXTURE_SOURCE_FILES
|
||||
AltRsmiTests.cpp
|
||||
ArgCheckTests.cpp
|
||||
ShmTests.cpp
|
||||
P2pTests.cpp
|
||||
common/main_fixtures.cpp
|
||||
common/EnvVars.cpp
|
||||
)
|
||||
|
||||
# Add rccl-UnitTestsFixtures binary
|
||||
add_executable(rccl-UnitTestsFixtures ${TEST_FIXTURE_SOURCE_FILES})
|
||||
|
||||
list(APPEND RCCL_TEST_EXECUTABLES rccl-UnitTestsFixtures)
|
||||
|
||||
add_dependencies(rccl-UnitTestsFixtures replace_static_in_hipify)
|
||||
endif()
|
||||
|
||||
## Set include directories for the target(s)
|
||||
foreach(target ${RCCL_TEST_EXECUTABLES})
|
||||
target_include_directories(${target} PRIVATE ${ROCM_PATH} ${GTEST_INCLUDE_DIRS})
|
||||
target_include_directories(${target} PRIVATE ${PROJECT_BINARY_DIR}/include) # for generated rccl.h header
|
||||
target_include_directories(${target} PRIVATE ${PROJECT_BINARY_DIR}/hipify/src/include) # for rccl_bfloat16.h
|
||||
target_include_directories(${target} PRIVATE ${PROJECT_BINARY_DIR}/hipify/src/include/plugin) # for recorder tests
|
||||
|
||||
# Get the compile definitions from the main rccl target
|
||||
# These helps to keep the test compile definitions in sync with the main rccl target
|
||||
# Also, all the structure layout remains the same across all the targets
|
||||
get_target_property(RCCL_COMPILE_DEFINITIONS rccl COMPILE_DEFINITIONS)
|
||||
if(RCCL_COMPILE_DEFINITIONS)
|
||||
target_compile_definitions(${target} PRIVATE ${RCCL_COMPILE_DEFINITIONS})
|
||||
endif()
|
||||
|
||||
# Also get interface compile definitions
|
||||
get_target_property(RCCL_INTERFACE_COMPILE_DEFINITIONS rccl INTERFACE_COMPILE_DEFINITIONS)
|
||||
if(RCCL_INTERFACE_COMPILE_DEFINITIONS)
|
||||
target_compile_definitions(${target} PRIVATE ${RCCL_INTERFACE_COMPILE_DEFINITIONS})
|
||||
endif()
|
||||
|
||||
## Set compile definitions
|
||||
if(LL128_ENABLED)
|
||||
target_compile_definitions(${target} PRIVATE ENABLE_LL128)
|
||||
endif()
|
||||
if(OPENMP_TESTS_ENABLED)
|
||||
target_compile_definitions(${target} PRIVATE ENABLE_OPENMP)
|
||||
endif()
|
||||
target_compile_definitions(${target} PRIVATE ROCM_PATH="${ROCM_PATH}")
|
||||
|
||||
## Set rccl unittests linked libraries
|
||||
target_link_libraries(${target} PRIVATE ${GTEST_BOTH_LIBRARIES})
|
||||
target_link_libraries(${target} PRIVATE hip::host hip::device hsa-runtime64::hsa-runtime64)
|
||||
target_link_libraries(${target} PRIVATE Threads::Threads)
|
||||
target_link_libraries(${target} PRIVATE dl)
|
||||
target_link_libraries(${target} PRIVATE fmt::fmt-header-only)
|
||||
if(OPENMP_TESTS_ENABLED)
|
||||
target_link_libraries(${target} PRIVATE "${OpenMP_CXX_FLAGS}")
|
||||
endif()
|
||||
|
||||
# Link rccl library
|
||||
foreach(test_executable IN LISTS RCCL_TEST_EXECUTABLES)
|
||||
target_include_directories(${test_executable} PRIVATE ${RCCL_COMMON_INCLUDE_DIRS})
|
||||
target_compile_definitions(${test_executable} PRIVATE ${RCCL_COMMON_COMPILE_DEFS})
|
||||
target_link_libraries(${test_executable} PRIVATE ${RCCL_COMMON_LINK_LIBS})
|
||||
if(BUILD_SHARED_LIBS)
|
||||
target_link_libraries(${target} PRIVATE rccl)
|
||||
set_property(TARGET ${target} PROPERTY INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib;${ROCM_PATH}/lib;${CMAKE_BINARY_DIR}")
|
||||
target_link_libraries(${test_executable} PRIVATE rccl)
|
||||
set_property(TARGET ${test_executable} PROPERTY INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib;${ROCM_PATH}/lib;${CMAKE_BINARY_DIR}")
|
||||
else()
|
||||
add_dependencies(${target} rccl)
|
||||
target_link_libraries(${target} PRIVATE dl rt numa -lrccl -L${CMAKE_BINARY_DIR} -lrocm_smi64 -L${ROCM_PATH}/lib -L${ROCM_PATH}/rocm_smi/lib)
|
||||
add_dependencies(${test_executable} rccl)
|
||||
target_link_libraries(${test_executable} PRIVATE dl rt numa -lrccl -L${CMAKE_BINARY_DIR} -lrocm_smi64 -L${ROCM_PATH}/lib -L${ROCM_PATH}/rocm_smi/lib)
|
||||
endif()
|
||||
set_property(TARGET ${target} PROPERTY BUILD_RPATH "${CMAKE_BINARY_DIR};${ROCM_PATH}/lib")
|
||||
|
||||
# Install the binary
|
||||
rocm_install(TARGETS ${target} COMPONENT tests)
|
||||
set_property(TARGET ${test_executable} PROPERTY BUILD_RPATH "${CMAKE_BINARY_DIR};${ROCM_PATH}/lib")
|
||||
rocm_install(TARGETS ${test_executable} COMPONENT tests)
|
||||
endforeach()
|
||||
|
||||
endif()
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1 @@
|
||||
src/transport/p2p.cc:initCeOperation,legacyIPC
|
||||
@@ -20,26 +20,29 @@
|
||||
# THE SOFTWARE.
|
||||
|
||||
# Usage:
|
||||
# ./replace_static_functions.sh <source_file> [--replace-vars] [--verbose]
|
||||
# ./replace_static.sh <source_file> [--replace-vars] [--verbose] [--exclude-list=func1,func2,var1]
|
||||
#
|
||||
# - Replaces all 'static' function definitions with non-static.
|
||||
# - Replaces all 'static inline' with 'inline'.
|
||||
# - If --replace-vars is given, also replaces 'static' at variable definitions.
|
||||
# - If --exclude-list is given, skips listed functions/variables.
|
||||
# - If --verbose is given, shows a diff of the changes.
|
||||
|
||||
set -e
|
||||
|
||||
SOURCE_FILE="$1"
|
||||
shift
|
||||
|
||||
REPLACE_VARS=0
|
||||
VERBOSE=0
|
||||
EXCLUDE_LIST=""
|
||||
|
||||
for arg in "$@"; do
|
||||
if [[ "$arg" == "--replace-vars" ]]; then
|
||||
REPLACE_VARS=1
|
||||
fi
|
||||
if [[ "$arg" == "--verbose" ]]; then
|
||||
VERBOSE=1
|
||||
fi
|
||||
case "$arg" in
|
||||
--replace-vars) REPLACE_VARS=1 ;;
|
||||
--verbose) VERBOSE=1 ;;
|
||||
--exclude-list=*) EXCLUDE_LIST="${arg#*=}" ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ ! -f "$SOURCE_FILE" ]]; then
|
||||
@@ -48,41 +51,70 @@ if [[ ! -f "$SOURCE_FILE" ]]; then
|
||||
fi
|
||||
|
||||
TMP_FILE="${SOURCE_FILE}.tmp.$$"
|
||||
cp "$SOURCE_FILE" "$TMP_FILE"
|
||||
|
||||
# Regex explanation:
|
||||
# \b : Word boundary, ensures 'static' and 'inline' are matched as whole words.
|
||||
# static : Matches the literal word 'static'.
|
||||
# [[:space:]]+ : Matches one or more whitespace characters (spaces, tabs, etc.) between 'static' and 'inline'.
|
||||
# inline : Matches the literal word 'inline'.
|
||||
# \b : Word boundary after 'inline'.
|
||||
echo "[INFO] Replacing 'static inline' with 'inline' in $SOURCE_FILE"
|
||||
sed -E 's/\bstatic[[:space:]]+inline\b/inline/g' "$SOURCE_FILE" > "$TMP_FILE"
|
||||
|
||||
# Regex explanation:
|
||||
# ^ : Start of the line.
|
||||
# ([[:space:]]*) : Captures any leading whitespace at the start of the line (indentation).
|
||||
# (inline[[:space:]]+|__device__[[:space:]]+|__forceinline__[[:space:]]+|__host__[[:space:]]+|__global__[[:space:]]+|)* :
|
||||
# Matches zero or more occurrences of common C/C++/CUDA qualifiers (each followed by whitespace).
|
||||
# ([[:space:]]*(...|)*) : The outer group allows for any combination/order of these qualifiers.
|
||||
# static[[:space:]]+ : Matches the literal word 'static' followed by one or more spaces/tabs.
|
||||
# \1 : In the replacement, refers to the leading whitespace and any qualifiers (without 'static').
|
||||
#
|
||||
# Removes 'static' after any qualifiers before the function name
|
||||
echo "[INFO] Replacing 'static' in function qualifiers in $SOURCE_FILE"
|
||||
sed -E -i 's/^([[:space:]]*(inline[[:space:]]+|__device__[[:space:]]+|__forceinline__[[:space:]]+|__host__[[:space:]]+|__global__[[:space:]]+|)*)static[[:space:]]+/\1/g' "$TMP_FILE"
|
||||
|
||||
|
||||
# Regex explanation:
|
||||
# ^ : Start of the line.
|
||||
# ([[:space:]]*) : Captures any leading whitespace at the start of the line.
|
||||
# static : Matches the literal word 'static'.
|
||||
# ([[:space:]]+) : Captures one or more spaces after 'static'.
|
||||
if [[ "$REPLACE_VARS" == "1" ]]; then
|
||||
echo "[INFO] Replacing 'static' at variable definitions in $SOURCE_FILE"
|
||||
# This matches 'static' at the start of a line (possibly with spaces), followed by a type and a variable name
|
||||
sed -E -i 's/^([[:space:]]*)static([[:space:]]+)/\1/g' "$TMP_FILE"
|
||||
# Prepare exclude regex if needed
|
||||
if [[ -n "$EXCLUDE_LIST" ]]; then
|
||||
# Convert comma-separated list to alternation regex
|
||||
EXCLUDE_REGEX="($(echo "$EXCLUDE_LIST" | sed 's/,/|/g'))"
|
||||
fi
|
||||
|
||||
# Mark lines with excluded function or variable names
|
||||
if [[ -n "$EXCLUDE_LIST" ]]; then
|
||||
IFS=',' read -ra EXCLUDES <<< "$EXCLUDE_LIST"
|
||||
for name in "${EXCLUDES[@]}"; do
|
||||
# Mark function definitions/declarations to skip (robust to qualifiers/types)
|
||||
sed -E -i "/static[[:space:]]+([a-zA-Z_][a-zA-Z0-9_:[:space:]\*\&]*)[[:space:]]+${name}[[:space:]]*(\(|;)/s/^/__STATIC_SKIP__/" "$TMP_FILE"
|
||||
# Mark variable definitions/declarations to skip (no '(' on the line)
|
||||
sed -E -i '/\(/!s/static[[:space:]]+.*\b'"${name}"'\b[[:space:]]*(=|;)/__STATIC_SKIP__&/' "$TMP_FILE"
|
||||
done
|
||||
fi
|
||||
|
||||
# s/\bstatic[[:space:]]+inline\b/inline/g
|
||||
# - Matches 'static' followed by one or more spaces and then 'inline' as a whole word.
|
||||
# - Replaces it with just 'inline'.
|
||||
# - Example: 'static inline int foo()' -> 'inline int foo()'
|
||||
# s/^([[:space:]]*(inline[[:space:]]+|__device__[[:space:]]+|__forceinline__[[:space:]]+|__host__[[:space:]]+|__global__[[:space:]]+|)*)static[[:space:]]+/\1/g
|
||||
# - Matches lines that start with optional whitespace, then any qualifiers (inline, __device__, etc.), then 'static' and spaces.
|
||||
# - Removes 'static' but preserves the qualifiers and indentation.
|
||||
# - Example: ' inline static int foo()' -> ' inline int foo()'
|
||||
sed -E -i '/^__STATIC_SKIP__/!{
|
||||
s/\bstatic[[:space:]]+inline\b/inline/g
|
||||
s/^([[:space:]]*(inline[[:space:]]+|__device__[[:space:]]+|__forceinline__[[:space:]]+|__host__[[:space:]]+|__global__[[:space:]]+|)*)static[[:space:]]+/\1/g
|
||||
}' "$TMP_FILE"
|
||||
|
||||
# # Always remove 'static' from function definitions/declarations, except excluded
|
||||
# sed -E -i '/^__STATIC_SKIP__/!s/^([[:space:]]*(inline[[:space:]]+|__device__[[:space:]]+|__forceinline__[[:space:]]+|__host__[[:space:]]+|__global__[[:space:]]+|)*)static[[:space:]]+/\1/g' "$TMP_FILE"
|
||||
|
||||
# # Replace 'static inline' with 'inline' everywhere except marked lines
|
||||
# sed -E -i '/^__STATIC_SKIP__/!s/\bstatic[[:space:]]+inline\b/inline/g' "$TMP_FILE"
|
||||
|
||||
# Remove 'static' at variable definitions, excluding variables in EXCLUDE_LIST
|
||||
if [[ "$REPLACE_VARS" == "1" ]]; then
|
||||
if [[ -n "$EXCLUDE_LIST" ]]; then
|
||||
# Regex explanation:
|
||||
# '/^__STATIC_SKIP__/{b}; /\(/b; s/^([[:space:]]*)static([[:space:]]+)/\1/g'
|
||||
# - /^__STATIC_SKIP__/{b}; If the line starts with __STATIC_SKIP__, branch (skip substitution).
|
||||
# - /\(/b; If the line contains '(', branch (skip substitution; likely a function).
|
||||
# - s/^([[:space:]]*)static([[:space:]]+)/\1/g
|
||||
# - Matches 'static' at the start of a line (possibly after indentation).
|
||||
# - Removes 'static', preserving indentation.
|
||||
# - Only applies to lines not skipped above (i.e., not excluded and not functions).
|
||||
sed -E -i '/^__STATIC_SKIP__/{b}; /\(/b; s/^([[:space:]]*)static([[:space:]]+)/\1/g' "$TMP_FILE"
|
||||
else
|
||||
# Regex explanation:
|
||||
# '/\(/!s/^([[:space:]]*)static([[:space:]]+)/\1/g'
|
||||
# - /\(/! Only apply to lines that do NOT contain '(' (i.e., not functions).
|
||||
# - s/^([[:space:]]*)static([[:space:]]+)/\1/g
|
||||
# - Matches 'static' at the start of a line (possibly after indentation).
|
||||
# - Removes 'static', preserving indentation.
|
||||
sed -E -i '/\(/!s/^([[:space:]]*)static([[:space:]]+)/\1/g' "$TMP_FILE"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Remove the marker after all substitutions, preserving original line formatting
|
||||
sed -E -i 's/([[:space:]]*)__STATIC_SKIP__/\1/' "$TMP_FILE"
|
||||
|
||||
if [[ "$VERBOSE" == "1" ]]; then
|
||||
echo "[INFO] Showing diff for changes:"
|
||||
diff -u "$SOURCE_FILE" "$TMP_FILE" || true
|
||||
|
||||
Reference in New Issue
Block a user