Skip to content

Commit 5052656

Browse files
committed
split scheduler and asm gen
1 parent a451579 commit 5052656

File tree

9 files changed

+555
-462
lines changed

9 files changed

+555
-462
lines changed
+1-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
11
set(LLVM_TARGET_DEFINITIONS Passes.td)
22
mlir_tablegen(Passes.h.inc -gen-pass-decls -name ASMGen)
33
add_public_tablegen_target(CompigraASMGenIncGen)
4-
add_dependencies(compigra-headers CompigraASMGenIncGen)
5-
6-
# GUROBI Optimizer related setup
7-
# Check if GUROBI_INSTALL_DIR is provided as a CMake parameter
8-
if(GUROBI_INSTALL_DIR)
9-
message(STATUS "GUROBI_INSTALL_DIR is set via CMake parameter: ${GUROBI_INSTALL_DIR}")
10-
include_directories(${GUROBI_INSTALL_DIR}/include)
11-
add_definitions(-DHAVE_GUROBI)
12-
message(STATUS "Including Gurobi include directory: ${GUROBI_INSTALL_DIR}/include")
13-
else()
14-
message(WARNING "GUROBI_INSTALL_DIR is not set. Gurobi will not be included.")
15-
endif()
4+
add_dependencies(compigra-headers CompigraASMGenIncGen)

include/compigra/ASMGen/OpenEdgeASM.h

