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

Change the paths for generated model MLIR files and data files to the build path. #441

Merged
merged 9 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 7 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
17 changes: 11 additions & 6 deletions examples/BuddyBert/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
add_custom_command(
OUTPUT ${BUDDY_EXAMPLES_DIR}/BuddyBert/forward.mlir ${BUDDY_EXAMPLES_DIR}/BuddyBert/subgraph0.mlir ${BUDDY_EXAMPLES_DIR}/BuddyBert/arg0.data ${BUDDY_EXAMPLES_DIR}/BuddyBert/arg1.data
COMMAND python3 ${BUDDY_EXAMPLES_DIR}/BuddyBert/import-bert.py
OUTPUT ${BUDDY_BINARY_DIR}/../examples/BuddyBert/forward.mlir
Copy link
Member

Choose a reason for hiding this comment

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

${CMAKE_CURRENT_BINARY_DIR}/forward.mlir

${BUDDY_BINARY_DIR}/../examples/BuddyBert/subgraph0.mlir
${BUDDY_BINARY_DIR}/../examples/BuddyBert/arg0.data
${BUDDY_BINARY_DIR}/../examples/BuddyBert/arg1.data
COMMAND python3 ${BUDDY_EXAMPLES_DIR}/BuddyBert/import-bert.py
Copy link
Member

Choose a reason for hiding this comment

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

${CMAKE_CURRENT_SOURCE_DIR}/import-bert.py

--output-dir ${BUDDY_BINARY_DIR}/../examples/BuddyBert
Copy link
Member

Choose a reason for hiding this comment

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

${CMAKE_CURRENT_BINARY_DIR}

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}/BuddyBert/forward.mlir
COMMAND ${LLVM_TOOLS_BINARY_DIR}/mlir-opt ${BUDDY_BINARY_DIR}/../examples/BuddyBert/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 -O0 -o ${BUDDY_BINARY_DIR}/../examples/BuddyBert/forward.o
DEPENDS ${BUDDY_EXAMPLES_DIR}/BuddyBert/forward.mlir
DEPENDS ${BUDDY_BINARY_DIR}/../examples/BuddyBert/forward.mlir
COMMENT "Building forward.o"
VERBATIM)

