Skip to content

Commit

Permalink
[examples] Update the pipeline and fix numerical errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
NaOHCC committed Nov 22, 2024
1 parent d06fdf7 commit b706097
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions examples/BuddyLeNet/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,44 @@ target_link_directories(buddy-lenet-run PRIVATE ${LLVM_LIBRARY_DIR})
if(NOT DEFINED BUDDY_ENABLE_PNG)
message(FATAL_ERROR "To run LeNet inference, the png library is required. Please define BUDDY_ENABLE_PNG for CMake.")
endif()
set(BUDDY_LENET_LIBS LENET mlir_c_runner_utils ${PNG_LIBRARIES})
set(BUDDY_LENET_LIBS LENET mlir_c_runner_utils mlir_async_runtime mlir_runner_utils mlir_cuda_runtime ${PNG_LIBRARIES})

target_link_libraries(buddy-lenet-run ${BUDDY_LENET_LIBS})

set(ONE_SHOT_BUFFERIZE_OPTION "bufferize-function-boundaries=1 function-boundary-type-conversion=identity-layout-map")
set(LOWER_TO_NVVM_OPTION "cubin-chip=sm_80 cubin-features=+ptx71 cubin-format=fatbin")
set(CONVERT_MEMCPY_TO_GPU_OPTION "process-args=1")
set(CONVERT_MEMCPY_TO_GPU_OPTION_DISABLE_PROCESS_ARG "process-args=0")

add_custom_command(
OUTPUT forward_gpu.o
COMMAND ${BUDDY_BINARY_DIR}/buddy-opt ${BUDDY_EXAMPLES_DIR}/BuddyLeNet/forward.mlir
-buffer-deallocation
-canonicalize -cse -expand-strided-metadata -convert-memcpy-to-gpu -gpu-async-region |
${LLVM_TOOLS_BINARY_DIR}/mlir-opt -llvm-request-c-wrappers --gpu-to-llvm |
${LLVM_TOOLS_BINARY_DIR}/mlir-translate -mlir-to-llvmir |
${LLVM_TOOLS_BINARY_DIR}/llvm-as |
${LLVM_TOOLS_BINARY_DIR}/llc -filetype=obj -relocation-model=pic -O0 -o ${BUDDY_BINARY_DIR}/../examples/BuddyLeNet/forward_gpu.o
DEPENDS ${BUDDY_EXAMPLES_DIR}/BuddyLeNet/forward.mlir
COMMENT "Building forward_gpu.o"
VERBATIM)

add_custom_command(
OUTPUT subgraph0_gpu.o
COMMAND ${LLVM_TOOLS_BINARY_DIR}/mlir-opt ${BUDDY_EXAMPLES_DIR}/BuddyLeNet/subgraph0.mlir
-pass-pipeline "builtin.module(func.func(tosa-to-linalg-named, tosa-to-linalg, tosa-to-tensor, tosa-to-arith))" |
${LLVM_TOOLS_BINARY_DIR}/mlir-opt
-one-shot-bufferize=${ONE_SHOT_BUFFERIZE_OPTION}
-buffer-deallocation
${BUDDY_BINARY_DIR}/buddy-opt
-one-shot-bufferize
-func-bufferize-dynamic-offset
-convert-linalg-to-parallel-loops
-canonicalize
-gpu-map-parallel-loops
-convert-parallel-loops-to-gpu
-gpu-kernel-outlining
-buffer-deallocation
-canonicalize
-cse |
${BUDDY_BINARY_DIR}/buddy-opt -convert-memcpy-to-gpu -gpu-async-region -canonicalize |
${BUDDY_BINARY_DIR}/buddy-opt -convert-memcpy-to-gpu=${CONVERT_MEMCPY_TO_GPU_OPTION_DISABLE_PROCESS_ARG} -gpu-async-region -canonicalize |
${LLVM_TOOLS_BINARY_DIR}/mlir-opt -llvm-request-c-wrappers --test-lower-to-nvvm=${LOWER_TO_NVVM_OPTION} |
${LLVM_TOOLS_BINARY_DIR}/mlir-translate -mlir-to-llvmir |
${LLVM_TOOLS_BINARY_DIR}/llvm-as |
Expand All @@ -89,7 +106,7 @@ add_custom_command(
COMMENT "Building subgraph0_gpu.o"
VERBATIM)

add_library(LENET_GPU STATIC subgraph0_gpu.o forward.o)
add_library(LENET_GPU STATIC subgraph0_gpu.o forward_gpu.o)

SET_TARGET_PROPERTIES(LENET_GPU PROPERTIES LINKER_LANGUAGE C)

Expand Down

0 comments on commit b706097

Please sign in to comment.