Skip to content

Commit

Permalink
Add EmitC support in TTRT; Enable CI (#1732)
Browse files Browse the repository at this point in the history
  • Loading branch information
svuckovicTT authored Jan 17, 2025
1 parent 5aa2503 commit 990c6a3
Show file tree
Hide file tree
Showing 17 changed files with 513 additions and 88 deletions.
1 change: 1 addition & 0 deletions .clang-format-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tools/ttnn-standalone/*.cpp
26 changes: 22 additions & 4 deletions .github/actions/build-tt-mlir-action/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ inputs:
enable-op-model:
description: "Enable op model interface tests"
required: true
enable-emitc:
description: "Enable EmitC tests"
required: true
build-name:
description: "A unique name for this build (e.g., 'run' or 'perf')"
required: true
Expand Down Expand Up @@ -45,12 +48,11 @@ runs:
-DTTMLIR_ENABLE_OPMODEL=${{ inputs.enable-op-model }} \
-S ${{ inputs.work-dir }}
- name: Build and Install
- name: Build
shell: bash
run: |
source env/activate
cmake --build ${{ inputs.build-output-dir }}
cmake --install ${{ inputs.build-output-dir }} --component Test
- name: Build ttrt
shell: bash
Expand All @@ -65,6 +67,23 @@ runs:
source env/activate
ttrt query --save-artifacts
- name: Compile dylibs for EmitC
shell: bash
if: inputs.enable-emitc == 'ON'
run: |
source env/activate
export LD_LIBRARY_PATH="${TTMLIR_TOOLCHAIN_DIR}/lib:${LD_LIBRARY_PATH}"
llvm-lit -sv ${{ inputs.work-dir }}/test/ttmlir/EmitC/TTNN
${{ inputs.work-dir }}/tools/ttnn-standalone/ci_compile_dylib.py
# Install needs to run after the "Compile dylibs" step
#
- name: Install
shell: bash
run: |
source env/activate
cmake --install ${{ inputs.build-output-dir }} --component Test
- name: Run tt-mlir tests
shell: bash
run: |
Expand All @@ -90,10 +109,9 @@ runs:
- name: Upload Test Report
uses: actions/upload-artifact@v4
with:
name: test-reports-${{ inputs.runs-on }}-perf-${{ inputs.enable-perf }}-op_model-${{ inputs.enable-op-model }}
name: test-reports-${{ inputs.runs-on }}-perf-${{ inputs.enable-perf }}-op_model-${{ inputs.enable-op-model }}-emitc-${{ inputs.enable-emitc }}
path: ${{ inputs.test_report_path }}


- name: Upload ttrt .whl
uses: actions/upload-artifact@v4
with:
Expand Down
75 changes: 48 additions & 27 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ jobs:
fail-fast: false
matrix:
build: [
{runs-on: ubuntu-latest, enable_perf: OFF, enable_op_model: OFF, name: "run", ttrt_flags: ""},
{runs-on: ubuntu-latest, enable_perf: ON, enable_op_model: OFF, name: "perf", ttrt_flags: ""},
{runs-on: ubuntu-latest, enable_perf: OFF, enable_op_model: OFF, enable_emitc: OFF, name: "run", ttrt_flags: ""},
{runs-on: ubuntu-latest, enable_perf: ON, enable_op_model: OFF, enable_emitc: OFF, name: "perf", ttrt_flags: ""},
{runs-on: ubuntu-latest, enable_perf: OFF, enable_op_model: OFF, enable_emitc: ON, name: "emitc", ttrt_flags: ""},
]

name: Build and test tt-mlir (compute machine)
Expand All @@ -117,7 +118,7 @@ jobs:
id: strings
shell: bash
env:
job-name: "Build tt-mlir (${{ matrix.build.runs-on }}, ${{ matrix.build.enable_perf }}, ${{ matrix.build.enable_op_model }}, ${{ matrix.build.name }})"
job-name: "Build tt-mlir (${{ matrix.build.runs-on }}, ${{ matrix.build.enable_perf }}, ${{ matrix.build.enable_op_model }}, ${{ matrix.build.enable_emitc }}, ${{ matrix.build.name }})"
run: |
echo "work-dir=$(pwd)" >> "$GITHUB_OUTPUT"
echo "build-output-dir=$(pwd)/build" >> "$GITHUB_OUTPUT"
Expand Down Expand Up @@ -146,6 +147,7 @@ jobs:
with:
enable-perf: ${{ matrix.build.enable_perf }}
enable-op-model: ${{ matrix.build.enable_op_model }}
enable-emitc: ${{ matrix.build.enable_emitc }}
build-name: ${{ matrix.build.name }}
build-output-dir: ${{ steps.strings.outputs.build-output-dir }}
install-output-dir: ${{ steps.strings.outputs.install-output-dir }}
Expand All @@ -164,12 +166,13 @@ jobs:
fail-fast: false
matrix:
build: [
{runs-on: n150, enable_perf: OFF, name: "run", ttrt_flags: "--non-zero"},
{runs-on: n150, enable_perf: ON, name: "perf"},
{runs-on: n300, enable_perf: OFF, name: "run", ttrt_flags: "--non-zero"},
{runs-on: n300, enable_perf: ON, name: "perf"},
{runs-on: n150, enable_perf: OFF, enable_emitc: OFF, name: "run", build_name: "run", ttrt_flags: "--non-zero"},
{runs-on: n150, enable_perf: ON, enable_emitc: OFF, name: "perf", build_name: "perf"},
{runs-on: n150, enable_perf: OFF, enable_emitc: ON, name: "run", build_name: "emitc", ttrt_flags: "--emitc"},
{runs-on: n300, enable_perf: OFF, enable_emitc: OFF, name: "run", build_name: "run", ttrt_flags: "--non-zero"},
{runs-on: n300, enable_perf: ON, enable_emitc: OFF, name: "perf", build_name: "perf"},
]
name: "run-tests (${{ matrix.build.runs-on }}, ${{ matrix.build.enable_perf }}, ${{ matrix.build.name }})"
name: "run-tests (${{ matrix.build.runs-on }}, ${{ matrix.build.enable_perf }}, ${{ matrix.build.enable_emitc }}, ${{ matrix.build.build_name }})"

runs-on:
- in-service
Expand All @@ -194,7 +197,7 @@ jobs:
id: strings
shell: bash
env:
job-name: "run-tests (${{ matrix.build.runs-on }}, ${{ matrix.build.enable_perf }}, ${{ matrix.build.name }})"
job-name: "run-tests (${{ matrix.build.runs-on }}, ${{ matrix.build.enable_perf }}, ${{ matrix.build.enable_emitc }}, ${{ matrix.build.build_name }})"
run: |
echo "work-dir=$(pwd)" >> "$GITHUB_OUTPUT"
echo "build-output-dir=$(pwd)/build" >> "$GITHUB_OUTPUT"
Expand All @@ -216,7 +219,7 @@ jobs:
- name: Use build artifacts
uses: actions/download-artifact@v4
with:
name: install-artifacts-${{ matrix.build.name }}
name: install-artifacts-${{ matrix.build.build_name }}
path: ${{ steps.strings.outputs.install-output-dir }}

# This is needed to preserve file permissions
Expand All @@ -234,7 +237,7 @@ jobs:
- name: Download ttrt run whls
uses: actions/download-artifact@v4
with:
name: ttrt-whl-${{ matrix.build.name }}
name: ttrt-whl-${{ matrix.build.build_name }}

- name: Install ttrt run whls
shell: bash
Expand All @@ -258,9 +261,19 @@ jobs:
ln -sf ${{ steps.strings.outputs.install-output-dir }} ${{ steps.strings.outputs.build-output-dir }}
llvm-lit -sv ${{ steps.strings.outputs.build-output-dir }}/test
- name: Generate EmitC tests
shell: bash
if: matrix.build.enable_emitc == 'ON'
run: |
source env/activate
export LD_LIBRARY_PATH="${TTMLIR_TOOLCHAIN_DIR}/lib:${LD_LIBRARY_PATH}"
export SYSTEM_DESC_PATH="${GITHUB_WORKSPACE}/ttrt-artifacts/system_desc.ttsys"
ln -sf ${{ steps.strings.outputs.install-output-dir }} ${{ steps.strings.outputs.build-output-dir }}
llvm-lit -sv ${{ steps.strings.outputs.build-output-dir }}/test/ttmlir/EmitC/TTNN
- name: Run functional tests
shell: bash
if: matrix.build.enable_perf == 'OFF'
if: matrix.build.enable_perf == 'OFF' && matrix.build.enable_emitc == 'OFF'
run: |
source env/activate
ttrt ${{ matrix.build.name }} ${{ matrix.build.ttrt_flags }} ${{ steps.strings.outputs.build-output-dir }}/test/ttmlir/Silicon
Expand All @@ -273,12 +286,19 @@ jobs:
ttrt ${{ matrix.build.name }} ${{ matrix.build.ttrt_flags }} ${{ steps.strings.outputs.build-output-dir }}/test/ttmlir/Silicon/TTNN/perf_unit
cp ttrt_report.xml ${{ steps.strings.outputs.test_report_path }}
- name: Run emitc tests
shell: bash
if: matrix.build.enable_emitc == 'ON'
run: |
source env/activate
ttrt ${{ matrix.build.name }} ${{ matrix.build.ttrt_flags }} ${{ steps.strings.outputs.build-output-dir }}/test/ttmlir/EmitC
- name: Upload ttrt test report json
if: always()
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.build.runs-on }}_${{ matrix.build.name }}_results.json
path: ${{ matrix.build.name }}_results.json
name: ${{ matrix.build.runs-on }}_${{ matrix.build.enable_perf }}_${{ matrix.build.enable_emitc }}_${{ matrix.build.build_name }}_results.json
path: ${{ matrix.build.build_name }}_results.json

- name: Upload Test Report xml
uses: actions/upload-artifact@v4
Expand All @@ -292,7 +312,7 @@ jobs:
if: success() || failure()
with:
report_paths: ${{ steps.strings.outputs.test_report_path }}
check_name: TTRT ${{ matrix.build.runs-on }} ${{ matrix.build.name }} Tests
check_name: TTRT ${{ matrix.build.runs-on }} ${{ matrix.build.build_name }} Tests

run-ttrt-tests:

Expand All @@ -304,7 +324,7 @@ jobs:
fail-fast: false
matrix:
build: [
{runs-on: n150, enable_perf: ON, name: "perf"},
{runs-on: n150, enable_perf: ON, name: "perf", build_name: "perf"},
]

runs-on:
Expand All @@ -331,7 +351,7 @@ jobs:
id: strings
shell: bash
env:
job-name: "${{ github.job }} (${{ matrix.build.runs-on }}, ${{ matrix.build.enable_perf }}, ${{ matrix.build.name }})"
job-name: "${{ github.job }} (${{ matrix.build.runs-on }}, ${{ matrix.build.enable_perf }}, ${{ matrix.build.enable_emitc }}, ${{ matrix.build.build_name }})"
run: |
echo "work-dir=$(pwd)" >> "$GITHUB_OUTPUT"
echo "build-output-dir=$(pwd)/build" >> "$GITHUB_OUTPUT"
Expand All @@ -352,7 +372,7 @@ jobs:
- name: Use build artifacts
uses: actions/download-artifact@v4
with:
name: install-artifacts-${{ matrix.build.name }}
name: install-artifacts-${{ matrix.build.build_name }}
path: ${{ steps.strings.outputs.install-output-dir }}

# This is needed to preserve file permissions
Expand All @@ -370,7 +390,7 @@ jobs:
- name: Download ttrt run whls
uses: actions/download-artifact@v4
with:
name: ttrt-whl-${{ matrix.build.name }}
name: ttrt-whl-${{ matrix.build.build_name }}

- name: Install ttrt run whls
shell: bash
Expand Down Expand Up @@ -406,7 +426,7 @@ jobs:
uses: actions/upload-artifact@v4
if: success() || failure()
with:
name: test-reports-${{ matrix.build.runs-on }}-${{ matrix.build.name }}
name: test-reports-${{ matrix.build.runs-on }}-${{ matrix.build.build_name }}
path: ${{ steps.strings.outputs.test_report_path }}

- name: Show Test Report
Expand All @@ -426,7 +446,7 @@ jobs:
fail-fast: false
matrix:
build: [
{runs-on: n150, enable_perf: OFF, name: "run"},
{runs-on: n150, enable_perf: OFF, name: "run", build_name: "run"},
]

runs-on:
Expand Down Expand Up @@ -462,7 +482,7 @@ jobs:
- name: Use build artifacts
uses: actions/download-artifact@v4
with:
name: install-artifacts-${{ matrix.build.name }}
name: install-artifacts-${{ matrix.build.build_name }}
path: ${{ steps.strings.outputs.install-output-dir }}

# This is needed to preserve file permissions
Expand All @@ -480,7 +500,7 @@ jobs:
- name: Download ttrt run whls
uses: actions/download-artifact@v4
with:
name: ttrt-whl-${{ matrix.build.name }}
name: ttrt-whl-${{ matrix.build.build_name }}

# Runtime tests currently require ttrt whls to be installed
- name: Install ttrt run whls
Expand Down Expand Up @@ -596,7 +616,7 @@ jobs:
fail-fast: false
matrix:
build: [
{runs-on: n300, enable_perf: OFF, enable_op_model: ON, name: "op_model" , ttrt_flags: ""}
{runs-on: n300, enable_perf: OFF, enable_op_model: ON, enable_emitc: OFF, name: "op_model", build_name: "op_model", ttrt_flags: ""}
]

name: Run build and test tt-mlir (TT machine)
Expand All @@ -622,7 +642,7 @@ jobs:
id: strings
shell: bash
env:
job-name: "Build tt-mlir (${{ matrix.build.runs-on }}, ${{ matrix.build.enable_perf }}, ${{ matrix.build.enable_op_model }}, ${{ matrix.build.name }})"
job-name: "Build tt-mlir (${{ matrix.build.runs-on }}, ${{ matrix.build.enable_perf }}, ${{ matrix.build.enable_op_model }}, ${{ matrix.build.enable_emitc }}, ${{ matrix.build.build_name }})"
run: |
echo "work-dir=$(pwd)" >> "$GITHUB_OUTPUT"
echo "build-output-dir=$(pwd)/build" >> "$GITHUB_OUTPUT"
Expand All @@ -644,15 +664,16 @@ jobs:
uses: hendrikmuhs/[email protected]
with:
create-symlink: true
key: ${{ matrix.build.runs-on }}-run-ON-perf-${{ matrix.build.enable_perf }}-op_model-${{ matrix.build.enable_op_model }}-${{ env.SDK_VERSION }}
key: ${{ matrix.build.runs-on }}-run-ON-perf-${{ matrix.build.enable_perf }}-op_model-${{ matrix.build.enable_op_model }}-${{ matrix.build.enable_emitc }}-${{ env.SDK_VERSION }}

# Build project
- name: Run build and test tt-mlir
uses: ./.github/actions/build-tt-mlir-action
with:
enable-perf: ${{ matrix.build.enable_perf }}
enable-op-model: ${{ matrix.build.enable_op_model }}
build-name: ${{ matrix.build.name }}
enable-emitc: ${{ matrix.build.enable_emitc }}
build-name: ${{ matrix.build.build_name }}
build-output-dir: ${{ steps.strings.outputs.build-output-dir }}
install-output-dir: ${{ steps.strings.outputs.install-output-dir }}
work-dir: ${{ steps.strings.outputs.work-dir }}
Expand Down
18 changes: 18 additions & 0 deletions runtime/include/tt/runtime/test/dylib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-FileCopyrightText: (c) 2024 Tenstorrent AI ULC
//
// SPDX-License-Identifier: Apache-2.0

#ifndef TT_RUNTIME_TEST_DYLIB_H
#define TT_RUNTIME_TEST_DYLIB_H

#include "tt/runtime/types.h"

namespace tt::runtime::ttnn::test {

void *openSo(std::string path);
std::vector<Tensor> runSoProgram(void *so, std::string func_name,
std::vector<Tensor> inputs, Device device);
bool compareOuts(std::vector<Tensor> &lhs, std::vector<Tensor> &rhs);
} // namespace tt::runtime::ttnn::test

#endif // TT_RUNTIME_TEST_DYLIB_H
3 changes: 2 additions & 1 deletion runtime/lib/ttnn/runtime.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: (c) 2024 Tenstorrent AI ULC
//
// SPDX-License-Identifier: Apache-2.0

#include "tt/runtime/detail/debug.h"
#include "tt/runtime/detail/logger.h"
#include "tt/runtime/detail/ttnn.h"
Expand Down Expand Up @@ -167,7 +168,7 @@ Tensor createTensor(Device device, Layout layout,
createOwnedTensor(nullptr, shape, stride, itemsize,
utils::fromTTNNDataType(layoutDesc.dataType));
Tensor out = utils::createRuntimeTensorFromTTNN(tensor);
return toLayout(out, device, layout);
return ::tt::runtime::ttnn::toLayout(out, device, layout);
}
DeviceVariant targetDevice =
getTargetDevice(device.as<::ttnn::MeshDevice>(DeviceRuntime::TTNN));
Expand Down
1 change: 1 addition & 0 deletions runtime/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ else()
add_library(TTRuntimeTTNNTestHelpers
STATIC
${CMAKE_CURRENT_SOURCE_DIR}/include/tt/runtime/ttnn/test/utils.cpp
${CMAKE_CURRENT_SOURCE_DIR}/include/tt/runtime/ttnn/test/dylib.cpp
)
set_property(TARGET TTRuntimeTTNNTestHelpers PROPERTY CXX_STANDARD 20)
target_compile_options(TTRuntimeTTNNTestHelpers PUBLIC -mavx -mavx2 -fsized-deallocation)
Expand Down
Loading

0 comments on commit 990c6a3

Please sign in to comment.