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

[handshake-sim] Added complete modularity for execution models #13

Merged
merged 16 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 14 additions & 14 deletions experimental/data/handshake-simulator-configuration.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"handshake.fork":"defaultFork",
"handshake.merge":"defaultMerge",
"handshake.control_merge":"defaultControlMerge",
"handshake.mux":"defaultMux",
"handshake.br":"defaultBranch",
"handshake.cond_br":"defaultConditionalMerge",
"handshake.sink":"defaultSink",
"handshake.constant":"defaultConstant",
"handshake.buffer":"defaultBuffer",
"handshake.load":"defaultDynamaticLoad",
"handshake.store":"defaultDynamaticStore",
"handshake.return":"defaultDynamaticReturn",
"handshake.end":"defaultEnd",
"handshake.memory_controller":"defaultMemoryController"
"handshake.fork":"default.handshake.fork",
"handshake.merge":"default.handshake.merge",
"handshake.control_merge":"default.handshake.control_merge",
"handshake.mux":"default.handshake.mux",
"handshake.br":"default.handshake.br",
"handshake.cond_br":"default.handshake.cond_br",
"handshake.sink":"default.handshake.sink",
"handshake.constant":"default.handshake.constant",
"handshake.buffer":"default.handshake.buffer",
"handshake.load":"default.handshake.load",
"handshake.store":"default.handshake.store",
"handshake.return":"default.handshake.return",
"handshake.end":"default.handshake.end",
"handshake.memory_controller":"default.handshake.memory_controller"
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
//===- ExecModels.h - Handshake MLIR and Dynamatic Operations -------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Inherited from CIRCT which holds the informations about each operation
//
//===----------------------------------------------------------------------===//

#ifndef EXPERIMENTAL_TOOLS_HANDSHAKESIMULATOR_EXECMODELS_H
#define EXPERIMENTAL_TOOLS_HANDSHAKESIMULATOR_EXECMODELS_H

#include "circt/Dialect/Handshake/HandshakeOps.h"
#include "mlir/IR/Value.h"
#include "llvm/ADT/Any.h"
#include "llvm/Support/Debug.h"
#include <string>

