-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Vectorization] Add Gcc loops benchmarks (#56)
* Add `GccLoop*` case * Add reference to gcc-loops in README
- Loading branch information
1 parent
3a0b816
commit 9f23d02
Showing
43 changed files
with
2,730 additions
and
2 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,34 @@ | ||
//===- MLIRGccLoopsEx1.mlir ----------------------------------------------------===// | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file provides the MLIR GccLoopsEx1 function. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
|
||
func.func @mlir_gccloopsex1(%A: memref<?xi32>, %B: memref<?xi32>, | ||
%C: memref<?xi32>) { | ||
%c0 = arith.constant 0 : index | ||
%c1 = arith.constant 1 : index | ||
%n = memref.dim %B, %c0 : memref<?xi32> | ||
scf.for %i = %c0 to %n step %c1 { | ||
%b_val = memref.load %B[%i] : memref<?xi32> | ||
%c_val = memref.load %C[%i] : memref<?xi32> | ||
%result = arith.addi %b_val, %c_val : i32 | ||
memref.store %result, %A[%i] : memref<?xi32> | ||
} | ||
return | ||
} |
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,43 @@ | ||
//===- MLIRGccLoopsEx10a.mlir ----------------------------------------------------===// | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file provides the MLIR GccLoopsEx10a function. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
func.func @mlir_gccloopsex10a(%sa: memref<?xi16>, %sb: memref<?xi16>, %sc: memref<?xi16>, | ||
%ia: memref<?xi32>, %ib: memref<?xi32>, %ic: memref<?xi32>) { | ||
%c0 = arith.constant 0 : index | ||
%c1 = arith.constant 1 : index | ||
%c10 = arith.constant 10 : index | ||
|
||
scf.for %iv = %c0 to %c10 step %c1{ | ||
%ib_value = memref.load %ib[%iv] : memref<?xi32> | ||
%ic_value = memref.load %ic[%iv] : memref<?xi32> | ||
%sum_ib_ic = arith.addi %ib_value, %ic_value : i32 | ||
memref.store %sum_ib_ic, %ia[%iv] : memref<?xi32> | ||
|
||
%sb_value = memref.load %sb[%iv] : memref<?xi16> | ||
%sc_value = memref.load %sc[%iv] : memref<?xi16> | ||
%sum_sb_sc = arith.addi %sb_value, %sc_value : i16 | ||
memref.store %sum_sb_sc, %sa[%iv] : memref<?xi16> | ||
} | ||
return | ||
} | ||
|
||
|
||
|
||
|
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,88 @@ | ||
//===- MLIRGccLoopsEx10aBenchmark.cpp --------------------------------------------===// | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file implements the benchmark for buddy-opt tool in buddy-mlir project. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include <benchmark/benchmark.h> | ||
#include <buddy/Core/Container.h> | ||
#include <iostream> | ||
|
||
// Declare the gccloopsex10a C interface. | ||
extern "C" { | ||
void _mlir_ciface_mlir_gccloopsex10a(MemRef<short, 1> *sa, MemRef<short, 1> *sb, MemRef<short, 1> *sc, | ||
MemRef<int, 1> *ia, MemRef<int, 1> *ib, MemRef<int, 1> *ic); | ||
} | ||
|
||
// Define input and output sizes. | ||
intptr_t sizesInputArrayMLIRGccLoopsEx10a[1] = {10}; | ||
intptr_t sizesOutputArrayMLIRGccLoopsEx10a[1] = {10}; | ||
// Define the MemRef container for inputs and outputs. | ||
int input1i_data_ex10a[10] = {1,2,3,4,5,6,7,8,9,10}; | ||
int input2i_data_ex10a[10] = {1,1,1,1,1,1,1,1,1,1}; | ||
short input1s_data_ex10a[10] = {1,2,3,4,5,6,7,8,9,10}; | ||
short input2s_data_ex10a[10] = {1,1,1,1,1,1,1,1,1,1}; | ||
MemRef<int, 1> input1iMLIRGccLoopsEx10a(input1i_data_ex10a, sizesInputArrayMLIRGccLoopsEx10a); | ||
MemRef<int, 1> input2iMLIRGccLoopsEx10a(input2i_data_ex10a, sizesInputArrayMLIRGccLoopsEx10a); | ||
MemRef<int, 1> outputiMLIRGccLoopsEx10a(sizesOutputArrayMLIRGccLoopsEx10a, 0); | ||
MemRef<short, 1> input1sMLIRGccLoopsEx10a(input1s_data_ex10a, sizesInputArrayMLIRGccLoopsEx10a); | ||
MemRef<short, 1> input2sMLIRGccLoopsEx10a(input2s_data_ex10a, sizesInputArrayMLIRGccLoopsEx10a); | ||
MemRef<short, 1> outputsMLIRGccLoopsEx10a(sizesOutputArrayMLIRGccLoopsEx10a, 0); | ||
|
||
static void MLIR_GccLoopsEx10a(benchmark::State &state) { | ||
for (auto _ : state) { | ||
for (int i = 0; i < state.range(0); ++i) { | ||
_mlir_ciface_mlir_gccloopsex10a(&outputsMLIRGccLoopsEx10a, &input1sMLIRGccLoopsEx10a, &input2sMLIRGccLoopsEx10a, | ||
&outputiMLIRGccLoopsEx10a, &input1iMLIRGccLoopsEx10a, &input2iMLIRGccLoopsEx10a); | ||
} | ||
} | ||
} | ||
|
||
// Register benchmarking function. | ||
BENCHMARK(MLIR_GccLoopsEx10a)->Arg(1); | ||
|
||
// Generate result image. | ||
void generateResultMLIRGccLoopsEx10a() { | ||
// Define the MemRef descriptor for inputs and outputs. | ||
int input1i_data_ex10a[10] = {1,2,3,4,5,6,7,8,9,10}; | ||
int input2i_data_ex10a[10] = {1,1,1,1,1,1,1,1,1,1}; | ||
short input1s_data_ex10a[10] = {2,3,4,5,6,7,8,9,10,11}; | ||
short input2s_data_ex10a[10] = {1,1,1,1,1,1,1,1,1,1}; | ||
MemRef<int, 1> input1i(input1i_data_ex10a, sizesInputArrayMLIRGccLoopsEx10a); | ||
MemRef<int, 1> input2i(input2i_data_ex10a, sizesInputArrayMLIRGccLoopsEx10a); | ||
MemRef<int, 1> outputi(sizesOutputArrayMLIRGccLoopsEx10a, 0); | ||
MemRef<short, 1> input1s(input1s_data_ex10a, sizesInputArrayMLIRGccLoopsEx10a); | ||
MemRef<short, 1> input2s(input2s_data_ex10a, sizesInputArrayMLIRGccLoopsEx10a); | ||
MemRef<short, 1> outputs(sizesOutputArrayMLIRGccLoopsEx10a, 0); | ||
// Run the gccloopsex10a. | ||
_mlir_ciface_mlir_gccloopsex10a(&outputs, &input1s, &input2s, | ||
&outputi, &input1i, &input2i); | ||
// Print the output. | ||
std::cout << "--------------------------------------------------------" | ||
<< std::endl; | ||
std::cout << "MLIR_GccLoopsEx10a: MLIR GccLoopsEx10a Operation" << std::endl; | ||
std::cout << "[ "; | ||
for (size_t i = 0; i < outputi.getSize(); i++) { | ||
std::cout << outputi.getData()[i] << " "; | ||
} | ||
std::cout << "]" << std::endl; | ||
std::cout << "[ "; | ||
for (size_t i = 0; i < outputs.getSize(); i++) { | ||
std::cout << outputs.getData()[i] << " "; | ||
} | ||
std::cout << "]" << std::endl; | ||
} |
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,36 @@ | ||
//===- MLIRGccLoopsEx10b.mlir ----------------------------------------------------===// | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file provides the MLIR GccLoopsEx10b function. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
func.func @mlir_gccloopsex10b(%sb: memref<?xi16>, %ia: memref<?xi32>) { | ||
%c0 = arith.constant 0 : index | ||
%c1 = arith.constant 1 : index | ||
%c10 = arith.constant 10 : index | ||
|
||
scf.for %iv = %c0 to %c10 step %c1{ | ||
%sb_value = memref.load %sb[%iv] : memref<?xi16> | ||
%sb_value_exti = arith.extsi %sb_value : i16 to i32 | ||
memref.store %sb_value_exti, %ia[%iv] : memref<?xi32> | ||
} | ||
return | ||
} | ||
|
||
|
||
|
||
|
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,66 @@ | ||
//===- MLIRGccLoopsEx10bBenchmark.cpp --------------------------------------------===// | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file implements the benchmark for buddy-opt tool in buddy-mlir project. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include <benchmark/benchmark.h> | ||
#include <buddy/Core/Container.h> | ||
#include <iostream> | ||
|
||
// Declare the gccloopsex10b C interface. | ||
extern "C" { | ||
void _mlir_ciface_mlir_gccloopsex10b(MemRef<short, 1> *sb, MemRef<int, 1> *ia); | ||
} | ||
|
||
// Define input and output sizes. | ||
intptr_t sizesInputArrayMLIRGccLoopsEx10b[1] = {10}; | ||
intptr_t sizesOutputArrayMLIRGccLoopsEx10b[1] = {10}; | ||
// Define the MemRef container for input and output. | ||
short input_data_ex10b[10] = {1,2,3,4,5,6,7,8,9,10}; | ||
MemRef<short, 1> inputMLIRGccLoopsEx10b(input_data_ex10b, sizesInputArrayMLIRGccLoopsEx10b); | ||
MemRef<int, 1> outputMLIRGccLoopsEx10b(sizesOutputArrayMLIRGccLoopsEx10b, 0); | ||
|
||
static void MLIR_GccLoopsEx10b(benchmark::State &state) { | ||
for (auto _ : state) { | ||
for (int i = 0; i < state.range(0); ++i) { | ||
_mlir_ciface_mlir_gccloopsex10b(&inputMLIRGccLoopsEx10b, &outputMLIRGccLoopsEx10b); | ||
} | ||
} | ||
} | ||
|
||
// Register benchmarking function. | ||
BENCHMARK(MLIR_GccLoopsEx10b)->Arg(1); | ||
|
||
// Generate result image. | ||
void generateResultMLIRGccLoopsEx10b() { | ||
// Define the MemRef descriptor for input and output. | ||
short input_data_ex10b[10] = {1,2,3,4,5,6,7,8,9,10}; | ||
MemRef<short, 1> input(input_data_ex10b, sizesInputArrayMLIRGccLoopsEx10b); | ||
MemRef<int, 1> output(sizesOutputArrayMLIRGccLoopsEx10b, 0); | ||
// Run the gccloopsex10b. | ||
_mlir_ciface_mlir_gccloopsex10b(&input, &output); | ||
// Print the output. | ||
std::cout << "--------------------------------------------------------" | ||
<< std::endl; | ||
std::cout << "MLIR_GccLoopsEx10b: MLIR GccLoopsEx10b Operation" << std::endl; | ||
std::cout << "[ "; | ||
for (size_t i = 0; i < output.getSize(); i++) { | ||
std::cout << output.getData()[i] << " "; | ||
} | ||
std::cout << "]" << std::endl; | ||
} |
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,49 @@ | ||
//===- MLIRGccLoopsEx11.mlir ----------------------------------------------------===// | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file provides the MLIR GccLoopsEx11 function. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
func.func @mlir_gccloopsex11(%A: memref<?xi32>, %B: memref<?xi32>, | ||
%C: memref<?xi32>, %D: memref<?xi32>) { | ||
%c0 = arith.constant 0 : index | ||
%c1 = arith.constant 1 : index | ||
%c2 = arith.constant 2 : index | ||
%c5 = arith.constant 5 : index | ||
|
||
scf.for %iv = %c0 to %c5 step %c1{ | ||
%two_iv = arith.muli %iv, %c2 : index | ||
%two_iv_1 = arith.addi %two_iv, %c1 : index | ||
%b_2_iv = memref.load %B[%two_iv] : memref<?xi32> | ||
%b_2_iv_1 = memref.load %B[%two_iv_1] : memref<?xi32> | ||
%c_2_iv = memref.load %C[%two_iv] : memref<?xi32> | ||
%c_2_iv_1 = memref.load %C[%two_iv_1] : memref<?xi32> | ||
%temp1 = arith.muli %b_2_iv_1, %c_2_iv_1 : i32 | ||
%temp2 = arith.muli %b_2_iv, %c_2_iv : i32 | ||
%a_value = arith.subi %temp1, %temp2 : i32 | ||
memref.store %a_value, %A[%iv] : memref<?xi32> | ||
%temp3 = arith.muli %b_2_iv, %c_2_iv_1 : i32 | ||
%temp4 = arith.muli %b_2_iv_1, %c_2_iv : i32 | ||
%d_value = arith.subi %temp3, %temp4 : i32 | ||
memref.store %d_value, %D[%iv] : memref<?xi32> | ||
} | ||
return | ||
} | ||
|
||
|
||
|
||
|
Oops, something went wrong.