Skip to content

Commit

Permalink
Merge branch 'buddy-compiler:main' into compareImg_dev
Browse files Browse the repository at this point in the history
  • Loading branch information
taiqzheng authored Jun 15, 2023
2 parents 5195a53 + 43bdf3f commit 6c1d11b
Show file tree
Hide file tree
Showing 34 changed files with 2,351 additions and 261 deletions.
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ set(BUDDY_OPT_TRIPLE x86_64-unknown-linux-gnu CACHE STRING "Target Triple.")
message(STATUS "Configuring Target Architecture: ${BUDDY_OPT_ATTR}")
message(STATUS "Configuring Target Triple: ${BUDDY_OPT_TRIPLE}")

set(BUILD_TESTS OFF CACHE BOOL "Build tests")
set(BUILD_VALIDATION OFF CACHE BOOL "Build validations")
set(BUILD_CORRECTNESS OFF CACHE BOOL "Build correctness checking")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BUDDY_BINARY_DIR})

# Add BUDDY files to the include path
include_directories(${BUDDY_MAIN_INCLUDE_DIR})
include_directories(${BUDDY_MLIR_INTERFACE_DIR})
include_directories(${BUDDY_THIRDPARTY_INCLUDE_DIR})

# MLIR binary directory.
set(LLVM_MLIR_BINARY_DIR ${BUDDY_MLIR_BUILD_DIR}/../llvm/build/bin)
Expand Down Expand Up @@ -111,3 +115,8 @@ check_simd()

add_subdirectory(benchmarks)
add_subdirectory(utils)

if (BUILD_VALIDATION)
add_subdirectory(validation)
endif()

40 changes: 22 additions & 18 deletions benchmarks/AudioProcessing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ add_subdirectory(${KFR_DIR} ./kfr)
include_directories(${KFR_DIR}/include)

#-------------------------------------------------------------------------------
# DAP Dialect Buddy Biquad Operation
# MLIR Biquad Operation
#-------------------------------------------------------------------------------

