Skip to content

Commit

Permalink
update .gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Oct 18, 2024
1 parent e154c3a commit 05680ec
Show file tree
Hide file tree
Showing 90 changed files with 27,774 additions and 2,132 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@
.cache

# Clangd configurations
.clangd
.clangd

# submodule
/llvm
thirdparty/pybind11
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@
path = thirdparty/riscv-gnu-toolchain
url = https://github.com/riscv-collab/riscv-gnu-toolchain.git
shallow = true
[submodule "thirdparty/pybind11"]
path = thirdparty/pybind11
url = https://github.com/pybind/pybind11.git
8 changes: 3 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ set(BUDDY_EXAMPLES_DIR ${BUDDY_SOURCE_DIR}/examples)
set(BUDDY_MIDEND_INCLUDE_DIR ${BUDDY_SOURCE_DIR}/midend/include/)
set(BUDDY_THIRDPARTY_INCLUDE_DIR ${BUDDY_SOURCE_DIR}/thirdparty/include/)
set(BUDDY_MLIR_PYTHON_PACKAGES_DIR ${BUDDY_BUILD_DIR}/python_packages)
set(BUDDY_RUNTIME_DIR ${BUDDY_SOURCE_DIR}/runtime)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BUDDY_BINARY_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${BUDDY_LIBRARY_DIR})
Expand All @@ -106,11 +107,6 @@ if(BUDDY_MLIR_ENABLE_DIP_LIB)
find_package(PNG REQUIRED)
endif()

if(BUDDY_ENABLE_PNG)
add_definitions(-DBUDDY_ENABLE_PNG)
find_package(PNG REQUIRED)
endif()

# Generate libraries into `lib` of build directory.
set(LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)

Expand All @@ -125,6 +121,7 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${BUDDY_SOURCE_DIR}/lib)
include_directories(${BUDDY_THIRDPARTY_INCLUDE_DIR})
include_directories(${BUDDY_SOURCE_DIR}/frontend/Interfaces)
include_directories(${BUDDY_RUNTIME_DIR}/profiler/include)

# Add MLIR and LLVM headers to the include path
include_directories(${LLVM_INCLUDE_DIRS})
Expand Down Expand Up @@ -240,6 +237,7 @@ add_subdirectory(backend)
add_subdirectory(tools)
add_subdirectory(examples)
add_subdirectory(tests)
add_subdirectory(runtime)

#-------------------------------------------------------------------------------
# Target check-buddy
Expand Down
14 changes: 0 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,6 @@ $ export LLVM_MLIR_BUILD_DIR=$PWD/../llvm/build
$ export PYTHONPATH=${LLVM_MLIR_BUILD_DIR}/tools/mlir/python_packages/mlir_core:${BUDDY_MLIR_BUILD_DIR}/python_packages:${PYTHONPATH}
```

To configure the build environment for using image processing libraries, follow these steps:

```
$ cmake -G Ninja .. \
-DMLIR_DIR=$PWD/../llvm/build/lib/cmake/mlir \
-DLLVM_DIR=$PWD/../llvm/build/lib/cmake/llvm \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DCMAKE_BUILD_TYPE=RELEASE \
-DBUDDY_MLIR_ENABLE_DIP_LIB=ON \
-DBUDDY_ENABLE_PNG=ON
$ ninja
$ ninja check-buddy
```

To build buddy-mlir with custom LLVM sources:

```
Expand Down
4 changes: 2 additions & 2 deletions examples/BuddyGraph/import-dynamo-break.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def forward(self, b, c):
primary_registry=tosa.ops_registry,
aot_autograd_decomposition=aot_autograd_decompositions
)
model_opt = torch.compile(model, backend=dynamo_compiler)
print(model_opt(a, b))
# model_opt = torch.compile(model, backend=dynamo_compiler)
# print(model_opt(a, b))

torch._dynamo.reset()

