Skip to content

Commit

Permalink
add optimization algorithm to cli
Browse files Browse the repository at this point in the history
  • Loading branch information
simon1hofmann committed Aug 2, 2023
1 parent 5c24280 commit 7ec41ef
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
89 changes: 89 additions & 0 deletions cli/cmd/physical_design/optimize.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//
// Created by Simon Hofmann on 02.08.23.
//

#ifndef FICTION_CMD_OPTIMIZE_HPP
#define FICTION_CMD_OPTIMIZE_HPP

#include <fiction/algorithms/physical_design/optimization.hpp>
#include <fiction/layouts/clocked_layout.hpp>
#include <fiction/traits.hpp>
#include <fiction/types.hpp>

#include <alice/alice.hpp>

namespace alice
{
/**
* Optimizes a 2DDWave-clocked Cartesian layout.
*/
class optimize_command : public command
{
public:
/**
* Standard constructor. Adds descriptive information, options, and flags.
*
* @param e alice::environment that specifies stores etc.
*/
explicit optimize_command(const environment::ptr& e) : command(e, "Optimizes a 2DDWave-clocked Cartesian layout.")
{}

protected:
/**
* Optimizes a 2DDWave-clocked Cartesian layout.
*/
void execute() override
{
auto& gls = store<fiction::gate_layout_t>();

// error case: empty gate-level layout store
if (gls.empty())
{
env->out() << "[w] no gate layout in store" << std::endl;
return;
}

const auto& lyt = gls.current();

const auto check_clocking_scheme = [](auto&& lyt_ptr)
{ return lyt_ptr->is_clocking_scheme(fiction::clock_name::TWODDWAVE); };

// error case: layout is not 2DDWave-clocked
if (const auto is_twoddwave_clocked = std::visit(check_clocking_scheme, lyt); !is_twoddwave_clocked)
{
env->out() << "[e] layout has to be 2DDWave-clocked" << std::endl;
return;
}

const auto apply_optimization = [](auto&& lyt_ptr)
{
using Lyt = typename std::decay_t<decltype(lyt_ptr)>::element_type;

if constexpr (fiction::is_cartesian_layout_v<Lyt>)
{
fiction::post_layout_optimization(*lyt_ptr);
}
else
{
std::cout << "[e] layout has to be Cartesian" << std::endl;
}

return std::nullopt;
};

try
{
std::visit(apply_optimization, lyt);
}
catch (...)
{
env->out() << "[e] an error occurred while optimizing" << std::endl;
}
}
};

ALICE_ADD_COMMAND(optimize, "Physical Design")

} // namespace alice

#endif // FICTION_CMD_OPTIMIZE_HPP
1 change: 1 addition & 0 deletions cli/commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "cmd/physical_design/exact.hpp"
#include "cmd/physical_design/hex.hpp"
#include "cmd/physical_design/onepass.hpp"
#include "cmd/physical_design/optimize.hpp"
#include "cmd/physical_design/ortho.hpp"
#include "cmd/technology/area.hpp"
#include "cmd/technology/cell.hpp"
Expand Down

0 comments on commit 7ec41ef

Please sign in to comment.