-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'buddy-compiler:main' into LeNet-GPU
- Loading branch information
Showing
45 changed files
with
5,449 additions
and
504 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
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,75 @@ | ||
// RUN: buddy-opt %s \ | ||
// RUN: -matmul-transpose-b-vectorization \ | ||
// RUN: -convert-linalg-to-affine-loops \ | ||
// RUN: -lower-affine \ | ||
// RUN: -convert-vector-to-scf \ | ||
// RUN: -convert-scf-to-cf \ | ||
// RUN: -convert-vector-to-llvm \ | ||
// RUN: -convert-math-to-llvm \ | ||
// RUN: -convert-math-to-libm \ | ||
// RUN: -convert-arith-to-llvm \ | ||
// RUN: -convert-func-to-llvm \ | ||
// RUN: -expand-strided-metadata \ | ||
// RUN: -finalize-memref-to-llvm \ | ||
// RUN: -reconcile-unrealized-casts \ | ||
// RUN: | mlir-cpu-runner -e main -entry-point-result=void \ | ||
// RUN: -shared-libs=%mlir_runner_utils_dir/libmlir_runner_utils%shlibext \ | ||
// RUN: -shared-libs=%mlir_runner_utils_dir/libmlir_c_runner_utils%shlibext \ | ||
// RUN: | FileCheck %s | ||
|
||
func.func private @printMemrefF32(memref<*xf32>) | ||
|
||
func.func @test(%a : memref<?x?xf32>, %b : memref<?x?xf32>, %c : memref<?x?xf32>) { | ||
linalg.matmul_transpose_b | ||
ins(%a, %b: memref<?x?xf32>, memref<?x?xf32>) | ||
outs(%c: memref<?x?xf32>) | ||
return | ||
} | ||
|
||
func.func @alloc_f32(%arg0: index, %arg1: index, %arg4: f32) -> memref<?x?xf32> { | ||
%c0 = arith.constant 0 : index | ||
%c1 = arith.constant 1 : index | ||
%0 = memref.alloc(%arg0, %arg1) : memref<?x?xf32> | ||
scf.for %idx0 = %c0 to %arg0 step %c1 { | ||
scf.for %idx1 = %c0 to %arg1 step %c1 { | ||
memref.store %arg4, %0[%idx0, %idx1] : memref<?x?xf32> | ||
} | ||
} | ||
return %0 : memref<?x?xf32> | ||
} | ||
|
||
func.func @main(){ | ||
%c32 = arith.constant 32 : index | ||
%c1024 = arith.constant 1024 : index | ||
%c3 = arith.constant 3 : index | ||
%f0 = arith.constant 0.0 : f32 | ||
%f1 = arith.constant 1.0 : f32 | ||
|
||
%m0 = call @alloc_f32(%c32,%c1024, %f1) : (index, index, f32) -> memref<?x?xf32> | ||
%m1 = call @alloc_f32(%c32,%c1024, %f1) : (index, index, f32) -> memref<?x?xf32> | ||
%m2 = call @alloc_f32(%c32,%c32, %f0) : (index, index, f32) -> memref<?x?xf32> | ||
|
||
call @test(%m0, %m1, %m2) : (memref<?x?xf32>, memref<?x?xf32>, memref<?x?xf32>) -> () | ||
|
||
%printed_m2 = memref.cast %m2 : memref<?x?xf32> to memref<*xf32> | ||
|
||
// CHECK: Unranked Memref base@ = {{.*}} rank = 2 offset = 0 sizes = [32, 32] strides = [32, 1] data = | ||
// CHECK-NEXT: [ | ||
// CHECK: [1024{{(, 1024)*}}] | ||
call @printMemrefF32(%printed_m2) : (memref<*xf32>) -> () | ||
|
||
%m3 = call @alloc_f32(%c3,%c3, %f1) : (index, index, f32) -> memref<?x?xf32> | ||
%m4 = call @alloc_f32(%c3,%c3, %f1) : (index, index, f32) -> memref<?x?xf32> | ||
%m5 = call @alloc_f32(%c3,%c3, %f0) : (index, index, f32) -> memref<?x?xf32> | ||
|
||
call @test(%m3, %m4, %m5) : (memref<?x?xf32>, memref<?x?xf32>, memref<?x?xf32>) -> () | ||
|
||
%printed_m5 = memref.cast %m5 : memref<?x?xf32> to memref<*xf32> | ||
|
||
// CHECK: Unranked Memref base@ = {{.*}} rank = 2 offset = 0 sizes = [3, 3] strides = [3, 1] data = | ||
// CHECK-NEXT: [ | ||
// CHECK: [3{{(, 3)*}}] | ||
call @printMemrefF32(%printed_m5) : (memref<*xf32>) -> () | ||
|
||
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
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
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
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,75 @@ | ||
//===- RFFT.cpp - Example of DAP RFFT Operation ---------------------------===// | ||
// | ||
// 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. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// An example of the RFFT function from Whisper Preprocessor operation. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include <buddy/DAP/DAP.h> | ||
#include <chrono> | ||
#include <fstream> | ||
#include <iostream> | ||
|
||
#define testLength 840 | ||
|
||
using namespace dap; | ||
using namespace std; | ||
|
||
// Print [Log] label in bold blue format. | ||
void printLogLabel() { std::cout << "\033[34;1m[Log] \033[0m"; } | ||
|
||
// Write preprocessing results to a text file. | ||
void printResult(MemRef<double, 1> &outputMemRef) { | ||
ofstream fout("whisperPreprocessResultRFFT.txt"); | ||
// Print title. | ||
fout << "-----------------------------------------" << std::endl; | ||
fout << "[ Buddy RFFT Result ]" << std::endl; | ||
fout << "-----------------------------------------" << std::endl; | ||
// Print reuslt data. | ||
for (int i = 0; i < testLength; ++i) { | ||
fout << outputMemRef[i] << std::endl; | ||
} | ||
fout.close(); | ||
} | ||
|
||
int main() { | ||
// Print the title of this example. | ||
const std::string title = "RFFT Operation Powered by Buddy Compiler"; | ||
std::cout << "\033[33;1m" << title << "\033[0m" << std::endl; | ||
|
||
double *inputAlign = new double[testLength]; | ||
for (int i = 0; i < testLength; ++i) { | ||
inputAlign[i] = static_cast<double>(i); | ||
} | ||
intptr_t inputSizes[1] = {testLength}; | ||
MemRef<double, 1> inputMemRef(inputAlign, inputSizes); | ||
|
||
printLogLabel(); | ||
std::cout << "Running RFFT operation" << std::endl; | ||
const auto loadStart = std::chrono::high_resolution_clock::now(); | ||
dap::RFFT(&inputMemRef); | ||
const auto loadEnd = std::chrono::high_resolution_clock::now(); | ||
const std::chrono::duration<double, std::milli> loadTime = | ||
loadEnd - loadStart; | ||
printLogLabel(); | ||
std::cout << "RFFT time: " << (double)(loadTime.count()) / 1000 | ||
<< "s\n" | ||
<< std::endl; | ||
|
||
printResult(inputMemRef); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.