Skip to content

Commit

Permalink
Merge branch 'main' into brosko/fix_log_l1membar
Browse files Browse the repository at this point in the history
  • Loading branch information
broskoTT authored Oct 28, 2024
2 parents 357154e + 8a7a764 commit a74e970
Show file tree
Hide file tree
Showing 42 changed files with 751 additions and 429 deletions.
163 changes: 21 additions & 142 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,147 +1,26 @@
---
Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: -1
BasedOnStyle: Google
ColumnLimit: 120
IndentWidth: 4

# This will make access modifiers (public/protected/private) sit on the same indentation as `class` keyword
AccessModifierOffset: -4

# Arguments, parameters and construction initializer are broken as following:
# - Try to fit everything into single line (controlled by ColumnLimit).
# - If it doesn't fit, break immediately after open bracket (in case of arguments and parameters)
# or after colon in case of constructor initializers.
# - Try to fit everything else into the second line.
# - If it doesn't fit in second line, then each argument, parameter or initializer will sit in its own line.
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
# AfterCaseLabel: false
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false

# When constructor initializers exist in the constructor definition, leave the colon as last thing on the original
# line instead of putting it on the next line.
BreakConstructorInitializers: AfterColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: true
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<ext/.*\.h>'
Priority: 2
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Never
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Right
RawStringFormats:
- Language: Cpp
Delimiters:
- cc
- CC
- cpp
- Cpp
- CPP
- 'c++'
- 'C++'
CanonicalDelimiter: ''
BasedOnStyle: google
- Language: TextProto
Delimiters:
- pb
- PB
- proto
- PROTO
EnclosingFunctions:
- EqualsProto
- EquivToProto
- PARSE_PARTIAL_TEXT_PROTO
- PARSE_TEST_PROTO
- PARSE_TEXT_PROTO
- ParseTextOrDie
- ParseTextProtoOrDie
CanonicalDelimiter: ''
BasedOnStyle: google
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 4
UseTab: Never
...

# Disallow single statements after if/else/for/while/do without curly braces.
InsertBraces: true

# Separate definition blocks, including classes, structs, enums, and functions.
SeparateDefinitionBlocks: Always
6 changes: 6 additions & 0 deletions .gersemirc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/BlankSpruce/gersemi/master/gersemi/configuration.schema.json

definitions: [cmake]
indent: 4
line_length: 80
list_expansion: favour-expansion
6 changes: 3 additions & 3 deletions .github/workflows/build-device.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Builds umd_device.
# Builds device.
# Build is performed on all supported OS versions.
name: Build Target

Expand All @@ -16,7 +16,7 @@ on:
type: number

env:
BUILD_TARGET: umd_device
BUILD_TARGET: device
BUILD_OUTPUT_DIR: ./build
LIB_OUTPUT_DIR: ./build/lib
DEPS_OUTPUT_DIR: ./build/_deps
Expand All @@ -34,7 +34,7 @@ jobs:
{runs-on: ubuntu-20.04, docker-image: tt-umd-ci-ubuntu-20.04},
]

name: Build umd_device for any arch on ${{ matrix.build.runs-on }}
name: Build device for any arch on ${{ matrix.build.runs-on }}
runs-on: ${{ matrix.build.runs-on }}
container:
image: ghcr.io/${{ github.repository }}/${{ matrix.build.docker-image }}:latest
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,23 @@ jobs:
uses: ./.github/workflows/build-device.yml
with:
timeout: 10

pre-commit:
name: Run Pre-commit Hooks and Propose Fixes
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history so 'origin/main' is available
ref: ${{ github.head_ref }}

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.11

- name: Run Pre-commit and Fix Issues
uses: pre-commit/[email protected]
with:
extra_args: "--from-ref origin/main --to-ref HEAD"
1 change: 1 addition & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ jobs:

env:
ARCH_NAME: ${{ inputs.arch }}
LD_LIBRARY_PATH: ./build/lib

steps:
- name: Cleanup tt-umd dir, and change directory as if we were in a github.repository
Expand Down
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
repos:
- repo: https://github.com/BlankSpruce/gersemi
rev: 0.16.2
hooks:
- id: gersemi
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v17.0.6
hooks:
- id: clang-format
91 changes: 29 additions & 62 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ include(cmake/compilers.cmake)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_POSITION_INDEPENDENT_CODE ON) # This also impacts dependencies brought in through CPM

