Skip to content

[DeepLearning/Models] add MobileNet-V3 Model benchmark #131

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

Merged
merged 8 commits into from
Aug 18, 2024
Merged
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
66 changes: 36 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ cmake_minimum_required(VERSION 3.10)
#-------------------------------------------------------------------------------
# Project setup and globals
#-------------------------------------------------------------------------------

project(buddy-benchmark LANGUAGES CXX C)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_FLAGS "-no-pie")
Expand All @@ -23,14 +22,27 @@ set(CMAKE_C_FLAGS "-no-pie")
set(BuddyMLIR_DIR ${BUDDY_MLIR_BUILD_DIR}/cmake)
find_package(BuddyMLIR REQUIRED CONFIG)

if(CROSS_COMPILE_RVV)
set(RISCV_GNU_TOOLCHAIN ${BUDDY_MLIR_BUILD_DIR}/thirdparty/riscv-gnu-toolchain)
set(RISCV_GNU_TOOLCHAIN_SYSROOT ${RISCV_GNU_TOOLCHAIN}/sysroot)
set(BUDDY_OPT_ATTR +v,+m CACHE STRING "Target Architecture.")
set(BUDDY_OPT_TRIPLE riscv64 CACHE STRING "Target Triple.")
set(BUDDY_MLIR_CROSS_LIB_DIR ${BUDDY_MLIR_BUILD_CROSS_DIR}/lib)
else()
Copy link
Member

@zhanghb97 zhanghb97 Aug 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CMake bug!
Please include BUDDY_OPT_TRIPLE and BUDDY_OPT_ATTR for local machine in the else branch.

set(BUDDY_OPT_ATTR avx512f CACHE STRING "Target Architecture.")
set(BUDDY_OPT_TRIPLE x86_64-unknown-linux-gnu CACHE STRING "Target Triple.")
set(BUDDY_MLIR_LIB_DIR ${BUDDY_MLIR_BUILD_DIR}/lib)
endif()
message(STATUS "Configuring Target Architecture: ${BUDDY_OPT_ATTR}")
message(STATUS "Configuring Target Triple: ${BUDDY_OPT_TRIPLE}")

# BUDDY project.
set(BUDDY_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(BUDDY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/bin)
set(BUDDY_EXAMPLES_DIR ${BUDDY_SOURCE_DIR}/examples)
set(BUDDY_OPT_ATTR avx512f CACHE STRING "Target Architecture.")
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(BUDDY_MLIR_BINARY_DIR ${BUDDY_MLIR_BUILD_DIR}/bin)
set(BUDDY_BENCHMARK_DEEP_LEARNING_DIR ${BUDDY_SOURCE_DIR}/benchmarks/DeepLearning)



set(BUILD_TESTS OFF CACHE BOOL "Build tests")
set(BUILD_VALIDATION OFF CACHE BOOL "Build validations")
Expand All @@ -49,10 +61,9 @@ set(LLVM_MLIR_LIBRARY_DIR ${BUDDY_MLIR_BUILD_DIR}/../llvm/build/lib)
# Helper functions.
include(${BUDDY_SOURCE_DIR}/cmake/buddy-benchmark.cmake)

#-------------------------------------------------------------------------------
# -------------------------------------------------------------------------------
# Deploy google/benchmark
#-------------------------------------------------------------------------------

# -------------------------------------------------------------------------------
message(STATUS "Configuring benchmarks: google")

include(ExternalProject)
Expand All @@ -65,12 +76,12 @@ ExternalProject_Add(project_googlebenchmark
TIMEOUT 10
BUILD_BYPRODUCTS <INSTALL_DIR>/lib/${CMAKE_STATIC_LIBRARY_PREFIX}benchmark${CMAKE_STATIC_LIBRARY_SUFFIX}
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/vendor/benchmark
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
-DBENCHMARK_ENABLE_TESTING=OFF
-DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}
-DCMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/vendor/benchmark
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
-DBENCHMARK_ENABLE_TESTING=OFF
-DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}
-DCMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
UPDATE_COMMAND ""
TEST_COMMAND "")

