Skip to content

Commit

Permalink
Merge branch 'main' into sum-pooling-bench
Browse files Browse the repository at this point in the history
  • Loading branch information
axmat authored Mar 20, 2022
2 parents 4ada498 + e511e25 commit 65f6023
Show file tree
Hide file tree
Showing 20 changed files with 229 additions and 16 deletions.
27 changes: 27 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior.

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. Ubuntu]
- Version [e.g. 20.04]

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context about the feature request here.
14 changes: 9 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ endif()

project(buddy-benchmark LANGUAGES CXX C)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_FLAGS "-no-pie")
set(CMAKE_C_FLAGS "-no-pie")
Expand Down Expand Up @@ -104,15 +104,19 @@ endif()
# Find OpenCV
#-------------------------------------------------------------------------------

find_package(OpenCV REQUIRED CONFIG)
include_directories(${OpenCV_INCLUDE_DIRS})
if(DEFINED IMAGE_PROCESSING_BENCHMARKS OR DEEP_LEARNING_BENCHMARKS)
find_package(OpenCV REQUIRED CONFIG)
include_directories(${OpenCV_INCLUDE_DIRS})
endif()

#-------------------------------------------------------------------------------
# Find PNG
#-------------------------------------------------------------------------------

find_package(PNG REQUIRED)
include_directories(${PNG_INCLUDE_DIR})
if(DEFINED IMAGE_PROCESSING_BENCHMARKS OR DEEP_LEARNING_BENCHMARKS)
find_package(PNG REQUIRED)
include_directories(${PNG_INCLUDE_DIR})
endif()

#-------------------------------------------------------------------------------
# Hardware detection
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,24 @@ Run the DepthwiseConv2DNhwcHwc operation benchmark:
$ cd <path to build>/bin && ./depthwise-conv-2d-nhwc-hwc-benchmark
```

## Audio Processing Benchmark

Currently, the audio processing benchmark includes the following frameworks or optimizers:

- KFR ([link](https://github.com/kfrlib/kfr))

*Note: Please replace the `/PATH/TO/*` with your local path.*

```
$ cd buddy-benchmark
$ mkdir build && cd build
$ cmake -G Ninja .. \
-DAUDIO_PROCESSING_BENCHMARKS=ON \
-DCMAKE_CXX_COMPILER=clang++ \
-DKFR_DIR=/PATH/TO/KFR/SOURCE/CODE \
$ ninja audio-processing-benchmark
```

## Testing

```
Expand Down
Binary file added benchmarks/AudioProcessing/Audios/NASA_Mars.wav
Binary file not shown.
20 changes: 20 additions & 0 deletions benchmarks/AudioProcessing/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#-------------------------------------------------------------------------------
# Audio Processing Benchmark Target
#-------------------------------------------------------------------------------

add_subdirectory(${KFR_DIR} ./kfr)

include_directories(${KFR_DIR}/include)

add_executable(audio-processing-benchmark
KFRFir.cpp
Main.cpp
)

target_link_directories(audio-processing-benchmark PRIVATE ${KFR_DIR}/build/)
target_link_libraries(audio-processing-benchmark
PRIVATE
kfr_io
kfr_dft
GoogleBenchmark
)
70 changes: 70 additions & 0 deletions benchmarks/AudioProcessing/KFRFir.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//===- KFRFir.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 KFR Fir function.
//
//===----------------------------------------------------------------------===//

#include <benchmark/benchmark.h>
#include <kfr/base.hpp>
#include <kfr/dft.hpp>
#include <kfr/dsp.hpp>
#include <kfr/io.hpp>

using namespace kfr;

univector<fbase, 1023> taps127;
univector<float, 2000000> aud;
univector<float> result;

// Initialize univector.
void initializeKFRFir() {
expression_pointer<fbase> kaiser =
to_pointer(window_kaiser(taps127.size(), 3.0));
fir_lowpass(taps127, 0.2, kaiser, true);
audio_reader_wav<float> reader(open_file_for_reading(
"../../benchmarks/AudioProcessing/Audios/NASA_Mars.wav"));
reader.read(aud.data(), aud.size());
}

// Benchmarking function.
static void KFR_FIR(benchmark::State &state) {
for (auto _ : state) {
for (int i = 0; i < state.range(0); ++i) {
result = kfr::fir(aud, taps127);
}
}
}

// Register benchmarking function.
BENCHMARK(KFR_FIR)->Arg(1);

// Generate result wav file.
void generateResultKFRFir() {
univector<float> generateResult = kfr::fir(aud, taps127);

audio_writer_wav<float> writer(open_file_for_writing("./ResultKFRFir.wav"),
audio_format{1 /* channel */,
audio_sample_type::i24,
100000 /* sample rate */});
writer.write(generateResult.data(), generateResult.size());
println("Sample Rate = ", writer.format().samplerate);
println("Channels = ", writer.format().channels);
println("Length = ", writer.format().length);
println("Duration (s) = ",
writer.format().length / writer.format().samplerate);
println("Bit depth = ", audio_sample_bit_depth(writer.format().type));
}
33 changes: 33 additions & 0 deletions benchmarks/AudioProcessing/Main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//===- Main.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 is the main file of the audio processing benchmark.
//
//===----------------------------------------------------------------------===//

