Skip to content

Commit

Permalink
resnet18
Browse files Browse the repository at this point in the history
  • Loading branch information
WuXintong123 committed Dec 19, 2024
1 parent 5acfb02 commit f7a1909
Show file tree
Hide file tree
Showing 24 changed files with 1,346 additions and 5 deletions.
1 change: 1 addition & 0 deletions examples/BuddyMobileNetV3/buddy-mobilenetv3-import.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from pathlib import Path
import numpy as np
import torch
import torch._inductor.lowering
import torchvision.models as models
from torch._inductor.decomposition import decompositions as inductor_decomp

Expand Down
74 changes: 74 additions & 0 deletions examples/BuddyResNet18/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
add_custom_command(
OUTPUT ${BUDDY_EXAMPLES_DIR}/BuddyResNet18/arg0.data
${BUDDY_EXAMPLES_DIR}/BuddyResNet18/forward.mlir
${BUDDY_EXAMPLES_DIR}/BuddyResNet18/subgraph0.mlir
COMMAND python3 ${BUDDY_EXAMPLES_DIR}/BuddyResNet18/buddy-resnet-import.py
COMMENT "Generating forward.mlir, subgraph0.mlir and parameter files"
)


add_custom_command(
OUTPUT forward.o
COMMAND ${LLVM_TOOLS_BINARY_DIR}/mlir-opt ${BUDDY_EXAMPLES_DIR}/BuddyResNet18/forward.mlir
-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_TOOLS_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_TOOLS_BINARY_DIR}/mlir-translate -mlir-to-llvmir |
${LLVM_TOOLS_BINARY_DIR}/llvm-as |
${LLVM_TOOLS_BINARY_DIR}/llc -filetype=obj -relocation-model=pic -O3
-o ${BUDDY_BINARY_DIR}/../examples/BuddyResNet18/forward.o
DEPENDS ${BUDDY_EXAMPLES_DIR}/BuddyResNet18/forward.mlir
COMMENT "Building forward.o"
VERBATIM)


add_custom_command(
OUTPUT subgraph0.o
COMMAND ${BUDDY_BINARY_DIR}/buddy-opt ${BUDDY_EXAMPLES_DIR}/BuddyResNet18/subgraph0.mlir
-pass-pipeline
"builtin.module(func.func(tosa-to-linalg-named, tosa-to-arith, tosa-to-linalg, tosa-to-tensor))" |
${BUDDY_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_TOOLS_BINARY_DIR}/mlir-translate -mlir-to-llvmir |
${LLVM_TOOLS_BINARY_DIR}/llvm-as |
${LLVM_TOOLS_BINARY_DIR}/llc -filetype=obj -relocation-model=pic -O3
-o ${BUDDY_BINARY_DIR}/../examples/BuddyResNet18/subgraph0.o
DEPENDS ${BUDDY_EXAMPLES_DIR}/BuddyResNet18/subgraph0.mlir
buddy-opt
COMMENT "Building subgraph0.o"
VERBATIM)

add_library(RESNET STATIC subgraph0.o forward.o)

SET_TARGET_PROPERTIES(RESNET PROPERTIES LINKER_LANGUAGE C)

add_executable(buddy-resnet-run buddy-resnet-main.cpp)
target_link_directories(buddy-resnet-run PRIVATE ${LLVM_LIBRARY_DIR})

set(BUDDY_RESNET_LIBS RESNET mlir_c_runner_utils BuddyLibDIP ${PNG_LIBRARIES})
target_link_libraries(buddy-resnet-run ${BUDDY_RESNET_LIBS})
Loading

0 comments on commit f7a1909

Please sign in to comment.