add_custom_command(OUTPUT buddy-biquad.o
add_custom_command(OUTPUT mlir-biquad.o
COMMAND ${BUDDY_MLIR_BUILD_DIR}/bin/buddy-opt
${BUDDY_SOURCE_DIR}/benchmarks/AudioProcessing/BuddyBiquad.mlir
-lower-dap="DAP-vector-splitting=${SPLITING_SIZE}" -convert-linalg-to-affine-loops
${BUDDY_SOURCE_DIR}/benchmarks/AudioProcessing/MLIRBiquad.mlir
-convert-linalg-to-affine-loops
-lower-affine -convert-scf-to-cf -convert-vector-to-llvm
--llvm-request-c-wrappers
-convert-arith-to-llvm
Expand All @@ -45,21 +45,21 @@ add_custom_command(OUTPUT buddy-biquad.o
${LLVM_MLIR_BINARY_DIR}/mlir-translate --mlir-to-llvmir |
${LLVM_MLIR_BINARY_DIR}/llc -mtriple=${BUDDY_OPT_TRIPLE}
-mattr=${BUDDY_OPT_ATTR} --filetype=obj
-o ${BUDDY_BINARY_DIR}/../benchmarks/AudioProcessing/buddy-biquad.o
-o ${BUDDY_BINARY_DIR}/../benchmarks/AudioProcessing/mlir-biquad.o
)
add_library(BuddyBiquad STATIC buddy-biquad.o)
set_target_properties(BuddyBiquad PROPERTIES LINKER_LANGUAGE CXX)
add_library(MLIRBiquad STATIC mlir-biquad.o)
set_target_properties(MLIRBiquad PROPERTIES LINKER_LANGUAGE CXX)

#-------------------------------------------------------------------------------
# DAP Dialect Buddy IIR Operation
# MLIR IIR Operation
#-------------------------------------------------------------------------------

# TODO:
# Support only when input audio size is multiple of splitting size.
# Add a support for all input audio size.
add_custom_command(OUTPUT buddy-iir.o
add_custom_command(OUTPUT mlir-iir.o
COMMAND ${BUDDY_MLIR_BUILD_DIR}/bin/buddy-opt
${BUDDY_SOURCE_DIR}/benchmarks/AudioProcessing/BuddyIir.mlir
${BUDDY_SOURCE_DIR}/benchmarks/AudioProcessing/MLIRIir.mlir
-lower-dap="DAP-vector-splitting=64" -convert-linalg-to-affine-loops
-lower-affine
-convert-scf-to-cf
Expand All @@ -71,27 +71,31 @@ add_custom_command(OUTPUT buddy-iir.o
${LLVM_MLIR_BINARY_DIR}/mlir-translate --mlir-to-llvmir |
${LLVM_MLIR_BINARY_DIR}/llc -mtriple=${BUDDY_OPT_TRIPLE}
-mattr=${BUDDY_OPT_ATTR} --filetype=obj
-o ${BUDDY_BINARY_DIR}/../benchmarks/AudioProcessing/buddy-iir.o
-o ${BUDDY_BINARY_DIR}/../benchmarks/AudioProcessing/mlir-iir.o
)
add_library(BuddyIir STATIC buddy-iir.o)
set_target_properties(BuddyIir PROPERTIES LINKER_LANGUAGE CXX)

add_library(MLIRIir STATIC mlir-iir.o)
set_target_properties(MLIRIir PROPERTIES LINKER_LANGUAGE CXX)
add_executable(audio-processing-benchmark
KFRFft.cpp
KFRFir.cpp
KFRIir.cpp
KFRBiquad.cpp
BuddyBiquadBenchmark.cpp
BuddyIirBenchmark.cpp
Main.cpp
)

target_link_directories(audio-processing-benchmark PRIVATE ${KFR_DIR}/build/)
target_link_directories(audio-processing-benchmark
PRIVATE
${KFR_DIR}/build/
${BUDDY_MLIR_LIB_DIR}
)

target_link_libraries(audio-processing-benchmark
PRIVATE
kfr_io
kfr_dft
BuddyBiquad
BuddyIir
MLIRBiquad
MLIRIir
BuddyLibDAP
GoogleBenchmark
)
2 changes: 1 addition & 1 deletion benchmarks/AudioProcessing/KFRFft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ void generateResultKFRFft() {
println("-------------------------------------------------------");
println("[ KFR FFT Result Information ]");
println("FFT operation finished!");
}
}
72 changes: 0 additions & 72 deletions benchmarks/AudioProcessing/KFRFir.cpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,3 @@ func.func @mlir_biquad(%in : memref<?xf32>, %filter : memref<?xf32>, %out : memr
}
return
}

func.func @buddy_biquad(%in : memref<?xf32>, %filter : memref<?xf32>, %out : memref<?xf32>) -> () {
dap.biquad %in, %filter, %out : memref<?xf32>, memref<?xf32>, memref<?xf32>
return
}
25 changes: 25 additions & 0 deletions benchmarks/AudioProcessing/MLIRFir.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//===- BuddyFir.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 Fir (Conv 1d) function.
//
//===----------------------------------------------------------------------===//

func.func @conv1d_linalg(%in : memref<?xf32>, %filter : memref<?xf32>, %out : memref<?xf32>) -> () {
linalg.conv_1d ins(%in, %filter : memref<?xf32>, memref<?xf32>)
outs(%out : memref<?xf32>)
return
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,3 @@ func.func @mlir_iir(%in : memref<?xf32>, %filter : memref<?x?xf32>, %out : memre
}
return
}

func.func @buddy_iir(%in : memref<?xf32>, %filter : memref<?x?xf32>, %out : memref<?xf32>) -> () {
dap.iir %in, %filter, %out : memref<?xf32>, memref<?x?xf32>, memref<?xf32>
return
}
4 changes: 0 additions & 4 deletions benchmarks/AudioProcessing/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,19 @@

#include <benchmark/benchmark.h>

void initializeKFRFir();
void initializeKFRBiquad();
void initializeKFRFft();
void initializeKFRIir();
void initializeBuddyBiquad();
void initializeBuddyIir();

void generateResultKFRFir();
void generateResultKFRBiquad();
void generateResultKFRFft();
void generateResultKFRIir();
void generateResultBuddyBiquad();
void generateResultBuddyIir();

int main(int argc, char **argv) {
initializeKFRFir();
initializeKFRBiquad();
initializeKFRFft();
initializeKFRIir();
Expand All @@ -45,7 +42,6 @@ int main(int argc, char **argv) {
::benchmark::Initialize(&argc, argv);
::benchmark::RunSpecifiedBenchmarks();

generateResultKFRFir();
generateResultKFRBiquad();
generateResultKFRFft();
generateResultKFRIir();
Expand Down
1 change: 1 addition & 0 deletions benchmarks/DeepLearning/Models/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ add_subdirectory(ResNet-V2-50)
add_subdirectory(MobileNet-V3)
add_subdirectory(Inception-V3)
add_subdirectory(ResNet-18)
add_subdirectory(EfficientNet-Quant)
46 changes: 46 additions & 0 deletions benchmarks/DeepLearning/Models/EfficientNet-Quant/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
set(QUANT_TOSA_PIPELINE "builtin.module(func.func(tosa-to-linalg-named),func.func(tosa-to-linalg),func.func(tosa-to-tensor))")

# Compile MLIR file to object file.
add_custom_command(OUTPUT efficientnet-quant.o
COMMAND
${LLVM_MLIR_BINARY_DIR}/mlir-opt ${CMAKE_CURRENT_SOURCE_DIR}/efficientnet.mlir
--pass-pipeline="${QUANT_TOSA_PIPELINE}" |
${LLVM_MLIR_BINARY_DIR}/mlir-opt
--tosa-to-arith="include-apply-rescale=1"
--test-linalg-transform-patterns="test-generalize-pad-tensor"
--linalg-bufferize
--convert-linalg-to-loops
--func-bufferize
--arith-bufferize
--tensor-bufferize
--finalizing-bufferize
--convert-vector-to-scf
--convert-scf-to-cf
--expand-strided-metadata
--lower-affine
--convert-vector-to-llvm
--memref-expand
--arith-expand
--convert-arith-to-llvm
--finalize-memref-to-llvm
--convert-math-to-llvm
--llvm-request-c-wrappers
--convert-func-to-llvm
--reconcile-unrealized-casts |
${LLVM_MLIR_BINARY_DIR}/mlir-translate --mlir-to-llvmir |
${LLVM_MLIR_BINARY_DIR}/llc -mtriple=${BUDDY_OPT_TRIPLE} -mattr=${BUDDY_OPT_ATTR}
--filetype=obj -o ${CMAKE_CURRENT_BINARY_DIR}/efficientnet-quant.o
)

add_library(EfficientNetQuant STATIC efficientnet-quant.o)
set_target_properties(EfficientNetQuant PROPERTIES LINKER_LANGUAGE CXX)

add_executable(efficientnet-quant-benchmark Main.cpp EfficientNetQuantBenchmark.cpp)
# Link libraries
target_link_directories(efficientnet-quant-benchmark PRIVATE ${LLVM_MLIR_LIBRARY_DIR})
target_link_libraries(efficientnet-quant-benchmark
EfficientNetQuant
GoogleBenchmark
mlir_c_runner_utils
${OpenCV_LIBS}
)
Loading

0 comments on commit 6c1d11b

Please sign in to comment.