WIP: moved hierarchical processor into db.

This commit is contained in:
Matthias Koefferlein 2018-11-15 23:41:44 +01:00
parent 04256a2753
commit f29fd3dfc6
26 changed files with 27 additions and 516 deletions

View File

@ -137,7 +137,9 @@ SOURCES = \
dbOriginalLayerEdgePairs.cc \
dbEdgePairsDelegate.cc \
dbDeepShapeStore.cc \
dbHierarchyBuilder.cc
dbHierarchyBuilder.cc \
dbLocalOperation.cc \
dbHierProcessor.cc
HEADERS = \
dbArray.h \
@ -244,7 +246,9 @@ HEADERS = \
dbOriginalLayerEdgePairs.h \
dbEdgePairsDelegate.h \
dbDeepShapeStore.h \
dbHierarchyBuilder.h
dbHierarchyBuilder.h \
dbLocalOperation.h \
dbHierProcessor.h
!equals(HAVE_QT, "0") {

View File

@ -25,8 +25,9 @@
#ifndef HDR_dbHierProcessor
#define HDR_dbHierProcessor
#include "dbCommon.h"
#include "dbLayout.h"
#include "dbPluginCommon.h"
#include "dbLocalOperation.h"
#include "tlThreadedWorkers.h"
@ -36,9 +37,9 @@
#include <unordered_map>
#include <unordered_set>
// @@@ should go into dbHash.h
#include "dbHash.h"
// @@@ should go into dbHash.h
namespace std
{
template <class C>
@ -82,7 +83,7 @@ class LocalProcessorCellContext;
class LocalProcessorContexts;
// TODO: move this somewhere else?
class DB_PLUGIN_PUBLIC ShapeInteractions
class DB_PUBLIC ShapeInteractions
{
public:
typedef std::unordered_map<unsigned int, std::vector<unsigned int> > container;
@ -120,7 +121,7 @@ private:
};
// TODO: should be hidden (private data?)
struct DB_PLUGIN_PUBLIC LocalProcessorCellDrop
struct DB_PUBLIC LocalProcessorCellDrop
{
LocalProcessorCellDrop (db::LocalProcessorCellContext *_parent_context, db::Cell *_parent, const db::ICplxTrans &_cell_inst)
: parent_context (_parent_context), parent (_parent), cell_inst (_cell_inst)
@ -134,7 +135,7 @@ struct DB_PLUGIN_PUBLIC LocalProcessorCellDrop
};
// TODO: should be hidden (private data?)
class DB_PLUGIN_PUBLIC LocalProcessorCellContext
class DB_PUBLIC LocalProcessorCellContext
{
public:
typedef std::pair<const db::Cell *, db::ICplxTrans> parent_inst_type;
@ -170,7 +171,7 @@ private:
tl::Mutex m_lock;
};
class DB_PLUGIN_PUBLIC LocalProcessorCellContexts
class DB_PUBLIC LocalProcessorCellContexts
{
public:
typedef std::pair<std::unordered_set<CellInstArray>, std::unordered_set<db::PolygonRef> > key_type;
@ -199,7 +200,7 @@ private:
std::unordered_map<key_type, db::LocalProcessorCellContext> m_contexts;
};
class DB_PLUGIN_PUBLIC LocalProcessorContexts
class DB_PUBLIC LocalProcessorContexts
{
public:
typedef std::unordered_map<db::Cell *, LocalProcessorCellContexts> contexts_per_cell_type;
@ -271,7 +272,7 @@ private:
mutable tl::Mutex m_lock;
};
class DB_PLUGIN_PUBLIC LocalProcessorContextComputationTask
class DB_PUBLIC LocalProcessorContextComputationTask
: public tl::Task
{
public:
@ -290,7 +291,7 @@ private:
db::Coord m_dist;
};
class DB_PLUGIN_PUBLIC LocalProcessorContextComputationWorker
class DB_PUBLIC LocalProcessorContextComputationWorker
: public tl::Worker
{
public:
@ -306,7 +307,7 @@ public:
}
};
class DB_PLUGIN_PUBLIC LocalProcessorResultComputationTask
class DB_PUBLIC LocalProcessorResultComputationTask
: public tl::Task
{
public:
@ -322,7 +323,7 @@ private:
unsigned int m_output_layer;
};
class DB_PLUGIN_PUBLIC LocalProcessorResultComputationWorker
class DB_PUBLIC LocalProcessorResultComputationWorker
: public tl::Worker
{
public:
@ -338,7 +339,7 @@ public:
}
};
class DB_PLUGIN_PUBLIC LocalProcessor
class DB_PUBLIC LocalProcessor
{
public:
LocalProcessor (db::Layout *layout, db::Cell *top);

View File

@ -25,8 +25,9 @@
#ifndef HDR_dbLocalOperation
#define HDR_dbLocalOperation
#include "dbCommon.h"
#include "dbLayout.h"
#include "dbPluginCommon.h"
#include <unordered_map>
#include <unordered_set>
@ -48,7 +49,7 @@ class ShapeInteractions;
* This class implements the actual operation. It receives a
* cluster of subject shapes vs. corresponding intruder shapes.
*/
class DB_PLUGIN_PUBLIC LocalOperation
class DB_PUBLIC LocalOperation
{
public:
/**
@ -109,7 +110,7 @@ public:
/**
* @brief Implements a boolean AND or NOT operation
*/
class DB_PLUGIN_PUBLIC BoolAndOrNotLocalOperation
class DB_PUBLIC BoolAndOrNotLocalOperation
: public LocalOperation
{
public:
@ -128,7 +129,7 @@ private:
* With a given wrap_count, the result will only contains shapes where
* the original shapes overlap at least "wrap_count" times.
*/
class DB_PLUGIN_PUBLIC SelfOverlapMergeLocalOperation
class DB_PUBLIC SelfOverlapMergeLocalOperation
: public LocalOperation
{
public:

View File

@ -30,7 +30,7 @@
static std::string testdata (const std::string &fn)
{
return tl::testsrc () + "/src/plugins/tools/netx/testdata/" + fn;
return tl::testsrc () + "/testdata/algo/" + fn;
}
enum TestMode

View File

@ -54,7 +54,8 @@ SOURCES = \
dbLoadLayoutOptionsTests.cc \
dbSaveLayoutOptionsTests.cc \
dbHierarchyBuilderTests.cc \
dbRecursiveShapeIteratorTests.cc
dbRecursiveShapeIteratorTests.cc \
dbHierProcessorTests.cc
INCLUDEPATH += $$TL_INC $$DB_INC $$GSI_INC
DEPENDPATH += $$TL_INC $$DB_INC $$GSI_INC

View File

@ -1,177 +0,0 @@
/*
KLayout Layout Viewer
Copyright (C) 2006-2018 Matthias Koefferlein
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "dbNetExtractor.h"
#include "dbHierProcessor.h"
#include "dbLayoutUtils.h"
#include "dbCellMapping.h"
#include "dbPolygonTools.h"
#include "dbBoxScanner.h"
#include "dbRecursiveShapeIterator.h"
#include "dbBoxConvert.h"
#include "tlLog.h"
namespace db
{
NetExtractor::NetExtractor()
: mp_orig_layout (0), mp_layout (0), mp_top_cell (0), m_nthreads (0)
{
// @@@
}
NetExtractor::~NetExtractor ()
{
delete mp_layout;
mp_layout = 0;
mp_top_cell = 0;
}
void
NetExtractor::set_threads (unsigned int nthreads)
{
m_nthreads = nthreads;
}
void
NetExtractor::open (const db::Layout &orig_layout, cell_index_type orig_top_cell)
{
tl::SelfTimer timer (tl::verbosity () >= 31, tl::to_string (tr ("Open layout")));
delete mp_layout;
mp_orig_layout = &orig_layout;
mp_layout = new db::Layout ();
mp_layout->dbu (orig_layout.dbu ());
mp_top_cell = &mp_layout->cell (mp_layout->add_cell (orig_layout.cell_name (orig_top_cell)));
// copy hierarchy
m_cm.clear ();
m_cm.create_from_names_full (*mp_layout, mp_top_cell->cell_index (), orig_layout, orig_top_cell);
}
void
NetExtractor::output (NetLayer a, const LayerProperties &lp)
{
mp_layout->set_properties (a.layer_index (), lp);
}
static double area_ratio (const db::Polygon &poly)
{
return double (poly.box ().area ()) / double (poly.area ());
}
static void split_polygon_into (const db::Polygon &poly, db::Shapes &dest, size_t max_points, double max_area_ratio)
{
size_t npoints = 0;
for (unsigned int c = 0; c < poly.holes () + 1; ++c) {
npoints += poly.contour (c).size ();
}
if (npoints > max_points || area_ratio (poly) > max_area_ratio) {
std::vector <db::Polygon> split_polygons;
db::split_polygon (poly, split_polygons);
for (std::vector <db::Polygon>::const_iterator sp = split_polygons.begin (); sp != split_polygons.end (); ++sp) {
split_polygon_into (*sp, dest, max_points, max_area_ratio);
}
} else {
dest.insert (db::PolygonRef (poly, dest.layout ()->shape_repository ()));
}
}
NetLayer
NetExtractor::load (unsigned int layer_index)
{
tl::SelfTimer timer (tl::verbosity () >= 31, tl::to_string (tr ("Loading layer ")) + mp_orig_layout->get_properties (layer_index).to_string ());
const double max_area_ratio = 3.0;
const size_t max_points = 16;
NetLayer lt (mp_layout->insert_layer ());
mp_layout->set_properties (lt.layer_index(), mp_orig_layout->get_properties (layer_index));
for (db::Layout::const_iterator c = mp_orig_layout->begin (); c != mp_layout->end (); ++c) {
if (m_cm.has_mapping (c->cell_index ())) {
db::cell_index_type ct = m_cm.cell_mapping (c->cell_index ());
db::Shapes &dest_shapes = mp_layout->cell (ct).shapes (lt.layer_index());
const db::Shapes &orig_shapes = c->shapes (layer_index);
for (db::Shapes::shape_iterator s = orig_shapes.begin (db::ShapeIterator::Polygons | db::ShapeIterator::Paths | db::ShapeIterator::Boxes); ! s.at_end (); ++s) {
// @@@ TODO: cache splitting and path to polygon conversion
db::Polygon poly;
s->polygon (poly);
split_polygon_into (poly, dest_shapes, max_points, max_area_ratio);
}
}
}
return lt;
}
NetLayer
NetExtractor::bool_and (NetLayer a, NetLayer b)
{
return and_or_not (a, b, true);
}
NetLayer
NetExtractor::bool_not (NetLayer a, NetLayer b)
{
return and_or_not (a, b, false);
}
NetLayer
NetExtractor::and_or_not (NetLayer a, NetLayer b, bool is_and)
{
unsigned int lout = mp_layout->insert_layer ();
db::BoolAndOrNotLocalOperation op (is_and);
db::LocalProcessor proc (mp_layout, mp_top_cell);
proc.set_threads (m_nthreads);
proc.run (&op, a.layer_index (), b.layer_index (), lout);
return NetLayer (lout);
}
db::Layout *
NetExtractor::layout_copy () const
{
tl_assert (mp_layout != 0);
return new db::Layout (*mp_layout);
}
}

View File

@ -1,120 +0,0 @@
/*
KLayout Layout Viewer
Copyright (C) 2006-2018 Matthias Koefferlein
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef HDR_dbNetExtractor
#define HDR_dbNetExtractor
#include "dbPluginCommon.h"
#include "dbLayout.h"
#include "dbCellMapping.h"
#include "tlTypeTraits.h"
namespace db
{
class NetLayer
{
public:
NetLayer (unsigned int index)
: m_layer_index (index)
{
// .. nothing yet ..
}
unsigned int layer_index () const
{
return m_layer_index;
}
private:
unsigned int m_layer_index;
};
/**
* @brief The net extractor
*
* ...
*/
class DB_PLUGIN_PUBLIC NetExtractor
{
public:
/**
* @brief Constructs a net extractor
*/
NetExtractor ();
~NetExtractor ();
// @@@
void open (const db::Layout &orig_layout, db::cell_index_type orig_top_cell);
NetLayer load (unsigned int layer_index);
NetLayer bool_and (NetLayer a, NetLayer b);
NetLayer bool_not (NetLayer a, NetLayer b);
void output (NetLayer a, const db::LayerProperties &lp);
db::Layout *layout_copy () const;
void set_threads (unsigned int nthreads);
unsigned int threads () const
{
return m_nthreads;
}
private:
// no copying
NetExtractor (const db::NetExtractor &);
NetExtractor &operator= (const db::NetExtractor &);
NetLayer and_or_not (NetLayer a, NetLayer b, bool is_and);
// @@@
const db::Layout *mp_orig_layout; // @@@ should be a smart pointer
db::Layout *mp_layout;
db::Cell *mp_top_cell;
db::CellMapping m_cm;
unsigned int m_nthreads;
};
}
namespace tl
{
template <>
struct type_traits<db::NetLayer> : public tl::type_traits<void>
{
// mark "NetLayer" as not having a default ctor
typedef tl::false_tag has_default_constructor;
};
template <>
struct type_traits<db::NetExtractor> : public tl::type_traits<void>
{
// mark "NetExtractor" as not copyable
typedef tl::false_tag has_copy_constructor;
};
}
#endif

View File

@ -1,29 +0,0 @@
/*
KLayout Layout Viewer
Copyright (C) 2006-2018 Matthias Koefferlein
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
namespace db
{
// @@@
}

View File

@ -1,18 +0,0 @@
TARGET = netx
DESTDIR = $$OUT_PWD/../../../../db_plugins
include($$PWD/../../../db_plugin.pri)
HEADERS = \
dbNetExtractor.h \
dbHierProcessor.h \
dbLocalOperation.h
SOURCES = \
dbNetExtractor.cc \
dbHierProcessor.cc \
dbNetExtractorPlugin.cc \
gsiDeclDbNetExtractor.cc \
dbLocalOperation.cc

View File

@ -1,90 +0,0 @@
/*
KLayout Layout Viewer
Copyright (C) 2006-2018 Matthias Koefferlein
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "dbNetExtractor.h"
#include "gsiDecl.h"
namespace gsi
{
gsi::Class<db::NetLayer> decl_NetLayer ("db", "NetLayer",
gsi::method ("layer_index", &db::NetLayer::layer_index,
"@@@"
),
"@brief The net extractor\n"
"\n"
"This class has been introduced in version 0.26."
);
void open2 (db::NetExtractor *ex, const db::Layout *orig_layout, const db::Cell *cell)
{
ex->open (*orig_layout, cell->cell_index ());
}
void output1 (db::NetExtractor *ex, const db::NetLayer &nl, const db::LayerProperties &lp)
{
ex->output (nl, lp);
}
void output2 (db::NetExtractor *ex, const db::NetLayer &nl, int layer, int datatype, const std::string &name)
{
ex->output (nl, db::LayerProperties (layer, datatype, name));
}
gsi::Class<db::NetExtractor> decl_NetNetExtractor ("db", "NetExtractor",
gsi::method ("open", &db::NetExtractor::open, gsi::arg ("orig_layout"), gsi::arg ("orig_top_cell_index"),
"@@@"
) +
gsi::method ("threads=", &db::NetExtractor::set_threads, gsi::arg ("nthreads"),
"@@@"
) +
gsi::method ("threads", &db::NetExtractor::threads,
"@@@"
) +
gsi::method_ext ("open", &open2, gsi::arg ("orig_layout"), gsi::arg ("orig_top_cell"),
"@@@"
) +
gsi::method_ext ("output", &output1, gsi::arg ("net_layer"), gsi::arg ("layer"),
"@@@"
) +
gsi::method_ext ("output", &output2, gsi::arg ("net_layer"), gsi::arg ("layer"), gsi::arg ("datatype"), gsi::arg ("name", std::string ()),
"@@@"
) +
gsi::method ("load", &db::NetExtractor::load, gsi::arg ("layer_index"),
"@@@"
) +
gsi::method ("bool_and", &db::NetExtractor::bool_and, gsi::arg ("a"), gsi::arg ("b"),
"@@@"
) +
gsi::method ("bool_not", &db::NetExtractor::bool_not, gsi::arg ("a"), gsi::arg ("b"),
"@@@"
) +
gsi::factory ("layout_copy", &db::NetExtractor::layout_copy,
"@@@"
),
"@brief The net extractor\n"
"\n"
"This class has been introduced in version 0.26."
);
}

View File

@ -1,11 +0,0 @@
TEMPLATE = subdirs
SUBDIRS = db_plugin unit_tests
unit_tests.depends += db_plugin
#!equals(HAVE_QT, "0") {
# SUBDIRS += lay_plugin
# lay_plugin.depends += db_plugin
#}

View File

@ -1,30 +0,0 @@
/*
KLayout Layout Viewer
Copyright (C) 2006-2018 Matthias Koefferlein
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "tlUnitTest.h"
TEST(1)
{
// .. nothing yet ..
}

View File

@ -1,21 +0,0 @@
DESTDIR_UT = $$OUT_PWD/../../../..
TARGET = net_tracer_tests
include($$PWD/../../../../lib_ut.pri)
SOURCES = \
dbNetExtractorTests.cc \
dbHierProcessorTests.cc \
INCLUDEPATH += $$LAY_INC $$TL_INC $$DB_INC $$GSI_INC $$PWD/../db_plugin $$PWD/../../../common
DEPENDPATH += $$LAY_INC $$TL_INC $$DB_INC $$GSI_INC $$PWD/../db_plugin $$PWD/../../../common
LIBS += -L$$DESTDIR_UT -lklayout_db -lklayout_tl -lklayout_gsi
# This makes the test pull the mebes library for testing (not installed)
PLUGINPATH = $$OUT_PWD/../../../../db_plugins
QMAKE_RPATHDIR += $$PLUGINPATH
LIBS += -L$$PLUGINPATH -lnetx