From ca4ba933a3e823136102c06651cea5822b9add02 Mon Sep 17 00:00:00 2001 From: mberenjk <146776561+mberenjk@users.noreply.github.com> Date: Thu, 28 Mar 2024 14:03:59 -0500 Subject: [PATCH] adding git version to rccl-tests (#69) Co-authored-by: mberenjk [ROCm/rccl-tests commit: 3f7f7859bfd863415f1671b723d9969f1207af9e] --- projects/rccl-tests/src/CMakeLists.txt | 15 ++++- projects/rccl-tests/src/Makefile | 14 ++++- .../rccl-tests/src/cmake/git_version.cmake | 62 +++++++++++++++++++ projects/rccl-tests/src/common.cu | 3 +- projects/rccl-tests/src/git_version.h | 6 ++ projects/rccl-tests/verifiable/Makefile | 2 +- 6 files changed, 97 insertions(+), 5 deletions(-) create mode 100644 projects/rccl-tests/src/cmake/git_version.cmake create mode 100644 projects/rccl-tests/src/git_version.h diff --git a/projects/rccl-tests/src/CMakeLists.txt b/projects/rccl-tests/src/CMakeLists.txt index 2ae943b13e..f0aae7cc10 100644 --- a/projects/rccl-tests/src/CMakeLists.txt +++ b/projects/rccl-tests/src/CMakeLists.txt @@ -68,6 +68,7 @@ endfunction() # Collect list of common source files #================================================================================================== set(COMMON_FILES + git_version.h common.h common.cu nccl1_compat.h @@ -109,11 +110,23 @@ foreach(COMMON_FILE ${COMMON_FILES}) ) endforeach() +# Create an initial git_version.cpp file (that will be updated with latest git version) +#================================================================================================== +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/git_version.cpp "") +list(APPEND HIP_COMMON_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/git_version.cpp) + +#Create a custom target that updates git_version.cpp and executes whenever rccl is built +add_custom_target(git_version_check + COMMENT "Updating git_version.cpp if necessary" + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/git_version.cmake + VERBATIM +) + # Compile common object library #================================================================================================== add_custom_target(hipify DEPENDS ${HIP_COMMON_SOURCES}) add_library(rccl_common OBJECT ${HIP_COMMON_SOURCES}) -add_dependencies(rccl_common hipify) +add_dependencies(rccl_common hipify git_version_check) target_link_libraries(rccl_common roc::rccl hip::device) if(USE_MPI) target_link_libraries(rccl_common MPI::MPI_CXX) diff --git a/projects/rccl-tests/src/Makefile b/projects/rccl-tests/src/Makefile index 00a17b56a8..6810e1ac2b 100644 --- a/projects/rccl-tests/src/Makefile +++ b/projects/rccl-tests/src/Makefile @@ -62,6 +62,11 @@ OBJ_FILES := $(SRC_FILES:%.cu=${DST_DIR}/%.o) BIN_FILES_LIST := all_reduce all_gather broadcast reduce_scatter reduce alltoall scatter gather sendrecv alltoallv BIN_FILES := $(BIN_FILES_LIST:%=${DST_DIR}/%_perf) +GIT_VERSION_FILE := ${DST_DIR}/src/git_version.cpp +GIT_REV := $(shell git log --pretty=format:'%h' -n 1) +GIT_DIFF := $(shell git diff --quiet --exit-code || echo +) +GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD) + build: ${BIN_FILES} clean: @@ -71,6 +76,11 @@ TEST_VERIFIABLE_SRCDIR := ../verifiable TEST_VERIFIABLE_BUILDDIR := $(BUILDDIR)/verifiable include ../verifiable/verifiable.mk +# Rule to create git_version.cpp +$(GIT_VERSION_FILE): + @mkdir -p ${DST_DIR}/src + @echo 'const char* rcclTestsGitHash = "$(GIT_BRANCH):$(GIT_REV)$(GIT_DIFF)";' > $@ + ${HIPIFY_DIR}/%.cu.cpp: %.cu @printf "Hipifying %-35s > %s\n" $< $@ @mkdir -p ${HIPIFY_DIR} @@ -81,7 +91,7 @@ ${HIPIFY_DIR}/%.h: %.h @mkdir -p ${HIPIFY_DIR} hipify-perl -quiet-warnings $< > $@ -${DST_DIR}/%.o: ${HIPIFY_DIR}/%.cu.cpp ${HIPIFY_DIR}/common.h $(TEST_VERIFIABLE_HDRS) +${DST_DIR}/%.o: ${HIPIFY_DIR}/%.cu.cpp ${HIPIFY_DIR}/common.h $(TEST_VERIFIABLE_HDRS) $(GIT_VERSION_FILE) @printf "Compiling %-35s > %s\n" $< $@ @mkdir -p ${DST_DIR} echo "$(HIPCC) -o $@ $(HIPCUFLAGS) -I. -c $<" @@ -92,7 +102,7 @@ ${DST_DIR}/timer.o: timer.cc timer.h @mkdir -p ${DST_DIR} $(CXX) $(CXXFLAGS) -o $@ -c timer.cc -${DST_DIR}/%_perf:${DST_DIR}/%.o ${DST_DIR}/common.o ${DST_DIR}/timer.o $(TEST_VERIFIABLE_OBJS) +${DST_DIR}/%_perf:${DST_DIR}/%.o ${DST_DIR}/common.o ${DST_DIR}/timer.o $(TEST_VERIFIABLE_OBJS) $(DST_DIR)/src/git_version.cpp @printf "Linking %-35s > %s\n" $< $@ @mkdir -p ${DST_DIR} echo "$(HIPCC) -o $@ $(HIPCUFLAGS) $^ ${HIPLDFLAGS}" diff --git a/projects/rccl-tests/src/cmake/git_version.cmake b/projects/rccl-tests/src/cmake/git_version.cmake new file mode 100644 index 0000000000..c320f0ca60 --- /dev/null +++ b/projects/rccl-tests/src/cmake/git_version.cmake @@ -0,0 +1,62 @@ +# 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. + +# Attempt to collect the latest git hash +execute_process(COMMAND git log --pretty=format:'%h' -n 1 + OUTPUT_VARIABLE GIT_REV + ERROR_QUIET) + +# Check if git information was found +if ("${GIT_REV}" STREQUAL "") + set(CURR_GIT_VERSION "const char *rcclTestsGitHash =\"Unknown \";") +else() + # Check for changes (denote with a '+') after hash + execute_process( + COMMAND bash -c "git diff --quiet --exit-code || echo +" + OUTPUT_VARIABLE GIT_DIFF) + # Collect branch information + execute_process( + COMMAND git rev-parse --abbrev-ref HEAD + OUTPUT_VARIABLE GIT_BRANCH) + + string(STRIP "${GIT_REV}" GIT_REV) + string(SUBSTRING "${GIT_REV}" 1 7 GIT_REV) + string(STRIP "${GIT_DIFF}" GIT_DIFF) + string(STRIP "${GIT_BRANCH}" GIT_BRANCH) + + set(CURR_GIT_VERSION "const char *rcclTestsGitHash =\"${GIT_BRANCH}:${GIT_REV}${GIT_DIFF}\";") +endif() + +# Compare file with older git version file (git_version.cpp) +if (EXISTS ${CMAKE_CURRENT_BINARY_DIR}/git_version.cpp) + #MESSAGE(STATUS "Found ${CMAKE_CURRENT_BINARY_DIR}/git_version.cpp") + file(READ ${CMAKE_CURRENT_BINARY_DIR}/git_version.cpp PREV_GIT_VERSION) + #message(STATUS "CURR GIT version: ${CURR_GIT_VERSION}") + #message(STATUS "PREV GIT version: ${PREV_GIT_VERSION}") + if (NOT "${CURR_GIT_VERSION}" STREQUAL "${PREV_GIT_VERSION}") + message(STATUS "Updating git_version.cpp") + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/git_version.cpp "${CURR_GIT_VERSION}") + else() + message(STATUS "No changes to git_version.cpp required") + endif() +else() + # Create git_version.cpp if it doesn't exist yet + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/git_version.cpp "${CURR_GIT_VERSION}") +endif() diff --git a/projects/rccl-tests/src/common.cu b/projects/rccl-tests/src/common.cu index dd9add2383..b034ca768c 100644 --- a/projects/rccl-tests/src/common.cu +++ b/projects/rccl-tests/src/common.cu @@ -21,6 +21,7 @@ //#define DEBUG_PRINT #include "verifiable.h" +#include "git_version.h" int test_ncclVersion = 0; // init'd with ncclGetVersion() @@ -1026,7 +1027,7 @@ testResult_t run() { if (blocking_coll) PRINT("# Blocking Enabled: wait for completion and barrier after each collective \n"); if (parallel_init) PRINT("# Parallel Init Enabled: threads call into NcclInitRank concurrently \n"); PRINT("#\n"); - + PRINT("rccl-tests: Version %s\n", rcclTestsGitHash); PRINT("# Using devices\n"); #define MAX_LINE 2048 char line[MAX_LINE]; diff --git a/projects/rccl-tests/src/git_version.h b/projects/rccl-tests/src/git_version.h new file mode 100644 index 0000000000..dda3d44c18 --- /dev/null +++ b/projects/rccl-tests/src/git_version.h @@ -0,0 +1,6 @@ +#ifndef RCCL_TESTS_GIT_VERSION_H_ +#define RCCL_TESTS_GIT_VERSION_H_ + +extern const char *rcclTestsGitHash; + +#endif diff --git a/projects/rccl-tests/verifiable/Makefile b/projects/rccl-tests/verifiable/Makefile index 182d44e727..4b71c03e2a 100644 --- a/projects/rccl-tests/verifiable/Makefile +++ b/projects/rccl-tests/verifiable/Makefile @@ -56,7 +56,7 @@ endif LIBRARIES += rccl HIPLDFLAGS += $(LIBRARIES:%=-l%) -all: $(DST_DIR)/verifiable.o $(DST_DIR)/self_test +all: $(DST_DIR)/verifiable.o $(DST_DIR)/self_test clean: rm -rf $(DST_DIR)