Expand All @@ -87,39 +98,34 @@ add_dependencies(GoogleBenchmark project_googlebenchmark)
find_package(Threads)
target_link_libraries(GoogleBenchmark INTERFACE Threads::Threads)

#-------------------------------------------------------------------------------
# -------------------------------------------------------------------------------
# Find OpenCV
#-------------------------------------------------------------------------------

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

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

# -------------------------------------------------------------------------------
if(DEFINED IMAGE_PROCESSING_BENCHMARKS)
find_package(PNG REQUIRED)
include_directories(${PNG_INCLUDE_DIR})
endif()

#-------------------------------------------------------------------------------
# -------------------------------------------------------------------------------
# Hardware detection
#-------------------------------------------------------------------------------

# -------------------------------------------------------------------------------
include(${BUDDY_SOURCE_DIR}/cmake/check-simd.cmake)
check_simd()

#-------------------------------------------------------------------------------
# -------------------------------------------------------------------------------
# Subdirectory
#-------------------------------------------------------------------------------

# -------------------------------------------------------------------------------
add_subdirectory(benchmarks)
add_subdirectory(utils)

if (BUILD_VALIDATION)
if(BUILD_VALIDATION)
add_subdirectory(validation)
endif()

1 change: 1 addition & 0 deletions benchmarks/DeepLearning/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
add_subdirectory(Models)
add_subdirectory(Ops)
1 change: 1 addition & 0 deletions benchmarks/DeepLearning/Models/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(MobileNet-V3)
7 changes: 7 additions & 0 deletions benchmarks/DeepLearning/Models/MobileNet-V3/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# model params file
arg0.data
arg1.data

# model mlir file
forward.mlir
subgraph0.mlir
161 changes: 161 additions & 0 deletions benchmarks/DeepLearning/Models/MobileNet-V3/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
add_custom_command(
OUTPUT
${BUDDY_BENCHMARK_DEEP_LEARNING_DIR}/Models/MobileNet-V3/forward.mlir
${BUDDY_BENCHMARK_DEEP_LEARNING_DIR}/Models/MobileNet-V3/subgraph0.mlir
COMMAND python3 ${BUDDY_BENCHMARK_DEEP_LEARNING_DIR}/Models/MobileNet-V3/buddy_mobilenetv3_import.py
COMMENT "Generating forward.mlir, subgraph0.mlir"
)

add_custom_command(
OUTPUT forward_auto_vectorization.o
COMMAND cat ${BUDDY_BENCHMARK_DEEP_LEARNING_DIR}/Models/MobileNet-V3/forward.mlir |
sed -e {s/@forward/@forward_auto_vectorization/} -e {s/@subgraph0/@subgraph0_auto_vectorization/} |
${LLVM_MLIR_BINARY_DIR}/mlir-opt
-pass-pipeline
"builtin.module(func.func(tosa-to-linalg-named, tosa-to-linalg, tosa-to-tensor, tosa-to-arith), \
empty-tensor-to-alloc-tensor, convert-elementwise-to-linalg, arith-bufferize, \
func.func(linalg-bufferize, tensor-bufferize), func-bufferize)" |
${LLVM_MLIR_BINARY_DIR}/mlir-opt
-pass-pipeline
"builtin.module(func.func(buffer-deallocation-simplification, convert-linalg-to-loops), \
eliminate-empty-tensors, func.func(llvm-request-c-wrappers), \
convert-math-to-llvm, convert-math-to-libm, convert-scf-to-cf, \
convert-arith-to-llvm, expand-strided-metadata, finalize-memref-to-llvm, \
convert-func-to-llvm, reconcile-unrealized-casts)" |
${LLVM_MLIR_BINARY_DIR}/mlir-translate -mlir-to-llvmir |
${LLVM_MLIR_BINARY_DIR}/llvm-as |
${LLVM_MLIR_BINARY_DIR}/llc -O3 -mtriple=${BUDDY_OPT_TRIPLE}
-mattr=${BUDDY_OPT_ATTR} -filetype=obj
-o ${BUDDY_BINARY_DIR}/../benchmarks/DeepLearning/Models/MobileNet-V3/forward_auto_vectorization.o
DEPENDS ${BUDDY_BENCHMARK_DEEP_LEARNING_DIR}/Models/MobileNet-V3/forward.mlir
COMMENT "Building forward_auto_vectorization.o"
VERBATIM)

