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

Extract CFDFC from standard level #4

Merged
merged 42 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
95f34df
init place-buffers pass
yuxwang99 May 12, 2023
32c6a51
init mlip variable for cfdfc
yuxwang99 May 17, 2023
b30bfcd
write milp to .lp
yuxwang99 May 17, 2023
98f650f
init CFDFC
yuxwang99 May 19, 2023
5be82a3
sync
yuxwang99 May 19, 2023
d714fa4
save dfs via operation
yuxwang99 May 21, 2023
2cc001c
milp for CFDFC
yuxwang99 May 21, 2023
b16b28a
buffer placement draft
yuxwang99 May 30, 2023
0e831df
update init implementation of buffer placement
yuxwang99 Jun 7, 2023
d1db4b9
init second level CFDFC extraction for buffer placement
yuxwang99 Jun 8, 2023
03c105c
delete prev extraction method
yuxwang99 Jun 8, 2023
1c897d2
merge main
yuxwang99 Jun 8, 2023
1076309
config parameters for CFDFC extraction
yuxwang99 Jun 9, 2023
9414278
provide option for extraction MG
yuxwang99 Jun 9, 2023
a75c294
init MG extraction implement
yuxwang99 Jun 12, 2023
a03e708
Merge branch 'main' of github.com:EPFL-LAP/dynamatic into extractMG
yuxwang99 Jun 12, 2023
ccdaf7e
update print func
yuxwang99 Jun 13, 2023
fba6048
extractMG PR
yuxwang99 Jun 13, 2023
da03980
cancel debug print
yuxwang99 Jun 13, 2023
3868955
add option that allows to only operate on first MG
yuxwang99 Jun 14, 2023
3adcb6b
clear aborted functions in MILP optimization
yuxwang99 Jun 14, 2023
8fb3370
write exec num to the created MG
yuxwang99 Jun 14, 2023
0d39a2d
fix the execNum val name
yuxwang99 Jun 14, 2023
9c3c015
Merge branch 'main' of github.com:EPFL-LAP/dynamatic into extractMG
yuxwang99 Jun 14, 2023
93de0a1
change format
yuxwang99 Jun 14, 2023
63cb9a0
add comments for extraction MILP
yuxwang99 Jun 14, 2023
10872bc
adapt channel connections to units
yuxwang99 Jun 18, 2023
2adf6ad
refactor the extractMG
yuxwang99 Jun 21, 2023
273f52f
change data structure to store extraction result
yuxwang99 Jun 21, 2023
bb26a3d
merge with main
yuxwang99 Jun 23, 2023
4a63443
delete dfs
yuxwang99 Jun 24, 2023
13cb62c
formalize extractMG
yuxwang99 Jun 24, 2023
fe1c161
formalize CMakeList file
yuxwang99 Jun 24, 2023
f9c8152
formalize extractMG pass description
yuxwang99 Jun 24, 2023
89d9bc3
Conditional compilation based on Gurobi install
lucas-rami Jun 29, 2023
86f2bfe
Merge branch 'main' of github.com:EPFL-LAP/dynamatic into extractMG
yuxwang99 Jun 30, 2023
bda642a
format variables in extractMG
yuxwang99 Jun 30, 2023
0b30e29
update comments for data struct
yuxwang99 Jun 30, 2023
bd15aff
Merge branch 'main' of github.com:EPFL-LAP/dynamatic into extractMG
yuxwang99 Jul 1, 2023
2e3a092
delete useless pointer to archBB
yuxwang99 Jul 2, 2023
868723b
move defition of CFDFC to extractMG.h
yuxwang99 Jul 2, 2023
54f6a70
delete the new object of Arch
yuxwang99 Jul 4, 2023
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
4 changes: 3 additions & 1 deletion .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"${workspaceFolder}/circt/llvm/llvm/include/",
"${workspaceFolder}/circt/llvm/mlir/include/",
"${workspaceFolder}/circt/llvm/build/include/",
"${workspaceFolder}/circt/llvm/build/tools/mlir/include/"
"${workspaceFolder}/circt/llvm/build/tools/mlir/include/",
// Gurobi
"${env:GUROBI_HOME}/include/"
],
"intelliSenseMode": "linux-clang-x64",
"compilerPath": "/usr/bin/clang",
Expand Down
27 changes: 26 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ else ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
endif ()

include(FindPackageHandleStandardArgs)

