Skip to content

Commit

Permalink
Merge amd-staging into amd-master 20231205
Browse files Browse the repository at this point in the history
Change-Id: Ib8b0672f8993cfd995d567f582dd9b33d03ddac4
Signed-off-by: Galantsev, Dmitrii <dmitrii.galantsev@amd.com>
  • Loading branch information
dmitrii-galantsev committed Dec 5, 2023
1 parent ad5d1b6 commit db2d128
Show file tree
Hide file tree
Showing 15 changed files with 567 additions and 254 deletions.
4 changes: 4 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
Language: Cpp
BasedOnStyle: Google
ColumnLimit: 100
25 changes: 25 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# THIS FILE IS GENERATED FROM .clangd!
# Run .update-clang-tidy.sh to regenerate.
Checks:
bugprone*,
clang-analyzer*,
google*,
misc*,
modernize*,
-abseil*,
-bugprone-easily-swappable-parameters,
-bugprone-reserved-identifier,
-clang-analyzer-security.insecureAPI.strcpy,
-cppcoreguidelines*,
-cppcoreguidelines-pro*,
-misc-non-copyable-objects,
-misc-use-anonymous-namespace,
-modernize-avoid-c-arrays,
-modernize-redundant-void-arg,
-modernize-use-auto,
-modernize-use-nodiscard,
-modernize-use-noexcept,
-modernize-use-trailing-return-type,
-modernize-use-using,
-performance*,
-readability*,
37 changes: 37 additions & 0 deletions .clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
CompileFlags:
Remove: -W*
Add: [-Wall, -pedantic, -I/opt/rocm/include, -I/opt/rocm/include/hsa, -I/opt/rocm/include/rocprofiler]
Compiler: clang++

# list here: https://clang.llvm.org/extra/clang-tidy/checks/list.html
Diagnostics:
UnusedIncludes: Strict
# rules below are copied into .clang-tidy using ./.update-clang-tidy.sh
# please keep the rules sorted alphabetically
ClangTidy:
Add: [
bugprone*,
clang-analyzer*,
google*,
misc*,
modernize*,
]
Remove: [
abseil*,
bugprone-easily-swappable-parameters,
bugprone-reserved-identifier,
clang-analyzer-security.insecureAPI.strcpy,
cppcoreguidelines*,
cppcoreguidelines-pro*,
misc-non-copyable-objects,
misc-use-anonymous-namespace,
modernize-avoid-c-arrays,
modernize-redundant-void-arg,
modernize-use-auto,
modernize-use-nodiscard,
modernize-use-noexcept,
modernize-use-trailing-return-type,
modernize-use-using,
performance*,
readability*,
]
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ root = true
charset = utf-8
indent_style = space
indent_size = 2
max_line_length = 100
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ device/
__pycache__
README
README.html

# do NOT ignore these files
!.clang-format
!.clang-tidy
!.clangd
30 changes: 30 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# - How to use:
# python3 -m pip install pre-commit
# pre-commit install --install hooks
# Upon a new commit - the hooks should automagically run
#
# - How to skip:
# git commit --no-verify
# or
# SKIP=clang-format-docker git commit
# SKIP=cpplint-docker git commit

fail_fast: false
repos:
# For portability I decided to use Docker containers
- repo: https://github.com/dmitrii-galantsev/pre-commit-docker-cpplint
rev: 0.0.3
hooks:
- id: clang-format-docker
- id: cpplint-docker
# Below is a local way of running formatters and linters
# NOTE: clang-tidy is not used in the above tests
# - repo: https://github.com/pocc/pre-commit-hooks
# rev: v1.3.5
# hooks:
# - id: clang-format
# args: [--no-diff, -i]
# - id: clang-tidy
# args: [-p=build, --quiet]
# - id: cpplint
# args: [--verbose=5]
36 changes: 36 additions & 0 deletions .update-clang-tidy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash

set -x # trace
set -e # exit immediately if command fails
set -u # exit if an undefined variable is found

awk '
BEGIN {
print "# THIS FILE IS GENERATED FROM .clangd!"
print "# Run ./.update-clang-tidy.sh to regenerate."
print "Checks:"
}
/Add: \[$/{
a=1
next
}
/]/{
a=0
}
a{
gsub(/^\s+/," ")
print
}
/Remove: \[$/{
r=1
next
}
/]/{
r=0
}
r{
gsub(/^\s+/," -")
print
}
' .clangd | tee .clang-tidy
35 changes: 21 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,31 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set (CMAKE_SHARED_LINKER_FLAGS "-Wl,--build-id=sha1")
endif()

# Use this instead of above for 32 bit
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")

if ("${CMAKE_BUILD_TYPE}" STREQUAL Release)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
else ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb -O0 -DDEBUG")
endif ()

## Address Sanitize Flag
if (${ADDRESS_SANITIZER})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -g")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -g -fno-omit-frame-pointer")
set(CMAKE_EXE_LINKER_FLAGS -fsanitize=address)

if (BUILD_SHARED_LIBS})
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -shared-libsan" )
if (BUILD_SHARED_LIBS)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -shared-libasan")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -shared-libasan")
endif()
else ()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libsan" )
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libsan")
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libasan")
endif()
endif ()
else ()
## Security breach mitigation flags
Expand All @@ -116,21 +132,12 @@ else ()
"${CMAKE_CXX_FLAGS} -Wtrampolines -Wl,-z,now")
endif ()

# Use this instead of above for 32 bit
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")

if ("${CMAKE_BUILD_TYPE}" STREQUAL Release)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
else ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb -O0 -DDEBUG")
endif ()

set(COMMON_SRC_DIR "${PROJECT_SOURCE_DIR}/src")
set(COMMON_INC_DIR "${PROJECT_SOURCE_DIR}/include/rocm_smi")
set(SHR_MUTEX_DIR "${PROJECT_SOURCE_DIR}/third_party/shared_mutex")

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/third_party/shared_mutex)
${CMAKE_CURRENT_SOURCE_DIR}/third_party/shared_mutex)

set(CMN_SRC_LIST "${COMMON_SRC_DIR}/rocm_smi_device.cc")
set(CMN_SRC_LIST ${CMN_SRC_LIST} "${COMMON_SRC_DIR}/rocm_smi_main.cc")
Expand Down
3 changes: 3 additions & 0 deletions CPPLINT.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set noparent
linelength=100
filter=-build/include_subdir,-legal/copyright,-runtime/printf,-build/c++11,-runtime/int,-build/header_guard
4 changes: 2 additions & 2 deletions rocm_smi/example/rocm_smi_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -745,8 +745,8 @@ auto print_error_or_value(rsmi_status_t status_code, const T& metric) {
return str_values;
}
else if constexpr ((std::is_same_v<T, std::uint16_t>) ||
(std::is_same_v<T, std::uint32_t>) ||
(std::is_same_v<T, std::uint64_t>)) {
(std::is_same_v<T, std::uint32_t>) ||
(std::is_same_v<T, std::uint64_t>)) {
return std::to_string(metric);
}
}
Expand Down
Loading

0 comments on commit db2d128

Please sign in to comment.