Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
3e2b686
Integrate custom TTNN extension for Pytorch
kevinwuTT Feb 28, 2025
459ba0d
Make changes to work on BERT
kevinwuTT Feb 28, 2025
d7cf8ba
No changes to utils.py
kevinwuTT Mar 1, 2025
90aefb8
Add CPP lint hook that uses clang-format to reformat files
kevinwuTT Mar 5, 2025
7e5f1e4
Separate TtnnTensorImpl to cpp
kevinwuTT Mar 5, 2025
85a36c2
Split cpp extension tests
kevinwuTT Mar 5, 2025
bc90cbe
Inline some helper functions
kevinwuTT Mar 7, 2025
91bea1f
Use long casting to fix BERT
kevinwuTT Mar 7, 2025
1e67171
Update cpp extension bert test with different dynamic inputs
kevinwuTT Mar 7, 2025
057fd7d
Rename some external cpp extension functions
kevinwuTT Mar 7, 2025
f5df356
Move privateuse1 rename to when custom extension is loaded
kevinwuTT Mar 7, 2025
c7bae1a
Major refactoring
kevinwuTT Mar 10, 2025
06c04c0
Refactor some utils
kevinwuTT Mar 10, 2025
5dd3f60
Ensure get_ttnn_tensor doesn't modify any members. Move ttnn::empty t…
kevinwuTT Mar 10, 2025
fbb2707
Add build document for Open Registration API
kevinwuTT Mar 11, 2025
e036ccb
Separate hpp/cpp for TtnnGuard
kevinwuTT Mar 11, 2025
b88c853
Split TtnnCustomAllocator to cpp/hpp
kevinwuTT Mar 11, 2025
1e3665d
Fix some namespace consistencies and update doc
kevinwuTT Mar 12, 2025
6971724
Remove site-packages variable for now
kevinwuTT Mar 12, 2025
bb7da5f
Remove debug code that has already been moved
kevinwuTT Mar 12, 2025
5c10415
Fix oops
kevinwuTT Mar 12, 2025
8307691
Clean up functionality test and check for truncation
kevinwuTT Mar 13, 2025
be5055d
Rename ttnn_device to ttnn_torch_device for more emphasis
kevinwuTT Mar 13, 2025
27c9aba
Glob cpp files instead of manually listing them
kevinwuTT Mar 13, 2025
dd233b0
Revise doc instructions and update for latest version of tt-metal
kevinwuTT Mar 14, 2025
ea36729
Add additional troubleshooting notes
kevinwuTT Mar 14, 2025
c6b3f22
Revise BERT test to support multiple iteraitons and batches
kevinwuTT Mar 19, 2025
4e4a028
Remove accidentally committed doc
kevinwuTT Mar 20, 2025
566ef06
Test: remove extra layout ops
kevinwuTT Mar 24, 2025
1ef1c1c
Remove dependencies on libc++
kevinwuTT Apr 8, 2025
e38e819
Add workaround problematic compiler macros by undefining them in the …
kevinwuTT Apr 9, 2025
ceb72f8
Use source instead of period for better clarity
kevinwuTT Apr 14, 2025
96fefa7
Switch to_layout to always use TILE
kevinwuTT Apr 15, 2025
0b996c9
Refactor dev directories somewhat
kevinwuTT Apr 15, 2025
3b17d23
Gix integration with ttnn: IDevice->MeshDevice
philei-tt Apr 28, 2025
058ab0c
Restructure cpp-extension (#988)
philei-tt Apr 30, 2025
6427bac
Upload missing registration cpp file
philei-tt Apr 30, 2025
fcd0e41
Fix buffer creation after latest ttnn updates
philei-tt Apr 30, 2025
0e67e1e
Add non-working but compiling ttnn+torch
philei-tt May 5, 2025
e9ef410
Fix cmake integration
philei-tt May 5, 2025
8e9f194
Remove unneeded pybind cpm
philei-tt May 5, 2025
f6e374e
Add torch building instructions
philei-tt May 6, 2025
d007630
Add setup for cpp-ext, add python demo, refactor code structure
philei-tt May 6, 2025
a92f637
Cmake clean up
philei-tt May 6, 2025
8886ff1
Add missing __init__.py in tools
philei-tt May 6, 2025
116c800
Remove dead imports from ttnn_device_mode.py
philei-tt May 7, 2025
c0f376c
Add BUILD_EXAMPLES option. Add log in find_python_workaround
philei-tt May 7, 2025
93dc826
Add tt-metal git submodule
philei-tt May 7, 2025
d1408da
Make submodule integration
philei-tt May 7, 2025
19d78c5
Remove python_demo.py
philei-tt May 7, 2025
18be99e
Remove commented cmake code from third-party
philei-tt May 7, 2025
e5da0db
Make tensr.to("ttnn") work
philei-tt May 8, 2025
abefe6d
Fix single device index management
philei-tt May 8, 2025
9de80e0
Use device to_layout
philei-tt May 8, 2025
19670d0
Add optional torchvision build instructions
philei-tt May 8, 2025
928997e
Clean up: address some comments from draft PR
philei-tt May 8, 2025
50e9728
Some cmake fixes for ubuntu22
philei-tt May 8, 2025
6f265a8
Move torch compilation after all pip deps installed
philei-tt May 9, 2025
7639c9c
Fix -Wl,rpath syntax
philei-tt May 9, 2025
6caf039
Update instructions to compile cpp extension
kevinwuTT May 9, 2025
89ba6c2
Remove debug print
philei-tt May 13, 2025
90e003a
Update workflow to update submodule version
philei-tt May 13, 2025
f0a9bf2
Add workflow for cpp extensions
philei-tt May 13, 2025
6ff6774
Update cpp-extension workflow
philei-tt May 13, 2025
eaf5204
Update cpp-extension workflow
philei-tt May 13, 2025
d4a9d5d
Update cpp-extension workflow
philei-tt May 13, 2025
8b46210
Attempt to fix cpp native workdlow
philei-tt May 13, 2025
e876c06
Fix cpp extensipn workflow
philei-tt May 14, 2025
b29a1ba
Update cpp extension workflow
philei-tt May 14, 2025
a50a6c9
Update workflow
philei-tt May 14, 2025
28893a5
Update workflow
philei-tt May 14, 2025
4205b6b
update workflow
philei-tt May 14, 2025
9856ff0
update workflow
philei-tt May 14, 2025
0abfda5
Restructure cpp extension workflow
philei-tt May 14, 2025
3ee89d9
Fix cpp extension workflow
philei-tt May 14, 2025
33ec4c1
Add separate build and separate test cpp extension workflow
philei-tt May 14, 2025
b834925
Update build workflow
philei-tt May 14, 2025
9107f80
Fixing build cpp extension workflow
philei-tt May 14, 2025
50cc51f
Experimenting with nfs
philei-tt May 14, 2025
a7296cc
Fixing fetchingc cache for cpp extension
philei-tt May 14, 2025
85f740c
update workflow
philei-tt May 14, 2025
f48d4e9
Update cache dir in build extension
philei-tt May 14, 2025
a6b24ed
try to run cpp extesnions tests from cache
philei-tt May 14, 2025
3f0f6a7
Add ccache
philei-tt May 14, 2025
3c7fc3c
try to build with cache
philei-tt May 14, 2025
e763152
Try to add build artifact to update-ttnn-wheel
philei-tt May 15, 2025
be995b1
Uncomment stuff in update-ttnn-wheel
philei-tt May 15, 2025
26afdaa
Run native tests
philei-tt May 15, 2025
391aa17
Add torch-compatible build with a script
philei-tt May 16, 2025
80ab738
Remove hardocded hashes for .cpm dependencies
philei-tt May 16, 2025
af57617
Move ttnn includes and lib files search in sep. cmake script
philei-tt May 16, 2025
ecdfdb7
Remove stdandard search in torch flags
philei-tt May 16, 2025
d248948
Initialize uint32 TTNN tensors with ROW_MAJOR and apply additional ch…
kevinwuTT May 16, 2025
cb10a23
Test ci build cache with a new building process
philei-tt May 16, 2025
d166889
Install curl
philei-tt May 16, 2025
a8cbbb0
Fix branch
philei-tt May 16, 2025
611e53d
Use strictly g++-12 for cpp-extension
philei-tt May 16, 2025
572e480
g++ -> g++-12 in toolchain for tt-metal build
philei-tt May 16, 2025
d5ecfd1
Run tests from cache
philei-tt May 16, 2025
8c425a5
Update caching for cpp extensions
philei-tt May 16, 2025
2d51ad8
Run cpp tests from cache
philei-tt May 16, 2025
ead78d2
Rebuild cache
philei-tt May 16, 2025
44319b4
Rerun tests after fixed cache
philei-tt May 16, 2025
7156490
Trying to fix test
philei-tt May 16, 2025
10fedce
Update actions files tow work after merging to main
philei-tt May 18, 2025
cb03d72
Change BERT sequence length to 384
kevinwuTT May 19, 2025
c535bf6
Update docs for installation of cpp extension
philei-tt May 20, 2025
017353e
Fix specifying compiler for cpp extension. Update docs
philei-tt May 20, 2025
4dd2578
Update docs/OpenRegistrationAPI.md
philei-tt May 20, 2025
69413ac
Fix identation in open registration docs
philei-tt May 21, 2025
bb7c441
Fix grammar
philei-tt May 21, 2025
229bf18
Align community-issue-tagging workflow with main
philei-tt May 21, 2025
0bbe1e3
Add batch size 8 and 16 to cpp ext bert test
philei-tt May 22, 2025
40e2e5f
Add option to disable loading params once
philei-tt May 22, 2025
089633c
Add cpp extension support to conftest
philei-tt May 22, 2025
54b2807
Pass build type to build_cpp_extension.sh
philei-tt May 22, 2025
8bfe41a
Import ttnn_module only when native device is detected
kevinwuTT May 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 149 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
---
Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: -4
InsertNewlineAtEOF: true
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
BreakConstructorInitializers: AfterColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
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
InsertBraces: true
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: Left
QualifierAlignment: Left
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: false
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
...
68 changes: 68 additions & 0 deletions .github/actions/build_cpp_extension_artifacts/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: "C++ Extension Build Artifacts"
description: "Builds C++ library for cpp extension"
runs:
using: "composite"
steps:
- name: Docker Cleanup
shell: bash
run: |
docker system prune -a -f
df -h # Debug space

- name: Install dependencies
shell: bash
run: |
apt upgrade -y && apt update -y
apt install -y cmake python3 python3-venv python3-pip git-lfs ccache gcc-12 g++-12

git config --global --add safe.directory /home/ubuntu/actions-runner/_work/pytorch2.0_ttnn/pytorch2.0_ttnn
git config --global --add safe.directory /__w/pytorch2.0_ttnn/pytorch2.0_ttnn

# Remove hugepages setup from install_dependencies.sh
sed -i '/^configure_hugepages() {/,/^}/c\configure_hugepages() {\n echo "Skip hugepages installation"\n}' ./torch_ttnn/cpp_extension/third-party/tt-metal/install_dependencies.sh
./torch_ttnn/cpp_extension/third-party/tt-metal/install_dependencies.sh

- name: Install python dependencies
shell: bash
run: |
python3 -m pip install --upgrade pip
python3 -m pip config set global.extra-index-url https://download.pytorch.org/whl/cpu
python3 -m pip install -r requirements-dev.txt
python3 -m pip install pytest-github-report

pip install --force-reinstall pip==21.2.4
python3 -m pip install numpy setuptools wheel
python3 -m pip install -e .

- name: Setup submodules
shell: bash
run: |
git submodule sync
git submodule update --init --recursive
git submodule foreach 'git lfs fetch --all && git lfs pull'

- name: Build C++ Extensions
shell: bash
run: |
cd torch_ttnn/cpp_extension
./build_cpp_extension.sh

- name: Upload Build Artifacts
shell: bash
run: |
cd torch_ttnn/cpp_extension
PYTHON_LIB_SUFFIX=$(python3 -c "import importlib.machinery; print(importlib.machinery.EXTENSION_SUFFIXES[0])")
mkdir -p $CACHE_DIR
CCACHE_DIR=$(ccache --get-config cache_dir)

# cpp-extension cache
cp -r build $CACHE_DIR
cp -r ttnn_device_extension${PYTHON_LIB_SUFFIX} $CACHE_DIR

# tt-metal cache
mkdir -p $CACHE_DIR/tt-metal
cp -r third-party/tt-metal/build $CACHE_DIR/tt-metal/
cp -r third-party/tt-metal/.cpmcache $CACHE_DIR/tt-metal/

# ccache
cp -r $CCACHE_DIR $CACHE_DIR
158 changes: 158 additions & 0 deletions .github/workflows/run-cpp-native-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
name: "C++ Extension Tests"

on:
push:
branches:
- main
paths:
- 'torch_ttnn/cpp_extension/**'
- 'tests/cpp_extension/**'
pull_request:
paths:
- "torch_ttnn/cpp_extension/**"
- "tests/cpp_extension/**"
workflow_dispatch:
inputs:
docker_tag:
description: "Docker container tag to use"
required: false
type: string
default: "ghcr.io/tenstorrent/pytorch2.0_ttnn/ubuntu-22.04-amd64:latest"

jobs:
cpp-extension-tests:
runs-on: ["in-service", "nfs"]
container:
image: ${{ github.event.inputs.docker_tag || 'ghcr.io/tenstorrent/pytorch2.0_ttnn/ubuntu-22.04-amd64:latest' }}
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GH_TOKEN }}
options: >-
--rm -v /dev/hugepages-1G:/dev/hugepages-1G --device /dev/tenstorrent
-v ${{ github.workspace }}:${{ github.workspace }} -w ${{ github.workspace }}
-v /mnt/tt-metal-pytorch-cache/.cache:/root/.cache
env:
CACHE_DIR: /root/.cache/cpp-extension-cache
steps:
- uses: actions/checkout@v4
with:
lfs: true
fetch-depth: 0
submodules: "recursive"