Expand Down
1 change: 1 addition & 0 deletions examples/BuddyMobileNetV3/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
add_custom_command(
OUTPUT ${BUDDY_EXAMPLES_DIR}/BuddyMobileNetV3/arg0.data
${BUDDY_EXAMPLES_DIR}/BuddyMobileNetV3/arg1.data
${BUDDY_EXAMPLES_DIR}/BuddyMobileNetV3/forward.mlir
${BUDDY_EXAMPLES_DIR}/BuddyMobileNetV3/subgraph0.mlir
COMMAND python3 ${BUDDY_EXAMPLES_DIR}/BuddyMobileNetV3/buddy-mobilenetv3-import.py
Expand Down
3 changes: 1 addition & 2 deletions examples/BuddyMobileNetV3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ $ cmake -G Ninja .. \
-DCMAKE_BUILD_TYPE=RELEASE \
-DBUDDY_MLIR_ENABLE_PYTHON_PACKAGES=ON \
-DPython3_EXECUTABLE=$(which python3) \
-DBUDDY_MLIR_ENABLE_DIP_LIB=ON \
-DBUDDY_ENABLE_PNG=ON
-DBUDDY_MLIR_ENABLE_DIP_LIB=ON
$ ninja
$ ninja check-buddy
```
Expand Down
21 changes: 7 additions & 14 deletions examples/BuddyMobileNetV3/buddy-mobilenetv3-import.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,9 @@
"The environment variable 'MOBILENETV3_MODEL_PATH' is not set or is invalid."
)

model = models.mobilenet_v3_small(
weights=models.MobileNet_V3_Small_Weights.IMAGENET1K_V1, pretrained=True
)
model = models.mobilenet_v3_small(weights=models.MobileNet_V3_Small_Weights.IMAGENET1K_V1, pretrained=True)
model = model.eval()

# Remove the num_batches_tracked attribute.
for layer in model.modules():
if isinstance(layer, torch.nn.BatchNorm2d):
if hasattr(layer, "num_batches_tracked"):
del layer.num_batches_tracked

# Initialize Dynamo Compiler with specific configurations as an importer.
dynamo_compiler = DynamoCompiler(
primary_registry=tosa.ops_registry,
Expand Down Expand Up @@ -76,10 +68,11 @@


float32_param = np.concatenate(
[
param.detach().numpy().reshape([-1])
for param in params
if param.dtype == torch.float32
]
[param.detach().numpy().reshape([-1]) for param in params if param.dtype == torch.float32]
)
float32_param.tofile(Path(current_path) / "arg0.data")

int64_param = np.concatenate(
[param.detach().numpy().reshape([-1]) for param in params if param.dtype == torch.int64]
)
int64_param.tofile(Path(current_path) / "arg1.data")
65 changes: 34 additions & 31 deletions examples/BuddyMobileNetV3/buddy-mobilenetv3-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,42 +33,42 @@ const std::string ImgName = "dog.png";
// Declare the mobilenet C interface.
extern "C" void _mlir_ciface_forward(MemRef<float, 2> *output,
MemRef<float, 1> *arg0,
MemRef<long long, 1> *arg1,
MemRef<float, 4> *input);

/// Print [Log] label in bold blue format.
void printLogLabel() { std::cout << "\033[34;1m[Log] \033[0m"; }

/// Load parameters into data container.
void loadParameters(const std::string &paramFilePath,
MemRef<float, 1> &params) {
const auto loadStart = std::chrono::high_resolution_clock::now();
// Open the parameter file in binary mode.
std::ifstream paramFile(paramFilePath, std::ios::in | std::ios::binary);
if (!paramFile.is_open()) {
throw std::runtime_error("[Error] Failed to open params file!");
void loadParameters(const std::string &floatParamPath,
const std::string &int64ParamPath,
MemRef<float, 1> &floatParam,
MemRef<long long, 1> &int64Param) {
std::ifstream floatParamFile(floatParamPath, std::ios::in | std::ios::binary);
if (!floatParamFile.is_open()) {
std::string errMsg = "Failed to open float param file: " +
std::filesystem::canonical(floatParamPath).string();
throw std::runtime_error(errMsg);
}
printLogLabel();
std::cout << "Loading params..." << std::endl;
printLogLabel();
// Print the canonical path of the parameter file.
std::cout << "Params file: " << std::filesystem::canonical(paramFilePath)
<< std::endl;
// Read the parameter data into the provided memory reference.
paramFile.read(reinterpret_cast<char *>(params.getData()),
sizeof(float) * (params.getSize()));
if (paramFile.fail()) {
throw std::runtime_error("Error occurred while reading params file!");
floatParamFile.read(reinterpret_cast<char *>(floatParam.getData()),
floatParam.getSize() * sizeof(float));
if (floatParamFile.fail()) {
throw std::runtime_error("Failed to read float param file");
}
paramFile.close();
const auto loadEnd = std::chrono::high_resolution_clock::now();
const std::chrono::duration<double, std::milli> loadTime =
loadEnd - loadStart;
printLogLabel();
std::cout << "Params load time: " << (double)(loadTime.count()) / 1000
<< "s\n"
<< std::endl;
}
floatParamFile.close();

std::ifstream int64ParamFile(int64ParamPath, std::ios::in | std::ios::binary);
if (!int64ParamFile.is_open()) {
std::string errMsg = "Failed to open int64 param file: " +
std::filesystem::canonical(int64ParamPath).string();
throw std::runtime_error(errMsg);
}
int64ParamFile.read(reinterpret_cast<char *>(int64Param.getData()),
int64Param.getSize() * sizeof(long long));
if (int64ParamFile.fail()) {
throw std::runtime_error("Failed to read int64 param file");
}
int64ParamFile.close();
}

// Softmax function.
void softmax(float *input, size_t size) {
Expand Down Expand Up @@ -124,10 +124,13 @@ int main() {

// Load model parameters from the specified file.
std::string paramsDir = mobilenetDir + "/arg0.data";
MemRef<float, 1> paramsContainer({ParamsSize});
loadParameters(paramsDir, paramsContainer);
std::string intDir = mobilenetDir + "/arg1.data";
MemRef<float, 1> paramsContainerf32({ParamsSize});
MemRef<long long, 1> ParamsContainerInt64({34});
loadParameters(paramsDir, intDir, paramsContainerf32, ParamsContainerInt64);
// Call the forward function of the model.
_mlir_ciface_forward(&output, &paramsContainer, &inputResize);
_mlir_ciface_forward(&output, &paramsContainerf32, &ParamsContainerInt64,
&inputResize);

auto out = output.getData();
softmax(out, 1000);
Expand Down
6 changes: 6 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ if(BUDDY_DSL_EXAMPLES)
add_subdirectory(ToyDSL)
endif()


if (BUDDY_PROFILE_EXAMPLES)
add_subdirectory(Profiler)
endif()


configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
Expand Down
65 changes: 0 additions & 65 deletions examples/MLIRLinalg/linalg-batch-matmul-dync.mlir

This file was deleted.

82 changes: 0 additions & 82 deletions examples/MLIRLinalg/linalg-conv2d_nhwc_fhwc.mlir

This file was deleted.

Loading

0 comments on commit 05680ec

Please sign in to comment.