-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding more tosa tests for combined precision inputs and broadcast (#650
) * Add floatxfloat_sub_elem tosa test * Add floatxfloat_add_elem tosa test * Add floatxfloat_sel tosa test * Add bf16xfloat_sub_elem tosa test * Add bf16xfloat_add_elem tosa test * Add i16xi16_sub_elem broadcast tests * Add i8xi8_sub_elem broadcast tests * Reorganize bf16xbf16 broadcast tosa tests * Add floatxfloat_sub_elem broadcast tests * Fix tosa lowering pipeline for bf16xbf16 sub_elem broadcast tests
- Loading branch information
1 parent
3a5e6ea
commit 067b00b
Showing
72 changed files
with
1,197 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
24 changes: 24 additions & 0 deletions
24
test/Integration/Dialect/TOSA/bf16xfloat_add_elem/bf16xfloat_add_elem.mlir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// Copyright (C) 2023, Advanced Micro Devices, Inc. | ||
|
||
// REQUIRES: valid_xchess_license | ||
// RUN: mlir-opt %s --pass-pipeline="builtin.module(func.func(tosa-to-linalg-named, tosa-to-linalg))" -o linalg.mlir | ||
// RUN: mlir-opt linalg.mlir --linalg-fuse-elementwise-ops --eliminate-empty-tensors --empty-tensor-to-alloc-tensor --one-shot-bufferize="allow-return-allocs allow-unknown-ops bufferize-function-boundaries function-boundary-type-conversion=identity-layout-map" --drop-equivalent-buffer-results --buffer-results-to-out-params --buffer-deallocation --canonicalize --cse --convert-linalg-to-affine-loops --affine-super-vectorize="virtual-vector-size=16" -o affine.mlir | ||
// RUN: aie-opt affine.mlir --convert-vector-to-aievec="aie-target=aieml" -lower-affine -o aievec.mlir | ||
// RUN: aie-translate aievec.mlir -aieml=true --aievec-to-cpp -o dut.cc | ||
// RUN: xchesscc_wrapper aie2 -f -g +s +w work +o work -I%S -I. %S/testbench.cc dut.cc | ||
// RUN: mkdir -p data | ||
// RUN: mkdir -p %t | ||
// RUN: mkdir -p %basename_t | ||
// RUN: xca_udm_dbg --aiearch aie-ml -qf -T -P %aietools/data/aie_ml/lib/ -t "%S/../profiling.tcl ./work/a.out" >& xca_udm_dbg.stdout | ||
// RUN: FileCheck --input-file=./xca_udm_dbg.stdout %s | ||
// CHECK: TEST PASSED | ||
|
||
module { | ||
func.func @dut(%arg0: tensor<1024xbf16>, %arg1: tensor<1024xf32>) -> (tensor<1024xf32>) { | ||
%1 = "tosa.cast" (%arg0) : (tensor<1024xbf16>) -> (tensor<1024xf32>) | ||
%2 = "tosa.add"(%1,%arg1) : (tensor<1024xf32>, tensor<1024xf32>) -> (tensor<1024xf32>) | ||
return %2 : tensor<1024xf32> | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#pragma once | ||
constexpr unsigned const IN0_SIZE = 1024; | ||
constexpr unsigned const IN1_SIZE = 1024; | ||
constexpr unsigned const OUT0_SIZE = 1024; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// clang-format off | ||
void dut(bfloat16 * restrict v1, float * restrict v2, float * restrict v3) { | ||
size_t v4 = 0; | ||
size_t v5 = 1024; | ||
size_t v6 = 16; | ||
for (size_t v7 = v4; v7 < v5; v7 += v6) | ||
chess_prepare_for_pipelining | ||
chess_loop_range(64, 64) | ||
{ | ||
v16bfloat16 v8 = *(v16bfloat16 *)(v1 + v7); | ||
v16float v9 = *(v16float *)(v2 + v7); | ||
v16accfloat v10 = ups_to_v16accfloat(v8); | ||
v16accfloat v11 = v16accfloat(v9); | ||
v16accfloat v12 = add(v10, v11); | ||
v16float v13 = v16float(v12); | ||
*(v16float *)(v3 + v7) = v13; | ||
} | ||
return; | ||
} | ||
// clang-format on |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
test/Integration/Dialect/TOSA/bf16xfloat_sub_elem/bf16xfloat_sub_elem.mlir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// Copyright (C) 2023, Advanced Micro Devices, Inc. | ||
|
||
// REQUIRES: valid_xchess_license | ||
// RUN: mlir-opt %s --pass-pipeline="builtin.module(func.func(tosa-to-linalg-named, tosa-to-linalg))" -o linalg.mlir | ||
// RUN: mlir-opt linalg.mlir --linalg-fuse-elementwise-ops --eliminate-empty-tensors --empty-tensor-to-alloc-tensor --one-shot-bufferize="allow-return-allocs allow-unknown-ops bufferize-function-boundaries function-boundary-type-conversion=identity-layout-map" --drop-equivalent-buffer-results --buffer-results-to-out-params --buffer-deallocation --canonicalize --cse --convert-linalg-to-affine-loops --affine-super-vectorize="virtual-vector-size=16" -o affine.mlir | ||
// RUN: aie-opt affine.mlir --convert-vector-to-aievec="aie-target=aieml" -lower-affine -o aievec.mlir | ||
// RUN: aie-translate aievec.mlir -aieml=true --aievec-to-cpp -o dut.cc | ||
// RUN: xchesscc_wrapper aie2 -f -g +s +w work +o work -I%S -I. %S/testbench.cc dut.cc | ||
// RUN: mkdir -p data | ||
// RUN: xca_udm_dbg --aiearch aie-ml -qf -T -P %aietools/data/aie_ml/lib/ -t "%S/../profiling.tcl ./work/a.out" >& xca_udm_dbg.stdout | ||
// RUN: FileCheck --input-file=./xca_udm_dbg.stdout %s | ||
// CHECK: TEST PASSED | ||
|
||
module { | ||
func.func @dut(%arg0: tensor<1024xbf16>, %arg1: tensor<1024xf32>) -> (tensor<1024xf32>) { | ||
%1 = "tosa.cast" (%arg0) : (tensor<1024xbf16>) -> (tensor<1024xf32>) | ||
%2 = "tosa.sub"(%1,%arg1) : (tensor<1024xf32>, tensor<1024xf32>) -> (tensor<1024xf32>) | ||
return %2 : tensor<1024xf32> | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#pragma once | ||
constexpr unsigned const IN0_SIZE = 1024; | ||
constexpr unsigned const IN1_SIZE = 1024; | ||
constexpr unsigned const OUT0_SIZE = 1024; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// clang-format off | ||
void dut(bfloat16 * restrict v1, float * restrict v2, float * restrict v3) { | ||
size_t v4 = 0; | ||
size_t v5 = 1024; | ||
size_t v6 = 16; | ||
for (size_t v7 = v4; v7 < v5; v7 += v6) | ||
chess_prepare_for_pipelining | ||
chess_loop_range(64, 64) | ||
{ | ||
v16bfloat16 v8 = *(v16bfloat16 *)(v1 + v7); | ||
v16float v9 = *(v16float *)(v2 + v7); | ||
v16accfloat v10 = ups_to_v16accfloat(v8); | ||
v16accfloat v11 = v16accfloat(v9); | ||
v16accfloat v12 = sub(v10, v11); | ||
v16float v13 = v16float(v12); | ||
*(v16float *)(v3 + v7) = v13; | ||
} | ||
return; | ||
} | ||
// clang-format on |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#pragma once | ||
constexpr unsigned const IN0_SIZE = 1024; | ||
constexpr unsigned const IN1_SIZE = 1024; | ||
constexpr unsigned const OUT0_SIZE = 1024; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// clang-format off | ||
void dut(float * restrict v1, float * restrict v2, float * restrict v3) { | ||
size_t v4 = 0; | ||
size_t v5 = 1024; | ||
size_t v6 = 16; | ||
for (size_t v7 = v4; v7 < v5; v7 += v6) | ||
chess_prepare_for_pipelining | ||
chess_loop_range(64, 64) | ||
{ | ||
v16float v8 = *(v16float *)(v1 + v7); | ||
v16float v9 = *(v16float *)(v2 + v7); | ||
v16accfloat v10 = v16accfloat(v8); | ||
v16accfloat v11 = v16accfloat(v9); | ||
v16accfloat v12 = add(v10, v11); | ||
v16float v13 = v16float(v12); | ||
*(v16float *)(v3 + v7) = v13; | ||
} | ||
return; | ||
} | ||
// clang-format on |
20 changes: 20 additions & 0 deletions
20
test/Integration/Dialect/TOSA/floatxfloat_add_elem/floatxfloat_add_elem.mlir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// Copyright (C) 2023, Advanced Micro Devices, Inc. | ||
|
||
// REQUIRES: valid_xchess_license | ||
// RUN: mlir-opt %s --pass-pipeline="builtin.module(func.func(tosa-to-linalg-named, tosa-to-linalg))" -o linalg.mlir | ||
// RUN: mlir-opt linalg.mlir --linalg-fuse-elementwise-ops --eliminate-empty-tensors --empty-tensor-to-alloc-tensor --one-shot-bufferize="allow-return-allocs allow-unknown-ops bufferize-function-boundaries function-boundary-type-conversion=identity-layout-map" --drop-equivalent-buffer-results --buffer-results-to-out-params --buffer-deallocation --canonicalize --cse --convert-linalg-to-affine-loops --affine-super-vectorize="virtual-vector-size=16" -o affine.mlir | ||
// RUN: aie-opt affine.mlir --convert-vector-to-aievec="aie-target=aieml" -lower-affine | aie-translate -aieml=true --aievec-to-cpp -o dut.cc | ||
// RUN: xchesscc_wrapper aie2 -f -g +s +w work +o work -I%S -I. %S/testbench.cc dut.cc | ||
// RUN: mkdir -p data | ||
// RUN: xca_udm_dbg --aiearch aie-ml -qf -T -P %aietools/data/aie_ml/lib/ -t "%S/../profiling.tcl ./work/a.out" >& xca_udm_dbg.stdout | ||
// RUN: FileCheck --input-file=./xca_udm_dbg.stdout %s | ||
// CHECK: TEST PASSED | ||
|
||
module { | ||
func.func @dut(%arg0: tensor<1024xf32>, %arg1: tensor<1024xf32>) -> (tensor<1024xf32>) { | ||
%1 = "tosa.add"(%arg0,%arg1) : (tensor<1024xf32>, tensor<1024xf32>) -> (tensor<1024xf32>) | ||
return %1 : tensor<1024xf32> | ||
} | ||
} | ||
|
55 changes: 55 additions & 0 deletions
55
test/Integration/Dialect/TOSA/floatxfloat_add_elem/testbench.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include "../common/testbench.h" | ||
#include "defines.h" | ||
#include <algorithm> | ||
#include <cstdint> | ||
#include <cstdio> | ||
#include <cstdlib> | ||
void dut(float *restrict in0, float *restrict in1, float *restrict out0); | ||
void dut_ref(float *in0, float *in1, float *out0); | ||
|
||
alignas(32) float g_in0[IN0_SIZE]; | ||
alignas(32) float g_in1[IN1_SIZE]; | ||
alignas(32) float g_out0[OUT0_SIZE]; | ||
alignas(32) float g_out0Ref[OUT0_SIZE]; | ||
|
||
int main(int argc, char *argv[]) { | ||
std::string dataDir(TO_STR(DATA_DIR)); | ||
srand(10); | ||
std::generate(g_in0, g_in0 + IN0_SIZE, | ||
[&]() { return random_float(-80, 80, 10); }); | ||
std::generate(g_in1, g_in1 + IN1_SIZE, | ||
[&]() { return random_float(-80, 80, 10); }); | ||
|
||
writeData(g_in0, IN0_SIZE, dataDir + "/in0.txt"); | ||
writeData(g_in1, IN1_SIZE, dataDir + "/in1.txt"); | ||
|
||
chess_memory_fence(); | ||
auto cyclesBegin = chess_cycle_count(); | ||
dut(g_in0, g_in1, g_out0); | ||
auto cyclesEnd = chess_cycle_count(); | ||
chess_memory_fence(); | ||
|
||
auto cycleCount = (int)(cyclesEnd - cyclesBegin); | ||
reportCycleCount(cycleCount, dataDir + "/cycle_count.txt"); | ||
|
||
writeData(g_out0, OUT0_SIZE, dataDir + "/out0.txt"); | ||
|
||
dut_ref(g_in0, g_in1, g_out0Ref); | ||
writeData(g_out0Ref, OUT0_SIZE, dataDir + "/out0_ref.txt"); | ||
|
||
bool ok = true; | ||
ok &= checkData(g_out0, g_out0Ref, OUT0_SIZE, 0, 1e-2, 1e-2); | ||
|
||
if (ok) | ||
printf("TEST PASSED\n"); | ||
else | ||
printf("TEST FAILED\n"); | ||
|
||
return ok ? 0 : 1; | ||
} | ||
|
||
void dut_ref(float *in0, float *in1, float *out0) { | ||
for (unsigned k = 0; k < OUT0_SIZE; k += 1) { | ||
out0[k] = in0[k] + in1[k]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#pragma once | ||
constexpr unsigned const IN0_SIZE = 1024; | ||
constexpr unsigned const IN1_SIZE = 1024; | ||
constexpr unsigned const OUT0_SIZE = 1024; |
Oops, something went wrong.