+4-41
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "compigra/CgraDialect.h"
1717
#include "compigra/CgraInterfaces.h"
1818
#include "compigra/CgraOps.h"
19+
#include "compigra/Scheduler/KernelSchedule.h"
1920
#include "compigra/Transforms/SatMapItDATE2023InputGen/PrintSatMapItDAG.h"
2021
#ifdef HAVE_GUROBI
2122
#include "gurobi_c++.h"
@@ -29,11 +30,6 @@ namespace compigra {
2930
#include "compigra/ASMGen/Passes.h.inc"
3031

3132
// Schedule unit is a pair of time and PE, and the register to store the result
32-
struct ScheduleUnit {
33-
int time;
34-
int pe;
35-
int reg;
36-
};
3733

3834
class OpenEdgeASMGen {
3935
public:
@@ -52,52 +48,19 @@ class OpenEdgeASMGen {
5248
/// Get the earliest execution time of operations in the block
5349
int getEarliestExecutionTime(Block *block);
5450

55-
int getConnectedBlock(int block, std::string direction);
5651

57-
/// Assign the schedule results from SAT-MapIt printout to the operations
58-
LogicalResult assignSchedule(mlir::Block::OpListType &ops,
59-
std::map<int, Instruction> instructions);
6052

61-
void writeOpResult(Operation *op, int time, int pe, int reg) {
62-
ScheduleUnit unit = {time, pe, reg};
63-
solution[op] = unit;
64-
}
53+
54+
55+
6556

6657
const std::map<Operation *, ScheduleUnit> getCurrSolution() {
6758
return solution;
6859
}
6960

70-
/// Struct to hold the data for each instruction
71-
#ifdef HAVE_GUROBI
72-
LogicalResult createSchedulerAndSolve();
73-
74-
void initObjectiveFunction(GRBModel &model, GRBVar &funcStartT,
75-
GRBVar &funcEndT,
76-
std::map<Operation *, GRBVar> &timeOpVar,
77-
std::map<Block *, GRBVar> &timeBlkEntry,
78-
std::map<Block *, GRBVar> &timeBlkExit);
79-
void initVariables(GRBModel &model, std::map<Block *, GRBVar> &timeBlkEntry,
80-
std::map<Block *, GRBVar> &timeBlkExit,
81-
std::map<Operation *, GRBVar> &timeOpVar,
82-
std::map<Operation *, GRBVar> &spaceOpVar);
83-
void initKnownSchedule(GRBModel &model,
84-
std::map<Operation *, GRBVar> &timeOpVar,
85-
std::map<Operation *, GRBVar> &spaceOpVar);
86-
void initOpTimeConstraints(GRBModel &model,
87-
std::map<Operation *, GRBVar> &timeOpVar,
88-
std::map<Block *, GRBVar> &timeBlkEntry,
89-
std::map<Block *, GRBVar> &timeBlkExit);
90-
void initOpSpaceConstraints(GRBModel &model,
91-
std::map<Operation *, GRBVar> &spaceOpVar);
92-
void initOpTimeSpaceConstraints(GRBModel &model,
93-
std::map<Operation *, GRBVar> &timeOpVar,
94-
std::map<Operation *, GRBVar> &spaceOpVar);
95-
9661
// void printKownSchedule();
9762
std::map<Operation *, Instruction> knownRes;
9863

99-
#endif
100-
10164
protected:
10265
Region &region;
10366
unsigned maxReg;
+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
//===- KernelSchedule.h - Declare the class for ops schedule ----*- C++ -*-===//
2+
//
3+
// Compigra is under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file defines class for schedule functions.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef KERNEL_SCHEDULE_H
14+
#define KERNEL_SCHEDULE_H
15+
16+
#include "compigra/Transforms/SatMapItDATE2023InputGen/PrintSatMapItDAG.h"
17+
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
18+
using namespace mlir;
19+
20+
#ifdef HAVE_GUROBI
21+
#include "gurobi_c++.h"
22+
#endif
23+
24+
/// CGRA base scheduler class, where T is the struct that define the placement
25+
/// of the operation.
26+
namespace compigra {
27+
28+
template <typename T> class CGRAKernelScheduler {
29+
public:
30+
CGRAKernelScheduler(unsigned maxReg, unsigned nRow, unsigned nCol)
31+
: maxReg(maxReg), nRow(nRow), nCol(nCol) {}
32+
33+
virtual LogicalResult createSchedulerAndSolve() { return success(); };
34+
35+
/// Get the schedule result
36+
std::map<Operation *, T> getSolution() { return solution; }
37+
38+
/// Get the schedule result for the operation
39+
T getSolution(Operation *op) { return solution[op]; }
40+
41+
protected:
42+
// maximum number of registers in the PE;
43+
unsigned maxReg;
44+
45+
// number of rows and columns in the CGRA
46+
unsigned nRow, nCol;
47+
48+
std::map<Operation *, T> solution;
49+
};
50+
51+
struct ScheduleUnit {
52+
int time;
53+
int pe;
54+
int reg;
55+
};
56+
57+
/// OpenEdge kernel scheduler class
58+
class OpenEdgeKernelScheduler : public CGRAKernelScheduler<ScheduleUnit> {
59+
public:
60+
/// Initialize the region which contains the operations and the maximum number
61+
/// of PEs
62+
OpenEdgeKernelScheduler(Region &region, unsigned maxReg, unsigned grid)
63+
: CGRAKernelScheduler<ScheduleUnit>(maxReg, grid, grid), region(region) {}
64+
65+
LogicalResult createSchedulerAndSolve() override;
66+
67+
protected:
68+
Region &region;
69+
70+
public:
71+
#ifdef HAVE_GUROBI
72+
73+
void initObjectiveFunction(GRBModel &model, GRBVar &funcStartT,
74+
GRBVar &funcEndT,
75+
std::map<Operation *, GRBVar> &timeOpVar,
76+
std::map<Block *, GRBVar> &timeBlkEntry,
77+
std::map<Block *, GRBVar> &timeBlkExit);
78+
void initVariables(GRBModel &model, std::map<Block *, GRBVar> &timeBlkEntry,
79+
std::map<Block *, GRBVar> &timeBlkExit,
80+
std::map<Operation *, GRBVar> &timeOpVar,
81+
std::map<Operation *, GRBVar> &spaceOpVar);
82+
void initKnownSchedule(GRBModel &model,
83+
std::map<Operation *, GRBVar> &timeOpVar,
84+
std::map<Operation *, GRBVar> &spaceOpVar);
85+
void initOpTimeConstraints(GRBModel &model,
86+
std::map<Operation *, GRBVar> &timeOpVar,
87+
std::map<Block *, GRBVar> &timeBlkEntry,
88+
std::map<Block *, GRBVar> &timeBlkExit);
89+
void initOpSpaceConstraints(GRBModel &model,
90+
std::map<Operation *, GRBVar> &spaceOpVar);
91+
void initOpTimeSpaceConstraints(GRBModel &model,
92+
std::map<Operation *, GRBVar> &timeOpVar,
93+
std::map<Operation *, GRBVar> &spaceOpVar);
94+
#endif
95+
96+
private:
97+
int getConnectedBlock(int block, std::string direction);
98+
void writeOpResult(Operation *op, int time, int pe, int reg) {
99+
ScheduleUnit unit = {time, pe, reg};
100+
solution[op] = unit;
101+
}
102+
103+
public:
104+
/// Assign the schedule results from SAT-MapIt printout to the operations
105+
void assignSchedule(mlir::Block::OpListType &ops,
106+
std::map<int, Instruction> instructions);
107+
108+
// void printKownSchedule();
109+
std::map<Operation *, Instruction> knownRes;
110+
};
111+
} // namespace compigra
112+
113+
#endif // KERNEL_SCHEDULE_H

lib/compigra/ASMGen/CMakeLists.txt

+1-17
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,4 @@ CompigraASMGenIncGen
99

1010
LINK_LIBS PUBLIC
1111
MLIRIR
12-
)
13-
14-
# GUROBI Optimizer related setup
15-
# Check if GUROBI_INSTALL_DIR is provided as a CMake parameter
16-
if(GUROBI_INSTALL_DIR)
17-
message(STATUS "GUROBI_INSTALL_DIR is set via CMake parameter: ${GUROBI_INSTALL_DIR}")
18-
add_definitions(-DHAVE_GUROBI)
19-
include_directories(${GUROBI_INSTALL_DIR}/include)
20-
include_directories(${GUROBI_INSTALL_DIR}/src/cpp)
21-
target_link_libraries(MLIRCompigraASMGen PUBLIC
22-
${GUROBI_INSTALL_DIR}/lib/libgurobi_c++.a
23-
${GUROBI_INSTALL_DIR}/lib/libgurobi110.so)
24-
message(STATUS "Including Gurobi include directory: ${GUROBI_INSTALL_DIR}/include")
25-
message(STATUS "Linking Gurobi library: ${GUROBI_INSTALL_DIR}/lib")
26-
else()
27-
message(WARNING "GUROBI_INSTALL_DIR is not set. Gurobi will not be included.")
28-
endif()
12+
)

0 commit comments

Comments
 (0)