[SWDEV-505176] Submodule Unified Header in AMDSMI

Signed-off-by: Maisam Arif <Maisam.Arif@amd.com>

[ROCm/amdsmi commit: a315b62e37]
This commit is contained in:
Narlo, Joseph
2025-07-30 13:37:01 -05:00
zatwierdzone przez GitHub
rodzic cab2270feb
commit 0e895cf235
6 zmienionych plików z 278 dodań i 6 usunięć
+4
Wyświetl plik
@@ -0,0 +1,4 @@
[submodule "include/unified_amdsmi"]
path = include/unified_amdsmi
url = git@github.com:AMD-ROCm-Internal/amdsmi_unified.git
branch = amd-mainline
+27 -6
Wyświetl plik
@@ -216,6 +216,27 @@ set(CMN_INC_LIST
add_subdirectory("rocm_smi")
add_subdirectory("src")
# By default, try to build amdsmi.h header file from the Unified Header repository.
# Allow the User to bypass building amdsmi.h by setting BUILD_HEADER=OFF on the
# command line. Cannot build amdsmi.h if the Unified Header submodule # has not
# been initiated.
set(UH_DIR "${PROJECT_SOURCE_DIR}/include/unified_amdsmi/scripts")
if(NOT DEFINED BUILD_HEADER)
if(EXISTS "${UH_DIR}")
set(BUILD_HEADER "ON")
endif()
elseif(${BUILD_HEADER} STREQUAL "OFF")
unset(BUILD_HEADER CACHE)
elseif(NOT EXISTS "${UH_DIR}")
message("Unified Header will not be generated")
message("Must initiate Unified Header submodule")
unset(BUILD_HEADER CACHE)
endif()
if(BUILD_HEADER)
add_subdirectory("include")
endif()
if(BUILD_TESTS)
set(TESTS_COMPONENT "tests")
#add_subdirectory("tests/rocm_smi_test")
@@ -270,12 +291,12 @@ install(
set(CPACK_RPM_PACKAGE_LICENSE "MIT")
if(ENABLE_ASAN_PACKAGING)
# install license file in share/doc/amd_smi-asan folder
install(
FILES ${CPACK_RESOURCE_FILE_LICENSE}
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/doc/${CPACK_PACKAGE_NAME}-asan
RENAME LICENSE.txt
COMPONENT asan)
# install license file in share/doc/amd_smi-asan folder
install(
FILES ${CPACK_RESOURCE_FILE_LICENSE}
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/doc/${CPACK_PACKAGE_NAME}-asan
RENAME LICENSE.txt
COMPONENT asan)
endif()
# docs are installed into different share directory from tests and examples
install(
+82
Wyświetl plik
@@ -252,6 +252,88 @@ be found at `build/tests/amd_smi_test/`.
To build the documentation, follow the instructions at
[Building documentation](https://rocm.docs.amd.com/en/latest/contribute/building.html).
## Development only
This section describes the prerequisites and steps to build Unified Header from source.
### The Unified Header submodule in the Linux BM repository
The steps needed to setup and initialize the Unified Header submodule is as follows:
1. The script has the command line option, --help, which displays all command line options and defaults.
Ex. tools/config_unified_header_submodule.sh --help
``` shell
Usage: tools/config_unified_header_submodule.sh --option --opt <value>
option
--help : Prints usage and exit
--remove : Removes existing Unified Header submodule
opt <value>
--dir <value> : Directory that contains the Unified Header dir
Default is "include"
--name <value> : Directory Name of the Unified Header
Default is "unified_amdsmi"
Note:
Must run script from repository root directory
```
2. Initialize submodule
Ex. Use command line options to specify Unified Header directory
``` shell
tools/config_unified_header_submodule.sh --dir include --name unified_amdsmi
```
Ex. The arguments in the above example are the defaults, so running the script with no arguments will produce the same results
``` shell
tools/config_unified_header_submodule.sh
```
3. Un-initialize submodule when no longer needed
``` shell
tools/config_unified_header_submodule.sh --remove
```
>[!NOTE]
>Complete this section only if the User needs to create the Unified Header amdsmi.h file and use
>this header when building. Otherwise, the build will use the existing amdsmi.h file which is
>already included in the repository.
### Build and install the Unified Header amdsmi.h
If the User has initialized the Unified Header submodule, the Unified Header amdsmi.h will automatically be generated
and used when the Linux driver is being built. The User can also explicitly use the Unified Header by setting the
command line option when building via cmake.
Building with the unified header using CMAKE flag:
Ex. Building without a cmake command line option builds and uses the Unified Header amdsmi.h
```bash
mkdir -p build
cd build
cmake ..
make -j $(nproc)
```
OR Building with a cmake command line option. Change BUILD_HEADER Option to either On or OFF:
-DBUILD_HEADER=On builds and uses the Unified Header amdsmi.h
-DBUILD_HEADER=OFF uses the existing include/amd_smi/amdsmi.h
```bash
mkdir -p build
cd build
cmake -DBUILD_HEADER=[ON|OFF] ..
make -j $(nproc)
```
Once the build successfully completes:
1. Commit any changes in the Unified Header submodule
2. Commit any changes in the amd-smi repo as needed for fixes or new feature submissions
>[!NOTE]
>Prerequisite: Install the Unified Header submodule in the Linux BM repository
## DISCLAIMER
The information contained herein is for informational purposes only, and is subject to change without notice. In
@@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.20)
# Generate Unified Header amdsmi.h
if(BUILD_HEADER)
set(UNIFIED_DIR "unified_amdsmi")
set(UNIFIED_H "${UNIFIED_DIR}/amdsmi.h")
set(AMDSMI_H "amd_smi/amdsmi.h")
execute_process(
COMMAND ./create_header.py linguest_gpu_cpu
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${UNIFIED_DIR}/scripts
OUTPUT_VARIABLE pyout
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(
COMMAND mv -f ${UNIFIED_H} ${AMDSMI_H}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE lsout
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
Submodule projects/amdsmi/include/unified_amdsmi added at e095c13f44
@@ -0,0 +1,146 @@
#!/usr/bin/env bash
# Script creates and/or configures the Unified Header submodule
# to work with the Unified Header repository.
#
# User must have access to the Unified Header repository,
# ssh credentials, which resides in the repository.
#
# Should only be run once
# Exit script immediately on any error
set -eu
# Prerequisite: Cloning github amdsmi repository:
# git clone git@github.com:AMD-ROCm-Internal/amdsmi.git
# Defaults:
UH_DIR="include"
UH_NAME="unified_amdsmi"
show_help="False"
remove_module="False"
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
show_help="True"
shift
;;
-r|--remove)
remove_module="True"
shift
;;
-d|--dir)
UH_DIR=$2
shift
shift
;;
-n|--name)
UH_NAME=$2
shift
shift
;;
*|-*|--*)
echo "Unknown option $1"
show_help="True"
shift
;;
esac
done
if [ "${show_help}" == "True" ]
then
echo ""
echo "Usage: $0 --option --opt <value>"
echo " option"
echo " --help : Prints usage and exit"
echo " --remove : Removes existing Unified Header submodule"
echo ""
echo " opt <value>"
echo " --dir <value> : Directory that contains the Unified Header dir"
echo " Default is \"${UH_DIR}\""
echo " --name <value> : Directory Name of the Unified Header"
echo " Default is \"${UH_NAME}\""
echo " Note:"
echo " Must run script from repository root directory"
echo ""
exit 0
fi
if [ "${remove_module}" == "True" ]
then
git submodule deinit -f "${UH_DIR}/${UH_NAME}/"
exit 0
fi
# Find repository root dir
REPO_ROOT_DIR=$PWD
while [[ ! -d "${REPO_ROOT_DIR}/.git" ]]
do
REPO_ROOT_DIR=$(dirname ${REPO_ROOT_DIR})
if [[ "${REPO_ROOT_DIR}" == "/" ]]
then
echo "Repository root dir not found"
exit 0
fi
done
# Determine whether to create or configure the submodule
action="Config"
if [ ! -d "${REPO_ROOT_DIR}/${UH_DIR}/${UH_NAME}" ]
then
action="Create"
else
if [ -f "${REPO_ROOT_DIR}/${UH_DIR}/${UH_NAME}/.git" ]
then
echo "Unified Header submodule is already configured"
exit 1
fi
if [ ! -f ".git/modules/${UH_DIR}/${UH_NAME}/config" ]
then
rmdir"${UH_DIR}/${UH_NAME}"
action="Create"
fi
fi
echo "$action Unified Header submodule"
# Directory where the Unified Header is created
if [ "$action" == "Create" ]
then
if [ ! -d "${REPO_ROOT_DIR}/${UH_DIR}" ]
then
mkdir -p ${REPO_ROOT_DIR}/${UH_DIR}
fi
cd ${REPO_ROOT_DIR}/${UH_DIR}
git submodule add -f -b amd-mainline git@github.com:AMD-ROCm-Internal/amdsmi_unified.git ${UH_NAME}
fi
# Changes "username" in 3 git files to your Unified Header username
# amdsmi/.gitmodules
# amdsmi/.git/config
# amdsmi/.git/modules/${UH_DIR}/${UH_NAME}/config
cd ${REPO_ROOT_DIR}
if [ "$action" == "Config" ]
then
# Initializes the submodule
git submodule init
git submodule update
fi
cd ${REPO_ROOT_DIR}/${UH_DIR}/${UH_NAME}
SUBMODULE_BRANCH=$(git config -f ${REPO_ROOT_DIR}/.gitmodules submodule.${UH_DIR}/${UH_NAME}.branch || echo "amd-mainline")
git checkout ${SUBMODULE_BRANCH}
cd ${REPO_ROOT_DIR}
if [ "$action" == "Create" ]
then
echo "Unified Header submodule has been created"
echo "Commit and push changes to github repository"
echo " git commit -s -m \"[ticket-id] Awesome Unified Header submodule addition\""
echo " git push"
else
echo "Unified Header submodule has been configured"
fi
exit 0