Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add benchmark for the sum pooling vectorization pass #28

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
func @buddy_pooling_nhwc_sum(%input: memref<1x1024x1024x1xf32>, %filter: memref<3x3xf32>,
%output: memref<1x1022x1022x1xf32>) {

linalg.pooling_nhwc_sum
{strides = dense<1>: tensor<2xi64>, dilations = dense<1>: tensor<2xi64>}
ins(%input, %filter: memref<1x1024x1024x1xf32>, memref<3x3xf32>)
outs(%output: memref<1x1022x1022x1xf32>)

return
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//===- PoolingNhwcSumBenchmark.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 sum pooling (nhwc) operation.
//
//===----------------------------------------------------------------------===//

#include "Utils/Container.h"
#include <benchmark/benchmark.h>

namespace {

// Declare the pooling_nhwc_sum interface.
extern "C" {
void _mlir_ciface_buddy_pooling_nhwc_sum(MemRef<float, 4> *input,
MemRef<float, 2> *kernel,
MemRef<float, 4> *output);
}

// Create input, filter, and output.
MemRef<float, 4> input({1, 1024, 1024, 1}, 0.1);
MemRef<float, 2> kernel({3, 3}, 1.0);
intptr_t sizesOutput[4] = {1, 1022, 1022, 1};
MemRef<float, 4> output(sizesOutput);

// Define benchmark function.
void Buddy_PoolingNhwcSum(benchmark::State &state) {
for (auto _ : state) {
for (int i = 0; i < state.range(0); ++i) {
_mlir_ciface_buddy_pooling_nhwc_sum(&input, &kernel, &output);
}
}
}

} // namespace

// Register benchmarking function with different arguments.
BENCHMARK(Buddy_PoolingNhwcSum)->Arg(1)->Unit(benchmark::kMillisecond);
BENCHMARK(Buddy_PoolingNhwcSum)->Arg(4)->Unit(benchmark::kMillisecond);

75 changes: 62 additions & 13 deletions benchmarks/DeepLearning/Ops/PoolingNhwcSumOp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,63 @@
add_buddy_ops_benchmark(pooling-nhwc-sum-benchmark
MLIR PoolingNhwcSum.mlir
BITCODE pooling-nhwc-sum.o
LIBRARY PoolingNhwcSum
OPTIONS
-convert-linalg-to-loops
-convert-scf-to-cf
-convert-linalg-to-llvm
-lower-affine
--convert-memref-to-llvm
-convert-func-to-llvm='emit-c-wrappers=1'
-reconcile-unrealized-casts
SOURCE Main.cpp MLIROptBenchmark.cpp
#-------------------------------------------------------------------------------
# MLIR Linalg Dialect PoolingNhwcSum Operation + Upstream Lowering Passes
#-------------------------------------------------------------------------------

add_custom_command(OUTPUT mlir-pooling-nhwc-sum.o
COMMAND ${LLVM_MLIR_BINARY_DIR}/mlir-opt
${CMAKE_CURRENT_SOURCE_DIR}/MLIRPoolingNhwcSum.mlir
-convert-linalg-to-loops
-convert-scf-to-cf
-convert-linalg-to-llvm
-lower-affine
--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
${CMAKE_CURRENT_BINARY_DIR}/mlir-pooling-nhwc-sum.o
)
add_library(MLIRPoolingNhwcSum ${CMAKE_CURRENT_BINARY_DIR}/mlir-pooling-nhwc-sum.o)
set_target_properties(MLIRPoolingNhwcSum PROPERTIES LINKER_LANGUAGE CXX)

#-------------------------------------------------------------------------------
# MLIR Linalg Dialect PoolingNhwcSum Operation + CB Pooling algorithm
#-------------------------------------------------------------------------------

add_custom_command(OUTPUT buddy-pooling-nhwc-sum.o
COMMAND ${BUDDY_OPT_BUILD_DIR}/bin/buddy-opt
${CMAKE_CURRENT_SOURCE_DIR}/BuddyPoolingNhwcSum.mlir
-pooling-vectorization
-lower-affine
-convert-vector-to-scf
-convert-scf-to-cf
-tensor-bufferize
-convert-vector-to-llvm
-convert-memref-to-llvm
-convert-arith-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
${CMAKE_CURRENT_BINARY_DIR}/buddy-pooling-nhwc-sum.o
)
add_library(BuddyPoolingNhwcSum ${CMAKE_CURRENT_BINARY_DIR}/buddy-pooling-nhwc-sum.o)
set_target_properties(BuddyPoolingNhwcSum PROPERTIES LINKER_LANGUAGE CXX)

#-------------------------------------------------------------------------------
# PoolingNhwcSum Benchmark Target
#-------------------------------------------------------------------------------

add_executable(pooling-nhwc-sum-benchmark
Main.cpp
MLIRPoolingNhwcSumBenchmark.cpp
BuddyPoolingNhwcSumBenchmark.cpp
)

target_link_libraries(pooling-nhwc-sum-benchmark
GoogleBenchmark
MLIRPoolingNhwcSum
BuddyPoolingNhwcSum
Container
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
func @pooling_nhwc_sum(%input: memref<1x1024x1024x1xf32>, %filter: memref<3x3xf32>,
%output: memref<1x1022x1022x1xf32>) {

linalg.pooling_nhwc_sum
{strides = dense<1>: tensor<2xi64>, dilations = dense<1>: tensor<2xi64>}
ins(%input, %filter: memref<1x1024x1024x1xf32>, memref<3x3xf32>)
outs(%output: memref<1x1022x1022x1xf32>)

return
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===- MLIROptBenchmark.cpp -----------------------------------------------===//
//===- PoolingNhwcSumBenchmark.cpp ----------------------------------------===//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,13 +31,13 @@ void _mlir_ciface_pooling_nhwc_sum(MemRef<float, 4> *input,
}

// Create input, filter, and output.
MemRef<float, 4> input({1, 6, 6, 1}, 1.0);
MemRef<float, 4> input({1, 1024, 1024, 1}, 0.1);
MemRef<float, 2> filter({3, 3}, 1.0);
intptr_t sizesOutput[4] = {1, 3, 3, 1};
intptr_t sizesOutput[4] = {1, 1022, 1022, 1};
MemRef<float, 4> output(sizesOutput);

// Define benchmark function.
void BM_PoolingNhwcSum(benchmark::State &state) {
void MLIR_PoolingNhwcSum(benchmark::State &state) {
for (auto _ : state) {
for (int i = 0; i < state.range(0); ++i) {
_mlir_ciface_pooling_nhwc_sum(&input, &filter, &output);
Expand All @@ -48,18 +48,5 @@ void BM_PoolingNhwcSum(benchmark::State &state) {
} // namespace

// Register benchmarking function with different arguments.
BENCHMARK(BM_PoolingNhwcSum)->Arg(1);
BENCHMARK(BM_PoolingNhwcSum)->Arg(4);

// Print result function.
void printResult() {
// Create the output memref.
MemRef<float, 4> output(sizesOutput);
// Run the mlir function.
_mlir_ciface_pooling_nhwc_sum(&input, &filter, &output);
// Print the output.
std::cout << "Output: [ ";
for (int i = 0; i < 9; ++i)
std::cout << output[i] << " ";
std::cout << "]" << std::endl;
}
BENCHMARK(MLIR_PoolingNhwcSum)->Arg(1)->Unit(benchmark::kMillisecond);
BENCHMARK(MLIR_PoolingNhwcSum)->Arg(4)->Unit(benchmark::kMillisecond);
4 changes: 0 additions & 4 deletions benchmarks/DeepLearning/Ops/PoolingNhwcSumOp/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@

#include <benchmark/benchmark.h>

void printResult();

int main(int argc, char **argv) {
// Run benchmarks.
::benchmark::Initialize(&argc, argv);
::benchmark::RunSpecifiedBenchmarks();
// Print result.
printResult();

return 0;
}
10 changes: 0 additions & 10 deletions benchmarks/DeepLearning/Ops/PoolingNhwcSumOp/PoolingNhwcSum.mlir

This file was deleted.