add_custom_command(
OUTPUT subgraph0_auto_vectorization.o
COMMAND cat ${BUDDY_BENCHMARK_DEEP_LEARNING_DIR}/Models/MobileNet-V3/subgraph0.mlir |
sed -e {s/@subgraph0/@subgraph0_auto_vectorization/} |
${BUDDY_MLIR_BINARY_DIR}/buddy-opt
-pass-pipeline
"builtin.module(func.func(tosa-to-linalg-named, tosa-to-arith, tosa-to-linalg, tosa-to-tensor))" |
${BUDDY_MLIR_BINARY_DIR}/buddy-opt
-convert-elementwise-to-linalg
-func-bufferize-dynamic-offset
-arith-bufferize
-func-bufferize
-tensor-bufferize
-linalg-bufferize
-finalizing-bufferize
-convert-linalg-to-loops
-lower-affine
-convert-scf-to-cf
-llvm-request-c-wrappers
-convert-math-to-llvm
-convert-math-to-libm
-convert-arith-to-llvm
-convert-func-to-llvm
-expand-strided-metadata
-finalize-memref-to-llvm
-reconcile-unrealized-casts |
${LLVM_MLIR_BINARY_DIR}/mlir-translate -mlir-to-llvmir |
${LLVM_MLIR_BINARY_DIR}/llvm-as |
${LLVM_MLIR_BINARY_DIR}/llc -O3 -mtriple=${BUDDY_OPT_TRIPLE}
-mattr=${BUDDY_OPT_ATTR} -filetype=obj
-o ${BUDDY_BINARY_DIR}/../benchmarks/DeepLearning/Models/MobileNet-V3/subgraph0_auto_vectorization.o
DEPENDS ${BUDDY_BENCHMARK_DEEP_LEARNING_DIR}/Models/MobileNet-V3/subgraph0.mlir
${BUDDY_MLIR_BINARY_DIR}/buddy-opt
COMMENT "Building subgraph0_auto_vectorization.o"
VERBATIM)

add_custom_command(
OUTPUT forward_vectorization.o
COMMAND cat ${BUDDY_BENCHMARK_DEEP_LEARNING_DIR}/Models/MobileNet-V3/forward.mlir |
sed -e {s/@forward/@forward_vectorization/} -e {s/@subgraph0/@subgraph0_vectorization/} |
${LLVM_MLIR_BINARY_DIR}/mlir-opt
-pass-pipeline
"builtin.module(func.func(tosa-to-linalg-named, tosa-to-linalg, tosa-to-tensor, tosa-to-arith), \
empty-tensor-to-alloc-tensor, convert-elementwise-to-linalg, arith-bufferize, \
func.func(linalg-bufferize, tensor-bufferize), func-bufferize)" |
${LLVM_MLIR_BINARY_DIR}/mlir-opt
-pass-pipeline
"builtin.module(func.func(buffer-deallocation-simplification, convert-linalg-to-loops), \
eliminate-empty-tensors, func.func(llvm-request-c-wrappers), \
convert-math-to-llvm, convert-math-to-libm, convert-scf-to-cf, \
convert-arith-to-llvm, expand-strided-metadata, finalize-memref-to-llvm, \
convert-func-to-llvm, reconcile-unrealized-casts)" |
${LLVM_MLIR_BINARY_DIR}/mlir-translate -mlir-to-llvmir |
${LLVM_MLIR_BINARY_DIR}/llvm-as |
${LLVM_MLIR_BINARY_DIR}/llc -O3 -mtriple=${BUDDY_OPT_TRIPLE}
-mattr=${BUDDY_OPT_ATTR} -filetype=obj
-o ${BUDDY_BINARY_DIR}/../benchmarks/DeepLearning/Models/MobileNet-V3/forward_vectorization.o
DEPENDS ${BUDDY_BENCHMARK_DEEP_LEARNING_DIR}/Models/MobileNet-V3/forward.mlir
COMMENT "Building forward_vectorization.o"
VERBATIM)