namespace dynamatic {
namespace experimental {

struct ExecutableModel;

using ModelMap =
std::map<std::string,
std::unique_ptr<dynamatic::experimental::ExecutableModel>>;

/// Initialises the mapping from operations to the configurated structure
/// ADD YOUR STRUCT TO THE CORRESPONDING MAP IN THIS METHOD
mlir::LogicalResult initialiseMap(llvm::StringMap<std::string> &funcMap,
ModelMap &models);

/// Data structure to hold functions to execute each components
struct ExecutableModel {
/// A wrapper function to do all the utility stuff in order to simulate
/// the execution correctly
virtual bool tryExecute(llvm::DenseMap<mlir::Value, llvm::Any> &valueMap,
llvm::DenseMap<unsigned, unsigned> &memoryMap,
llvm::DenseMap<mlir::Value, double> &timeMap,
std::vector<std::vector<llvm::Any>> &store,
llvm::SmallVector<mlir::Value> &scheduleList,
ModelMap &models, circt::Operation &op) = 0;

virtual ~ExecutableModel(){};
};

//----------------------------------------------------------------------------//
// Execution models structure definitions //
//----------------------------------------------------------------------------//

//--- Default CIRCT models ---------------------------------------------------//

struct DefaultFork : public ExecutableModel {
virtual bool tryExecute(llvm::DenseMap<mlir::Value, llvm::Any> &valueMap,
llvm::DenseMap<unsigned, unsigned> &memoryMap,
llvm::DenseMap<mlir::Value, double> &timeMap,
std::vector<std::vector<llvm::Any>> &store,
llvm::SmallVector<mlir::Value> &scheduleList,
ModelMap &models, circt::Operation &op) override;
};

struct DefaultMerge : public ExecutableModel {
bool tryExecute(llvm::DenseMap<mlir::Value, llvm::Any> &valueMap,
llvm::DenseMap<unsigned, unsigned> &memoryMap,
llvm::DenseMap<mlir::Value, double> &timeMap,
std::vector<std::vector<llvm::Any>> &store,
llvm::SmallVector<mlir::Value> &scheduleList, ModelMap &models,
circt::Operation &op) override;
};

struct DefaultControlMerge : public ExecutableModel {
bool tryExecute(llvm::DenseMap<mlir::Value, llvm::Any> &valueMap,
llvm::DenseMap<unsigned, unsigned> &memoryMap,
llvm::DenseMap<mlir::Value, double> &timeMap,
std::vector<std::vector<llvm::Any>> &store,
llvm::SmallVector<mlir::Value> &scheduleList, ModelMap &models,
circt::Operation &op) override;
};

struct DefaultMux : public ExecutableModel {
bool tryExecute(llvm::DenseMap<mlir::Value, llvm::Any> &valueMap,
llvm::DenseMap<unsigned, unsigned> &memoryMap,
llvm::DenseMap<mlir::Value, double> &timeMap,
std::vector<std::vector<llvm::Any>> &store,
llvm::SmallVector<mlir::Value> &scheduleList, ModelMap &models,
circt::Operation &op) override;
};

struct DefaultBranch : public ExecutableModel {
bool tryExecute(llvm::DenseMap<mlir::Value, llvm::Any> &valueMap,
llvm::DenseMap<unsigned, unsigned> &memoryMap,
llvm::DenseMap<mlir::Value, double> &timeMap,
std::vector<std::vector<llvm::Any>> &store,
llvm::SmallVector<mlir::Value> &scheduleList, ModelMap &models,
circt::Operation &op) override;
};

struct DefaultConditionalBranch : public ExecutableModel {
bool tryExecute(llvm::DenseMap<mlir::Value, llvm::Any> &valueMap,
llvm::DenseMap<unsigned, unsigned> &memoryMap,
llvm::DenseMap<mlir::Value, double> &timeMap,
std::vector<std::vector<llvm::Any>> &store,
llvm::SmallVector<mlir::Value> &scheduleList, ModelMap &models,
circt::Operation &op) override;
};

struct DefaultSink : public ExecutableModel {
bool tryExecute(llvm::DenseMap<mlir::Value, llvm::Any> &valueMap,
llvm::DenseMap<unsigned, unsigned> &memoryMap,
llvm::DenseMap<mlir::Value, double> &timeMap,
std::vector<std::vector<llvm::Any>> &store,
llvm::SmallVector<mlir::Value> &scheduleList, ModelMap &models,
circt::Operation &op) override;
};

struct DefaultConstant : public ExecutableModel {
bool tryExecute(llvm::DenseMap<mlir::Value, llvm::Any> &valueMap,
llvm::DenseMap<unsigned, unsigned> &memoryMap,
llvm::DenseMap<mlir::Value, double> &timeMap,
std::vector<std::vector<llvm::Any>> &store,
llvm::SmallVector<mlir::Value> &scheduleList, ModelMap &models,
circt::Operation &op) override;
};

struct DefaultBuffer : public ExecutableModel {
bool tryExecute(llvm::DenseMap<mlir::Value, llvm::Any> &valueMap,
llvm::DenseMap<unsigned, unsigned> &memoryMap,
llvm::DenseMap<mlir::Value, double> &timeMap,
std::vector<std::vector<llvm::Any>> &store,
llvm::SmallVector<mlir::Value> &scheduleList, ModelMap &models,
circt::Operation &op) override;
};

//--- Custom models ----------------------------------------------------------//

} // namespace experimental
} // namespace dynamatic

#endif // EXPERIMENTAL_TOOLS_HANDSHAKESIMULATOR_EXECMODELS_H
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
namespace dynamatic {
namespace experimental {

bool simulate(llvm::StringRef toplevelFunction,
mlir::LogicalResult simulate(llvm::StringRef toplevelFunction,
llvm::ArrayRef<std::string> inputArgs,
mlir::OwningOpRef<mlir::ModuleOp> &module,
mlir::MLIRContext &context,
llvm::StringMap<std::string> &config);
llvm::StringMap<std::string> &funcMap);
} // namespace dynamatic
} // namespace experimental

Expand Down
2 changes: 1 addition & 1 deletion experimental/tools/handshake-simulator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_llvm_executable(handshake-simulator handshake-simulator.cpp Simulation.cpp)
add_llvm_executable(handshake-simulator handshake-simulator.cpp Simulation.cpp ExecModels.cpp)

llvm_update_compile_flags(handshake-simulator)
target_link_libraries(handshake-simulator PRIVATE
Expand Down
Loading