add_custom_command(
OUTPUT subgraph0.o
COMMAND ${BUDDY_BINARY_DIR}/buddy-opt ${BUDDY_EXAMPLES_DIR}/BuddyBert/subgraph0.mlir
COMMAND ${BUDDY_BINARY_DIR}/buddy-opt ${BUDDY_BINARY_DIR}/../examples/BuddyBert/subgraph0.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, func-bufferize-dynamic-offset, arith-bufferize, func.func(linalg-bufferize, tensor-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 -O0 -o ${BUDDY_BINARY_DIR}/../examples/BuddyBert/subgraph0.o
DEPENDS ${BUDDY_EXAMPLES_DIR}/BuddyBert/subgraph0.mlir
DEPENDS ${BUDDY_BINARY_DIR}/../examples/BuddyBert/subgraph0.mlir
COMMENT "Building subgraph0.o"
VERBATIM)

Expand Down
4 changes: 2 additions & 2 deletions examples/BuddyBert/bert-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ int main() {
/// Load weights to MemRef container.
MemRef<float, 1> arg0({109486854});
MemRef<long long, 1> arg1({512});
loadParameters("../../examples/BuddyBert/arg0.data",
"../../examples/BuddyBert/arg1.data", arg0, arg1);
loadParameters("../../build/examples/BuddyBert/arg0.data",
Copy link
Member

Choose a reason for hiding this comment

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

Use environment variable.

"../../build/examples/BuddyBert/arg1.data", arg0, arg1);

/// Get user message and build Text container.
std::cout << "What sentence do you want to say to BERT?" << std::endl;
Expand Down
28 changes: 21 additions & 7 deletions examples/BuddyBert/import-bert.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# ===---------------------------------------------------------------------------

import os
import argparse
from pathlib import Path

import numpy as np
Expand All @@ -30,6 +31,20 @@
from torch._inductor.decomposition import decompositions as inductor_decomp
from transformers import BertForSequenceClassification, BertTokenizer

# Parse command-line arguments
parser = argparse.ArgumentParser(description="BERT model AOT importer")
parser.add_argument(
"--output-dir",
type=str,
default="./",
help="Directory to save output files"
)
args = parser.parse_args()

# Ensure output directory exists
output_dir = os.path.abspath(args.output_dir)
os.makedirs(output_dir, exist_ok=True)

model = BertForSequenceClassification.from_pretrained(
"bhadresh-savani/bert-base-uncased-emotion"
)
Expand Down Expand Up @@ -57,20 +72,19 @@
graphs[0].fuse_ops(pattern_list)
driver = GraphDriver(graphs[0])
driver.subgraphs[0].lower_to_top_level_ir()
path_prefix = os.path.dirname(os.path.abspath(__file__))
with open(os.path.join(path_prefix, "subgraph0.mlir"), "w") as module_file:

# Write the MLIR module and forward graph to the specified output directory
with open(os.path.join(output_dir, "subgraph0.mlir"), "w") as module_file:
print(driver.subgraphs[0]._imported_module, file=module_file)
with open(os.path.join(path_prefix, "forward.mlir"), "w") as module_file:
with open(os.path.join(output_dir, "forward.mlir"), "w") as module_file:
print(driver.construct_main_graph(True), file=module_file)

params = dynamo_compiler.imported_params[graph]
current_path = os.path.dirname(os.path.abspath(__file__))

float32_param = np.concatenate(
[param.detach().numpy().reshape([-1]) for param in params[:-1]]
)

float32_param.tofile(Path(current_path) / "arg0.data")
float32_param.tofile(Path(output_dir) / "arg0.data")

int64_param = params[-1].detach().numpy().reshape([-1])
int64_param.tofile(Path(current_path) / "arg1.data")
int64_param.tofile(Path(output_dir) / "arg1.data")
21 changes: 12 additions & 9 deletions examples/BuddyLeNet/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
add_custom_command(
OUTPUT ${BUDDY_EXAMPLES_DIR}/BuddyLeNet/forward.mlir ${BUDDY_EXAMPLES_DIR}/BuddyLeNet/subgraph0.mlir ${BUDDY_EXAMPLES_DIR}/BuddyLeNet/arg0.data
OUTPUT ${BUDDY_BINARY_DIR}/../examples/BuddyLeNet/forward.mlir
${BUDDY_BINARY_DIR}/../examples/BuddyLeNet/subgraph0.mlir
${BUDDY_BINARY_DIR}/../examples/BuddyLeNet/arg0.data
COMMAND python3 ${BUDDY_EXAMPLES_DIR}/BuddyLeNet/buddy-lenet-import.py
--output-dir ${BUDDY_BINARY_DIR}/../examples/BuddyLeNet
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}/BuddyLeNet/forward.mlir
COMMAND ${LLVM_TOOLS_BINARY_DIR}/mlir-opt ${BUDDY_BINARY_DIR}/../examples/BuddyLeNet/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 -O0 -o ${BUDDY_BINARY_DIR}/../examples/BuddyLeNet/forward.o
DEPENDS ${BUDDY_EXAMPLES_DIR}/BuddyLeNet/forward.mlir
DEPENDS ${BUDDY_BINARY_DIR}/../examples/BuddyLeNet/forward.mlir
COMMENT "Building forward.o"
VERBATIM)

add_custom_command(
OUTPUT subgraph0.o
COMMAND ${LLVM_TOOLS_BINARY_DIR}/mlir-opt ${BUDDY_EXAMPLES_DIR}/BuddyLeNet/subgraph0.mlir
COMMAND ${LLVM_TOOLS_BINARY_DIR}/mlir-opt ${BUDDY_BINARY_DIR}/../examples/BuddyLeNet/subgraph0.mlir
-pass-pipeline "builtin.module(func.func(tosa-to-linalg-named, tosa-to-linalg, tosa-to-tensor, tosa-to-arith))" |
${BUDDY_BINARY_DIR}/buddy-opt
-eliminate-empty-tensors
Expand All @@ -46,7 +49,7 @@ add_custom_command(
${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/subgraph0.o
DEPENDS ${BUDDY_EXAMPLES_DIR}/BuddyLeNet/subgraph0.mlir
DEPENDS ${BUDDY_BINARY_DIR}/../examples/BuddyLeNet/subgraph0.mlir
COMMENT "Building subgraph0.o"
VERBATIM)

Expand All @@ -71,20 +74,20 @@ 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
COMMAND ${BUDDY_BINARY_DIR}/buddy-opt ${BUDDY_BINARY_DIR}/../examples/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
DEPENDS ${BUDDY_BINARY_DIR}/../examples/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
COMMAND ${LLVM_TOOLS_BINARY_DIR}/mlir-opt ${BUDDY_BINARY_DIR}/../examples/BuddyLeNet/subgraph0.mlir
-pass-pipeline "builtin.module(func.func(tosa-to-linalg-named, tosa-to-linalg, tosa-to-tensor, tosa-to-arith))" |
${BUDDY_BINARY_DIR}/buddy-opt
-one-shot-bufferize
Expand All @@ -102,7 +105,7 @@ add_custom_command(
${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/subgraph0_gpu.o
DEPENDS ${BUDDY_EXAMPLES_DIR}/BuddyLeNet/subgraph0.mlir
DEPENDS ${BUDDY_BINARY_DIR}/../examples/BuddyLeNet/subgraph0.mlir
COMMENT "Building subgraph0_gpu.o"
VERBATIM)

Expand Down
23 changes: 18 additions & 5 deletions examples/BuddyLeNet/buddy-lenet-import.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import os
from pathlib import Path
import argparse

import numpy as np
import torch
Expand All @@ -30,6 +31,20 @@
from buddy.compiler.ops import tosa
from model import LeNet

# Parse command-line arguments.
parser = argparse.ArgumentParser(description="LeNet model AOT importer")
parser.add_argument(
"--output-dir",
type=str,
default="./",
help="Directory to save output files."
)
args = parser.parse_args()

# Ensure output directory exists.
output_dir = Path(args.output_dir)
output_dir.mkdir(parents=True, exist_ok=True)

# Retrieve the LeNet model path from environment variables.
model_path = os.environ.get("LENET_EXAMPLE_PATH")
if model_path is None:
Expand Down Expand Up @@ -58,17 +73,15 @@
graphs[0].fuse_ops(pattern_list)
driver = GraphDriver(graphs[0])
driver.subgraphs[0].lower_to_top_level_ir()
path_prefix = os.path.dirname(os.path.abspath(__file__))
with open(os.path.join(path_prefix, "subgraph0.mlir"), "w") as module_file:
with open(output_dir / "subgraph0.mlir", "w") as module_file:
print(driver.subgraphs[0]._imported_module, file=module_file)
with open(os.path.join(path_prefix, "forward.mlir"), "w") as module_file:
with open(output_dir / "forward.mlir", "w") as module_file:
print(driver.construct_main_graph(True), file=module_file)

params = dynamo_compiler.imported_params[graph]
current_path = os.path.dirname(os.path.abspath(__file__))

float32_param = np.concatenate(
[param.detach().numpy().reshape([-1]) for param in params]
)

float32_param.tofile(Path(current_path) / "arg0.data")
float32_param.tofile(output_dir / "arg0.data")
2 changes: 1 addition & 1 deletion examples/BuddyLeNet/buddy-lenet-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ int main() {
MemRef<float, 2> output(sizesOutput);

// Load model parameters from the specified file.
std::string paramsDir = lenetDir + "/arg0.data";
std::string paramsDir = lenetDir + "../../build/examples/BuddyLeNet/arg0.data";
MemRef<float, 1> paramsContainer({ParamsSize});
loadParameters(paramsDir, paramsContainer);

Expand Down
16 changes: 10 additions & 6 deletions examples/BuddyLlama/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
add_custom_command(
OUTPUT ${BUDDY_EXAMPLES_DIR}/BuddyLlama/forward.mlir ${BUDDY_EXAMPLES_DIR}/BuddyLlama/subgraph0.mlir ${BUDDY_EXAMPLES_DIR}/BuddyLlama/arg0.data
COMMAND ${Python3_EXECUTABLE} ${BUDDY_EXAMPLES_DIR}/BuddyLlama/import-llama2.py
OUTPUT ${BUDDY_BINARY_DIR}/../examples/BuddyLlama/forward.mlir
${BUDDY_BINARY_DIR}/../examples/BuddyLlama/subgraph0.mlir
${BUDDY_BINARY_DIR}/../examples/BuddyLlama/arg0.data
COMMAND ${Python3_EXECUTABLE} ${BUDDY_EXAMPLES_DIR}/BuddyLlama/import-llama2.py
--output-dir ${BUDDY_BINARY_DIR}/../examples/BuddyLlama
COMMENT "Generating forward.mlir, subgraph0.mlir and arg0.data..."
)


add_custom_command(
OUTPUT forward.o
COMMAND ${LLVM_TOOLS_BINARY_DIR}/mlir-opt ${BUDDY_EXAMPLES_DIR}/BuddyLlama/forward.mlir
COMMAND ${LLVM_TOOLS_BINARY_DIR}/mlir-opt ${BUDDY_BINARY_DIR}/../examples/BuddyLlama/forward.mlir
-pass-pipeline "builtin.module(func.func(tosa-to-linalg-named),func.func(tosa-to-linalg),func.func(tosa-to-tensor),func.func(tosa-to-arith))" |
${BUDDY_BINARY_DIR}/buddy-opt
-arith-expand
Expand Down Expand Up @@ -44,13 +48,13 @@ add_custom_command(
${LLVM_TOOLS_BINARY_DIR}/llvm-as |
${LLVM_TOOLS_BINARY_DIR}/llc -filetype=obj -relocation-model=pic -O3
-o ${BUDDY_BINARY_DIR}/../examples/BuddyLlama/forward.o
DEPENDS buddy-opt ${BUDDY_EXAMPLES_DIR}/BuddyLlama/forward.mlir
DEPENDS buddy-opt ${BUDDY_BINARY_DIR}/../examples/BuddyLlama/forward.mlir
COMMENT "Building forward.o "
VERBATIM)

add_custom_command(
OUTPUT subgraph.o
COMMAND ${LLVM_TOOLS_BINARY_DIR}/mlir-opt ${BUDDY_EXAMPLES_DIR}/BuddyLlama/subgraph0.mlir
COMMAND ${LLVM_TOOLS_BINARY_DIR}/mlir-opt ${BUDDY_BINARY_DIR}/../examples/BuddyLlama/subgraph0.mlir
-pass-pipeline "builtin.module(func.func(tosa-to-linalg-named),func.func(tosa-to-linalg),func.func(tosa-to-tensor),func.func(tosa-to-arith))" |
${BUDDY_BINARY_DIR}/buddy-opt
-convert-elementwise-to-linalg
Expand Down Expand Up @@ -90,7 +94,7 @@ add_custom_command(
${LLVM_TOOLS_BINARY_DIR}/llvm-as |
${LLVM_TOOLS_BINARY_DIR}/llc -filetype=obj -relocation-model=pic -O3
-o ${BUDDY_BINARY_DIR}/../examples/BuddyLlama/subgraph.o
DEPENDS buddy-opt ${BUDDY_EXAMPLES_DIR}/BuddyLlama/subgraph0.mlir
DEPENDS buddy-opt ${BUDDY_BINARY_DIR}/../examples/BuddyLlama/subgraph0.mlir
COMMENT "Building subgraph.o "
VERBATIM)

Expand Down
24 changes: 20 additions & 4 deletions examples/BuddyLlama/import-llama2.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# ===---------------------------------------------------------------------------

import os
import argparse
import torch
import torch._dynamo as dynamo
from transformers import LlamaForCausalLM, LlamaTokenizer
Expand All @@ -30,6 +31,20 @@
from buddy.compiler.graph import GraphDriver
from buddy.compiler.graph.transform import simply_fuse

# Add argument parser to allow custom output directory.
parser = argparse.ArgumentParser(description="LLaMA2 model AOT importer")
parser.add_argument(
"--output-dir",
type=str,
default="./",
help="Directory to save output files."
)
args = parser.parse_args()

# Ensure the output directory exists.
output_dir = args.output_dir
os.makedirs(output_dir, exist_ok=True)

# Retrieve the LLaMA model path from environment variables.
model_path = os.environ.get("LLAMA_MODEL_PATH")
if model_path is None:
Expand Down Expand Up @@ -60,12 +75,13 @@
graphs[0].fuse_ops(pattern_list)
driver = GraphDriver(graphs[0])
driver.subgraphs[0].lower_to_top_level_ir()
path_prefix = os.path.dirname(os.path.abspath(__file__))
with open(os.path.join(path_prefix, "subgraph0.mlir"), "w") as module_file:

# Save the generated files to the specified output directory.
with open(os.path.join(output_dir, "subgraph0.mlir"), "w") as module_file:
print(driver.subgraphs[0]._imported_module, file=module_file)
with open(os.path.join(path_prefix, "forward.mlir"), "w") as module_file:
with open(os.path.join(output_dir, "forward.mlir"), "w") as module_file:
print(driver.construct_main_graph(True), file=module_file)
all_param = numpy.concatenate(
[param.detach().numpy().reshape([-1]) for param in params]
)
all_param.tofile(os.path.join(path_prefix, "arg0.data"))
all_param.tofile(os.path.join(output_dir, "arg0.data"))
2 changes: 1 addition & 1 deletion examples/BuddyLlama/llama-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ int main() {

/// Define directories of vacabulary and parameter file.
const std::string vocabDir = "../../examples/BuddyLlama/vocab.txt";
const std::string paramsDir = "../../examples/BuddyLlama/arg0.data";
const std::string paramsDir = "../../build/examples/BuddyLlama/arg0.data";

/// Get user message.
std::string inputStr;
Expand Down
15 changes: 8 additions & 7 deletions examples/BuddyMobileNetV3/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
add_custom_command(
OUTPUT ${BUDDY_EXAMPLES_DIR}/BuddyMobileNetV3/arg0.data
${BUDDY_EXAMPLES_DIR}/BuddyMobileNetV3/forward.mlir
${BUDDY_EXAMPLES_DIR}/BuddyMobileNetV3/subgraph0.mlir
OUTPUT ${BUDDY_BINARY_DIR}/../examples/BuddyMobileNetV3/arg0.data
${BUDDY_BINARY_DIR}/../examples/BuddyMobileNetV3/forward.mlir
${BUDDY_BINARY_DIR}/../examples/BuddyMobileNetV3/subgraph0.mlir
COMMAND python3 ${BUDDY_EXAMPLES_DIR}/BuddyMobileNetV3/buddy-mobilenetv3-import.py
--output-dir ${BUDDY_BINARY_DIR}/../examples/BuddyMobileNetV3
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}/BuddyMobileNetV3/forward.mlir
COMMAND ${LLVM_TOOLS_BINARY_DIR}/mlir-opt ${BUDDY_BINARY_DIR}/../examples/BuddyMobileNetV3/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, \
Expand All @@ -25,14 +26,14 @@ add_custom_command(
${LLVM_TOOLS_BINARY_DIR}/llvm-as |
${LLVM_TOOLS_BINARY_DIR}/llc -filetype=obj -relocation-model=pic -O3
-o ${BUDDY_BINARY_DIR}/../examples/BuddyMobileNetV3/forward.o
DEPENDS ${BUDDY_EXAMPLES_DIR}/BuddyMobileNetV3/forward.mlir
DEPENDS ${BUDDY_BINARY_DIR}/../examples/BuddyMobileNetV3/forward.mlir
COMMENT "Building forward.o"
VERBATIM)


add_custom_command(
OUTPUT subgraph0.o
COMMAND ${BUDDY_BINARY_DIR}/buddy-opt ${BUDDY_EXAMPLES_DIR}/BuddyMobileNetV3/subgraph0.mlir
COMMAND ${BUDDY_BINARY_DIR}/buddy-opt ${BUDDY_BINARY_DIR}/../examples/BuddyMobileNetV3/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
Expand All @@ -58,7 +59,7 @@ add_custom_command(
${LLVM_TOOLS_BINARY_DIR}/llvm-as |
${LLVM_TOOLS_BINARY_DIR}/llc -filetype=obj -relocation-model=pic -O3
-o ${BUDDY_BINARY_DIR}/../examples/BuddyMobileNetV3/subgraph0.o
DEPENDS ${BUDDY_EXAMPLES_DIR}/BuddyMobileNetV3/subgraph0.mlir
DEPENDS ${BUDDY_BINARY_DIR}/../examples/BuddyMobileNetV3/subgraph0.mlir
buddy-opt
COMMENT "Building subgraph0.o"
VERBATIM)
Expand Down
Loading