#include <benchmark/benchmark.h>

void initializeKFRFir();

void generateResultKFRFir();

int main(int argc, char **argv) {
initializeKFRFir();
::benchmark::Initialize(&argc, argv);
::benchmark::RunSpecifiedBenchmarks();
generateResultKFRFir();
return 0;
}
4 changes: 4 additions & 0 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ endif()
if(DEEP_LEARNING_BENCHMARKS)
add_subdirectory(DeepLearning)
endif()

if(AUDIO_PROCESSING_BENCHMARKS)
add_subdirectory(AudioProcessing)
endif()
2 changes: 1 addition & 1 deletion benchmarks/DeepLearning/Models/Inception-V3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ add_buddy_model_benchmark(inception-v3-benchmark
-memref-expand -arith-expand
--convert-memref-to-llvm
--convert-math-to-llvm
--convert-std-to-llvm='emit-c-wrappers=1'
--convert-func-to-llvm='emit-c-wrappers=1'
--reconcile-unrealized-casts
SOURCE Main.cpp InceptionBenchmark.cpp
)
2 changes: 1 addition & 1 deletion benchmarks/DeepLearning/Models/MobileNet-V2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ add_buddy_model_benchmark(mobilenet-benchmark
-memref-expand -arith-expand
--convert-memref-to-llvm
--convert-math-to-llvm
--convert-std-to-llvm='emit-c-wrappers=1'
--convert-func-to-llvm='emit-c-wrappers=1'
--reconcile-unrealized-casts
SOURCE Main.cpp MobileNetBenchmark.cpp
)
2 changes: 1 addition & 1 deletion benchmarks/DeepLearning/Models/MobileNet-V3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ add_buddy_model_benchmark(mobilenet-v3-benchmark
-memref-expand -arith-expand
--convert-memref-to-llvm
--convert-math-to-llvm
--convert-std-to-llvm='emit-c-wrappers=1'
--convert-func-to-llvm='emit-c-wrappers=1'
--reconcile-unrealized-casts
SOURCE Main.cpp MobileNetBenchmark.cpp
)
2 changes: 1 addition & 1 deletion benchmarks/DeepLearning/Models/ResNet-V2-50/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ add_buddy_model_benchmark(resnet_v2_50-benchmark
-memref-expand -arith-expand
--convert-memref-to-llvm
--convert-math-to-llvm
--convert-std-to-llvm='emit-c-wrappers=1'
--convert-func-to-llvm='emit-c-wrappers=1'
--reconcile-unrealized-casts
SOURCE Main.cpp ResNetBenchmark.cpp
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ add_buddy_ops_benchmark(conv-2d-nchw-fchw-benchmark
-convert-linalg-to-llvm
-lower-affine
--convert-memref-to-llvm
-convert-std-to-llvm='emit-c-wrappers=1'
-convert-func-to-llvm='emit-c-wrappers=1'
-reconcile-unrealized-casts
SOURCE Main.cpp MLIROptBenchmark.cpp
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ add_buddy_ops_benchmark(conv-2d-nhwc-hwcf-benchmark
-convert-linalg-to-llvm
-lower-affine
--convert-memref-to-llvm
-convert-std-to-llvm='emit-c-wrappers=1'
-convert-func-to-llvm='emit-c-wrappers=1'
-reconcile-unrealized-casts
SOURCE Main.cpp MLIROptBenchmark.cpp
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ add_buddy_ops_benchmark(depthwise-conv-2d-nhwc-hwc-benchmark
-convert-linalg-to-llvm
-lower-affine
--convert-memref-to-llvm
-convert-std-to-llvm='emit-c-wrappers=1'
-convert-func-to-llvm='emit-c-wrappers=1'
-reconcile-unrealized-casts
SOURCE Main.cpp MLIROptBenchmark.cpp
)
24 changes: 20 additions & 4 deletions benchmarks/ImageProcessing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ message(STATUS "Configuring MLIR Linalg Tile Size: ${MLIR_LINALG_TILE}")
add_custom_command(OUTPUT mlir-conv2d.o
COMMAND ${LLVM_MLIR_BINARY_DIR}/mlir-opt
${BUDDY_SOURCE_DIR}/benchmarks/ImageProcessing/MLIRConv2D.mlir
-linalg-tile="tile-sizes=${MLIR_LINALG_TILE},${MLIR_LINALG_TILE}"
-convert-linalg-to-loops
-convert-scf-to-cf -convert-linalg-to-llvm
-lower-affine -convert-scf-to-cf --convert-memref-to-llvm
-convert-std-to-llvm='emit-c-wrappers=1'
-convert-func-to-llvm='emit-c-wrappers=1'
-reconcile-unrealized-casts |
${LLVM_MLIR_BINARY_DIR}/mlir-translate --mlir-to-llvmir |
${LLVM_MLIR_BINARY_DIR}/llc -mtriple=${BUDDY_OPT_TRIPLE}
Expand All @@ -49,7 +48,7 @@ add_custom_command(OUTPUT buddy-conv2d.o
-conv-vectorization="strip-mining=${SPLITING_SIZE}"
-convert-vector-to-scf
-lower-affine -convert-scf-to-cf -convert-vector-to-llvm
-convert-memref-to-llvm -convert-std-to-llvm='emit-c-wrappers=1'
-convert-memref-to-llvm -convert-func-to-llvm='emit-c-wrappers=1'
-reconcile-unrealized-casts |
${LLVM_MLIR_BINARY_DIR}/mlir-translate --mlir-to-llvmir |
${LLVM_MLIR_BINARY_DIR}/llc -mtriple=${BUDDY_OPT_TRIPLE}
Expand All @@ -59,6 +58,23 @@ add_custom_command(OUTPUT buddy-conv2d.o
add_library(BuddyConv2D STATIC buddy-conv2d.o)
set_target_properties(BuddyConv2D PROPERTIES LINKER_LANGUAGE CXX)

# add_custom_command(OUTPUT buddy-conv2d.o
# COMMAND ${BUDDY_OPT_BUILD_DIR}/bin/buddy-opt
# ${BUDDY_SOURCE_DIR}/benchmarks/ImageProcessing/BuddyConv2D.mlir
# -linalg-tile="tile-sizes=${MLIR_LINALG_TILE},${MLIR_LINALG_TILE}"
# -conv-vectorization="tile-sizes=${MLIR_LINALG_TILE},${MLIR_LINALG_TILE}"
# -convert-vector-to-scf
# -lower-affine -convert-scf-to-cf -convert-vector-to-llvm
# -convert-memref-to-llvm -convert-func-to-llvm='emit-c-wrappers=1'
# -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 ${BUDDY_BINARY_DIR}/../benchmarks/ImageProcessing/buddy-conv2d.o
# )
# add_library(BuddyConv2D STATIC buddy-conv2d.o)
# set_target_properties(BuddyConv2D PROPERTIES LINKER_LANGUAGE CXX)

#-------------------------------------------------------------------------------
# Buddy DIP Dialect Corr2D Operation + CB Algorithm
#-------------------------------------------------------------------------------
Expand All @@ -68,7 +84,7 @@ add_custom_command(OUTPUT buddy-corr2d.o
${BUDDY_SOURCE_DIR}/benchmarks/ImageProcessing/BuddyCorr2D.mlir
-lower-dip="DIP-strip-mining=${SPLITING_SIZE}"
-lower-affine -convert-scf-to-cf -convert-vector-to-llvm
-convert-memref-to-llvm -convert-std-to-llvm='emit-c-wrappers=1'
-convert-memref-to-llvm -convert-func-to-llvm='emit-c-wrappers=1'
-reconcile-unrealized-casts |
${LLVM_MLIR_BINARY_DIR}/mlir-translate --mlir-to-llvmir |
${LLVM_MLIR_BINARY_DIR}/llc -mtriple=${BUDDY_OPT_TRIPLE}
Expand Down
Binary file added benchmarks/ImageProcessing/Images/YuTu1022.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added benchmarks/ImageProcessing/Images/YuTu18.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions benchmarks/ImageProcessing/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
//===----------------------------------------------------------------------===//

#include <benchmark/benchmark.h>
#include <stdexcept>

void initializeMLIRConv2D(char **);
void initializeBuddyConv2D(char **);
Expand Down

0 comments on commit 65f6023

Please sign in to comment.