if (DEFINED ENV{CMAKE_C_COMPILER} AND DEFINED ENV{CMAKE_CXX_COMPILER})
message(STATUS "Setting C and C++ compiler from environment variables")
Expand All @@ -19,88 +20,54 @@ else()
FIND_AND_SET_CLANG17()
endif()

project(umd_device)
project(
umd
VERSION 0.1.0
DESCRIPTION "Tenstorrent User Mode Driver"
HOMEPAGE_URL "https://github.com/tenstorrent/tt-umd"
LANGUAGES
CXX
)

list(PREPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
CHECK_COMPILERS()
include(check_libcpp)

include(GNUInstallDirs)
set(MASTER_PROJECT OFF)
if(PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(MASTER_PROJECT ON)
message("-- UMD: Building as master project")
endif()

if(MASTER_PROJECT)
message(STATUS "UMD: Building as master project")
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Release build is the default" FORCE)
set(CMAKE_BUILD_TYPE
"Release"
CACHE STRING
"Release build is the default"
FORCE
)
endif()

option(ENABLE_ASAN "Enable build with AddressSanitizer" OFF)
message(STATUS "Build with ASAN: ${ENABLE_ASAN}")

set(SANITIZER_ENABLED ${ENABLE_ASAN})

option(ENABLE_MSAN "Enable build with MemorySanitizer" OFF)
message(STATUS "Build with MSAN: ${ENABLE_MSAN}")

if(SANITIZER_ENABLED AND ENABLE_MSAN)
message(FATAL_ERROR "Multiple sanitizers are not supported")
elseif(ENABLE_MSAN)
set(SANITIZER_ENABLED ${ENABLE_MSAN})
endif()

option(ENABLE_TSAN "Enable build with ThreadSanitizer" OFF)
message(STATUS "Build with TSAN: ${ENABLE_TSAN}")

if(SANITIZER_ENABLED AND ENABLE_TSAN)
message(FATAL_ERROR "Multiple sanitizers are not supported")
elseif(ENABLE_TSAN)
set(SANITIZER_ENABLED ${ENABLE_TSAN})
endif()

option(ENABLE_UBSAN "Enable build with UndefinedBehaviorSanitizer" OFF)
message(STATUS "Build with UBSAN: ${ENABLE_UBSAN}")

if(SANITIZER_ENABLED AND ENABLE_UBSAN)
message(FATAL_ERROR "Multiple sanitizers are not supported")
endif()

unset(SANITIZER_ENABLED)

add_library(compiler_flags INTERFACE)
target_compile_options(
compiler_flags
INTERFACE -DFMT_HEADER_ONLY
$<$<BOOL:${ENABLE_ASAN}>:-fsanitize=address>
$<$<BOOL:${ENABLE_MSAN}>:-fsanitize=memory>
$<$<BOOL:${ENABLE_TSAN}>:-fsanitize=thread>
$<$<BOOL:${ENABLE_UBSAN}>:-fsanitize=undefined>)

add_library(linker_flags INTERFACE)
target_link_options(
linker_flags
INTERFACE
$<$<BOOL:${ENABLE_ASAN}>:-fsanitize=address>
$<$<BOOL:${ENABLE_MSAN}>:-fsanitize=memory>
$<$<BOOL:${ENABLE_TSAN}>:-fsanitize=thread>
$<$<BOOL:${ENABLE_UBSAN}>:-fsanitize=undefined>)

target_link_libraries(compiler_flags INTERFACE linker_flags)
include(sanitizer_options)
endif()

message(STATUS "UMD build type: ${CMAKE_BUILD_TYPE}")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g -DDEBUG=DEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -DDEBUG=DEBUG")

include(${PROJECT_SOURCE_DIR}/cmake/dependencies.cmake)
add_compile_definitions(
$<$<CONFIG:Debug>:DEBUG>
$<$<CONFIG:RelWithDebInfo>:DEBUG>
)

add_library(umd_common_directories INTERFACE)
target_include_directories(umd_common_directories INTERFACE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/device)
include(dependencies)

add_subdirectory(${PROJECT_SOURCE_DIR}/device)
add_subdirectory(device)

option(TT_UMD_BUILD_TESTS "Enables build of tt_umd tests" OFF)
if(TT_UMD_BUILD_TESTS)
add_subdirectory(${PROJECT_SOURCE_DIR}/tests)
add_subdirectory(tests)
endif(TT_UMD_BUILD_TESTS)

include(packaging)
Loading

0 comments on commit a74e970

Please sign in to comment.