From 6a6cca059ae8a36a3f5c16d9f813c284e9d76918 Mon Sep 17 00:00:00 2001 From: zhanghb97 Date: Tue, 27 Aug 2024 04:24:54 +0000 Subject: [PATCH 1/3] [examples] Add memref type generation example. --- examples/BuddyGen/.gitignore | 4 +++ examples/BuddyGen/GenMemRef.cpp | 43 +++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 examples/BuddyGen/.gitignore create mode 100644 examples/BuddyGen/GenMemRef.cpp diff --git a/examples/BuddyGen/.gitignore b/examples/BuddyGen/.gitignore new file mode 100644 index 0000000000..df9389428a --- /dev/null +++ b/examples/BuddyGen/.gitignore @@ -0,0 +1,4 @@ +log.mlir +log.ll +log.s +a.out diff --git a/examples/BuddyGen/GenMemRef.cpp b/examples/BuddyGen/GenMemRef.cpp new file mode 100644 index 0000000000..86cb9aa0c9 --- /dev/null +++ b/examples/BuddyGen/GenMemRef.cpp @@ -0,0 +1,43 @@ +//===- GenMemRef.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. +// +//===----------------------------------------------------------------------===// + +// $ export LLVM_DIR=$PWD/../../llvm/ +// $ export LLVM_BUILD_DIR=$LLVM_DIR/build +// $ c++ GenMemRef.cpp \ + -I $LLVM_DIR/llvm/include/ -I $LLVM_BUILD_DIR/include/ \ + -I $LLVM_DIR/mlir/include/ -I $LLVM_BUILD_DIR/tools/mlir/include/ \ + -L$LLVM_BUILD_DIR/lib -lMLIRIR -lMLIRParser -lMLIRSupport -lLLVMCore \ + -lLLVMSupport -lncurses -ltinfo -lstdc++ -lLLVMDemangle \ + -o a.out +// $ a.out + +#include "mlir/Dialect/MemRef/IR/MemRef.h" +#include "mlir/IR/BuiltinTypes.h" +#include "mlir/IR/MLIRContext.h" + +int main() { + mlir::MLIRContext context; + mlir::OpBuilder builder(&context); + mlir::Type eleType = builder.getF64Type(); + // Target memref type: + // `memref>` + mlir::MemRefType memrefType = mlir::MemRefType::get( + {mlir::ShapedType::kDynamic}, eleType, + mlir::StridedLayoutAttr::get( + &context, /*offset=*/mlir::ShapedType::kDynamic, /*strides=*/{1})); + memrefType.dump(); + return 0; +} From 5e5a6a569cb08648b960512cff09bc76b62f3459 Mon Sep 17 00:00:00 2001 From: zhanghb97 Date: Tue, 27 Aug 2024 04:29:29 +0000 Subject: [PATCH 2/3] [NFC] Fix typo. --- examples/BuddyGen/GenMemRef.cpp | 2 +- examples/BuddyLlama/import-llama2.py | 17 +++++++++-------- .../BuddyMobileNetV3/buddy-mobilenetv3-main.cpp | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/examples/BuddyGen/GenMemRef.cpp b/examples/BuddyGen/GenMemRef.cpp index 86cb9aa0c9..8ca2526b79 100644 --- a/examples/BuddyGen/GenMemRef.cpp +++ b/examples/BuddyGen/GenMemRef.cpp @@ -22,7 +22,7 @@ -L$LLVM_BUILD_DIR/lib -lMLIRIR -lMLIRParser -lMLIRSupport -lLLVMCore \ -lLLVMSupport -lncurses -ltinfo -lstdc++ -lLLVMDemangle \ -o a.out -// $ a.out +// $ ./a.out #include "mlir/Dialect/MemRef/IR/MemRef.h" #include "mlir/IR/BuiltinTypes.h" diff --git a/examples/BuddyLlama/import-llama2.py b/examples/BuddyLlama/import-llama2.py index fbd12e5bff..2903d6bd81 100644 --- a/examples/BuddyLlama/import-llama2.py +++ b/examples/BuddyLlama/import-llama2.py @@ -1,11 +1,3 @@ -import os -import torch -import torch._dynamo as dynamo -from transformers import LlamaForCausalLM, LlamaTokenizer -from torch._inductor.decomposition import decompositions as inductor_decomp -import numpy - -from buddy.compiler.frontend import DynamoCompiler # ===- import-llama2.py -------------------------------------------------------- # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -25,6 +17,15 @@ # This is the test of llama2 model. # # ===--------------------------------------------------------------------------- + +import os +import torch +import torch._dynamo as dynamo +from transformers import LlamaForCausalLM, LlamaTokenizer +from torch._inductor.decomposition import decompositions as inductor_decomp +import numpy + +from buddy.compiler.frontend import DynamoCompiler from buddy.compiler.ops import tosa from buddy.compiler.graph import GraphDriver from buddy.compiler.graph.transform import simply_fuse diff --git a/examples/BuddyMobileNetV3/buddy-mobilenetv3-main.cpp b/examples/BuddyMobileNetV3/buddy-mobilenetv3-main.cpp index 68d9d15411..0c5318b37d 100644 --- a/examples/BuddyMobileNetV3/buddy-mobilenetv3-main.cpp +++ b/examples/BuddyMobileNetV3/buddy-mobilenetv3-main.cpp @@ -1,4 +1,4 @@ -//===- MobileNetBenchmark.cpp ---------------------------------------------===// +//===- buddy-mobilenetv3-main.cpp -----------------------------------------===// // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. From 952d5586b54771279d1e8f1ced3059c988ec9c45 Mon Sep 17 00:00:00 2001 From: ShiHaoGao <61191871+ShiHaoGao@users.noreply.github.com> Date: Tue, 27 Aug 2024 20:07:01 +0800 Subject: [PATCH 3/3] [Docs] Add Python Virtual Environment Setup Guide. (#373) --- .gitignore | 3 +++ docs/PythonEnvironment.md | 10 ++++++++++ docs/{RVVEnviroment.md => RVVEnvironment.md} | 0 3 files changed, 13 insertions(+) create mode 100644 docs/PythonEnvironment.md rename docs/{RVVEnviroment.md => RVVEnvironment.md} (100%) diff --git a/.gitignore b/.gitignore index 485cccfcf9..1ffba60cbc 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,6 @@ # Clangd cache .cache + +# Clangd configurations +.clangd \ No newline at end of file diff --git a/docs/PythonEnvironment.md b/docs/PythonEnvironment.md new file mode 100644 index 0000000000..77f431e85c --- /dev/null +++ b/docs/PythonEnvironment.md @@ -0,0 +1,10 @@ +# Python Virtual Environment Setup Guide for Buddy-mlir + +We recommend you to use anaconda3 to create python virtual environment. You should install python packages as buddy-mlir/requirements. + +```bash +$ conda create -n python=3.11 +$ conda activate +$ cd buddy-mlir +$ pip install -r requirements.txt +``` \ No newline at end of file diff --git a/docs/RVVEnviroment.md b/docs/RVVEnvironment.md similarity index 100% rename from docs/RVVEnviroment.md rename to docs/RVVEnvironment.md