Merge pull request #24 from hanchenye/c-frontend

Added C frontend
This commit is contained in:
Hanchen Ye 2021-05-01 00:44:16 -05:00 committed by GitHub
commit 10179b4a8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 1469 additions and 13 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "llvm"]
path = llvm
url = git@github.com:circt/llvm.git

View File

@ -25,6 +25,10 @@ find_package(MLIR REQUIRED CONFIG)
message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
message(STATUS "Using ClangConfig.cmake in: ${CLANG_DIR}")
set(Clang_DIR ${CLANG_DIR})
find_package(Clang REQUIRED)
set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/bin)
set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/lib)
@ -50,6 +54,7 @@ include(AddLLVM)
include(AddMLIR)
include(HandleLLVMOptions)
include_directories(${CLANG_INCLUDE_DIRS})
include_directories(${LLVM_INCLUDE_DIRS})
include_directories(${MLIR_INCLUDE_DIRS})
include_directories(${PROJECT_SOURCE_DIR}/include)

View File

@ -3,13 +3,22 @@
This project aims to create a framework that ultimately converts an algorithm written in a high level language into an efficient hardware implementation. With multiple levels of intermediate representations (IRs), MLIR appears to be the ideal tool for exploring ways to optimize the eventual design at various levels of abstraction (e.g. various levels of parallelism). Our framework will be based on MLIR, it will incorporate a backend for high level synthesis (HLS) C/C++ code. However, the key contribution will be our parameterization and optimization of a tremendously large design space.
## Quick Start
### 0. Download ScaleHLS and LLVM
```
$ git clone git@github.com:hanchenye/scalehls.git
$ cd scalehls
$ git submodule init
$ git submodule update
```
### 1. Install LLVM and MLIR
**IMPORTANT** This step assumes that you have cloned LLVM from (https://github.com/circt/llvm/tree/main) to `$LLVM_DIR` and checked out the `main` branch. To build LLVM and MLIR, run:
This step assumes this repository is cloned to `$SCALEHLS_DIR`. To build LLVM and MLIR, run:
```sh
$ mkdir $LLVM_DIR/build
$ cd $LLVM_DIR/build
$ mkdir $SCALEHLS_DIR/llvm/build
$ cd $SCALEHLS_DIR/llvm/build
$ cmake -G Ninja ../llvm \
-DLLVM_ENABLE_PROJECTS="mlir" \
-DLLVM_ENABLE_PROJECTS="mlir;llvm;clang;clang-extra-tools" \
-DLLVM_TARGETS_TO_BUILD="X86;RISCV" \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DCMAKE_BUILD_TYPE=DEBUG
@ -18,13 +27,16 @@ $ ninja check-mlir
```
### 2. Install ScaleHLS
This step assumes this repository is cloned to `$SCALEHLS_DIR`. To build and launch the tests, run:
To build and launch the tests, run:
```sh
$ mkdir $SCALEHLS_DIR/build
$ cd $SCALEHLS_DIR/build
$ cmake -G Ninja .. \
-DMLIR_DIR=$LLVM_DIR/build/lib/cmake/mlir \
-DLLVM_DIR=$LLVM_DIR/build/lib/cmake/llvm \
-DMLIR_DIR=$PWD/../llvm/build/lib/cmake/mlir \
-DLLVM_DIR=$PWD/../llvm/build/lib/cmake/llvm \
-DCLANG_DIR=$PWD/../llvm/build/lib/cmake/clang \
-DCMAKE_C_COMPILER=$PWD/../llvm/build/bin/clang \
-DCMAKE_CXX_COMPILER=$PWD/../llvm/build/bin/clang++ \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DCMAKE_BUILD_TYPE=DEBUG
$ ninja check-scalehls

View File

@ -7,8 +7,9 @@
#ifndef SCALEHLS_DIALECT_HLSCPP_ATTRIBUTES_TD
#define SCALEHLS_DIALECT_HLSCPP_ATTRIBUTES_TD
class HLSCppAttr<string name, string baseCppClass = "::mlir::Attribute">
: AttrDef<HLSCppDialect, name, baseCppClass>;
class HLSCppAttr<string name, list<Trait> traits = [],
string baseCppClass = "::mlir::Attribute">
: AttrDef<HLSCppDialect, name, traits, baseCppClass>;
def Resource : HLSCppAttr<"Resource"> {
let summary = "Resource utilization information";

View File

@ -9,6 +9,7 @@
#include "mlir/Transforms/LoopUtils.h"
#include "scalehls/Transforms/Passes.h"
#include "scalehls/Transforms/Utils.h"
#include "llvm/Support/Debug.h"
#define DEBUG_TYPE "scalehls"

1
llvm Submodule

@ -0,0 +1 @@
Subproject commit 49745f87e61014ac2a9e93bcad1225c55695b9b7

View File

@ -7,6 +7,7 @@ configure_lit_site_cfg(
set(SCALEHLS_TEST_DEPENDS
FileCheck count not
scalehls-clang
scalehls-opt
scalehls-translate
benchmark-gen

View File

@ -21,7 +21,7 @@ config.name = 'SCALEHLS'
config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
# suffixes: A list of file extensions to treat as test files.
config.suffixes = ['.mlir', '.ini']
config.suffixes = ['.mlir', '.ini', '.c']
# test_source_root: The root path where tests are located.
config.test_source_root = os.path.dirname(__file__)
@ -51,8 +51,10 @@ config.test_exec_root = os.path.join(config.scalehls_obj_root, 'test')
# Tweak the PATH to include the tools dir.
llvm_config.with_environment('PATH', config.llvm_tools_dir, append_path=True)
tool_dirs = [config.scalehls_tools_dir, config.mlir_tools_dir, config.llvm_tools_dir]
tool_dirs = [config.scalehls_tools_dir,
config.mlir_tools_dir, config.llvm_tools_dir]
tools = [
'scalehls-clang',
'scalehls-opt',
'scalehls-translate',
'benchmark-gen'

View File

@ -0,0 +1,13 @@
// RUN: scalehls-clang %s | FileCheck %s
// CHECK: func @syrk(
void syrk(float alpha, float beta, float C[32][32], float A[32][32]) {
for (int i = 0; i < 32; i++) {
for (int j = 0; j <= i; j++) {
C[i][j] *= beta;
for (int k = 0; k < 32; k++) {
C[i][j] += alpha * A[i][k] * A[j][k];
}
}
}
}

View File

@ -1,3 +1,4 @@
add_subdirectory(scalehls-clang)
add_subdirectory(scalehls-opt)
add_subdirectory(scalehls-translate)
add_subdirectory(benchmark-gen)

View File

@ -0,0 +1,17 @@
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
add_llvm_tool(scalehls-clang
scalehls-clang.cpp
)
llvm_update_compile_flags(scalehls-clang)
target_link_libraries(scalehls-clang
PRIVATE
${dialect_libs}
clangFrontend
clangTooling
clangBasic
)

File diff suppressed because it is too large Load Diff

View File

@ -13,6 +13,6 @@ int main(int argc, char **argv) {
mlir::scalehls::registerAllDialects(registry);
mlir::scalehls::registerAllPasses();
return mlir::failed(
mlir::MlirOptMain(argc, argv, "ScaleHLS Optimization Tool", registry));
return mlir::failed(mlir::MlirOptMain(
argc, argv, "ScaleHLS Optimization Tool", registry, true));
}