add_custom_command(
OUTPUT subgraph0_vectorization.o
COMMAND cat ${BUDDY_BENCHMARK_DEEP_LEARNING_DIR}/Models/MobileNet-V3/subgraph0.mlir |
sed -e {s/@subgraph0/@subgraph0_vectorization/} |
${BUDDY_MLIR_BINARY_DIR}/buddy-opt
-pass-pipeline
"builtin.module(func.func(tosa-to-linalg-named, tosa-to-arith, tosa-to-linalg, tosa-to-tensor))" |
${BUDDY_MLIR_BINARY_DIR}/buddy-opt
-convert-elementwise-to-linalg
-func-bufferize-dynamic-offset
-arith-bufferize
-func-bufferize
-tensor-bufferize
-linalg-bufferize
-finalizing-bufferize
-batchmatmul-optimize
-convert-linalg-to-affine-loops
-lower-affine
-convert-vector-to-scf
-convert-scf-to-cf
-llvm-request-c-wrappers
-convert-vector-to-llvm
-convert-math-to-llvm
-convert-math-to-libm
-convert-arith-to-llvm
-convert-func-to-llvm
-expand-strided-metadata
-finalize-memref-to-llvm
-reconcile-unrealized-casts |
${LLVM_MLIR_BINARY_DIR}/mlir-translate -mlir-to-llvmir |
${LLVM_MLIR_BINARY_DIR}/llvm-as |
${LLVM_MLIR_BINARY_DIR}/llc -O3 -mtriple=${BUDDY_OPT_TRIPLE}
-mattr=${BUDDY_OPT_ATTR} -filetype=obj
-o ${BUDDY_BINARY_DIR}/../benchmarks/DeepLearning/Models/MobileNet-V3/subgraph0_vectorization.o
DEPENDS ${BUDDY_BENCHMARK_DEEP_LEARNING_DIR}/Models/MobileNet-V3/subgraph0.mlir
${BUDDY_MLIR_BINARY_DIR}/buddy-opt
COMMENT "Building subgraph0_vectorization.o"
VERBATIM)

add_library(MOBILENETV3_AUTO_VECTORIZATION STATIC subgraph0_auto_vectorization.o forward_auto_vectorization.o)
set_target_properties(MOBILENETV3_AUTO_VECTORIZATION PROPERTIES LINKER_LANGUAGE CXX)

add_library(MOBILENETV3_VECTORIZATION STATIC subgraph0_vectorization.o forward_vectorization.o)
set_target_properties(MOBILENETV3_VECTORIZATION PROPERTIES LINKER_LANGUAGE CXX)

add_executable(dl-model-mobileNetV3-benchmark
GoogleBenchmarkMain.cpp
)

set_target_properties(dl-model-mobileNetV3-benchmark PROPERTIES
LINK_FLAGS "-static"
)

set(BenchmarkTool GoogleBenchmark)

if(CROSS_COMPILE_RVV)
set(BUDDY_LIB_DIR ${BUDDY_MLIR_CROSS_LIB_DIR})
else()
set(BUDDY_LIB_DIR ${BUDDY_MLIR_LIB_DIR})
endif()

target_link_libraries(dl-model-mobileNetV3-benchmark
${BenchmarkTool}
MOBILENETV3_AUTO_VECTORIZATION
MOBILENETV3_VECTORIZATION
${BUDDY_LIB_DIR}/libStaticMLIRCRunnerUtils.a
)
Loading