- name: Docker Cleanup
run: |
docker system prune -a -f
df -h # Debug space

- name: Update system
run: |
apt update -y && apt upgrade -y
apt install -y curl jq
- name: Update .gitsubmodules
run: |
# Fetch the latest pre-release tag from the target repository
latest_pre_release=$(curl -s https://api.github.com/repos/tenstorrent/tt-metal/releases | jq -r '[.[] | select(.prerelease == true)][0].tag_name')
# Strip leading 'v' from the tag (e.g., v0.51.0 -> 0.51.0)
latest_version="${latest_pre_release#v}"
sed -i "/\[submodule \"torch_ttnn\/cpp_extension\/third-party\/tt-metal\"\]/,/^\[/{s/^\s*branch\s*=.*/\tbranch = $latest_version/}" .gitmodules
echo "Updated .gitmodules with the latest version: $latest_version"

- name: Install dependencies
run: |
apt upgrade -y && apt update -y
apt install -y cmake python3 python3-venv python3-pip git-lfs ccache
git config --global --add safe.directory /home/ubuntu/actions-runner/_work/pytorch2.0_ttnn/pytorch2.0_ttnn
git config --global --add safe.directory /__w/pytorch2.0_ttnn/pytorch2.0_ttnn

# Remove hugepages setup from install_dependencies.sh
sed -i '/^configure_hugepages() {/,/^}/c\configure_hugepages() {\n echo "Skip hugepages installation"\n}' ./torch_ttnn/cpp_extension/third-party/tt-metal/install_dependencies.sh
./torch_ttnn/cpp_extension/third-party/tt-metal/install_dependencies.sh

- name: Install python dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip config set global.extra-index-url https://download.pytorch.org/whl/cpu
python3 -m pip install -r requirements-dev.txt
python3 -m pip install pytest-github-report

pip install --force-reinstall pip==21.2.4
python3 -m pip install numpy setuptools wheel
python3 -m pip install -e .

- name: Setup submodules
run: |
git submodule sync
git submodule update --init --recursive
git submodule foreach 'git lfs fetch --all && git lfs pull'

- name: Build/Fetch C++ Extensions
run: |
cd torch_ttnn/cpp_extension
PYTHON_LIB_SUFFIX=$(python3 -c "import importlib.machinery; print(importlib.machinery.EXTENSION_SUFFIXES[0])")

CCACHE_DIR=$(ccache --get-config cache_dir)
mkdir -p $CCACHE_DIR

# Check if cache exists with required components
CACHE_FOUND=0
if [ -d "$CACHE_DIR/build" ] && [ -f "$CACHE_DIR/ttnn_device_extension${PYTHON_LIB_SUFFIX}" ]; then
CACHE_FOUND=1
echo "Cache found with all required components. Using cached build."

# cpp-extension cache
cp -r $CACHE_DIR/build .
cp -r $CACHE_DIR/ttnn_device_extension${PYTHON_LIB_SUFFIX} .

# tt-metal cache
cp -r $CACHE_DIR/tt-metal/build third-party/tt-metal/
cp -r $CACHE_DIR/tt-metal/.cpmcache third-party/tt-metal/

# ccache
cp -r $CACHE_DIR/ccache/* $CCACHE_DIR
else
echo "Cache not found or incomplete. Building C++ extensions"
fi
./build_cpp_extension.sh

# Update cache with new build if not was not present before
if [ $CACHE_FOUND -eq 0 ]; then
mkdir -p $CACHE_DIR

# cpp-extension cache
cp -r build $CACHE_DIR
cp -r ttnn_device_extension${PYTHON_LIB_SUFFIX} $CACHE_DIR

# tt-metal cache
mkdir -p $CACHE_DIR/tt-metal
cp -r third-party/tt-metal/build $CACHE_DIR/tt-metal/
cp -r third-party/tt-metal/.cpmcache $CACHE_DIR/tt-metal/

# ccache
cp -r $CCACHE_DIR $CACHE_DIR
fi
cd ${{ github.workspace }}

- name: Run C++ Extension Tests
run: |
export TT_METAL_HOME=$(realpath ./torch_ttnn/cpp_extension/third-party/tt-metal)
pytest tests/cpp_extension/test_cpp_extension_functionality.py -v
pytest tests/cpp_extension/test_bert_cpp_extension.py -v

tests-passed:
if: ${{ always() }}
outputs:
didpass: ${{ steps.check.outputs.didpass }}
runs-on: ubuntu-latest
needs: [cpp-extension-tests]
steps:
- id: check
run: |
cpp_tests_result="${{ needs.cpp-extension-tests.result}}"
if [[ $cpp_tests_result == "success" || $cpp_tests_result == "skipped" ]]; then
echo "didpass=0" >> $GITHUB_OUTPUT
exit 0
else
echo "didpass=1" >> $GITHUB_OUTPUT
exit 1
fi
Loading