#-------------------------------------------------------------------------------
# CIRCT/MLIR/LLVM configuration
#-------------------------------------------------------------------------------
Expand Down Expand Up @@ -62,13 +64,17 @@ option(LLVM_BUILD_TOOLS "Build the LLVM tools. If OFF, just generate build targe
# Dynamatic configuration
#-------------------------------------------------------------------------------

# Define some variables for Dynamatic
set(DYNAMATIC_SOURCE_DIR ${CMAKE_SOURCE_DIR})
set(DYNAMATIC_INCLUDE_DIR ${DYNAMATIC_SOURCE_DIR}/include)

set(DYNAMATIC_BINARY_DIR ${CMAKE_BINARY_DIR})
set(DYNAMATIC_TOOLS_DIR ${DYNAMATIC_BINARY_DIR}/bin)
set(DYNAMATIC_BIN_INCLUDE_DIR ${DYNAMATIC_BINARY_DIR}/include)

# Add our own directory to the list of search paths for CMake modules
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")

# Dynamatic include directories
include_directories(${DYNAMATIC_INCLUDE_DIR})
include_directories(${DYNAMATIC_BIN_INCLUDE_DIR})
include_directories(${DYNAMATIC_SOURCE_DIR}/tutorials/include)
Expand All @@ -93,6 +99,25 @@ function(add_dynamatic_dialect_library name)
add_dynamatic_library(${ARGV} DEPENDS dynamatic-headers)
endfunction()

#-------------------------------------------------------------------------------
# Gurobi setup
#-------------------------------------------------------------------------------

find_package(GUROBI)
if (GUROBI_FOUND)
message(STATUS "Found Gurobi")
message(STATUS "${GUROBI_LIBRARY}")
message(STATUS "${GUROBI_CXX_LIBRARY}")

include_directories(${GUROBI_INCLUDE_DIRS})
else()
message(WARNING "Gurobi wasn't found, the buffer placement infrastructure \
that requires solving an MILP will not be built with the \
project.")
endif()

include_directories(${GUROBI_INCLUDE_DIRS})

#-------------------------------------------------------------------------------
# Directory setup
#-------------------------------------------------------------------------------
Expand Down
39 changes: 39 additions & 0 deletions cmake/modules/FindGUROBI.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# From https://support.gurobi.com/hc/en-us/articles/360039499751-How-do-I-use-CMake-to-build-Gurobi-C-C-projects-

find_path(GUROBI_INCLUDE_DIRS
NAMES gurobi_c.h
HINTS ${GUROBI_DIR} $ENV{GUROBI_HOME}
PATH_SUFFIXES include)

find_library(GUROBI_LIBRARY
NAMES gurobi gurobi100
HINTS ${GUROBI_DIR} $ENV{GUROBI_HOME}
PATH_SUFFIXES lib)


if(MSVC)
set(MSVC_YEAR "2017")

if(MT)
set(M_FLAG "mt")
else()
set(M_FLAG "md")
endif()

find_library(GUROBI_CXX_LIBRARY
NAMES gurobi_c++${M_FLAG}${MSVC_YEAR}
HINTS ${GUROBI_DIR} $ENV{GUROBI_HOME}
PATH_SUFFIXES lib)
find_library(GUROBI_CXX_DEBUG_LIBRARY
NAMES gurobi_c++${M_FLAG}d${MSVC_YEAR}
HINTS ${GUROBI_DIR} $ENV{GUROBI_HOME}
PATH_SUFFIXES lib)
else()
find_library(GUROBI_CXX_LIBRARY
NAMES gurobi_c++
HINTS ${GUROBI_DIR} $ENV{GUROBI_HOME}
PATH_SUFFIXES lib)
set(GUROBI_CXX_DEBUG_LIBRARY ${GUROBI_CXX_LIBRARY})
endif()

find_package_handle_standard_args(GUROBI DEFAULT_MSG GUROBI_LIBRARY)
67 changes: 67 additions & 0 deletions include/dynamatic/Transforms/BufferPlacement/ExtractMG.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//===- UtilsForExtractMG.h - utils for extracting marked graph *- C++ ---*-===//
//
// This file declaresfunction supports for CFDFCircuit extraction.
//
//===----------------------------------------------------------------------===//

#ifndef DYNAMATIC_TRANSFORMS_EXTRACTMG_H
#define DYNAMATIC_TRANSFORMS_EXTRACTMG_H

#include "circt/Dialect/Handshake/HandshakeOps.h"
#include "dynamatic/Support/LLVM.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/IR/BuiltinTypes.h"

namespace dynamatic {
namespace buffer {

/// Data structure for archs between the two basic blocks
/// srcBB: index of the source basic block;
/// dstBB: index of the destination basic block;
/// execFreq: execution frequency of the arch;
/// isBackEdge: whether the arch is a back edge.
struct ArchBB {
unsigned srcBB, dstBB, execFreq;
bool isBackEdge;
};

/// Data structure for control-free dataflow circuits which
/// stores the units and channels inside it.
/// The CFDFC has properties for the buffer placement optimization, including
/// the target period, and maximum period.
struct CFDFC {
double targetCP, maxCP;
std::vector<Operation *> units;
std::vector<Value> channels;

unsigned execN = 0; // execution times of CFDFC
};

/// Read the simulation file of standard level execution and store the results
/// in the map.
LogicalResult readSimulateFile(const std::string &fileName,
std::map<ArchBB *, bool> &archs,
std::map<unsigned, bool> &bbs);

/// Define the MILP CFDFC extraction models, and write the optimization results
/// to the map.
LogicalResult extractCFDFCircuit(std::map<ArchBB *, bool> &archs,
std::map<unsigned, bool> &bbs, unsigned &freq);

/// Get the index of the basic block of an operation.
int getBBIndex(Operation *op);

/// Identify whether the channel is in selected the basic block.
bool isSelect(std::map<unsigned, bool> &bbs, Value val);

/// Identify whether the channel is in selected archs between the basic block.
bool isSelect(std::map<ArchBB *, bool> &archs, Value val);

/// Identify whether the connection between the source operation and
/// the destination operation is a back edge.
bool isBackEdge(Operation *opSrc, Operation *opDst);

} // namespace buffer
} // namespace dynamatic

#endif // DYNAMATIC_TRANSFORMS_EXTRACTMG_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===- HandshakePlaceBuffers.h - Place buffers in DFG -----------*- C++ -*-===//
//
// This file declares the --handshake-place-buffers pass.
//
//===----------------------------------------------------------------------===//

#ifndef DYNAMATIC_TRANSFORMS_PLACEBUFFERS_H
#define DYNAMATIC_TRANSFORMS_PLACEBUFFERS_H

#include "dynamatic/Support/LLVM.h"
#include "dynamatic/Transforms/BufferPlacement/ExtractMG.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"

namespace dynamatic {

std::unique_ptr<mlir::OperationPass<mlir::ModuleOp>>
createHandshakePlaceBuffersPass(bool firstMG = false,
std::string stdLevelInfo = "");

} // namespace dynamatic
#endif // DYNAMATIC_TRANSFORMS_PLACEBUFFERS_H
1 change: 1 addition & 0 deletions include/dynamatic/Transforms/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "dynamatic/Support/LLVM.h"
#include "dynamatic/Transforms/AnalyzeMemoryAccesses.h"
#include "dynamatic/Transforms/ArithReduceArea.h"
#include "dynamatic/Transforms/BufferPlacement/HandshakePlaceBuffers.h"
#include "dynamatic/Transforms/FlattenMemRefRowMajor.h"
#include "dynamatic/Transforms/HandshakeConcretizeIndexType.h"
#include "dynamatic/Transforms/HandshakeInferBasicBlocks.h"
Expand Down
15 changes: 14 additions & 1 deletion include/dynamatic/Transforms/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def HandshakePrepareForLegacy : Pass<"handshake-prepare-for-legacy", "mlir::Modu
let constructor = "dynamatic::createHandshakePrepareForLegacy()";
}


def HandshakeOptimizeBits : Pass<"optimize-bits" , "mlir::ModuleOp"> {
let summary = "Optimize bits width that can be reduced.";
let description = [{
Expand Down Expand Up @@ -107,6 +106,20 @@ def HandshakeMinimizeCstWidth : Pass<"handshake-minimize-cst-width", "mlir::Modu
let dependentDialects = ["mlir::arith::ArithDialect"];
}

def HandshakePlaceBuffers : Pass<"handshake-place-buffers", "mlir::ModuleOp"> {
let summary = "Insert buffers in dataflow graphs.";
let description = [{
The pass analyzes the circuit's channel prerequisites. Based the channel
prerequisite, the pass optimize the circuit performance by inserting buffers.
}];
let constructor = "dynamatic::createHandshakePlaceBuffersPass()";
let options = [
Option<"firstMG", "firstMG", "bool", "false",
"if true, only extract the first MG from the input file">,
Option<"stdLevelInfo", "std-level-info", "std::string", "",
"if true, extract CFDFC from standard level simluation">];
}

//===----------------------------------------------------------------------===//
// Other passes
//===----------------------------------------------------------------------===//
Expand Down
25 changes: 25 additions & 0 deletions lib/Transforms/BufferPlacement/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
if (NOT GUROBI_FOUND)
add_compile_definitions(DYNAMATIC_GUROBI_NOT_INSTALLED)
endif()

add_dynamatic_library(DynamaticBufferPlacement
ExtractMG.cpp
HandshakePlaceBuffers.cpp

DEPENDS
DynamaticTransformsPassIncGen

LINK_LIBS PUBLIC
MLIRIR
MLIRMemRefDialect
MLIRFuncDialect
MLIRSupport
MLIRTransformUtils
DynamaticSupport
)

target_link_libraries(DynamaticBufferPlacement
PUBLIC
${GUROBI_CXX_LIBRARY}
${GUROBI_LIBRARY}
)
Loading